Hugetlb: Migrating libhugetlbfs test truncate_reserve_wraparound.c
PATCH v4 1/1 Hugetlb: Migrating libhugetlbfs test truncate_reserve_wraparound.c
Test Description:
Test to verify the Hugepages_Rsvd before and after mmap, truncate and sigbus operations. At one stage, improper handling of tests against i_size could mess
up accounting of reserved hugepages on certain truncate operations.
Tested and verified that test passes for iterations: i10
---
Changes in v4:
- Moved local variables to run_test()
- Moved signal handler setup to setup()
- Added check for after_touch_rsvd == initial_rsvd
- Modified TFAIL messages based on review comments
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap35.c | 130 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c
runtest/hugetlb +1 -0
@@ -36,6 +36,7 @@ hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 hugemmap34 hugemmap34 +hugemmap35 hugemmap35 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -36,6 +36,7 @@ /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 /hugetlb/hugemmap/hugemmap34 +/hugetlb/hugemmap/hugemmap35 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +130 -0
130 lines not on this page · raw message
Signature · 5 lines
2.43.5 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +13
-0+/*\ +*[Descripiton] +* +* Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/truncate_reserve_wraparound.c +* +* At one stage, improper handling of tests against i_size could mess +* up accounting of reserved hugepages on certain truncate +* operations. +* +*/ + +#include <signal.h> +#include <setjmp.h>
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c line 28
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +10
-0+#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" + +static long hpage_size; +static int fd =-1 ; + +static sigjmp_buf sig_escape; + +static void sigbus_handler(int signum LTP_ATTRIBUTE_UNUSED, siginfo_t *si LTP_ATTRIBUTE_UNUSED, void *uc LTP_ATTRIBUTE_UNUSED)
Why do we bother with passing SA_SIGINFO to the sigaction() when we ingnore the parameters later?
Quoted 14 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +14
-0+{ +siglongjmp (sig_escape,17 ); +} + +static void run_test (void ) +{ + +static int sigbus_count; +unsigned long initial_rsvd, after_map_rsvd, after_touch_rsvd; +unsigned long after_trunc_rsvd, after_unmap_rsvd, after_sigbus_rsvd; +volatile unsigned int *q; +void *p; + + sigbus_count =0 ;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c line 52
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +10
-0+ + initial_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count before map: %lu" , initial_rsvd); + + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + q = p; + + after_map_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count after map: %lu" , after_map_rsvd);
Shouldn't we check that after_mmap_rsvd == initial_rsvd + 1 ?
Also we do have nice macros for assertions so we can do:
TST_EXP_EQ_LU(initial_rsvd + 1, after_mmap_rsvd); if (!TST_PASS) goto windup;
And we can use these macros in the rest of the comparsions as well. And with that we do not need to print the uselesstst_res(TPASS, "Test passed"); message
Quoted 80 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c new file +77
-0+ *q =0 ; + after_touch_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count after touch: %lu" , after_touch_rsvd); + +if (after_touch_rsvd != initial_rsvd) { +tst_res (TFAIL ,"Reserved after touch %lu instead of %lu" , after_touch_rsvd, initial_rsvd); + goto windup; + } + +SAFE_FTRUNCATE (fd,0 ); + after_trunc_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count after truncate: %lu" , after_trunc_rsvd); + +if (after_trunc_rsvd != initial_rsvd) { +tst_res (TFAIL ,"Reserved after truncate %lu instead of %lu" , after_trunc_rsvd, initial_rsvd); + goto windup; + } + +if (sigsetjmp (sig_escape,1 ) ==0 ) + *q;/* Fault, triggering a SIGBUS */ +else + sigbus_count++; + +if (sigbus_count !=1 ) { +tst_res (TFAIL ,"Didn't SIGBUS after truncate" ); + goto windup; + } + + after_sigbus_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count after sigbus: %lu" , after_sigbus_rsvd); + +if (after_sigbus_rsvd != initial_rsvd) { +tst_res (TFAIL ,"Reserved after SIGBUS %lu instead of %lu" , after_sigbus_rsvd, initial_rsvd); + goto windup; + } + +tst_res (TPASS ,"Test passed!" ); + +windup: +SAFE_MUNMAP (p, hpage_size); + after_unmap_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"Reserve count after munmap: %lu" , after_unmap_rsvd); + +} + +static void setup (void ) +{ + hpage_size =tst_get_hugepage_size (); + fd =tst_creat_unlinked (MNTPOINT ,0 ,0600 ); + +struct sigaction sa = { + .sa_sigaction = sigbus_handler, + .sa_flags =SA_SIGINFO , + }; + +SAFE_SIGACTION (SIGBUS , &sa,NULL ); +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag []) { + {"linux-git" ,"ebed4bfc8da8" }, + {} + }, + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .hugepages = {4 ,TST_NEEDS }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, +};Signature · 1 line
2.43.5
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp