From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it, Avinesh Kumar <avinesh.kumar@suse.com>,
Wei Gao <wegao@suse.com>, Mimi Zohar <zohar@linux.ibm.com>,
linux-integrity@vger.kernel.org
Subject: Re: [PATCH 2/2] ima_violations.sh: ima_mmap.c: Replace sleep with checkpoints
Date: Thu, 30 Apr 2026 11:16:35 +0200 [thread overview]
Message-ID: <afMd82ykYhNz9Msy@yuki.lan> (raw)
In-Reply-To: <20260428161034.947614-2-pvorel@suse.cz>
Hi!
> Using checkpoints is a proper way in LTP new API [1] to avoid races and
> waste of time. It reduces 3 sec sleep in ima_mmap.c and 1 sec sleep in
> ima_violations.sh with just checkpoints.
>
> NOTE: tst_reinit() is really needed instead of .needs_checkpoints = 1
> as documented in Shell-Test-API.asciidoc.
>
> [1] https://people.kernel.org/metan/why-sleep-is-almost-never-acceptable-in-tests
>
> Fixes: 0e4cbf753f ("security/ima: Rewrite tests into new API + fixes")
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/kernel/security/integrity/ima/src/ima_mmap.c | 7 ++++---
> .../kernel/security/integrity/ima/tests/ima_violations.sh | 6 +++++-
> 2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/kernel/security/integrity/ima/src/ima_mmap.c b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
> index 8596809ef4..09b22fd4f4 100644
> --- a/testcases/kernel/security/integrity/ima/src/ima_mmap.c
> +++ b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
> @@ -9,7 +9,6 @@
>
> #include "tst_test.h"
>
> -#define SLEEP_AFTER_CLOSE 3
> #define MMAPSIZE 1024
>
> static char *filename;
> @@ -35,8 +34,10 @@ static void run(void)
> file = SAFE_MMAP(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> SAFE_CLOSE(fd);
>
> - tst_res(TINFO, "sleep %ds", SLEEP_AFTER_CLOSE);
> - sleep(SLEEP_AFTER_CLOSE);
> + tst_reinit();
> + TST_CHECKPOINT_WAIT(0);
> + /* keep running until ima_violations.sh open and close file */
> + TST_CHECKPOINT_WAKE_AND_WAIT(0);
>
> tst_res(TPASS, "test completed");
> }
C helpers that call tst_reinit() should implement main(). These are not
complete tests, just helpers. The main problem is that if you add
tst_reinit() to a source that defines tst_test structure you are
initializing the test library for a second time, which overwrites the
some of the already initialized variables.
We probably want:
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 26f6510a0..971a184f2 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -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");
So that this kind of mistake is caught early.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2026-04-30 9:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 16:10 [PATCH 1/2] ima_violations.sh: Wait for ima_mmap to exit Petr Vorel
2026-04-28 16:10 ` [PATCH 2/2] ima_violations.sh: ima_mmap.c: Replace sleep with checkpoints Petr Vorel
2026-04-29 11:15 ` [LTP] " Martin Doucha
2026-04-29 12:00 ` Petr Vorel
2026-04-30 9:16 ` Cyril Hrubis [this message]
2026-04-30 9:03 ` [PATCH 1/2] ima_violations.sh: Wait for ima_mmap to exit Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afMd82ykYhNz9Msy@yuki.lan \
--to=chrubis@suse.cz \
--cc=avinesh.kumar@suse.com \
--cc=linux-integrity@vger.kernel.org \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
--cc=wegao@suse.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox