mmap/mmap14.c: new case to test MAP_LOCKED of mmap
PATCH 1/1 mmap/mmap14.c: new case to test MAP_LOCKED of mmap
Create test case for MAP_LOCKED of mmap.
Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mmap/mmap14.c | 133 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 testcases/kernel/syscalls/mmap/mmap14.c
runtest/syscalls +1 -0
@@ -562,6 +562,7 @@ mmap07 mmap07 mmap08 mmap08 mmap09 mmap09 mmap13 mmap13 +mmap14 mmap14 # test is broken, mask it for now. #mmap11 mmap11 -i 30000
testcases/kernel/syscalls/mmap/mmap14.c new file +133 -0
133 lines not on this page · raw message
Signature · 12 lines
1.8.1 ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
----- Original Message -----
Quoted 7 lines
From: "DAN LI" <[email protected]>
To: "LTP list" <[email protected]>
Sent: Thursday, 27 June, 2013 5:21:27 AM
Subject: [LTP] [PATCH]mmap/mmap14.c: new case to testMAP_LOCKEDof mmap
Quoted 6 lines
Create test case for
MAP_LOCKEDof mmap.Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.
Signed-off-by DAN LI <[email protected]>
Hi,
few small comments inline. Overall it looks good to me.
Quoted 94 lines
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mmap/mmap14.c | 133 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 testcases/kernel/syscalls/mmap/mmap14.cruntest/syscalls +1
-0@@ -562,6 +562,7 @@ mmap07 mmap07 mmap08 mmap08 mmap09 mmap09 mmap13 mmap13 +mmap14 mmap14 # test is broken, mask it for now. #mmap11 mmap11 -i 30000testcases/kernel/syscalls/mmap/mmap14.c new file +16
-0@@ -0,0 +1,133 @@ +/* +* Copyright (c) 2013 FNST, DAN LI <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */testcases/kernel/syscalls/mmap/mmap14.c new file +5
-0+ +/* +* Test Description: +* Verify MAP_LOCKED works fine. +* "Lock the pages of the mapped region into memory in the manner of mlock(2)."
+ *
+ * Expected Result:
+ *mmap()should succeed returning the address of the mapped region,
+ * and this region should be locked into memory.
+ */testcases/kernel/syscalls/mmap/mmap14.c new file +39
-0+#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <signal.h> +#include <stdint.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/shm.h> + +#include "test.h" +#include "usctest.h" + +#define TEMPFILE "mmapfile" +#define MMAPSIZE (1UL<<20) +#define LINELEN 256 + +char *TCID ="mmap14" ; +int TST_TOTAL =1 ; + +static char *addr; + +static void setup (void ); +static void cleanup (void ); + +int main (int argc,char *argv[]) +{ +int lc; +int ret; +int lock_sz; +char *msg; +char line[LINELEN ]; +FILE *fstatus =NULL ; + + msg =parse_opts (argc, argv,NULL ,NULL ); +if (msg !=NULL )
testcases/kernel/syscalls/mmap/mmap14.c line 76
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +10
-0+tst_brkm (TBROK ,NULL ,"OPTION PARSING ERROR - %s" , msg); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + + tst_count =0 ; + + addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
MAP_FILE doesn't seem to belong here.
Quoted 14 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +14
-0+ -1, 0); + +if (addr ==MAP_FAILED ) { +tst_resm (TFAIL |TERRNO ,"mmap of %s failed" ,TEMPFILE ); +continue ; + } + +if (STD_FUNCTIONAL_TEST ) { + + fstatus =fopen ("/proc/self/status" ,"r" ); +if (fstatus ==NULL ) +tst_brkm (TFAIL |TERRNO ,NULL ,"Open dev " +"status failed" ); +
testcases/kernel/syscalls/mmap/mmap14.c line 100
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +10
-0+while (fgets (line,LINELEN , fstatus) !=NULL ) +if (strstr (line,"VmLck" ) !=NULL ) +break ; + + ret =sscanf (line,"%*[^0-9]%d%*[^0-9]" , &lock_sz); +if (ret !=1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"Get lock " +"size failed" ); + +if (lock_sz ==MMAPSIZE /1024 )
Can you also print lock_sz if this condition fails?
Quoted 16 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +16
-0+tst_resm (TPASS ,"Functionality of mmap() " +"successful" ); + else + tst_resm(TFAIL, "Pages are not locked"); + + }else { +tst_resm (TPASS ,"call succeeded" ); + } + +fclose (fstatus); +if (munmap (addr,MMAPSIZE ) !=0 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"munmap failed" ); + } + +cleanup (); +tst_exit ();
testcases/kernel/syscalls/mmap/mmap14.c line 126
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +10
-0+ +} + +static void setup (void ) +{ +tst_sig (FORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir ();
Is tmp dir used for anything?
Regards,
Jan
Quoted 13 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +7
-1+} + +static void cleanup (void ) +{ +TEST_CLEANUP ; +tst_rmdir (); +} --1.8.1
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Quoted 8 lines
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 37 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +37
-0+int main (int argc,char *argv[]) +{ +int lc; +int ret; +int lock_sz; +char *msg; +char line[LINELEN ]; +FILE *fstatus =NULL ; + + msg =parse_opts (argc, argv,NULL ,NULL ); +if (msg !=NULL ) +tst_brkm (TBROK ,NULL ,"OPTION PARSING ERROR - %s" , msg); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + + tst_count =0 ; + + addr =mmap (NULL ,MMAPSIZE ,PROT_READ |PROT_WRITE , +MAP_FILE |MAP_PRIVATE |MAP_LOCKED |MAP_ANONYMOUS , +-1 ,0 ); + +if (addr ==MAP_FAILED ) { +tst_resm (TFAIL |TERRNO ,"mmap of %s failed" ,TEMPFILE ); +continue ; + } + +if (STD_FUNCTIONAL_TEST ) { + + fstatus =fopen ("/proc/self/status" ,"r" ); +if (fstatus ==NULL ) +tst_brkm (TFAIL |TERRNO ,NULL ,"Open dev " +"status failed" ); + +while (fgets (line,LINELEN , fstatus) !=NULL ) +if (strstr (line,"VmLck" ) !=NULL )
testcases/kernel/syscalls/mmap/mmap14.c line 102
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap14.c new file +10
-0+break ; + + ret =sscanf (line,"%*[^0-9]%d%*[^0-9]" , &lock_sz); +if (ret !=1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"Get lock " +"size failed" ); + +if (lock_sz ==MMAPSIZE /1024 ) +tst_resm (TPASS ,"Functionality of mmap() " +"successful" );
I know that it's unlikely that process would have some pages locked prior the mmap above, but getting the number of locked pages before the mmap after it and using the difference in the comparsion would be more robust. And the additional work needed for this is minimal, just move the part of the code that reads VmLck value into a function and call it before and after the mmap.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list