munlockall: add test case that verifies memory has been unlocked
PATCH v2 1/1 munlockall: add test case that verifies memory has been unlocked
Changes to v1:
- use a docparse comment
- use tabs for indentation
- report broken test and exit if any preparation/confirmation fails by using tst_brk(TBROK, ...)
- fix further violations reported by make check
I did not yet replace munlockall01.c because I am not familiar with that (legacy?) syntax and why uclinux needs special handling.
--- .../kernel/syscalls/munlockall/munlockall02.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 testcases/kernel/syscalls/munlockall/munlockall02.c
testcases/kernel/syscalls/munlockall/munlockall02.c new file +51 -0
@@ -0,0 +1,51 @@ +// 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 ) +{ +size_t size =0 ; + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) +tst_brk (TBROK ,"Locked memory after init should be 0 but is " +"%ld" , size); + +if (mlockall (MCL_CURRENT |MCL_FUTURE ) !=0 ) +tst_brk (TBROK ,"Could not lock memory using mlockall()" ); + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) +tst_brk (TBROK ,"Locked memory after mlockall() should be " +"greater than 0, but is %ld" , size); + +if (munlockall () !=0 ) +tst_brk (TBROK ,"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 Dennis,
Generally LGTM, thanks!
you should also add test into .gitignore and to some file in runtest/ (in this case into runtest/syscalls), if we don't simply replace your test with munlockall01.c as Cyril suggested (I would also vote for replacing it).
FYI you can have look for what we check:
https://github.com/linux-test-project/ltp/wiki/Maintainer-Patch-Review-Checklist
Quoted 9 lines
Changes to v1:
- use a docparse comment
- use tabs for indentation
- report broken test and exit if any preparation/confirmation fails by usingtst_brk(TBROK, ...)
- fix further violations reported bymake checkI did not yet replace
munlockall01.cbecause I am not familiar with
I guess Cyril meant just to replace munlockall01.c with what you wrote. +1 for this, there is no point to keep original munlockall01.c. And because you replace, you can delete the original copyright and can use GPL-2.0-or-later (original test was GPL v2 only).
Quoted 1 line
that (legacy?) syntax and why uclinux needs special handling.
uclinux is for nommu, we don't support it in new API (and nobody from the community standup for the support), it can be just deleted.
Quoted 26 lines
--- .../kernel/syscalls/munlockall/munlockall02.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 testcases/kernel/syscalls/munlockall/munlockall02.ctestcases/kernel/syscalls/munlockall/munlockall02.c new file +15
-0@@ -0,0 +1,51 @@ +// 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"
testcases/kernel/syscalls/munlockall/munlockall02.c line 25
Quoted 10 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +10
-0+ +static void verify_munlockall (void ) +{ +size_t size =0 ; + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) +tst_brk (TBROK ,"Locked memory after init should be 0 but is " +"%ld" , size);
nit: I would not split string (kernel source code also relaxed to 100 chars instead of 8O).
testcases/kernel/syscalls/munlockall/munlockall02.c line 28
Quoted 3 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +3
-0+ +if (mlockall (MCL_CURRENT |MCL_FUTURE ) !=0 ) +tst_brk (TBROK ,"Could not lock memory using mlockall()" );
Maybe use tst_brk(TBROK | TERRNO, to get errno printed?
testcases/kernel/syscalls/munlockall/munlockall02.c line 34
Quoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-0+ +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) +tst_brk (TBROK ,"Locked memory after mlockall() should be " +"greater than 0, but is %ld" , size);
I suppose < 0 really means no memory locked, thus really safe to quit before munlockall(), right?
testcases/kernel/syscalls/munlockall/munlockall02.c line 37
Quoted 3 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +3
-0+ +if (munlockall () !=0 ) +tst_brk (TBROK ,"Could not unlock memory using munlockall()" );
Also here use TBROK | TERRNO ?
testcases/kernel/syscalls/munlockall/munlockall02.c line 43
Quoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-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);
nit: also here I would join string to single line (still below 100 chars).
testcases/kernel/syscalls/munlockall/munlockall02.c line 45
Quoted 2 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +2
-0+ }else { +tst_res (TPASS ,"Test passed" );
nit maybe:
tst_res(TPASS, "Memory successfully locked and unlocked");
Kind regards,
Petr
Quoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-0+ } +} + +static struct tst_test test = { + .test_all = verify_munlockall, +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr,
Thank you very much for your feedback! I'll send a v3 which considers your suggestions.
Dennis
Quoted 110 lines · Petr Vorel
Hi Dennis,
Generally LGTM, thanks!
Reviewed-by Petr Vorel <[email protected]>you should also add test into .gitignore and to some file in runtest/ (in this case into runtest/syscalls), if we don't simply replace your test with
munlockall01.cas Cyril suggested (I would also vote for replacing it).FYI you can have look for what we check:
https://github.com/linux-test-project/ltp/wiki/Maintainer-Patch-Review-Checklist
Quoted 9 lines
Changes to v1:
- use a docparse comment
- use tabs for indentation
- report broken test and exit if any preparation/confirmation fails by usingtst_brk(TBROK, ...)
- fix further violations reported bymake checkI did not yet replace
munlockall01.cbecause I am not familiar withI guess Cyril meant just to replace
munlockall01.cwith what you wrote. +1 for this, there is no point to keep originalmunlockall01.c. And because you replace, you can delete the original copyright and can use GPL-2.0-or-later (original test was GPL v2 only).Quoted 1 line
that (legacy?) syntax and why uclinux needs special handling.
uclinux is for nommu, we don't support it in new API (and nobody from the community standup for the support), it can be just deleted.
Quoted 26 lines
--- .../kernel/syscalls/munlockall/munlockall02.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 testcases/kernel/syscalls/munlockall/munlockall02.ctestcases/kernel/syscalls/munlockall/munlockall02.c new file +15
-0@@ -0,0 +1,51 @@ +// 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" testcases/kernel/syscalls/munlockall/munlockall02.c line 25
Quoted 10 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +10
-0+ +static void verify_munlockall (void ) +{ +size_t size =0 ; + +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size !=0UL ) +tst_brk (TBROK ,"Locked memory after init should be 0 but is " +"%ld" , size);nit: I would not split string (kernel source code also relaxed to 100 chars instead of 8O).
testcases/kernel/syscalls/munlockall/munlockall02.c line 28
Quoted 3 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +3
-0+ +if (mlockall (MCL_CURRENT |MCL_FUTURE ) !=0 ) +tst_brk (TBROK ,"Could not lock memory using mlockall()" );Maybe use tst_brk(TBROK | TERRNO, to get errno printed?
testcases/kernel/syscalls/munlockall/munlockall02.c line 34
Quoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-0+ +SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) +tst_brk (TBROK ,"Locked memory after mlockall() should be " +"greater than 0, but is %ld" , size);I suppose < 0 really means no memory locked, thus really safe to quit before
munlockall(), right?testcases/kernel/syscalls/munlockall/munlockall02.c line 37
Quoted 3 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +3
-0+ +if (munlockall () !=0 ) +tst_brk (TBROK ,"Could not unlock memory using munlockall()" );Also here use TBROK | TERRNO ?
testcases/kernel/syscalls/munlockall/munlockall02.c line 43
Quoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-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);nit: also here I would join string to single line (still below 100 chars).
testcases/kernel/syscalls/munlockall/munlockall02.c line 45
Quoted 2 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +2
-0+ }else { +tst_res (TPASS ,"Test passed" );nit maybe:
tst_res(TPASS, "Memory successfully locked and unlocked");Kind regards,
PetrQuoted 6 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +6
-0+ } +} + +static struct tst_test test = { + .test_all = verify_munlockall, +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Petr Vorel
testcases/kernel/syscalls/munlockall/munlockall02.c line 34
Quoted 5 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +5
-0+SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) +tst_brk (TBROK ,"Locked memory after mlockall() should be " +"greater than 0, but is %ld" , size);I suppose < 0 really means no memory locked, thus really safe to quit before
munlockall(), right?
Forgot to reply to that.
< 0 should not happen due to unsigned type.
If the size is 0 then it is safe to quit. In general it should always be safe to exit even if there was memory locked, i.e. when the parsing of /proc/self/status is faulty or when wrong numbers are reported.
Dennis
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines · Petr Vorel
Quoted 7 lines
testcases/kernel/syscalls/munlockall/munlockall02.c line 34
Quoted 5 lines
testcases/kernel/syscalls/munlockall/munlockall02.c new file +5
-0+SAFE_FILE_LINES_SCANF ("/proc/self/status" ,"VmLck: %ld" , &size); + +if (size ==0UL ) +tst_brk (TBROK ,"Locked memory after mlockall() should be " +"greater than 0, but is %ld" , size);I suppose < 0 really means no memory locked, thus really safe to quit before
munlockall(), right?
Quoted 7 lines
Forgot to reply to that.
< 0 should not happen due to unsigned type.
If the size is 0 then it is safe to quit. In general it should always be safe to exit even if there was memory locked, i.e. when the parsing of
/proc/self/statusis faulty or when wrong numbers are reported.
Good point, thanks!
Kind regards,
Petr
Quoted 1 line
Dennis
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp