Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/blendmath/checkresult
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
grep -q "all blendmath checks passed" "$1" && ! grep -q "FAIL" "$1"
5 changes: 5 additions & 0 deletions tests/blendmath/skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# This test compiles blendmath.c and internal TP headers from the source
# tree, which is only available in run-in-place builds. Skip when testing
# installed packages.
[ -z "$SYSTEM_BUILD" ]
17 changes: 17 additions & 0 deletions tests/blendmath/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

# RIP layout: $HEADERS is $TOPDIR/include
TOPDIR=$(dirname "$HEADERS")

# blendmath.c references the rest of the TP (tc.c, spherical_arc.c,
# sp_scurve.c, motion globals). Only the tested functions are used here, so
# build with function sections and let the linker garbage-collect the rest
# instead of linking the whole trajectory planner.
gcc -O2 -Wall -ffunction-sections -fdata-sections -DULAPI -DUNIT_TEST \
-I"$HEADERS" -I"$TOPDIR/src" -I"$TOPDIR/src/emc" \
-o test_blendmath test_blendmath.c "$TOPDIR/src/emc/tp/blendmath.c" \
Comment thread
grandixximo marked this conversation as resolved.
-L"$LIBDIR" -Wl,-rpath,"$LIBDIR" -Wl,--gc-sections -lposemath -lm

./test_blendmath
rm -f test_blendmath
93 changes: 93 additions & 0 deletions tests/blendmath/test_blendmath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Unit tests for blendmath utility functions.
*
* Salvaged from the retired meson-only unit_tests/tp/test_blendmath.c
* (originally by Robert W. Ellenberg) and converted from the greatest
* framework to plain C so it can build and run as a runtest.
*/

#include <math.h>
#include <stdio.h>
#include <stdarg.h>

#include <rtapi.h>
#include <posemath.h>
#include "tp/blendmath.h"
#include "tp/tp_types.h"

/* kludge: satisfy rtapi_print_msg references without an rtapi app */
void rtapi_print_msg(msg_level_t level, const char *fmt, ...)
{
va_list args;

(void)level;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}

static int failures = 0;

#define CHECK(cond) do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
failures++; \
} \
} while (0)

#define CHECK_FALSE(cond) CHECK(!(cond))

static void test_pmCartCartParallel_numerical(void)
{
PmCartesian u0 = {1, 0, 0};
PmCartesian u_close = {cos(TP_ANGLE_EPSILON), sin(TP_ANGLE_EPSILON), 0};
int k;

CHECK(pmCartCartParallel(&u0, &u0, TP_ANGLE_EPSILON_SQ));
CHECK_FALSE(pmCartCartParallel(&u0, &u_close, 0.0));

/* Test that the tolerance makes sense */
CHECK_FALSE(pmCartCartParallel(&u0, &u_close, 0.5 * TP_ANGLE_EPSILON_SQ));
CHECK(pmCartCartParallel(&u0, &u_close, 1.5 * TP_ANGLE_EPSILON_SQ));

/* Try a bunch of other angles including anti-parallel */
for (k = 1; k <= 7; ++k) {
PmCartesian u_far = {cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0};
CHECK_FALSE(pmCartCartParallel(&u0, &u_far, TP_ANGLE_EPSILON_SQ));
}
}

static void test_pmCartCartAntiParallel_numerical(void)
{
PmCartesian u0 = {1, 0, 0};
PmCartesian u_close = {-cos(TP_ANGLE_EPSILON), sin(TP_ANGLE_EPSILON), 0};
PmCartesian u_opposite;
int k;

pmCartScalMult(&u0, -1.0, &u_opposite);
CHECK(pmCartCartAntiParallel(&u0, &u_opposite, TP_ANGLE_EPSILON_SQ));
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.0));

/* Test that the tolerance makes sense */
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.5 * TP_ANGLE_EPSILON_SQ));
CHECK(pmCartCartAntiParallel(&u0, &u_close, 1.5 * TP_ANGLE_EPSILON_SQ));

/* Try a bunch of other angles including anti-parallel */
for (k = 1; k <= 7; ++k) {
PmCartesian u_far = {-cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0};
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_far, TP_ANGLE_EPSILON_SQ));
}
}

int main(void)
{
test_pmCartCartParallel_numerical();
test_pmCartCartAntiParallel_numerical();

if (failures) {
printf("%d check(s) FAILED\n", failures);
return 1;
}
printf("all blendmath checks passed\n");
return 0;
}
48 changes: 48 additions & 0 deletions tests/interp/unit-conversion/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
N..... SET_XY_ROTATION(0.0000)
N..... SET_FEED_REFERENCE(CANON_XYZ)
N..... ON_RESET()
N..... COMMENT("Verify G20/G21 unit switching. The current position and the interpreter's")
N..... COMMENT("internal offsets are converted, while the numbered parameters that back")
N..... COMMENT("the work and axis offsets stay constant because they are stored in user")
N..... COMMENT("INI units. salvaged from the retired meson-only unit_tests/interp tests")
N..... USE_LENGTH_UNITS(CANON_UNITS_INCHES)
N..... COMMENT("interpreter: continuing to use same coordinate system")
N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
N..... SET_XY_ROTATION(0.0000)
N..... MESSAGE(" --- position conversion: move to x1 y2 z3 a4 b5 c6 in inches")
N..... STRAIGHT_TRAVERSE(1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000)
N..... MESSAGE(" in inches, expect 1 2 3 4 5 6: 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
N..... MESSAGE(" in mm, expect 25.4 50.8 76.2 4 5 6: 25.400000 50.800000 76.200000 4.000000 5.000000 6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_INCHES)
N..... MESSAGE(" back in inches, expect 1 2 3 4 5 6: 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000")
N..... MESSAGE(" --- work offsets: g10 l2 p1 x1 y2 z3 a4 b5 c6, params stay in user units")
N..... SET_G5X_OFFSET(1, 1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000)
N..... SET_XY_ROTATION(0.0000)
N..... COMMENT("interpreter: continuing to use same coordinate system")
N..... MESSAGE(" params as stored, expect 1 2 3 4 5 6: 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
N..... MESSAGE(" unchanged after g21, expect 1 2 3 4 5 6: 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_INCHES)
N..... MESSAGE(" unchanged after g20, expect 1 2 3 4 5 6: 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000")
N..... MESSAGE(" --- axis offsets: g92 x1 y2 z3 a4 b5 c6, params stay in user units")
N..... SET_G92_OFFSET(-1.0000, -2.0000, -3.0000, -4.0000, -5.0000, -6.0000)
N..... MESSAGE(" params as stored, expect -1 -2 -3 -4 -5 -6: -1.000000 -2.000000 -3.000000 -4.000000 -5.000000 -6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
N..... MESSAGE(" unchanged after g21, expect -1 -2 -3 -4 -5 -6: -1.000000 -2.000000 -3.000000 -4.000000 -5.000000 -6.000000")
N..... USE_LENGTH_UNITS(CANON_UNITS_INCHES)
N..... MESSAGE(" unchanged after g20, expect -1 -2 -3 -4 -5 -6: -1.000000 -2.000000 -3.000000 -4.000000 -5.000000 -6.000000")
N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
N..... SET_G5X_OFFSET(1, 1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000)
N..... SET_XY_ROTATION(0.0000)
N..... SET_FEED_MODE(0, 0)
N..... SET_FEED_RATE(0.0000)
N..... STOP_SPINDLE_TURNING(0)
N..... SET_SPINDLE_MODE(0 0.0000)
N..... PROGRAM_END()
N..... ON_RESET()
N..... ON_RESET()
43 changes: 43 additions & 0 deletions tests/interp/unit-conversion/test.ngc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(Verify G20/G21 unit switching. The current position and the interpreter's)
(internal offsets are converted, while the numbered parameters that back)
(the work and axis offsets stay constant because they are stored in user)
(INI units. salvaged from the retired meson-only unit_tests/interp tests)

g20
g54
g92.1
g10 l2 p1 x0 y0 z0 a0 b0 c0

(debug, --- position conversion: move to x1 y2 z3 a4 b5 c6 in inches)
g0 x1 y2 z3 a4 b5 c6
(debug, in inches, expect 1 2 3 4 5 6: #5420 #5421 #5422 #5423 #5424 #5425)

g21
(debug, in mm, expect 25.4 50.8 76.2 4 5 6: #5420 #5421 #5422 #5423 #5424 #5425)

g20
(debug, back in inches, expect 1 2 3 4 5 6: #5420 #5421 #5422 #5423 #5424 #5425)

(debug, --- work offsets: g10 l2 p1 x1 y2 z3 a4 b5 c6, params stay in user units)
g10 l2 p1 x1 y2 z3 a4 b5 c6
g54
(debug, params as stored, expect 1 2 3 4 5 6: #5221 #5222 #5223 #5224 #5225 #5226)

g21
(debug, unchanged after g21, expect 1 2 3 4 5 6: #5221 #5222 #5223 #5224 #5225 #5226)

g20
(debug, unchanged after g20, expect 1 2 3 4 5 6: #5221 #5222 #5223 #5224 #5225 #5226)

(debug, --- axis offsets: g92 x1 y2 z3 a4 b5 c6, params stay in user units)
g92 x1 y2 z3 a4 b5 c6
(debug, params as stored, expect -1 -2 -3 -4 -5 -6: #5211 #5212 #5213 #5214 #5215 #5216)

g21
(debug, unchanged after g21, expect -1 -2 -3 -4 -5 -6: #5211 #5212 #5213 #5214 #5215 #5216)

g20
(debug, unchanged after g20, expect -1 -2 -3 -4 -5 -6: #5211 #5212 #5213 #5214 #5215 #5216)

g92.1
m2
3 changes: 3 additions & 0 deletions tests/interp/unit-conversion/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}' | sed 's/-0\.0000/0.0000/g'
exit "${PIPESTATUS[0]}"