munlockall: add test case that verifies memory has been unlocked
PATCH 1/1 munlockall: add test case that verifies memory has been unlocked
Adding a munlockall() test case that checks if it has the desired effect, i.e. after calling munlockall() no more memory is locked.
--- .../kernel/syscalls/munlockall/munlockall02.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 testcases/kernel/syscalls/munlockall/munlockall02.c
testcases/kernel/syscalls/munlockall/munlockall02.c new file +55 -0
@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright Red Hat +* Author: Dennis Brendel <[email protected]> +*/ + +/* +* [Description] +* +* Verify that munlockall(2) unlocks all previously locked memory +*/ + +#include <sys/mman.h> + +#include "tst_test.h" + +static void verify_munlockall (void ) +{ +unsigned long int size =0 ; + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) { +tst_res (TFAIL ,"Locked memory after init should be 0 " +"but is %ld" , size); + } + +if (mlockall (MCL_CURRENT |MCL_FUTURE ) !=0 ) { +tst_res (TFAIL ,"Could not lock memory using mlockall()" ); + } + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) { +tst_res (TFAIL ,"Locked memory after mlockall() should be greater " +"than 0, but is %ld" , size); + } + +if (munlockall () !=0 ) { +tst_res (TFAIL ,"Could not unlock memory using munlockall()" ); + } + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) { +tst_res (TFAIL ,"Locked memory after munlockall() should be 0 " +"but is %ld" , size); + }else { +tst_res (TPASS ,"Test passed" ); + } +} + +static struct tst_test test = { + .test_all = verify_munlockall, +};
Signature · 6 lines
2.44.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Generally this is much better test than the munlockall01.c so it would make more sense to replace munlockall01.c instead of adding a new test.
testcases/kernel/syscalls/munlockall/munlockall02.c line 7
Quoted 7 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +7
-0+// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright Red Hat +* Author: Dennis Brendel <[email protected]> +*/ + +/*
This should be docparse comment, i.e. start with /*\ so that it's picked up with the documentation parser.
Quoted 33 lines
+ * [Description]
+ *
+ * Verify that munlockall(2) unlocks all previously locked memory
+ */testcases/kernel/syscalls/munlockall/munlockall02.c new file +29
-0+ +#include <sys/mman.h> + +#include "tst_test.h" + +static void verify_munlockall (void ) +{ +unsigned long int size =0 ; + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) { +tst_res (TFAIL ,"Locked memory after init should be 0 " +"but is %ld" , size); + } + +if (mlockall (MCL_CURRENT |MCL_FUTURE ) !=0 ) { +tst_res (TFAIL ,"Could not lock memory using mlockall()" ); + } + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) { +tst_res (TFAIL ,"Locked memory after mlockall() should be greater " +"than 0, but is %ld" , size); + } + +if (munlockall () !=0 ) { +tst_res (TFAIL ,"Could not unlock memory using munlockall()" );
testcases/kernel/syscalls/munlockall/munlockall02.c line 50
Quoted 10 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +10
-0+ } + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) { +tst_res (TFAIL ,"Locked memory after munlockall() should be 0 " +"but is %ld" , size); + }else { +tst_res (TPASS ,"Test passed" ); + }
This obviously does not work, you have to either return from the function after each tst_res(TFAIL, ""); or set a flag and print TPASS only if the flag wasn't set.
testcases/kernel/syscalls/munlockall/munlockall02.c line 55
Quoted 5 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +5
-0+} + +static struct tst_test test = { + .test_all = verify_munlockall, +};
Also have you checked the test with 'make check' before sending the patch?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp