syscalls: ipc: Add shmget hugepage test
PATCH v6 1/1 syscalls: ipc: Add shmget hugepage test
Changes in v6:
- Added "tst_test.h" and "tst_hugepage.h" instead of hugetlb.h
- Modified code to use TEST() macro
--- runtest/syscalls | 1 + .../kernel/syscalls/ipc/shmget/.gitignore | 1 + .../kernel/syscalls/ipc/shmget/shmget07.c | 75 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 testcases/kernel/syscalls/ipc/shmget/shmget07.c
runtest/syscalls +1 -0
@@ -1547,6 +1547,7 @@ shmget03 shmget03 shmget04 shmget04 shmget05 shmget05 shmget06 shmget06 +shmget07 shmget07 shutdown01 shutdown01 shutdown02 shutdown02
testcases/kernel/syscalls/ipc/shmget/.gitignore +1 -0
@@ -3,3 +3,4 @@ /shmget04 /shmget05 /shmget06 +/shmget07
testcases/kernel/syscalls/ipc/shmget/shmget07.c new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.53.0
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Pavithra,
A few issues to address before this can be merged.
Quoted 3 lines
Changes in v6:
- Added "tst_test.h" and "tst_hugepage.h" instead ofhugetlb.h
- Modified code to useTEST()macro
The commit body should explain *why* the test is being added — what behavior it validates or what gap it fills. Changelog entries belong below the --- separator in the patch email, not in the commit message body. Please write a proper description here.
Quoted 1 line
+ * [Descripiton]
Two problems: "Descripiton" is a typo, and the [Description] label itself is deprecated in LTP doc comments. Drop the label entirely and write the description text directly.
Quoted 1 line
+static int
raw_fd;
raw_fd is zero-initialized by the compiler but fd 0 is stdin. More importantly, raw_fd is opened in run_test() and never closed anywhere — not at the end of run_test(), not in cleanup(). This leaks a file descriptor per test invocation.
Initialize it to -1, close it at the end of run_test(), and guard it in cleanup():
static int raw_fd = -1;
/* in cleanup(): */
if (raw_fd != -1)
SAFE_CLOSE(raw_fd);testcases/kernel/syscalls/ipc/shmget/shmget07.c line 29
Quoted 2 lines
testcases/kernel/syscalls/ipc/shmget/shmget07.c new file +2
-0+static size_t size; +static size_t i;
These are only used inside run_test() and do not carry state between calls. i should be declared as local and size can be initialized inside the setup() function.
testcases/kernel/syscalls/ipc/shmget/shmget07.c line 54
Quoted 4 lines
testcases/kernel/syscalls/ipc/shmget/shmget07.c new file +4
-0+ shmid =SAFE_SHMGET (IPC_PRIVATE , size,SHM_HUGETLB |SHM_R |SHM_W ); + + shmaddr =SAFE_SHMAT (shmid,0 ,SHM_RND ); +tst_res (TINFO ,"shmaddr: %p\n" , shmaddr);
Two issues here:
1. tst_res() appends its own newline — the "\n" in the format string produces a spurious blank line in the output. Remove it.
2. shmaddr is not tracked in cleanup(). If run_test() is aborted after SAFE_SHMAT (e.g. by a tst_brk() from a future change or a signal), the segment remains attached. Add to cleanup():
if (shmaddr)
SAFE_SHMDT(shmaddr); And reset shmaddr = NULL after SAFE_SHMDT in run_test().
testcases/kernel/syscalls/ipc/shmget/shmget07.c line 67
Quoted 2 lines
testcases/kernel/syscalls/ipc/shmget/shmget07.c new file +2
-0+SAFE_SHMDT (shmaddr); +}
When the test is run with -i N, each call to run_test() overwrites shmid and raw_fd with fresh values without releasing the previous iteration's resources:
- The previous raw_fd is never closed -> fd leak per iteration.
- The previous shmid is never IPC_RMID'd before being overwritten
-> shm segment leak per iteration; cleanup() only removes the last.
Remove shmid at the end of run_test() and reset it to -1 there, so cleanup() is only a safety net. Close raw_fd at the end of run_test() as well.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp