public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Stephen Bertram via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Stephen Bertram <sbertram@redhat.com>
Subject: [LTP] [PATCH v2] cachestat02: Harden parallel worker execution.
Date: Thu, 19 Feb 2026 08:50:01 -0500	[thread overview]
Message-ID: <20260219135019.1140234-1-sbertram@redhat.com> (raw)

This does not happen all the time but when running in parallel
sometimes one of the test instances will throw an error:
TFAIL: cs->nr_cache + cs->nr_evicted (297) != num_pages (512)

When LTP runs several instances of the cachestat tests in parallel, they share resources:
cachestat02: Uses a fixed shm name "myfile.bin". All instances use the same POSIX shared memory object.
That leads to:
Races on creation/removal of the same file/shm.
cachestat() reporting stats for a shared or partially overwritten file instead of the one the current process wrote.
nr_cache + nr_evicted not matching num_pages because the measured range is not the one written by this process.

The change is to create a unique file/shm space for each instance using the pid of each cachestat() process.
Harden parallel worker execution for cachestat02.

Signed-off-by: Stephen Bertram <sbertram@redhat.com>
---
 testcases/kernel/syscalls/cachestat/cachestat02.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/cachestat/cachestat02.c b/testcases/kernel/syscalls/cachestat/cachestat02.c
index 72428ee83..d6505c4a4 100644
--- a/testcases/kernel/syscalls/cachestat/cachestat02.c
+++ b/testcases/kernel/syscalls/cachestat/cachestat02.c
@@ -17,10 +17,9 @@
 #include <stdlib.h>
 #include "cachestat.h"
 
-#define FILENAME "myfile.bin"
-
 static int page_size;
 static char *page_data;
+static char shm_name[64];
 static struct cachestat *cs;
 static struct cachestat_range *cs_range;
 
@@ -32,7 +31,8 @@ static void test_cached_pages(const int num_pages)
 
 	memset(cs, 0, sizeof(struct cachestat));
 
-	fd = shm_open(FILENAME, O_RDWR | O_CREAT, 0600);
+	snprintf(shm_name, sizeof(shm_name), "/cachestat_%d.bin", getpid());
+	fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0600);
 	if (fd < 0)
 		tst_brk(TBROK | TERRNO, "shm_open error");
 
@@ -53,7 +53,7 @@ static void test_cached_pages(const int num_pages)
 	TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, num_pages);
 
 	SAFE_CLOSE(fd);
-	shm_unlink(FILENAME);
+	shm_unlink(shm_name);
 }
 
 static void run(void)
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2026-02-19 13:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19 13:50 Stephen Bertram via ltp [this message]
2026-02-20 10:55 ` [LTP] [PATCH v2] cachestat02: Harden parallel worker execution Cyril Hrubis
2026-02-24  8:44 ` Andrea Cervesato via ltp

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=20260219135019.1140234-1-sbertram@redhat.com \
    --to=ltp@lists.linux.it \
    --cc=sbertram@redhat.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