Import LinuxCNC source tree
This commit is contained in:
2
tests/blendmath/checkresult
Executable file
2
tests/blendmath/checkresult
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
grep -q "all blendmath checks passed" "$1" && ! grep -q "FAIL" "$1"
|
||||
5
tests/blendmath/skip
Executable file
5
tests/blendmath/skip
Executable file
@@ -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
tests/blendmath/test.sh
Executable file
17
tests/blendmath/test.sh
Executable file
@@ -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" \
|
||||
-L"$LIBDIR" -Wl,-rpath,"$LIBDIR" -Wl,--gc-sections -lposemath -lm
|
||||
|
||||
./test_blendmath
|
||||
rm -f test_blendmath
|
||||
93
tests/blendmath/test_blendmath.c
Normal file
93
tests/blendmath/test_blendmath.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user