Skip to content

Commit 3fdd1a8

Browse files
committed
tests: check the posemath parallel tests as a realtime component
tests/blendmath compiled blendmath.c into a userspace program with -DULAPI. Since blendmath.c exports pmCircleEffectiveMinRadius() (#4643), EXPORT_SYMBOL is undefined there, which GCC 13 lets through as an implicit int and GCC 14 rejects. The two functions it checks are posemath's now, so it becomes tests/posemath-parallel: a component loaded after tpmod, which exports them, the way tests/kins-jacobian checks the kinematics modules. A failed check fails the load. The checks themselves are unchanged.
1 parent 1b3a7fa commit 3fdd1a8

9 files changed

Lines changed: 125 additions & 117 deletions

File tree

‎src/emc/tp/tpmod.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
#include <rtapi.h>
1010
#include <rtapi_app.h>
1111
#include <hal.h>
12+
#include <posemath.h>
1213
MODULE_LICENSE("GPL");
1314

15+
// posemath is linked into each module that uses it. These two are
16+
// exported so a component loaded after tpmod can check them.
17+
EXPORT_SYMBOL(pmCartCartParallel);
18+
EXPORT_SYMBOL(pmCartCartAntiParallel);
19+
1420
#define TPMOD_DEBUG
1521
#undef TPMOD_DEBUG
1622

‎tests/blendmath/checkresult‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎tests/blendmath/skip‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎tests/blendmath/test.sh‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎tests/blendmath/test_blendmath.c‎

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
grep -q "all parallel checks passed" "$1" && ! grep -q "FAIL" "$1"
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Checks of the posemath parallel and anti-parallel vector tests.
3+
*
4+
* Salvaged from the retired meson-only unit_tests/tp/test_blendmath.c
5+
* (originally by Robert W. Ellenberg). Loaded after tpmod, which exports
6+
* the two functions; a failed check fails the load, and a failed load
7+
* fails the test.
8+
*
9+
* Author: LinuxCNC
10+
* License: GPL Version 2
11+
* System: Linux
12+
*/
13+
14+
#include <rtapi.h>
15+
#include <rtapi_app.h>
16+
#include <rtapi_errno.h>
17+
#include <rtapi_math.h>
18+
#include <hal.h>
19+
#include <posemath.h>
20+
21+
MODULE_LICENSE("GPL");
22+
MODULE_DESCRIPTION("posemath parallel check");
23+
24+
/* the tolerance the planner's blends use, ANGLE_EPSILON */
25+
#define ANGLE_EPSILON 1e-6
26+
#define ANGLE_EPSILON_SQ (ANGLE_EPSILON * ANGLE_EPSILON)
27+
28+
static int comp_id = -1;
29+
static int failures = 0;
30+
31+
#define CHECK(cond) do { \
32+
if (!(cond)) { \
33+
rtapi_print_msg(RTAPI_MSG_ERR, "parallelcheck: FAIL line %d: %s\n", \
34+
__LINE__, #cond); \
35+
failures++; \
36+
} \
37+
} while (0)
38+
39+
#define CHECK_FALSE(cond) CHECK(!(cond))
40+
41+
static void test_pmCartCartParallel_numerical(void)
42+
{
43+
PmCartesian u0 = {1, 0, 0};
44+
PmCartesian u_close = {cos(ANGLE_EPSILON), sin(ANGLE_EPSILON), 0};
45+
int k;
46+
47+
CHECK(pmCartCartParallel(&u0, &u0, ANGLE_EPSILON_SQ));
48+
CHECK_FALSE(pmCartCartParallel(&u0, &u_close, 0.0));
49+
50+
/* Test that the tolerance makes sense */
51+
CHECK_FALSE(pmCartCartParallel(&u0, &u_close, 0.5 * ANGLE_EPSILON_SQ));
52+
CHECK(pmCartCartParallel(&u0, &u_close, 1.5 * ANGLE_EPSILON_SQ));
53+
54+
/* Try a bunch of other angles including anti-parallel */
55+
for (k = 1; k <= 7; ++k) {
56+
PmCartesian u_far = {cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0};
57+
CHECK_FALSE(pmCartCartParallel(&u0, &u_far, ANGLE_EPSILON_SQ));
58+
}
59+
}
60+
61+
static void test_pmCartCartAntiParallel_numerical(void)
62+
{
63+
PmCartesian u0 = {1, 0, 0};
64+
PmCartesian u_close = {-cos(ANGLE_EPSILON), sin(ANGLE_EPSILON), 0};
65+
PmCartesian u_opposite = {-1, 0, 0};
66+
int k;
67+
68+
CHECK(pmCartCartAntiParallel(&u0, &u_opposite, ANGLE_EPSILON_SQ));
69+
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.0));
70+
71+
/* Test that the tolerance makes sense */
72+
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.5 * ANGLE_EPSILON_SQ));
73+
CHECK(pmCartCartAntiParallel(&u0, &u_close, 1.5 * ANGLE_EPSILON_SQ));
74+
75+
/* Try a bunch of other angles including anti-parallel */
76+
for (k = 1; k <= 7; ++k) {
77+
PmCartesian u_far = {-cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0};
78+
CHECK_FALSE(pmCartCartAntiParallel(&u0, &u_far, ANGLE_EPSILON_SQ));
79+
}
80+
}
81+
82+
int rtapi_app_main(void)
83+
{
84+
comp_id = hal_init("parallelcheck");
85+
if (comp_id < 0) { return comp_id; }
86+
87+
test_pmCartCartParallel_numerical();
88+
test_pmCartCartAntiParallel_numerical();
89+
90+
if (failures) {
91+
rtapi_print_msg(RTAPI_MSG_ERR, "parallelcheck: %d check(s) failed\n",
92+
failures);
93+
hal_exit(comp_id);
94+
return -ERANGE;
95+
}
96+
97+
rtapi_print("parallelcheck: all parallel checks passed\n");
98+
hal_ready(comp_id);
99+
return 0;
100+
}
101+
102+
void rtapi_app_exit(void) { hal_exit(comp_id); }

‎tests/posemath-parallel/skip‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# Builds a realtime component with halcompile, which needs the build
3+
# tools present. Skip when testing installed packages.
4+
[ -z "$SYSTEM_BUILD" ]

‎tests/posemath-parallel/test.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
halcompile --install parallelcheck.c >/dev/null
5+
6+
# tpmod exports the two checks; posemath is linked into each module that
7+
# uses it rather than loaded as a module of its own
8+
hal=$(mktemp --suffix=.hal)
9+
printf 'loadrt tpmod\nloadrt parallelcheck\n' > "$hal"
10+
halrun -f "$hal"
11+
rm -f "$hal"

0 commit comments

Comments
 (0)