Migrating the libhugetlbfs/testcases/truncate.c test
PATCH v2 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.
---
v2:
-Corrected typo
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap33.c | 72 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
@@ -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
@@ -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 +72 -0
72 lines not on this page · raw message
Signature · 5 lines
2.39.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 19
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +12
-0+/*\ +* [Description] +* +* Test Name: truncate +* 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" + +#define RANDOM_CONSTANT 0x1234ABCD
^
THis is not used at all.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 22
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+#define MNTPOINT "hugetlbfs/" +long hpage_size; +int fd;
These two should be static.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 29
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +6
-0+ + +static void sigbus_handler(int signum LTP_ATTRIBUTE_UNUSED) +{ +tst_res (TPASS ,"Test Passed" ); +exit (0 );
It's not safe to call exit(0) from a signal handler.
What should be done instead is to:
- add global static volatile int variable
- reset it before we attempt to access the truncated memory
- set it in the signal handler
- print TPASS/TFAIL based on the value of the variable in the run_test() function
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 35
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +6
-0+} + +static void run_test (void ) +{ +void *p; +volatile unsigned int *q;
^ I do not think that this has to be volatile. All in all this can be just: unsigned int *p; ... p = SAFE_MMAP(); ... *p = 0;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 41
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +6
-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 ); +if (p ==MAP_FAILED ) +tst_res (TFAIL ,"mmap failed..!!" );
SAFE_MMAP() cannot fail, it does exit the test with a failure if the it fails to map the memory.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 44
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+ q = p; + *q =0 ; +SAFE_SIGACTION (SIGBUS , &my_sigaction,NULL );
I guess that we can set up the handler in the setup instead.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 47
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+SAFE_FTRUNCATE (fd,0 ); + *q; +tst_res (TFAIL ,"Didn't SIGBUS" );
And we should SAFE_UNMAP() the memory here.
Also does the test work with -i 2 ?
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 54
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +7
-0+} + + +void setup (void ) +{ + hpage_size =tst_get_hugepage_size (); + fd =tst_creat_unlinked (MNTPOINT ,0 );
^
Wrong indentation, please make sure to run 'make check' and fix all the reported problems.
Quoted 24 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +18
-0+} + +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 · 5 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
Quoted 16 lines · Cyril Hrubis
Hi!
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 19
Quoted 13 lines
+/*\
+ * [Description]
+ *
+ * Test Name: truncate
+ * 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.
+ */testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +4
-0+ +#include "hugetlb.h" + +#define RANDOM_CONSTANT 0x1234ABCD^
THis is not used at all.
Will take care of this in v3.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 22
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+#define MNTPOINT "hugetlbfs/" +long hpage_size; +int fd;These two should be static.
Will take care of this in v3.
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 29
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +6
-0+ + +static void sigbus_handler(int signum LTP_ATTRIBUTE_UNUSED) +{ +tst_res (TPASS ,"Test Passed" ); +exit (0 );It's not safe to call exit(0) from a signal handler.
Quoted 9 lines
What should be done instead is to:
- add global static volatile int variable
- reset it before we attempt to access the truncated memory
- set it in the signal handler
- print TPASS/TFAIL based on the value of the variable in therun_test()
function
Will take care of this in v3.
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 35
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +6
-0+} + +static void run_test (void ) +{ +void *p; +volatile unsigned int *q;^ I do not think that this has to be volatile. All in all this can be just: unsigned int *p;
Quoted 7 lines
... p = SAFE_MMAP(); ... *p = 0;
This has to be volatile. The test logic is hunting for a bug that changes the value of q.
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 41
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+struct sigaction my_sigaction; + my_sigaction.sa_handler = sigbus_handler; + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE,
MAP_SHARED,testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+ fd, 0); +if (p ==MAP_FAILED ) +tst_res (TFAIL ,"mmap failed..!!" );
SAFE_MMAP()cannot fail, it does exit the test with a failure if the it
fails to map the memory.
Will take care of this in v3.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 44
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+ q = p; + *q =0 ; +SAFE_SIGACTION (SIGBUS , &my_sigaction,NULL );I guess that we can set up the handler in the setup instead.
Will take care of this in v3.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 47
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3
-0+SAFE_FTRUNCATE (fd,0 ); + *q; +tst_res (TFAIL ,"Didn't SIGBUS" );And we should
SAFE_UNMAP()the memory here.
Sure will take care of this in v3.
Quoted 2 lines
Also does the test work with -i 2 ?
The new Version ie., v3 works
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 54
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +7
-0+} + + +void setup (void ) +{ + hpage_size =tst_get_hugepage_size (); + fd =tst_creat_unlinked (MNTPOINT ,0 );^
Wrong indentation, please make sure to run 'make check' and fix
all
the reported problems.
Done in v3.
Quoted 25 lines
Quoted 25 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +18
-0+} + +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 · 5 lines
2.39.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp