Skip to content

Commit d639792

Browse files
committed
mem: HG_MALLOC unit tests: start-up handshake, robust CI check
A test child now runs only after internal_fork() has returned in the parent: a child that finished and exited within the parent's start-up wait was reported as "failed to initialize". The CI step finds the allocator check line unanchored, since other processes' log lines can share it.
1 parent 1bd397e commit d639792

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎.github/workflows/unittests.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,16 @@ jobs:
148148
run: script -e unit_tests.log -c 'sh -x scripts/build/do_build.sh DEFS_EXTRA_OPTS="-DUNIT_TESTS -fPIE -fPIC"'
149149

150150
# the same tests and the allocator suites with HG_MALLOC; the grep fails
151-
# the step if HG_MALLOC was not actually the allocator under test
151+
# the step if HG_MALLOC was not actually the allocator under test (not
152+
# anchored: other processes' log lines can share a line with the TAP one)
152153
- name: Run tests with HG_MALLOC
153154
env:
154155
MAKE_TGT: 'test'
155156
UT_ALLOC: 'HG_MALLOC'
156157
UT_MEM: '-m 64:1024 -M 16:256'
157158
run: |
158159
script -e unit_tests_hg.log -c 'sh -x scripts/build/do_build.sh DEFS_EXTRA_OPTS="-DUNIT_TESTS -fPIE -fPIC"'
159-
grep -q -E '^ok [0-9]+ - HG_MALLOC serves pkg and shm' unit_tests_hg.log
160+
grep -E 'ok [0-9]+ - HG_MALLOC serves pkg and shm' unit_tests_hg.log | grep -q -v 'not ok'
160161
161162
- name: Run tests with HG_MALLOC_DBG
162163
env:
@@ -165,7 +166,7 @@ jobs:
165166
UT_MEM: '-m 64:1024 -M 16:256'
166167
run: |
167168
script -e unit_tests_hg_dbg.log -c 'sh -x scripts/build/do_build.sh DEFS_EXTRA_OPTS="-DUNIT_TESTS -fPIE -fPIC"'
168-
grep -q -E '^ok [0-9]+ - HG_MALLOC serves pkg and shm' unit_tests_hg_dbg.log
169+
grep -E 'ok [0-9]+ - HG_MALLOC serves pkg and shm' unit_tests_hg_dbg.log | grep -q -v 'not ok'
169170
170171
- name: Collect test logs
171172
uses: actions/upload-artifact@v7

‎mem/test/test_hg_malloc.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
#define HGT_FAIL 2
5252

5353
static volatile int *hgt_verdict;
54+
/* set by the parent once internal_fork() has returned: a child that ran
55+
* and exited within the parent's start-up wait would otherwise be reported
56+
* as "failed to initialize" (internal_fork() checks for an exited child
57+
* before it re-reads the start-up result) */
58+
static volatile int *hgt_go;
5459

5560
int hg_ut_selected(void)
5661
{
@@ -92,16 +97,21 @@ static int hgt_in_child(char *desc, int (*fn)(void *), void *arg)
9297
int pid, waited;
9398

9499
*hgt_verdict = 0;
100+
*hgt_go = 0;
95101
pid = internal_fork(&ifp);
96102
if (pid < 0) {
97103
LM_ERR("failed to fork the '%s' child\n", desc);
98104
return 0;
99105
}
100106

101107
if (pid == 0) {
108+
for (waited = 0; *hgt_go == 0 && waited < HGT_WAIT_US;
109+
waited += HGT_STEP_US)
110+
usleep(HGT_STEP_US);
102111
*hgt_verdict = fn(arg) == 0 ? HGT_PASS : HGT_FAIL;
103112
exit(0);
104113
}
114+
*hgt_go = 1;
105115

106116
for (waited = 0; *hgt_verdict == 0 && waited < HGT_WAIT_US;
107117
waited += HGT_STEP_US)
@@ -448,8 +458,9 @@ void test_hg_malloc(void)
448458
return;
449459

450460
hgt_verdict = shm_malloc(sizeof *hgt_verdict);
451-
if (!hgt_verdict) {
452-
ok(0, "shm verdict slot");
461+
hgt_go = shm_malloc(sizeof *hgt_go);
462+
if (!hgt_verdict || !hgt_go) {
463+
ok(0, "shm verdict slots");
453464
return;
454465
}
455466

@@ -466,6 +477,7 @@ void test_hg_malloc(void)
466477
test_hg_double_free();
467478

468479
shm_free((void *)hgt_verdict);
480+
shm_free((void *)hgt_go);
469481
}
470482

471483
#endif /* HG_MALLOC */

0 commit comments

Comments
 (0)