Skip to contentSkip to conversation

Migrating the libhugetlbfs/testcases/truncate.c test

PATCH Superseded Shirisha G 3 participants 5 messages Mar 22, 2024 – Jun 28, 2024

lore
Share & tools
lore

Shirisha G

author
#0 lore raw

PATCH v4 1/1 Migrating the libhugetlbfs/testcases/truncate.c test

Test Description: Test is used to verify the correct functionality and compatibility of the library with the "truncate" system call when operating on files residing in a mounted
huge page filesystem.

---
v4:
--Addressed the below requested changes
1. Added SAFE_FTRUNCATE()
2. Fixed run test more times (-iN)
3. Fixed warning: unused parameter ‘signum’ [-Wunused-parameter]
4. Added blank lines wherever needed which helps the readability
5. Ran make check and fixed the issues
---
v3:
-Addressed the below requested changes
1. Removed RANDOM_CONSTANT
2. Made hpage_size and fd to static
3. Used a volatile variable as a flag
to pass test in the run_test()
4. Removed the failure condition for SAFE_MMAP()
5. Have setup the handler in the setup()
6. Added SAFE_MUNMAP()
7. Ran make check and fixed all issues
---
v2:
-Corrected typo

---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap33.c  | 87 +++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
index 299c07ac9..1300e80fb 100644
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap33 hugemmap33
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index c96fe8bfc..444acdf52 100644
@@ -34,6 +34,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap33
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.39.3
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi,

FYI supersede this one in patchwork (you send the patch it twice).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Shirisha G

Hi,

Quoted 1 line

Test Description: Test is used to verify the correct functionality

nit: I would remove "Test Description: " and instead point out the link from which test originated.

...

Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +7 -0
+static void run_test(void)
+{
+	void *p;
+	volatile unsigned int *q;
+
+	sigbus_count = 0;
+	test_pass = 0;

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 49

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +10 -0
+
+	struct sigaction my_sigaction;
+
+	my_sigaction.sa_handler = sigbus_handler;
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+			fd, 0);
+	q = p;
+	*q = 0;
+	SAFE_SIGACTION(SIGBUS, &my_sigaction, NULL);
+	SAFE_FTRUNCATE(fd, 0);

If any of these 2 SAFE_*() fails, we don't call SAFE_MUNMAP(), right? But at least in hugemmap27.c it's happily ignored, I guess it can stay.

The rest LGTM.

Kind regards,
Petr

Quoted 14 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +14 -0
+
+	if (sigsetjmp(sig_escape, 1) == 0)
+		*q;
+	else
+		sigbus_count++;
+
+	if (sigbus_count != 1)
+		tst_res(TFAIL, "Didn't SIGBUS");
+
+	if (test_pass == 1)
+		tst_res(TPASS, "Expected SIGBUS triggered");
+
+	SAFE_MUNMAP(p, hpage_size);
+}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Shirisha G

Hi!

Quoted 111 lines

Test Description: Test is used to verify the correct functionality and compatibility of the library with the "truncate" system call when operating on files residing in a mounted
huge page filesystem.

---
v4:
--Addressed the below requested changes
1. Added SAFE_FTRUNCATE()
2. Fixed run test more times (-iN)
3. Fixed warning: unused parameter ‘signum’ [-Wunused-parameter]
4. Added blank lines wherever needed which helps the readability
5. Ran make check and fixed the issues
---
v3:
-Addressed the below requested changes
1. Removed RANDOM_CONSTANT
2. Made hpage_size and fd to static
3. Used a volatile variable as a flag
to pass test in the run_test()
4. Removed the failure condition for SAFE_MMAP()
5. Have setup the handler in the setup()
6. Added SAFE_MUNMAP()
7. Ran make check and fixed all issues
---
v2:
-Corrected typo

---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap33.c  | 87 +++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
index 299c07ac9..1300e80fb 100644
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap33 hugemmap33
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index c96fe8bfc..444acdf52 100644
@@ -34,6 +34,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap33
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +46 -0
new file mode 100644
index 000000000..eb21e204c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [Description]
+ *
+ * Test case is used to verify the correct functionality
+ * and compatibility of the library with the "truncate" system call when
+ * operating on files residing in a mounted huge page filesystem.
+ */
+
+#include "hugetlb.h"
+#include <setjmp.h>
+#include <signal.h>
+
+#define MNTPOINT "hugetlbfs/"
+
+static long hpage_size;
+static int fd;
+static sigjmp_buf sig_escape;
+static volatile int test_pass;
+static int sigbus_count;
+
+static void sigbus_handler(int signum LTP_ATTRIBUTE_UNUSED)
+{
+	test_pass = 1;
+	siglongjmp(sig_escape, 17);
+}
+
+static void run_test(void)
+{
+	void *p;
+	volatile unsigned int *q;
+
+	sigbus_count = 0;
+	test_pass = 0;
+
+	struct sigaction my_sigaction;
+
+	my_sigaction.sa_handler = sigbus_handler;
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+			fd, 0);
+	q = p;

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 56

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +10 -0
+	*q = 0;
+	SAFE_SIGACTION(SIGBUS, &my_sigaction, NULL);
+
+	SAFE_FTRUNCATE(fd, 0);
+
+	if (sigsetjmp(sig_escape, 1) == 0)
+		*q;
+	else
+		sigbus_count++;
+

You should reset the SIGBUS handler to SIGDFL here, otherwise all subsequent runs run with the handler installed during the whole run_test() function. I suppose that you purposely install it after you have faulted a page in the file with *q = 0 to jump to the sigbus_count++ branch.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 60

Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +5 -0
+	if (sigbus_count != 1)
+		tst_res(TFAIL, "Didn't SIGBUS");
+
+	if (test_pass == 1)
+		tst_res(TPASS, "Expected SIGBUS triggered");

This is really redundant. Since we use siglongjmp() we don't need a variable set in the signal handler. And we have to report some result either case, so this should really be:

	if (sigbus_count)
		tst_res(TPASS, "Got SIGBUS");
	else
		tst_res(TFAIL, "Haven't got SIGBUS");
Quoted 33 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +26 -0
+	SAFE_MUNMAP(p, hpage_size);
+}
+
+
+static void setup(void)
+{
+	hpage_size = tst_get_hugepage_size();
+	fd = tst_creat_unlinked(MNTPOINT, 0);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_NEEDS},
+};
Signature · 6 lines
2.39.3



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi!

Quoted 4 lines

You should reset the SIGBUS handler to SIGDFL here, otherwise all subsequent runs run with the handler installed during the whole run_test() function. I suppose that you purposely install it after you have faulted a page in the file with *q = 0 to jump to the

^
In order not to jump

Quoted 1 line

sigbus_count++ branch.

^
when *q = 0 fails unexpectedly.

Signature · 5 lines
Cyril Hrubis
[email protected]

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