lib: tst_test: tst_reinit() abort when already initialized
PATCH 1/1 lib: tst_test: tst_reinit() abort when already initialized
Calling tst_reinit() when library is already initialized or calling it for a second time is always mistake. With that we silenty drop the old IPC region, that may have contained test results and there are likely other problems possibly caused by initializing the test library twice.
To fix that this patch adds tst_brk() that abort the test if we call tst_reinit() with already initialized test library.
--- lib/tst_test.c | 3 +++ 1 file changed, 3 insertions(+)
lib/tst_test.c +3 -0
@@ -196,6 +196,9 @@ void tst_reinit(void)size_t size =getpagesize ();int fd; +if (ipc) +tst_brk (TBROK ,"Test library already initialized!" ); +if (!path)tst_brk (TBROK ,IPC_ENV_VAR " is not defined" );
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines · Cyril Hrubis
Calling
tst_reinit()when library is already initialized or calling it for a second time is always mistake. With that we silenty drop the old IPC region, that may have contained test results and there are likely other problems possibly caused by initializing the test library twice.To fix that this patch adds
tst_brk()that abort the test if we calltst_reinit()with already initialized test library.Signed-off-by Cyril Hrubis <[email protected]>
The patch itself looks good, I'm just wondering how you found this issue, was it called twice somewhere/in a test?
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 8 lines
Quoted 8 lines
Calling
tst_reinit()when library is already initialized or calling it for a second time is always mistake. With that we silenty drop the old IPC region, that may have contained test results and there are likely other problems possibly caused by initializing the test library twice.To fix that this patch adds
tst_brk()that abort the test if we calltst_reinit()with already initialized test library.
Quoted 6 lines
Quoted 1 line
Signed-off-by Cyril Hrubis <[email protected]>Reviewed-by Li Wang <[email protected]>The patch itself looks good, I'm just wondering how you found this issue, was it called twice somewhere/in a test?
https://lists.linux.it/pipermail/ltp/2026-April/048084.html
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Patch merged, thanks!
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
I guess that we also need to revert:
https://lists.linux.it/pipermail/ltp/2026-April/048007.html
Since the IMA test is broken after this patch:
$./ima_mmap -f foo
tst_test.c:2042: TINFO: LTP version: 20260130-210-gcd9899ce4
tst_test.c:2045: TINFO: Tested kernel: 6.16.0 #1 SMP PREEMPT_DYNAMIC Tue Aug 12 10:49:53 CEST 2025 x86_64 tst_kconfig.c:90: TINFO: Parsing kernel config '/lib/modules/6.16.0/build/.config' tst_test.c:1870: TINFO: Overall timeout per run is 0h 00m 30s
tst_test.c:199: TBROK: Test library already initialized!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 5 lines · Cyril Hrubis
I guess that we also need to revert:
https://lists.linux.it/pipermail/ltp/2026-April/048007.html
Since the IMA test is broken after this patch:
You're right, tst_reinit() shouldn't be called in an LTP test with already initialized the IPC.
Or, we should convert ima_mmap.c into raw main() format proceduer.
Quoted 6 lines
$./ima_mmap -f foo
tst_test.c:2042: TINFO: LTP version: 20260130-210-gcd9899ce4
tst_test.c:2045: TINFO: Tested kernel: 6.16.0 #1 SMPPREEMPT_DYNAMICTue Aug 12 10:49:53 CEST 2025x86_64tst_kconfig.c:90: TINFO: Parsing kernel config '/lib/modules/6.16.0/build/.config' tst_test.c:1870: TINFO: Overall timeout per run is 0h 00m 30s
tst_test.c:199: TBROK: Test library already initialized!
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 1 line
Quoted 1 line
I guess that we also need to revert:
I look into Petr's patch, seems we can go another way to replace the checkpoint method.
How about this:
testcases/kernel/security/integrity/ima/src/ima_mmap.c +1 -4
@@ -34,10 +34,7 @@ static void run(void) file =SAFE_MMAP (NULL ,MMAPSIZE ,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );SAFE_CLOSE (fd); -tst_reinit (); -TST_CHECKPOINT_WAIT (0 ); -/* keep running until ima_violations.sh open and close file */ -TST_CHECKPOINT_WAKE_AND_WAIT (0 ); +raise (SIGSTOP );tst_res (TPASS ,"test completed" ); }
testcases/kernel/security/integrity/ima/tests/ima_violations.sh +11 -3
@@ -156,6 +156,14 @@ test2() validate $num_violations $count $search } +wait_process_stopped() +{ + while true; do + [ "$(awk '{print $3}' /proc/$1/stat 2>/dev/null)" = "T" ] && break + usleep 100000 + done +} + test3() { local pid
@@ -173,13 +181,13 @@ test3() ima_mmap -f $FILE & pid=$! - # wait for violations appear in logs - TST_CHECKPOINT_WAKE_AND_WAIT 0 + wait_process_stopped $pid open_file_read close_file_read - TST_CHECKPOINT_WAKE 0 + kill -CONT $pid + wait $pid validate $num_violations $count $search
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 2 lines
I look into Petr's patch, seems we can go another way to replace the checkpoint method.
I would rather change the binary to use TST_NO_DEFAULT_MAIN. It's not a test, just a helper binary, the tst_test structure shouldn't have been used to begin with.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Cyril Hrubis
Hi!
Quoted 2 lines
I look into Petr's patch, seems we can go another way to replace the checkpoint method.
I would rather change the binary to use
TST_NO_DEFAULT_MAIN. It's not a test, just a helper binary, thetst_teststructure shouldn't have been used to begin with.
That sounds reasonable! To avoid mixing with real LTP tests, we should keep the auxiliary binary clean.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
lib/tst_test.c void tst_reinit(void) · line 200
Quoted 4 lines · Cyril Hrubis
lib:
tst_test:tst_reinit()abort when already initializedlib/tst_test.c +2
-0+if (ipc) +tst_brk (TBROK ,"Test library already initialized!" );
Looks good.
---
Note:
Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25163012944
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp