Convert LTP kernel/mem/testcase to New API
cover Convert LTP kernel/mem/testcase to New API
This patchset is on purpose to convert lib/mem.c to new API, and the follows are all related testcase which using the memory test library. As you can see, one converted commit belong to a common subject(locatd in the same dir) at once.
Btw, I have tried to do cleanup/reorg for most of them, but it probably still not perfect by now, that's because my knowledge is limited. Anyway, before send out, test looks good(only two failures) from my x86_64(15G RAM, 2 numa nodes) box:
Seems the failed reason in oom02/5 is not testcase issue, it just because New API sets test time in 5mins.
<<<test_output>>>
tst_test.c:859: INFO: Timeout per run is 0h 05m 00s
mem.c:919: INFO: set overcommit_memory to 1
oom02.c:41: INFO: OOM on MPOL_BIND mempolicy...
mem.c:222: INFO: start normal OOM testing.
mem.c:144: INFO: expected victim is 13941.
...
mem.c:37: INFO: thread (7f7e99c51700), allocating 3221225472 bytes. mem.c:37: INFO: thread (7f7dd9450700), allocating 3221225472 bytes. tst_test.c:909: INFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1 tst_test.c:910: BROK: Test killed! (timeout?)
Summary:
passed 5 failed 0 skipped 0
warnings 0
Test Start Time: Mon Mar 27 06:15:30 2017
-----------------------------------------
Testcase Result Exit Value -------- ------ ---------- hugemmap01 PASS 0 hugemmap02 PASS 0 hugemmap04 PASS 0 hugemmap05 PASS 0 hugemmap06 PASS 0 hugemmap05_1 PASS 0 hugemmap05_2 PASS 0 hugemmap05_3 PASS 0 hugeshmat01 PASS 0 hugeshmat02 PASS 0 hugeshmat03 PASS 0 hugeshmat04 PASS 0 hugeshmat05 PASS 0 hugeshmctl01 PASS 0 hugeshmctl02 PASS 0 hugeshmctl03 PASS 0 hugeshmdt01 PASS 0 hugeshmget01 PASS 0 hugeshmget02 PASS 0 hugeshmget03 PASS 0 hugeshmget05 PASS 0 ksm01 PASS 0 ksm01_1 PASS 0 ksm02 PASS 0 ksm02_1 PASS 0 ksm03 PASS 0 ksm03_1 PASS 0 ksm04 PASS 0 ksm04_1 PASS 0 ksm05 PASS 0 ksm06 PASS 0 ksm06_1 PASS 0 ksm06_2 PASS 0 oom01 PASS 0 oom02 FAIL 2 oom03 PASS 0 oom04 PASS 0 oom05 FAIL 2 swapping01 CONF 32 cpuset01 PASS 0 thp01 PASS 0 thp02 PASS 0 thp03 PASS 0 overcommit_memory01 PASS 0 overcommit_memory02 PASS 0 overcommit_memory03 PASS 0 overcommit_memory04 PASS 0 overcommit_memory05 PASS 0 overcommit_memory06 PASS 0 max_map_count PASS 0
-----------------------------------------------
Total Failures: 2
Kernel Version: 3.10.0-514.el7.x86_64
Signature · 1 line
2.9.3
RFC PATCH 1/13 mem/lib: convert to new API
--- testcases/kernel/mem/include/mem.h | 8 +- testcases/kernel/mem/lib/mem.c | 268 ++++++++++++++++++------------------- 2 files changed, 132 insertions(+), 144 deletions(-)
testcases/kernel/mem/include/mem.h +3 -5
@@ -1,7 +1,7 @@#ifndef _MEM_H#define _MEM_H#include "config.h" -#include "test.h" +#include "tst_test.h" #if defined(__powerpc__) || defined(__powerpc64__)#define MAXNODES 256
@@ -84,16 +84,14 @@ void mount_mem(char *name, char *fs, char *options, char *path, char *path_new);void umount_mem (char *path,char *path_new);/* shared */ -unsigned int get_a_numa_node (void (*cleanup_fn)(void )); +unsigned int get_a_numa_node (void );int path_exist (const char *path, ...);long read_meminfo (char *item);void set_sys_tune (char *sys_file,long tune,int check);long get_sys_tune (char *sys_file); -void cleanup (void ); -void setup (void );void update_shm_size (size_t *shm_size);/* MMAP */ -int range_is_mapped (void (*cleanup_fn) (void ),unsigned long low,unsigned long high); +int range_is_mapped (unsigned long low,unsigned long high);#endif
testcases/kernel/mem/lib/mem.c +129 -139
716 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 2/13 mem/oom: convert to new API
--- testcases/kernel/mem/oom/oom01.c | 82 ++++++++++--------------- testcases/kernel/mem/oom/oom02.c | 82 +++++++++---------------- testcases/kernel/mem/oom/oom03.c | 109 +++++++++++++-------------------- testcases/kernel/mem/oom/oom04.c | 97 +++++++++++------------------ testcases/kernel/mem/oom/oom05.c | 129 ++++++++++++++++----------------------- 5 files changed, 191 insertions(+), 308 deletions(-)
testcases/kernel/mem/oom/oom01.c +31 -51
@@ -7,27 +7,19 @@* behaviours. It simply increase the memory consumption 3G each time * until all the available memory is consumed and OOM is triggered. * -* Copyright (C) 2010 Red Hat, Inc. -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. +* Copyright (C) 2010-2017 Red Hat, Inc. * -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* 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. * -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. +* 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. */ +#include <sys/types.h> #include <sys/stat.h> #include <errno.h>
@@ -35,53 +27,41 @@#include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include "test.h" #include "mem.h" -char *TCID ="oom01" ; -int TST_TOTAL =1 ; - -int main (int argc,char *argv[]) +static void verify_oom (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); -#if __WORDSIZE ==32 -tst_brkm (TCONF ,NULL ,"test is not designed for 32-bit system." ); +tst_brk (TCONF ,"test is not designed for 32-bit system." );#endif -setup (); +/* we expect mmap to fail before OOM is hit */ +set_sys_tune ("overcommit_memory" ,2 ,1 ); +oom (NORMAL ,0 ,ENOMEM ,0 ); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; +/* with overcommit_memory set to 0 or 1 there's no +* guarantee that mmap fails before OOM */ +set_sys_tune ("overcommit_memory" ,0 ,1 ); +oom (NORMAL ,0 ,ENOMEM ,1 ); -/* we expect mmap to fail before OOM is hit */ -set_sys_tune ("overcommit_memory" ,2 ,1 ); -oom (NORMAL ,0 ,ENOMEM ,0 ); - -/* with overcommit_memory set to 0 or 1 there's no -* guarantee that mmap fails before OOM */ -set_sys_tune ("overcommit_memory" ,0 ,1 ); -oom (NORMAL ,0 ,ENOMEM ,1 ); - -set_sys_tune ("overcommit_memory" ,1 ,1 ); -testoom (0 ,0 ,ENOMEM ,1 ); - } -cleanup (); -tst_exit (); +set_sys_tune ("overcommit_memory" ,1 ,1 ); +testoom (0 ,0 ,ENOMEM ,1 ); } -void setup (void ) +static void setup (void ) { -tst_require_root (); -tst_sig (FORK ,DEF_HANDLER , cleanup); -TEST_PAUSE ; - overcommit =get_sys_tune ("overcommit_memory" ); } -void cleanup (void ) +static void cleanup (void ) {set_sys_tune ("overcommit_memory" , overcommit,0 ); } + +static struct tst_test test = { + .tid ="oom01" , + .needs_root =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_oom, +};
testcases/kernel/mem/oom/oom02.c +29 -53
119 lines not on this page · raw message
testcases/kernel/mem/oom/oom03.c +42 -67
149 lines not on this page · raw message
testcases/kernel/mem/oom/oom04.c +36 -61
141 lines not on this page · raw message
testcases/kernel/mem/oom/oom05.c +53 -76
178 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 3/13 mem/ksm: convert to new API
Recast ksm_options structure to support parameter transfer.
--- testcases/kernel/mem/include/mem.h | 9 ++- testcases/kernel/mem/ksm/ksm01.c | 87 ++++++++++--------------- testcases/kernel/mem/ksm/ksm02.c | 124 ++++++++++++++--------------------- testcases/kernel/mem/ksm/ksm03.c | 89 ++++++++++--------------- testcases/kernel/mem/ksm/ksm04.c | 122 ++++++++++++++--------------------- testcases/kernel/mem/ksm/ksm05.c | 129 +++++++++++++++---------------------- testcases/kernel/mem/ksm/ksm06.c | 105 +++++++++++------------------- testcases/kernel/mem/lib/mem.c | 16 ++--- 8 files changed, 264 insertions(+), 417 deletions(-)
testcases/kernel/mem/include/mem.h +4 -5
@@ -44,6 +44,10 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);#define PATH_KSM "/sys/kernel/mm/ksm/" +char *opt_numstr, *opt_sizestr, *opt_unitstr; + +void create_same_memory (int size,int num,int unit); +void check_ksm_options (int *size,int *num,int *unit);void save_max_page_sharing (void );void restore_max_page_sharing (void );void test_ksm_merge_across_nodes (unsigned long nr_pages);
@@ -58,11 +62,6 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages);#define PATH_SHMMAX "/proc/sys/kernel/shmmax"void write_memcg (void ); -void create_same_memory (int size,int num,int unit); -int opt_num, opt_size, opt_unit; -char *opt_numstr, *opt_sizestr, *opt_unitstr; -void check_ksm_options (int *size,int *num,int *unit); -void ksm_usage (void );/* cpuset/memcg */
testcases/kernel/mem/ksm/ksm01.c +34 -53
130 lines not on this page · raw message
testcases/kernel/mem/ksm/ksm02.c +50 -74
173 lines not on this page · raw message
testcases/kernel/mem/ksm/ksm03.c +35 -54
131 lines not on this page · raw message
testcases/kernel/mem/ksm/ksm04.c +49 -73
175 lines not on this page · raw message
testcases/kernel/mem/ksm/ksm05.c +51 -78
184 lines not on this page · raw message
testcases/kernel/mem/ksm/ksm06.c +36 -69
159 lines not on this page · raw message
testcases/kernel/mem/lib/mem.c +5 -11
@@ -267,9 +267,10 @@ static void check(char *path, long int value)snprintf (fullpath,BUFSIZ ,PATH_KSM "%s" , path);SAFE_FILE_SCANF (fullpath,"%ld" , &actual_val); -tst_res (TINFO ,"%s is %ld." , path, actual_val);if (actual_val != value)tst_res (TFAIL ,"%s is not %ld." , path, value); +else +tst_res (TPASS ,"%s is %ld." , path, actual_val); }static void wait_ksmd_done (void )
@@ -649,12 +650,12 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)void check_ksm_options (int *size,int *num,int *unit) { -if (opt_size) { +if (opt_sizestr) { *size =atoi (opt_sizestr);if (*size <1 )tst_brk (TBROK ,"size cannot be less than 1." ); } -if (opt_unit) { +if (opt_unitstr) { *unit =atoi (opt_unitstr);if (*unit > *size) tst_brk(TBROK,
@@ -664,7 +665,7 @@ void check_ksm_options(int *size, int *num, int *unit)"the remainder of division of size by unit is " "not zero."); } -if (opt_num) { +if (opt_numstr) { *num =atoi (opt_numstr);if (*num <3 ) tst_brk(TBROK,
@@ -672,13 +673,6 @@ void check_ksm_options(int *size, int *num, int *unit) } } -void ksm_usage (void ) -{ -printf (" -n Number of processes\n" ); -printf (" -s Memory allocation size in MB\n" ); -printf (" -u Memory allocation unit in MB\n" ); -} -/* THP */ /* cpuset/memcg */
Signature · 1 line
2.9.3
RFC PATCH 4/13 mem/thp: convert to new API
--- runtest/mm | 2 +- testcases/kernel/mem/thp/thp01.c | 84 ++++++++++++++++---------------------- testcases/kernel/mem/thp/thp02.c | 87 ++++++++++++---------------------------- testcases/kernel/mem/thp/thp03.c | 87 +++++++++++++--------------------------- 4 files changed, 89 insertions(+), 171 deletions(-)
runtest/mm +1 -1
@@ -81,7 +81,7 @@ oom05 oom05 swapping01 swapping01 -i 5 -thp01 thp01 -I 120 +thp01 thp01 -I 10 thp02 thp02 thp03 thp03
testcases/kernel/mem/thp/thp01.c +34 -50
127 lines not on this page · raw message
testcases/kernel/mem/thp/thp02.c +26 -61
134 lines not on this page · raw message
testcases/kernel/mem/thp/thp03.c +28 -59
140 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 5/13 mem/hugetlb: convert to new API
--- testcases/kernel/mem/hugetlb/lib/hugetlb.c | 19 ++++++++++--------- testcases/kernel/mem/hugetlb/lib/hugetlb.h | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-)
testcases/kernel/mem/hugetlb/lib/hugetlb.c +10 -9
@@ -32,6 +32,7 @@* rm_shm() */ +#define TST_NO_DEFAULT_MAIN #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h>
@@ -42,14 +43,14 @@void check_hugepage (void ) {if (access (PATH_HUGEPAGES ,F_OK )) -tst_brkm (TCONF ,NULL ,"Huge page is not supported." ); +tst_brk (TCONF ,"Huge page is not supported." ); }/* * getipckey() - generates and returns a message key used by the "get" * calls to create an IPC resource. */ -int getipckey (void (*cleanup_fn) (void )) +int getipckey (void ) {const char a ='a' ;int ascii_a = (int )a;
@@ -60,7 +61,7 @@ int getipckey(void (*cleanup_fn) (void)) curdir =getcwd (curdir, size);if (curdir ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup_fn,"getcwd(curdir)" ); +tst_brk (TBROK |TERRNO ,"getcwd(curdir)" );/* * Get a Sys V IPC key
@@ -79,7 +80,7 @@ int getipckey(void (*cleanup_fn) (void)) ipc_key =ftok (curdir, ascii_a +random () %26 );if (ipc_key ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup_fn,"ftok" ); +tst_brk (TBROK |TERRNO , __func__);return ipc_key; }
@@ -87,13 +88,13 @@ int getipckey(void (*cleanup_fn) (void))/* * getuserid() - return the integer value for the "user" id */ -int getuserid (void (*cleanup_fn) (void ),char *user) +int getuserid (char *user) {struct passwd *ent; ent =getpwnam (user);if (ent ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup_fn,"getpwnam" ); +tst_brk (TBROK |TERRNO ,"getpwnam" );return ent->pw_uid; }
@@ -110,8 +111,8 @@ void rm_shm(int shm_id)* check for # of attaches ? */ if (shmctl (shm_id,IPC_RMID ,NULL ) ==-1 ) { -tst_resm (TINFO ,"WARNING: shared memory deletion failed." ); -tst_resm (TINFO ,"This could lead to IPC resource problems." ); -tst_resm (TINFO ,"id = %d" , shm_id); +tst_res (TINFO ,"WARNING: shared memory deletion failed." ); +tst_res (TINFO ,"This could lead to IPC resource problems." ); +tst_res (TINFO ,"id = %d" , shm_id); } }
testcases/kernel/mem/hugetlb/lib/hugetlb.h +5 -4
@@ -24,11 +24,12 @@#ifndef __HUGETLB_H#define __HUGETLB_H +#include <stdlib.h> #include <sys/ipc.h> #include <sys/shm.h> #include <errno.h> #include <sys/wait.h> -#include "test.h" +#include "tst_test.h" #define SHM_RD 0400#define SHM_WR 0200
@@ -49,12 +50,12 @@ key_t shmkey; /* an IPC key generated by ftok() */void check_hugepage (void ); -int getipckey (void (*cleanup_fn) (void )); -int getuserid (void (*cleanup_fn) (void ),char *user); +int getipckey (void ); +int getuserid (char *user);void rm_shm (int shm_id);char *nr_opt; -int sflag; +char *Hopt;long orig_hugepages;#endif /* hugetlb.h */
Signature · 1 line
2.9.3
RFC PATCH 6/13 mem/hugemmap: convert to new API
--- testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c | 180 +++++-------- testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c | 242 +++++++---------- testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 190 +++++--------- testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c | 291 ++++++++------------- testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c | 91 +++---- testcases/kernel/mem/hugetlb/lib/hugetlb.h | 2 + 6 files changed, 364 insertions(+), 632 deletions(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c +61 -119
@@ -1,20 +1,16 @@/* +* Copyright (c) International Business Machines Corp., 2004 +* Copyright (c) Linux Test Project, 2004-2017 * -* Copyright (c) International Business Machines Corp., 2004 +* 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 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 +* 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. */ /*
@@ -27,143 +23,86 @@* mmap() should succeed returning the address of the hugetlb mapped region. * The number of free huge pages should decrease. * -* Algorithm: -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* Create temporary directory. -* * Test: * Loop if the proper options are given. * Execute system call * Check return code, if system call failed (return=-1) * Log the errno and Issue a FAIL message. -* Cleanup: -* Print timing stats if options given -* Delete the temporary directory created. * * HISTORY * 04/2004 Written by Robbie Williamson */ -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdint.h> #include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "test.h" -#include "hugetlb.h" -#include "safe_macros.h" +#include <sys/mount.h> #include "mem.h" +#include "hugetlb.h" -static char TEMPFILE [MAXPATHLEN ]; +static struct tst_option options[] = { + {"H:" , &Hopt,"-H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"-s num Set the number of the been allocated hugepages" }, + {NULL ,NULL ,NULL } +}; -char *TCID ="hugemmap01" ; -int TST_TOTAL =1 ;static long *addr; -static int fildes; -static char *Hopt; +static int fildes;static long beforetest;static long aftertest;static long hugepagesmapped;static long hugepages =128 ; +static char TEMPFILE [MAXPATHLEN ]; -static void help (void ); - -int main (int ac,char **av) +static void test_hugemmap (void ) { -int lc; -int Hflag =0 ;long page_sz =0 ; -int sflag =0 ; -option_t options[] = { - {"H:" , &Hflag, &Hopt}, - {"s:" , &sflag, &nr_opt}, - {NULL ,NULL ,NULL } - }; +/* Creat a temporary file used for mapping */ + fildes =SAFE_OPEN (TEMPFILE ,O_RDWR |O_CREAT ,0666 ); -tst_parse_opts (ac, av, options, &help); +/* Note the number of free huge pages BEFORE testing */ + beforetest =read_meminfo ("HugePages_Free:" ); -if (!Hflag) { -tst_tmpdir (); - Hopt =tst_get_tmpdir (); - } -if (sflag) - hugepages =SAFE_STRTOL (NULL , nr_opt,0 ,LONG_MAX ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* Creat a temporary file used for mapping */ - fildes =open (TEMPFILE ,O_RDWR |O_CREAT ,0666 ); -if (fildes <0 ) -tst_brkm (TFAIL |TERRNO , cleanup,"open %s failed" , -TEMPFILE ); - - tst_count =0 ; - -/* Note the number of free huge pages BEFORE testing */ - beforetest =read_meminfo ("HugePages_Free:" ); - -/* Note the size of huge page size BEFORE testing */ - page_sz =read_meminfo ("Hugepagesize:" ) *1024 ; - - addr =mmap (NULL , page_sz,PROT_READ |PROT_WRITE , -MAP_SHARED , fildes,0 ); -if (addr ==MAP_FAILED ) { -tst_resm (TFAIL |TERRNO ,"mmap() Failed on %s" , -TEMPFILE ); -close (fildes); -continue ; - }else { -close (fildes); -tst_resm (TPASS ,"call succeeded" ); -/* force to allocate page and change HugePages_Free */ - *(int *)addr =0 ; - } - -/* -* Make sure the number of free huge pages -* AFTER testing decreased -*/ +/* Note the size of huge page size BEFORE testing */ + page_sz =read_meminfo ("Hugepagesize:" ) *1024 ; + + addr =mmap (NULL , page_sz,PROT_READ |PROT_WRITE , +MAP_SHARED , fildes,0 ); + +if (addr ==MAP_FAILED ) { +tst_res (TFAIL |TERRNO ,"mmap() Failed on %s" , +TEMPFILE ); + }else { +tst_res (TPASS ,"call succeeded" ); + +/* force to allocate page and change HugePages_Free */ + *(int *)addr =0 ; +/* Make sure the number of free huge pages AFTER testing decreased */ aftertest =read_meminfo ("HugePages_Free:" ); hugepagesmapped = beforetest - aftertest;if (hugepagesmapped <1 ) -tst_resm (TWARN ,"Number of HUGEPAGES_FREE stayed the" -" same. Okay if multiple copies running due" -" to test collision." ); - -/* Clean up things in case we are looping */ -/* Unmap the mapped memory */ -if (munmap (addr, page_sz) !=0 ) -tst_brkm (TFAIL |TERRNO ,NULL ,"munmap failed" ); - -close (fildes); +tst_res (TWARN ,"Number of HUGEPAGES_FREE stayed the" +" same. Okay if multiple copies running due" +" to test collision." ); +munmap (addr, page_sz); } -cleanup (); -tst_exit (); +close (fildes); }void setup (void ) { -TEST_PAUSE ; -tst_require_root ();check_hugepage (); + orig_hugepages =get_sys_tune ("nr_hugepages" ); + +if (!Hopt) + Hopt =tst_get_tmpdir ();if (mount ("none" , Hopt,"hugetlbfs" ,0 ,NULL ) <0 ) -tst_brkm (TBROK |TERRNO ,NULL ,"mount failed on %s" , Hopt); +tst_brk (TBROK |TERRNO ,"mount failed on %s" , Hopt); - orig_hugepages =get_sys_tune ("nr_hugepages" ); +if (nr_opt) + hugepages =SAFE_STRTOL (nr_opt,0 ,LONG_MAX );set_sys_tune ("nr_hugepages" , hugepages,1 ); +snprintf (TEMPFILE ,sizeof (TEMPFILE ),"%s/mmapfile%d" , Hopt,getpid ()); }
@@ -173,11 +112,14 @@ void cleanup(void)set_sys_tune ("nr_hugepages" , orig_hugepages,0 );umount (Hopt); -tst_rmdir (); } -static void help (void ) -{ -printf (" -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs\n" ); -printf (" -s num Set the number of the been allocated hugepages\n" ); -} +static struct tst_test test = { + .tid ="hugemmap01" , + .needs_root =1 , + .needs_tmpdir =1 , + .options = options, + .setup = setup, + .cleanup = cleanup, + .test_all = test_hugemmap, +};
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +97 -145
298 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c +66 -124
251 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c +107 -184
508 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c +31 -60
171 lines not on this page · raw message
testcases/kernel/mem/hugetlb/lib/hugetlb.h +2 -0
@@ -27,9 +27,11 @@#include <stdlib.h> #include <sys/ipc.h> #include <sys/shm.h> +#include <sys/param.h> #include <errno.h> #include <sys/wait.h> #include "tst_test.h" +#include "old_tmpdir.h" #define SHM_RD 0400#define SHM_WR 0200
Signature · 1 line
2.9.3
RFC PATCH 7/13 mem/hugeshmat: convert to new API
--- .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c | 177 +++++++++------------ .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c | 131 ++++++--------- .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c | 127 ++++++--------- .../kernel/mem/hugetlb/hugeshmat/hugeshmat04.c | 110 +++++-------- .../kernel/mem/hugetlb/hugeshmat/hugeshmat05.c | 68 +++----- 5 files changed, 231 insertions(+), 382 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c +71 -106
@@ -1,26 +1,19 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) Linux Test Project, 2001-2017 * -* Copyright (c) International Business Machines Corp., 2001 +* 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 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 +* 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. */ /* -* NAME -* hugeshmat01.c -* * DESCRIPTION * hugeshmat01 - test that shmat() works correctly *
@@ -39,107 +32,73 @@* issue a FAIL message * call cleanup * -* USAGE: <for command-line> -* hugeshmat01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* * HISTORY * 03/2001 - Written by Wayne Boyer * 04/2004 - Updated by Robbie Williamson -* -* RESTRICTIONS -* none */ -#include "hugetlb.h" -#include "safe_macros.h" #include "mem.h" +#include "hugetlb.h" -char *TCID ="hugeshmat01" ; -int TST_TOTAL =3 ; - -#define CASE0 10/* values to write into the shared */ -#define CASE1 20/* memory location. */ +#define CASE0 10/* values to write into the shared */ +#define CASE1 20/* memory location. */ static size_t shm_size;static int shm_id_1 =-1 ;static void *addr;static long hugepages =128 ; -static option_t options[] = { - {"s:" , &sflag, &nr_opt}, + +static struct tst_option options[] = { + {"s:" , &nr_opt,"-s num Set the number of the been allocated hugepages" }, {NULL ,NULL ,NULL } }; -struct test_case_t { +static struct tcase {int *shmid;void *addr;int flags; -}TC [] = { +} tcases[] = {/* a straight forward read/write attach */ - { - &shm_id_1,0 ,0 }, -/* -* an attach using non aligned memory -* -1 will be replaced with an unaligned addr -*/ - { - &shm_id_1, (void *)-1 ,SHM_RND }, -/* a read only attach */ - { - &shm_id_1,0 ,SHM_RDONLY } + {&shm_id_1,0 ,0 }, +/* +* an attach using non aligned memory +* -1 will be replaced with an unaligned addr +*/ + {&shm_id_1, (void *)-1 ,SHM_RND }, +/* a read only attach */ + {&shm_id_1,0 ,SHM_RDONLY } }; -static void check_functionality (int i); +static void check_functionality (unsigned int i); -int main (int ac,char **av) +static void verify_hugeshmat (unsigned int i) { -int lc, i; - -tst_parse_opts (ac, av, options,NULL ); - -if (sflag) - hugepages =SAFE_STRTOL (NULL , nr_opt,0 ,LONG_MAX ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { - addr =shmat (*(TC [i].shmid),TC [i].addr,TC [i].flags); -if (addr == (void *)-1 ) { -tst_brkm (TFAIL |TERRNO , cleanup,"shmat" ); - }else { -check_functionality (i); - } - -/* -* addr in TC[0] will be used to generate an unaligned -* address for TC[1] -*/ -if (i ==0 && addr != (void *)-1 ) -TC [1 ].addr = (void *)(((unsigned long )addr & - ~(SHMLBA -1 )) +SHMLBA - -1 ); -if (shmdt (addr) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmdt" ); - } +struct tcase *tc = &tcases[i]; + + addr =shmat (*(tc->shmid), tc->addr, tc->flags); +if (addr == (void *)-1 ) { +tst_brk (TFAIL |TERRNO ,"shmat" ); + }else { +check_functionality (i); } -cleanup (); -tst_exit (); + +/* +* addr in tcases[0] will be used to generate an unaligned +* address for tcases[1] +*/ +if (i ==0 && addr != (void *)-1 ) + tc[1 ].addr = (void *)(((unsigned long )addr & + ~(SHMLBA -1 )) +SHMLBA -1 ); +if (shmdt (addr) ==-1 ) +tst_brk (TBROK |TERRNO ,"shmdt" ); }/* * check_functionality - check various conditions to make sure they * are correct. */ -static void check_functionality (int i) +static void check_functionality (unsigned int i) {void *orig_add;int *shared;
@@ -149,17 +108,17 @@ static void check_functionality(int i)/* stat the shared memory ID */ if (shmctl (shm_id_1,IPC_STAT , &buf) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmctl" ); +tst_brk (TBROK |TERRNO ,"shmctl" );/* check the number of attaches */ if (buf.shm_nattch !=1 ) { -tst_resm (TFAIL ,"# of attaches is incorrect" ); +tst_res (TFAIL ,"# of attaches is incorrect" );return ; }/* check the size of the segment */ if (buf.shm_segsz != shm_size) { -tst_resm (TFAIL ,"segment size is incorrect" ); +tst_res (TFAIL ,"segment size is incorrect" );return ; }
@@ -182,9 +141,9 @@ static void check_functionality(int i)* specified in the man page. */ *shared =CASE1 ; - orig_add = addr + ((unsigned long )TC [i].addr %SHMLBA ); -if (orig_add !=TC [i].addr) { -tst_resm (TFAIL ,"shared memory address is not " + orig_add = addr + ((unsigned long )tcases[i].addr %SHMLBA ); +if (orig_add != tcases[i].addr) { +tst_res (TFAIL ,"shared memory address is not " "correct" );return ; }
@@ -196,22 +155,21 @@ static void check_functionality(int i)* because shared memory is persistent. */ if (*shared !=CASE1 ) { -tst_resm (TFAIL ,"shared memory value isn't correct" ); +tst_res (TFAIL ,"shared memory value isn't correct" );return ; }break ; } -tst_resm (TPASS ,"conditions and functionality are correct" ); +tst_res (TPASS ,"conditions and functionality are correct" ); } -void setup (void ) +static void setup (void ) {long hpage_size; -tst_require_root ();check_hugepage (); -tst_sig (NOFORK ,DEF_HANDLER , cleanup); -tst_tmpdir (); +if (nr_opt) + hugepages =SAFE_STRTOL (nr_opt,0 ,LONG_MAX ); orig_hugepages =get_sys_tune ("nr_hugepages" );set_sys_tune ("nr_hugepages" , hugepages,1 );
@@ -219,20 +177,27 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); - shmkey =getipckey (cleanup); + shmkey =getipckey (); shm_id_1 =shmget (shmkey++, shm_size,SHM_HUGETLB |SHM_RW |IPC_CREAT |IPC_EXCL );if (shm_id_1 ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmget" ); +tst_brk (TBROK |TERRNO ,"shmget" ); -TEST_PAUSE ; } -void cleanup (void ) +static void cleanup (void ) {rm_shm (shm_id_1); -set_sys_tune ("nr_hugepages" , orig_hugepages,0 ); - -tst_rmdir (); } + +static struct tst_test test = { + .tid ="hugeshmat01" , + .needs_root =1 , + .needs_tmpdir =1 , + .options = options, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_hugeshmat, + .setup = setup, + .cleanup = cleanup, +};
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c +51 -80
192 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c +46 -81
190 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +40 -70
176 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c +23 -45
129 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 8/13 mem/hugeshmctl: convert to new API
--- .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c | 206 +++++++++------------ .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c | 151 ++++++--------- .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c | 147 ++++++--------- 3 files changed, 205 insertions(+), 299 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +90 -116
@@ -1,27 +1,19 @@/* +* Copyright (c) International Business Machines Corp., 2004 +* Copyright (c) Linux Test Project, 2004-2017 * -* Copyright (c) International Business Machines Corp., 2004 +* 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 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 +* 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. */ /* -* NAME -* hugeshmctl01.c -* * DESCRIPTION * hugeshmctl01 - test the IPC_STAT, IPC_SET and IPC_RMID commands as * they are used with shmctl()
@@ -44,31 +36,14 @@* issue a PASS message * call cleanup * -* USAGE: <for command-line> -* hugeshmctl01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* * HISTORY * 03/2001 - Written by Wayne Boyer * 04/2004 - Updated by Robbie Williamson -* -* RESTRICTIONS -* none */ -#include "test.h" -#include "safe_macros.h" #include "mem.h" #include "hugetlb.h" -char *TCID ="hugeshmctl01" ; -int TST_TOTAL =4 ; -#define FIRST 0#define SECOND 1#define N_ATTACH 4
@@ -92,67 +67,54 @@ static void func_rmid(void);static void *set_shmat (void );static long hugepages =128 ; -static option_t options[] = { - {"s:" , &sflag, &nr_opt}, + +static struct tst_option options[] = { + {"s:" , &nr_opt,"-s num Set the number of the been allocated hugepages" }, {NULL ,NULL ,NULL } }; -struct test_case_t { +struct tcase {int cmd;void (*func_test) (void );void (*func_setup) (void ); -}TC [] = { - { -IPC_STAT , func_stat, stat_setup}, { -IPC_STAT , func_stat, stat_setup}, { -IPC_SET , func_set, set_setup}, { -IPC_RMID , func_rmid,NULL } +} tcases[] = { + {IPC_STAT , func_stat, stat_setup}, + {IPC_STAT , func_stat, stat_setup}, + {IPC_SET , func_set, set_setup}, + {IPC_RMID , func_rmid,NULL } }; -int main (int ac,char **av) +static void test_hugeshmctl (void ) { -int lc, i; +unsigned int i; -tst_parse_opts (ac, av, options,NULL ); +/* initialize stat_time */ + stat_time =FIRST ; -if (sflag) - hugepages =SAFE_STRTOL (NULL , nr_opt,0 ,LONG_MAX ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -/* initialize stat_time */ - stat_time =FIRST ; +/* +* Create a shared memory segment with read and write +* permissions. Do this here instead of in setup() +* so that looping (-i) will work correctly. +*/ + shm_id_1 =shmget (shmkey, shm_size, +SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); +if (shm_id_1 ==-1 ) +tst_brk (TBROK |TERRNO ,"shmget #main" ); +for (i =0 ; i <ARRAY_SIZE (tcases); i++) {/* -* Create a shared memory segment with read and write -* permissions. Do this here instead of in setup() -* so that looping (-i) will work correctly. +* if needed, set up any required conditions by +* calling the appropriate setup function */ - shm_id_1 =shmget (shmkey, shm_size, -SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); -if (shm_id_1 ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmget #main" ); +if (tcases[i].func_setup !=NULL ) + (*tcases[i].func_setup) (); -for (i =0 ; i <TST_TOTAL ; i++) { -/* -* if needed, set up any required conditions by -* calling the appropriate setup function -*/ -if (TC [i].func_setup !=NULL ) - (*TC [i].func_setup) (); - -if (shmctl (shm_id_1,TC [i].cmd, &buf) ==-1 ) { -tst_resm (TFAIL |TERRNO ,"shmctl #main" ); -continue ; - } - (*TC [i].func_test) (); +if (shmctl (shm_id_1, tcases[i].cmd, &buf) ==-1 ) { +tst_res (TFAIL |TERRNO ,"shmctl #main" ); +continue ; } + (*tcases[i].func_test) (); } -cleanup (); -tst_exit (); }/*
@@ -166,7 +128,7 @@ void *set_shmat(void) rval =shmat (shm_id_1,0 ,0 );if (rval == (void *)-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"set shmat" ); +tst_brk (TBROK |TERRNO ,"set shmat" );return rval; }
@@ -182,7 +144,15 @@ static void stat_setup(void)void *test;pid_t pid;sigset_t newmask, oldmask; - +struct sigaction sa; + +memset (&sa,'\0' ,sizeof (sa)); + sa.sa_handler = sighandler; + sa.sa_flags =0 ; +TEST (sigaction (SIGUSR1 , &sa,NULL )); +if (TEST_RETURN ==-1 ) +tst_brk (TBROK |TRERRNO , +"SIGSEGV signal setup failed" );/* * The first time through, let the children attach the memory. * The second time through, attach the memory first and let
@@ -210,12 +180,12 @@ static void stat_setup(void)sigemptyset (&newmask);sigaddset (&newmask,SIGUSR1 );if (sigprocmask (SIG_BLOCK , &newmask, &oldmask) <0 ) -tst_brkm (TBROK |TERRNO , cleanup,"block SIGUSR1 error" ); +tst_brk (TBROK |TERRNO ,"block SIGUSR1 error" );for (i =0 ; i <N_ATTACH ; i++) {switch (pid =fork ()) {case -1 : -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 : test = (stat_time ==FIRST ) ?set_shmat () : set_shared;
@@ -229,19 +199,19 @@ static void stat_setup(void)*/ rval =sigsuspend (&oldmask);if (rval !=-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"sigsuspend" ); +tst_brk (TBROK |TERRNO ,"sigsuspend" );/* * don't have to block SIGUSR1 any more, * recover the mask */ if (sigprocmask (SIG_SETMASK , &oldmask,NULL ) <0 ) -tst_brkm (TBROK |TERRNO , cleanup, +tst_brk (TBROK |TERRNO ,"child sigprocmask" );/* now we're back - detach the memory and exit */ if (shmdt (test) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup, +tst_brk (TBROK |TERRNO ,"shmdt in stat_setup()" );exit (0 );default :
@@ -252,7 +222,7 @@ static void stat_setup(void)/* parent doesn't have to block SIGUSR1, recover the mask */ if (sigprocmask (SIG_SETMASK , &oldmask,NULL ) <0 ) -tst_brkm (TBROK , cleanup,"parent sigprocmask" ); +tst_brk (TBROK ,"parent sigprocmask" );usleep (250000 ); }
@@ -270,12 +240,12 @@ static void func_stat(void) pid =getpid ();if (buf.shm_cpid != pid) { -tst_resm (TFAIL ,"creator pid is incorrect" ); +tst_res (TFAIL ,"creator pid is incorrect" ); goto fail; }if (buf.shm_segsz != shm_size) { -tst_resm (TFAIL ,"segment size is incorrect" ); +tst_res (TFAIL ,"segment size is incorrect" ); goto fail; }
@@ -286,18 +256,18 @@ static void func_stat(void)* that memory so the attaches equal N_ATTACH + stat_time (1). */ if (buf.shm_nattch !=N_ATTACH + stat_time) { -tst_resm (TFAIL ,"# of attaches is incorrect - %lu" , +tst_res (TFAIL ,"# of attaches is incorrect - %lu" , (unsigned long )buf.shm_nattch); goto fail; }/* use MODE_MASK to make sure we are comparing the last 9 bits */ if ((buf.shm_perm.mode &MODE_MASK ) != ((SHM_RW ) &MODE_MASK )) { -tst_resm (TFAIL ,"segment mode is incorrect" ); +tst_res (TFAIL ,"segment mode is incorrect" ); goto fail; } -tst_resm (TPASS ,"pid, size, # of attaches and mode are correct " +tst_res (TPASS ,"pid, size, # of attaches and mode are correct " "- pass #%d" , stat_time); fail:
@@ -319,15 +289,21 @@ static void stat_cleanup(void)/* wake up the childern so they can detach the memory and exit */ for (i =0 ; i <N_ATTACH ; i++)if (kill (pid_arr[i],SIGUSR1 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"kill with SIGUSR1" ); +tst_brk (TBROK |TERRNO ,"kill with SIGUSR1" );/* remove the parent's shared memory the second time through */ if (stat_time ==SECOND )if (shmdt (set_shared) ==-1 ) -tst_resm (TBROK |TERRNO ,"shmdt in stat_cleanup()" ); +tst_res (TBROK |TERRNO ,"shmdt in stat_cleanup()" ); stat_time++; } +static void sighandler (int sig) +{ +if (sig !=SIGUSR1 ) +tst_res (TFAIL ,"received unexpected signal %d" , sig); +} +/* * set_setup() - set up for the IPC_SET command with shmctl() */
@@ -347,21 +323,21 @@ static void func_set(void) {/* first stat the shared memory to get the new data */ if (shmctl (shm_id_1,IPC_STAT , &buf) ==-1 ) { -tst_resm (TBROK |TERRNO ,"shmctl in func_set()" ); +tst_res (TBROK |TERRNO ,"shmctl in func_set()" );return ; }if ((buf.shm_perm.mode &MODE_MASK ) != ((SHM_RW |NEWMODE ) &MODE_MASK )) { -tst_resm (TFAIL ,"new mode is incorrect" ); +tst_res (TFAIL ,"new mode is incorrect" );return ; }if (save_time >= buf.shm_ctime) { -tst_resm (TFAIL ,"change time is incorrect" ); +tst_res (TFAIL ,"change time is incorrect" );return ; } -tst_resm (TPASS ,"new mode and change time are correct" ); +tst_res (TPASS ,"new mode and change time are correct" ); }/*
@@ -371,31 +347,24 @@ static void func_rmid(void) {/* Do another shmctl() - we should get EINVAL */ if (shmctl (shm_id_1,IPC_STAT , &buf) !=-1 ) -tst_brkm (TBROK , cleanup,"shmctl in func_rmid() " +tst_brk (TBROK ,"shmctl in func_rmid() " "succeeded unexpectedly" );if (errno !=EINVAL ) -tst_resm (TFAIL |TERRNO ,"shmctl in func_rmid() failed " +tst_res (TFAIL |TERRNO ,"shmctl in func_rmid() failed " "unexpectedly - expect errno=EINVAL, got" );else -tst_resm (TPASS ,"shmctl in func_rmid() failed as expected, " +tst_res (TPASS ,"shmctl in func_rmid() failed as expected, " "shared memory appears to be removed" ); shm_id_1 =-1 ; } -static void sighandler (int sig) -{ -if (sig !=SIGUSR1 ) -tst_resm (TFAIL ,"received unexpected signal %d" , sig); -} -void setup (void ) {long hpage_size; -tst_require_root ();check_hugepage (); -tst_sig (FORK , sighandler, cleanup); -tst_tmpdir (); +if (nr_opt) + hugepages =SAFE_STRTOL (nr_opt,0 ,LONG_MAX ); orig_hugepages =get_sys_tune ("nr_hugepages" );set_sys_tune ("nr_hugepages" , hugepages,1 );
@@ -403,16 +372,21 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); - shmkey =getipckey (cleanup); - -TEST_PAUSE ; + shmkey =getipckey (); }void cleanup (void ) {rm_shm (shm_id_1); -set_sys_tune ("nr_hugepages" , orig_hugepages,0 ); - -tst_rmdir (); } + +static struct tst_test test = { + .tid ="hugeshmctl01" , + .needs_root =1 , + .needs_tmpdir =1 , + .options = options, + .setup = setup, + .cleanup = cleanup, + .test_all = test_hugeshmctl, +};
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c +58 -93
216 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c +57 -90
227 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 9/13 mm/hugeshmdt: convert to new API
--- .../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c | 122 ++++++++------------- 1 file changed, 46 insertions(+), 76 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c +46 -76
@@ -1,26 +1,19 @@/* +* Copyright (c) International Business Machines Corp., 2004 +* Copyright (c) Linux Test Project, 2004-2017 * -* Copyright (c) International Business Machines Corp., 2004 +* 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 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 +* 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. */ /* -* NAME -* hugeshmdt01.c -* * DESCRIPTION * hugeshmdt01 - check that largr shared memory is detached correctly *
@@ -41,29 +34,14 @@* issue a FAIL message * call cleanup * -* USAGE: <for command-line> -* hugeshmdt01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* * HISTORY * 03/2001 - Written by Wayne Boyer * 04/2004 - Updated by Robbie Williamson -* -* RESTRICTIONS -* none */ #include <setjmp.h> -#include "hugetlb.h" -#include "safe_macros.h" #include "mem.h" - -char *TCID ="hugeshmdt01" ; -int TST_TOTAL =1 ; +#include "hugetlb.h" static size_t shm_size;static int shm_id_1 =-1 ;
@@ -73,54 +51,43 @@ static int pass;static sigjmp_buf env;static long hugepages =128 ; -static option_t options[] = { - {"s:" , &sflag, &nr_opt}, +static struct tst_option options[] = { + {"s:" , &nr_opt,"-s num Set the number of the been allocated hugepages" }, {NULL ,NULL ,NULL } };static void check_functionality (void );static void sighandler (int sig); -int main (int ac,char **av) +static void hugeshmdt_test (void ) { -int lc; - -tst_parse_opts (ac, av, options,NULL ); - -if (sflag) - hugepages =SAFE_STRTOL (NULL , nr_opt,0 ,LONG_MAX ); +struct sigaction sa; -setup (); + sa.sa_handler = sighandler; +sigaction (SIGSEGV , &sa,NULL ); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -if (shmdt (shared) ==-1 ) { -tst_resm (TFAIL |TERRNO ,"shmdt" ); - }else { -check_functionality (); - } +if (shmdt (shared) ==-1 ) +tst_res (TFAIL |TERRNO ,"shmdt" ); +else +check_functionality (); -/* reattach the shared memory segment in case we are looping */ - shared =shmat (shm_id_1,0 ,0 ); -if (shared == (void *)-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmat #2: reattach" ); +/* reattach the shared memory segment in case we are looping */ + shared =shmat (shm_id_1,0 ,0 ); +if (shared == (void *)-1 ) +tst_brk (TBROK |TERRNO ,"shmat #2: reattach" ); -/* also reset pass */ - pass =0 ; - } -cleanup (); -tst_exit (); +/* also reset pass */ + pass =0 ; }static void check_functionality (void ) {/* stat the shared memory segment */ if (shmctl (shm_id_1,IPC_STAT , &buf) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmctl" ); +tst_brk (TBROK |TERRNO ,"shmctl" );if (buf.shm_nattch !=0 ) { -tst_resm (TFAIL ,"# of attaches is incorrect" ); +tst_res (TFAIL ,"# of attaches is incorrect" );return ; }
@@ -142,9 +109,9 @@ static void check_functionality(void) *shared =2 ;if (pass) -tst_resm (TPASS ,"huge shared memory detached correctly" ); +tst_res (TPASS ,"huge shared memory detached correctly" );else -tst_resm (TFAIL ,"huge shared memory was not detached " +tst_res (TFAIL ,"huge shared memory was not detached " "correctly" ); }
@@ -156,7 +123,7 @@ static void sighandler(int sig) pass =1 ;siglongjmp (env,1 ); }else { -tst_brkm (TBROK , cleanup,"unexpected signal received: %d" , sig); +tst_brk (TBROK ,"unexpected signal received: %d" , sig); } }
@@ -164,10 +131,9 @@ void setup(void) {long hpage_size; -tst_require_root ();check_hugepage (); -tst_sig (NOFORK , sighandler, cleanup); -tst_tmpdir (); +if (nr_opt) + hugepages =SAFE_STRTOL (nr_opt,0 ,LONG_MAX ); orig_hugepages =get_sys_tune ("nr_hugepages" );set_sys_tune ("nr_hugepages" , hugepages,1 );
@@ -175,30 +141,34 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); - shmkey =getipckey (cleanup); + shmkey =getipckey ();/* create a shared memory resource with read and write permissions */ shm_id_1 =shmget (shmkey, shm_size,SHM_HUGETLB |SHM_RW |IPC_CREAT |IPC_EXCL );if (shm_id_1 ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmget" ); +tst_brk (TBROK |TERRNO ,"shmget" );/* attach the shared memory segment */ shared =shmat (shm_id_1,0 ,0 );if (shared == (void *)-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"shmat #1" ); +tst_brk (TBROK |TERRNO ,"shmat #1" );/* give a value to the shared memory integer */ *shared =4 ; - -TEST_PAUSE ; }void cleanup (void ) {rm_shm (shm_id_1); -set_sys_tune ("nr_hugepages" , orig_hugepages,0 ); - -tst_rmdir (); } + +static struct tst_test test = { + .tid ="hugeshmdt01" , + .needs_root =1 , + .options = options, + .setup = setup, + .cleanup = cleanup, + .test_all = hugeshmdt_test, +};
Signature · 1 line
2.9.3
RFC PATCH 10/13 mem/hugeshmget: convert to new API
--- .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c | 166 ++++++++------------- .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c | 153 +++++++------------ .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 116 +++++--------- .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c | 119 +++++---------- 4 files changed, 202 insertions(+), 352 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c +62 -104
@@ -1,26 +1,19 @@/* +* Copyright (c) International Business Machines Corp., 2004 +* Copyright (c) Linux Test Project, 2004-2017 * -* Copyright (c) International Business Machines Corp., 2004 +* 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 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 +* 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. */ /* -* NAME -* hugeshmget01.c -* * DESCRIPTION * hugeshmget01 - test that shmget() correctly creates a large * shared memory segment
@@ -41,111 +34,67 @@* else issue a PASS message * call cleanup * -* USAGE: <for command-line> -* shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* * HISTORY * 03/2001 - Written by Wayne Boyer * 04/2004 - Updated by Robbie Williamson -* -* RESTRICTIONS -* none */ -#include "hugetlb.h" -#include "safe_macros.h" #include "mem.h" - -char *TCID ="hugeshmget01" ; -int TST_TOTAL =1 ; +#include "hugetlb.h" static size_t shm_size;static int shm_id_1 =-1 ;static long hugepages =128 ; -static option_t options[] = { - {"s:" , &sflag, &nr_opt}, +static struct tst_option options[] = { + {"s:" , &nr_opt,"-s num Set the number of the been allocated hugepages" }, {NULL ,NULL ,NULL } }; -int main (int ac,char **av) +static void test_hugeshmget (void ) { -int lc;struct shmid_ds buf; -tst_parse_opts (ac, av, options,NULL ); - -if (sflag) - hugepages =SAFE_STRTOL (NULL , nr_opt,0 ,LONG_MAX ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - - shm_id_1 =shmget (shmkey, shm_size, -SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); -if (shm_id_1 ==-1 ) { -tst_resm (TFAIL |TERRNO ,"shmget" ); - }else { -/* do a STAT and check some info */ -if (shmctl (shm_id_1,IPC_STAT , &buf) ==-1 ) { -tst_resm (TBROK |TERRNO , -"shmctl(IPC_STAT)" ); -continue ; - } -/* check the seqment size */ -if (buf.shm_segsz != shm_size) { -tst_resm (TFAIL ,"seqment size is not " -"correct" ); -continue ; - } -/* check the pid of the creator */ -if (buf.shm_cpid !=getpid ()) { -tst_resm (TFAIL ,"creator pid is not " -"correct" ); -continue ; - } -/* -* check the mode of the seqment -* mask out all but the lower 9 bits -*/ -if ((buf.shm_perm.mode &MODE_MASK ) != - ((SHM_RW ) &MODE_MASK )) { -tst_resm (TFAIL ,"segment mode is not " -"correct" ); -continue ; - } -/* if we get here, everything looks good */ -tst_resm (TPASS ,"size, pid & mode are correct" ); - } - -/* -* clean up things in case we are looping -*/ -if (shmctl (shm_id_1,IPC_RMID ,NULL ) ==-1 ) -tst_resm (TBROK |TERRNO ,"shmctl(IPC_RMID)" ); -else - shm_id_1 =-1 ; +/* do a STAT and check some info */ +if (shmctl (shm_id_1,IPC_STAT , &buf) ==-1 ) { +tst_res (TFAIL |TERRNO , +"shmctl(IPC_STAT)" ); +return ; + } +/* check the seqment size */ +if (buf.shm_segsz != shm_size) { +tst_res (TFAIL ,"seqment size is not " +"correct" ); +return ; + } +/* check the pid of the creator */ +if (buf.shm_cpid !=getpid ()) { +tst_res (TFAIL ,"creator pid is not " +"correct" ); +return ; + } +/* +* check the mode of the seqment +* mask out all but the lower 9 bits +*/ +if ((buf.shm_perm.mode &MODE_MASK ) != + ((SHM_RW ) &MODE_MASK )) { +tst_res (TFAIL ,"segment mode is not " +"correct" ); +return ; } -cleanup (); -tst_exit (); + +/* if we get here, everything looks good */ +tst_res (TPASS ,"size, pid & mode are correct" ); } -void setup (void ) +static void setup (void ) {long hpage_size; -tst_require_root ();check_hugepage (); -tst_sig (NOFORK ,DEF_HANDLER , cleanup); -tst_tmpdir (); +if (nr_opt) + hugepages =SAFE_STRTOL (nr_opt,0 ,LONG_MAX ); orig_hugepages =get_sys_tune ("nr_hugepages" );set_sys_tune ("nr_hugepages" , hugepages,1 );
@@ -153,16 +102,25 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); - shmkey =getipckey (cleanup); + shmkey =getipckey (); -TEST_PAUSE ; + shm_id_1 =shmget (shmkey, shm_size, +SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); +if (shm_id_1 ==-1 ) +tst_brk (TBROK |TERRNO ,"shmget" ); } -void cleanup (void ) +static void cleanup (void ) {rm_shm (shm_id_1); -set_sys_tune ("nr_hugepages" , orig_hugepages,0 ); - -tst_rmdir (); } + +static struct tst_test test = { + .tid ="hugeshmget01" , + .needs_root =1 , + .options = options, + .setup = setup, + .cleanup = cleanup, + .test_all = test_hugeshmget, +};
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c +58 -95
216 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +41 -75
176 lines not on this page · raw message
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c +41 -78
192 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 11/13 mem/cpuset: convert to new API
--- testcases/kernel/mem/cpuset/cpuset01.c | 155 ++++++++++++--------------------- 1 file changed, 58 insertions(+), 97 deletions(-)
testcases/kernel/mem/cpuset/cpuset01.c +58 -97
@@ -1,4 +1,16 @@/* +* Copyright (C) 2010-2017 Red Hat, Inc. +* +* 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. +* * Out Of Memory when changing cpuset's mems on NUMA. There was a * problem reported upstream that the allocator may see an empty * nodemask when changing cpuset's mems.
@@ -6,55 +18,18 @@* http://lkml.org/lkml/2010/5/4/79 * http://lkml.org/lkml/2010/5/4/80 * This test is based on the reproducers for the above issue. -* -* Copyright (C) 2010 Red Hat, Inc. -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. */ +#include "config.h" -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/stat.h> +#include <stdio.h> #include <sys/wait.h> -#include <ctype.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <math.h> #if HAVE_NUMAIF_H #include <numaif.h> #endif -#include <signal.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "test.h" #include "mem.h" #include "numa_helper.h" -char *TCID ="cpuset01" ; -int TST_TOTAL =1 ; -#if HAVE_NUMA_H &&HAVE_LINUX_MEMPOLICY_H &&HAVE_NUMAIF_H \ &&HAVE_MPOL_CONSTANTS volatile int end;
@@ -62,32 +37,13 @@ static int *nodes;static int nnodes;static long ncpus; -static void testcpuset (void ); static void sighandler(int signo LTP_ATTRIBUTE_UNUSED);static int mem_hog (void );static int mem_hog_cpuset (int ntasks);static long count_cpu (void ); -int main (int argc,char *argv[]) -{ - -tst_parse_opts (argc, argv,NULL ,NULL ); - - ncpus =count_cpu (); -if (get_allowed_nodes_arr (NH_MEMS |NH_CPUS , &nnodes, &nodes) <0 ) -tst_brkm (TBROK |TERRNO ,NULL ,"get_allowed_nodes_arr" ); -if (nnodes <=1 ) -tst_brkm (TCONF ,NULL ,"requires a NUMA system." ); - -setup (); -testcpuset (); -cleanup (); -tst_exit (); -} - -static void testcpuset (void ) +static void test_cpuset (void ) { -int lc;int child, i, status;unsigned long nmask[MAXNODES /BITS_PER_LONG ] = {0 };char mems[BUFSIZ ], buf[BUFSIZ ];
@@ -96,11 +52,11 @@ static void testcpuset(void)write_cpuset_files (CPATH_NEW ,"cpus" , buf);read_cpuset_files (CPATH ,"mems" , mems);write_cpuset_files (CPATH_NEW ,"mems" , mems); -SAFE_FILE_PRINTF (cleanup,CPATH_NEW "/tasks" ,"%d" ,getpid ()); +SAFE_FILE_PRINTF (CPATH_NEW "/tasks" ,"%d" ,getpid ());switch (child =fork ()) {case -1 : -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 :for (i =0 ; i < nnodes; i++) {if (nodes[i] >=MAXNODES )
@@ -108,37 +64,36 @@ static void testcpuset(void)set_node (nmask, nodes[i]); }if (set_mempolicy (MPOL_BIND , nmask,MAXNODES ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"set_mempolicy" ); +tst_brk (TBROK |TERRNO ,"set_mempolicy" );exit (mem_hog_cpuset (ncpus >1 ? ncpus :1 )); } -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -snprintf (buf,BUFSIZ ,"%d" , nodes[0 ]); -write_cpuset_files (CPATH_NEW ,"mems" , buf); -snprintf (buf,BUFSIZ ,"%d" , nodes[1 ]); -write_cpuset_files (CPATH_NEW ,"mems" , buf); - } + +snprintf (buf,BUFSIZ ,"%d" , nodes[0 ]); +write_cpuset_files (CPATH_NEW ,"mems" , buf); +snprintf (buf,BUFSIZ ,"%d" , nodes[1 ]); +write_cpuset_files (CPATH_NEW ,"mems" , buf);if (waitpid (child, &status,WUNTRACED |WCONTINUED ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); -if (WEXITSTATUS (status) !=0 ) -tst_resm (TFAIL ,"child exit status is %d" ,WEXITSTATUS (status)); +tst_brk (TBROK |TERRNO ,"waitpid" ); +if (WEXITSTATUS (status) !=0 ) { +tst_res (TFAIL ,"child exit status is %d" ,WEXITSTATUS (status)); +return ; + } + +tst_res (TPASS ,"cpuset test pass" ); } -void setup (void ) +static void setup (void ) { -tst_require_root (); - -if (tst_kvercmp (2 ,6 ,32 ) <0 ) -tst_brkm (TCONF ,NULL ,"2.6.32 or greater kernel required" ); - -tst_sig (FORK ,DEF_HANDLER , cleanup); -TEST_PAUSE ; -mount_mem ("cpuset" ,"cpuset" ,NULL ,CPATH ,CPATH_NEW ); + ncpus =count_cpu (); +if (get_allowed_nodes_arr (NH_MEMS |NH_CPUS , &nnodes, &nodes) <0 ) +tst_brk (TBROK |TERRNO ,"get_allowed_nodes_arr" ); +if (nnodes <=1 ) +tst_brk (TCONF ,"requires a NUMA system." ); } -void cleanup (void ) +static void cleanup (void ) {umount_mem (CPATH ,CPATH_NEW ); }
@@ -160,7 +115,7 @@ static int mem_hog(void) MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);if (addr ==MAP_FAILED ) { ret =1 ; -tst_resm (TFAIL |TERRNO ,"mmap" ); +tst_res (TFAIL |TERRNO ,"mmap" );break ; }memset (addr,0xF7 , pagesize *10 );
@@ -171,26 +126,26 @@ static int mem_hog(void)static int mem_hog_cpuset (int ntasks) { -int i, lc, status, ret =0 ; +int i, status, ret =0 ;struct sigaction sa;pid_t *pids;if (ntasks <=0 ) -tst_brkm (TBROK |TERRNO , cleanup,"ntasks is small." ); +tst_brk (TBROK |TERRNO ,"ntasks is small." ); sa.sa_handler = sighandler;if (sigemptyset (&sa.sa_mask) <0 ) -tst_brkm (TBROK |TERRNO , cleanup,"sigemptyset" ); +tst_brk (TBROK |TERRNO ,"sigemptyset" ); sa.sa_flags =0 ;if (sigaction (SIGUSR1 , &sa,NULL ) <0 ) -tst_brkm (TBROK |TERRNO , cleanup,"sigaction" ); +tst_brk (TBROK |TERRNO ,"sigaction" ); pids =malloc (sizeof (pid_t) * ntasks);if (pids ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"malloc" ); +tst_brk (TBROK |TERRNO ,"malloc" );for (i =0 ; i < ntasks; i++) {switch (pids[i] =fork ()) {case -1 : -tst_resm (TFAIL |TERRNO ,"fork %d" , pids[i]); +tst_res (TFAIL |TERRNO ,"fork %d" , pids[i]); ret =1 ;break ;case 0 :
@@ -200,22 +155,22 @@ static int mem_hog_cpuset(int ntasks)break ; } } -for (lc =0 ;TEST_LOOPING (lc); lc++) ; +while (i--) {if (kill (pids[i],SIGUSR1 ) ==-1 ) { -tst_resm (TFAIL |TERRNO ,"kill %d" , pids[i]); +tst_res (TFAIL |TERRNO ,"kill %d" , pids[i]); ret =1 ; } }while (waitpid (-1 , &status,WUNTRACED |WCONTINUED ) >0 ) {if (WIFEXITED (status)) {if (WEXITSTATUS (status) !=0 ) { -tst_resm (TFAIL ,"child exit status is %d" , +tst_res (TFAIL ,"child exit status is %d" ,WEXITSTATUS (status)); ret =1 ; } }else if (WIFSIGNALED (status)) { -tst_resm (TFAIL ,"child caught signal %d" , +tst_res (TFAIL ,"child caught signal %d" ,WTERMSIG (status)); ret =1 ; }
@@ -233,9 +188,15 @@ static long count_cpu(void) return ncpus; } +static struct tst_test test = { + .tid ="cpuset01" , + .needs_root =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = test_cpuset, + .min_kver ="2.6.32" , +}; +#else /* no NUMA */ -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"no NUMA development packages installed." ); -} +TST_TEST_TCONF ("no NUMA development packages installed." );#endif
Signature · 1 line
2.9.3
RFC PATCH 12/13 mem/swapping: convert to new API
--- testcases/kernel/mem/swapping/swapping01.c | 94 ++++++++++-------------------- 1 file changed, 32 insertions(+), 62 deletions(-)
testcases/kernel/mem/swapping/swapping01.c +32 -62
@@ -1,24 +1,15 @@/* -* Copyright (C) 2012 Red Hat, Inc. -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. +* Copyright (C) 2012-2017 Red Hat, Inc. * -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* 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. * -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. +* 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. */ /* * swapping01 - first time swap use results in heavy swapping
@@ -53,12 +44,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "test.h" #include "mem.h" -char *TCID ="swapping01" ; -int TST_TOTAL =1 ; -/* allow swapping 1 * phy_mem in maximum */ #define COE_DELTA 1/* will try to alloc 1.3 * phy_mem */
@@ -74,41 +61,29 @@ static long mem_over;static long mem_over_max;static pid_t pid; -int main (int argc,char *argv[]) +static void test_swapping (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); -#if __WORDSIZE ==32 -tst_brkm (TCONF ,NULL ,"test is not designed for 32-bit system." ); +tst_brk (TCONF ,"test is not designed for 32-bit system." );#endif -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -init_meminfo (); +init_meminfo (); -switch (pid =fork ()) { +switch (pid =fork ()) {case -1 : -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 :do_alloc ();exit (0 );default :check_swapping (); - } } -cleanup (); -tst_exit (); }static void init_meminfo (void ) { swap_free_init =read_meminfo ("SwapFree:" ); -if (FILE_LINES_SCANF (cleanup,"/proc/meminfo" ,"MemAvailable: %ld" , +if (FILE_LINES_SCANF ("/proc/meminfo" ,"MemAvailable: %ld" , &mem_available_init)) { mem_available_init =read_meminfo ("MemFree:" ) +read_meminfo ("Cached:" );
@@ -118,10 +93,10 @@ static void init_meminfo(void)/* at least 10MB available physical memory needed */ if (mem_available_init <10240 ) -tst_brkm (TCONF , cleanup,"Not enough available mem to test." ); +tst_brk (TCONF ,"Not enough available mem to test." );if (swap_free_init < mem_over_max) -tst_brkm (TCONF , cleanup,"Not enough swap space to test." ); +tst_brk (TCONF ,"Not enough swap space to test." ); }static void do_alloc (void )
@@ -129,17 +104,17 @@ static void do_alloc(void)long mem_count;void *s; -tst_resm (TINFO ,"available physical memory: %ld MB" , +tst_res (TINFO ,"available physical memory: %ld MB" , mem_available_init /1024 ); mem_count = mem_available_init + mem_over; -tst_resm (TINFO ,"try to allocate: %ld MB" , mem_count /1024 ); +tst_res (TINFO ,"try to allocate: %ld MB" , mem_count /1024 ); s =malloc (mem_count *1024 );if (s ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"malloc" ); +tst_brk (TBROK |TERRNO ,"malloc" );memset (s,1 , mem_count *1024 ); -tst_resm (TINFO ,"memory allocated: %ld MB" , mem_count /1024 ); +tst_res (TINFO ,"memory allocated: %ld MB" , mem_count /1024 );if (raise (SIGSTOP ) ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"kill" ); +tst_brk (TBROK |TERRNO ,"kill" );free (s); }
@@ -150,9 +125,9 @@ static void check_swapping(void)/* wait child stop */ if (waitpid (pid, &status,WUNTRACED ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" );if (!WIFSTOPPED (status)) -tst_brkm (TBROK , cleanup,"child was not stopped." ); +tst_brk (TBROK ,"child was not stopped." );/* Still occupying memory, loop for a while */ i =0 ;
@@ -169,25 +144,20 @@ static void check_swapping(void) swapped = swap_free_init - swap_free_now;if (swapped > mem_over_max) {kill (pid,SIGCONT ); -tst_brkm (TFAIL , cleanup,"heavy swapping detected: " +tst_brk (TFAIL ,"heavy swapping detected: " "%ld MB swapped." , swapped /1024 ); } -tst_resm (TPASS ,"no heavy swapping detected, %ld MB swapped." , +tst_res (TPASS ,"no heavy swapping detected, %ld MB swapped." , swapped /1024 );kill (pid,SIGCONT );/* wait child exit */ if (waitpid (pid, &status,0 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" ); } -void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - -void cleanup (void ) -{ -} +static struct tst_test test = { + .tid ="swapping01" , + .needs_root =1 , + .test_all = test_swapping, +};
Signature · 1 line
2.9.3
RFC PATCH 13/13 mem/tunable: convert to new API
--- testcases/kernel/mem/tunable/max_map_count.c | 104 ++++++---------- testcases/kernel/mem/tunable/min_free_kbytes.c | 111 +++++++---------- testcases/kernel/mem/tunable/overcommit_memory.c | 150 +++++++++-------------- 3 files changed, 140 insertions(+), 225 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +37 -67
@@ -1,4 +1,18 @@/* +* Copyright (C) 2012-2017 Red Hat, Inc. +* +* 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. +* +* Description: +* * The program is designed to test max_map_count tunable file * * The kernel Documentation say that:
@@ -24,32 +38,8 @@* ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] * * so we ignore this line during /proc/[pid]/maps reading. -* -* ******************************************************************** -* Copyright (C) 2012 Red Hat, Inc. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. -* -* ******************************************************************** */ +#define _GNU_SOURCE#include <sys/types.h> #include <sys/mman.h>
@@ -60,47 +50,19 @@#include <stdio.h> #include <stdlib.h> #include <sys/utsname.h> -#include "test.h" #include "mem.h" #define MAP_COUNT_DEFAULT 1024#define MAX_MAP_COUNT 65536L -char *TCID ="max_map_count" ; -int TST_TOTAL =1 ; -static long old_max_map_count;static long old_overcommit;static struct utsname un; -static long count_maps (pid_t pid); -static void max_map_count_test (void ); - -int main (int argc,char *argv[]) +static void setup (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -max_map_count_test (); - } - -cleanup (); -tst_exit (); -} - -void setup (void ) -{ -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); -TEST_PAUSE ; -if (access (PATH_SYSVM "max_map_count" ,F_OK ) !=0 ) -tst_brkm (TBROK |TERRNO ,NULL , +tst_brk (TBROK |TERRNO ,"Can't support to test max_map_count" ); old_max_map_count =get_sys_tune ("max_map_count" );
@@ -108,10 +70,10 @@ void setup(void)set_sys_tune ("overcommit_memory" ,2 ,1 );if (uname (&un) !=0 ) -tst_brkm (TBROK |TERRNO ,NULL ,"uname error" ); +tst_brk (TBROK |TERRNO ,"uname error" ); } -void cleanup (void ) +static void cleanup (void ) {set_sys_tune ("overcommit_memory" , old_overcommit,0 );set_sys_tune ("max_map_count" , old_max_map_count,0 );
@@ -162,7 +124,7 @@ static long count_maps(pid_t pid)snprintf (buf,BUFSIZ ,"/proc/%d/maps" , pid); fp =fopen (buf,"r" );if (fp ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"fopen %s" , buf); +tst_brk (TBROK |TERRNO ,"fopen %s" , buf);while (getline (&line, &len, fp) !=-1 ) {/* exclude vdso and vsyscall */ if (filter_map (line))
@@ -210,24 +172,24 @@ static void max_map_count_test(void)while (max_maps <= max_iters) {set_sys_tune ("max_map_count" , max_maps,1 ); -switch (pid =tst_fork ()) { +switch (pid =fork ()) {case -1 : -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 :while (mmap (NULL ,1 ,PROT_READ ,MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ) !=MAP_FAILED ) ;if (raise (SIGSTOP ) !=0 ) -tst_brkm (TBROK |TERRNO , tst_exit,"raise" ); +tst_brk (TBROK |TERRNO ,"raise" );exit (0 );default :break ; }/* wait child done mmap and stop */ if (waitpid (pid, &status,WUNTRACED ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" );if (!WIFSTOPPED (status)) -tst_brkm (TBROK , cleanup,"child did not stopped" ); +tst_brk (TBROK ,"child did not stopped" ); map_count =count_maps (pid);/* Note max_maps will be exceeded by one for
@@ -236,18 +198,26 @@ static void max_map_count_test(void)* writing this COMMENT! */ if (map_count == (max_maps +1 )) -tst_resm (TPASS ,"%ld map entries in total " +tst_res (TPASS ,"%ld map entries in total " "as expected." , max_maps);else -tst_resm (TFAIL ,"%ld map entries in total, but " +tst_res (TFAIL ,"%ld map entries in total, but " "expected %ld entries" , map_count, max_maps);/* make child continue to exit */ if (kill (pid,SIGCONT ) !=0 ) -tst_brkm (TBROK |TERRNO , cleanup,"kill" ); +tst_brk (TBROK |TERRNO ,"kill" );if (waitpid (pid, &status,0 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" ); max_maps = max_maps <<1 ; } } + +static struct tst_test test = { + .tid ="max_map_count" , + .needs_root =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = max_map_count_test, +};
testcases/kernel/mem/tunable/min_free_kbytes.c +46 -65
221 lines not on this page · raw message
testcases/kernel/mem/tunable/overcommit_memory.c +57 -93
247 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH 1/13 mem/lib: convert to new API
In reply to Li WangHi!
Quoted 23 lines
testcases/kernel/mem/lib/mem.c +3
-3@@ -88,7 +90,7 @@ static void child_alloc(int testcase, int lite, int threads)TEST (pthread_create (&th[i],NULL , child_alloc_thread, (void *)((long )testcase)));if (TEST_RETURN ) { -tst_resm (TINFO |TRERRNO ,"pthread_create" ); +tst_res (TINFO |TRERRNO ,"pthread_create" );/* * Keep going if thread other than first fails to * spawn due to lack of resources. @@ -128,10 +130,10 @@ void oom(int testcase, int lite, int retcode, int allow_sigkill)switch (pid =fork ()) {case -1 :if (errno == retcode) { -tst_resm (TPASS |TERRNO ,"fork" ); +tst_res (TPASS |TERRNO ,"fork" );return ; } -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 : threads =MAX (1 ,tst_ncpus () -1 );child_alloc (testcase, lite, threads);
testcases/kernel/mem/lib/mem.c void oom(int testcase, int lite, int retcode, int allow_sigkill) · line 142
Quoted 2 lines
testcases/kernel/mem/lib/mem.c +0
-0@@ -139,31 +141,31 @@ void oom(int testcase, int lite, int retcode, int allow_sigkill)break ; }
We have SAFE_FORK()
testcases/kernel/mem/lib/mem.c void oom(int testcase, int lite, int retcode, int allow_sigkill) · line 146
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +2
-2-tst_resm (TINFO ,"expected victim is %d." , pid); +tst_res (TINFO ,"expected victim is %d." , pid);if (waitpid (-1 , &status,0 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" );
And SAFE_WAITPID()
Quoted 164 lines
testcases/kernel/mem/lib/mem.c +28
-36if (WIFSIGNALED (status)) {if (allow_sigkill &&WTERMSIG (status) ==SIGKILL ) { -tst_resm (TPASS ,"victim signalled: (%d) %s" , +tst_res (TPASS ,"victim signalled: (%d) %s" ,SIGKILL ,tst_strsig (SIGKILL )); }else { -tst_resm (TFAIL ,"victim signalled: (%d) %s" , +tst_res (TFAIL ,"victim signalled: (%d) %s" ,WTERMSIG (status),tst_strsig (WTERMSIG (status))); } }else if (WIFEXITED (status)) {if (WEXITSTATUS (status) == retcode) { -tst_resm (TPASS ,"victim retcode: (%d) %s" , +tst_res (TPASS ,"victim retcode: (%d) %s" , retcode,strerror (retcode)); }else { -tst_resm (TFAIL ,"victim unexpectedly ended with " +tst_res (TFAIL ,"victim unexpectedly ended with " "retcode: %d, expected: %d" ,WEXITSTATUS (status), retcode); } }else { -tst_resm (TFAIL ,"victim unexpectedly ended" ); +tst_res (TFAIL ,"victim unexpectedly ended" ); } }@@ -178,10 +180,9 @@ static void set_global_mempolicy(int mempolicy)if (mempolicy) { ret =get_allowed_nodes_arr (NH_MEMS |NH_CPUS , &num_nodes, &nodes);if (ret !=0 ) -tst_brkm (TBROK |TERRNO , cleanup, -"get_allowed_nodes_arr" ); +tst_brk (TBROK |TERRNO ,"get_allowed_nodes_arr" );if (num_nodes <2 ) { -tst_resm (TINFO ,"mempolicy need NUMA system support" ); +tst_res (TINFO ,"mempolicy need NUMA system support" );free (nodes);return ; }@@ -193,7 +194,7 @@ static void set_global_mempolicy(int mempolicy)case MPOL_INTERLEAVE :case MPOL_PREFERRED :if (num_nodes ==2 ) { -tst_resm (TINFO ,"The mempolicy need " +tst_res (TINFO ,"The mempolicy need " "more than 2 numa nodes" );free (nodes);return ;@@ -204,10 +205,10 @@ static void set_global_mempolicy(int mempolicy) }break ;default : -tst_brkm (TBROK |TERRNO , cleanup,"Bad mempolicy mode" ); +tst_brk (TBROK |TERRNO ,"Bad mempolicy mode" ); }if (set_mempolicy (mempolicy, nmask,MAXNODES ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"set_mempolicy" ); +tst_brk (TBROK |TERRNO ,"set_mempolicy" ); }#endif }@@ -218,10 +219,10 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)set_global_mempolicy (mempolicy); -tst_resm (TINFO ,"start normal OOM testing." ); +tst_res (TINFO ,"start normal OOM testing." );oom (NORMAL , lite, retcode, allow_sigkill); -tst_resm (TINFO ,"start OOM testing for mlocked pages." ); +tst_res (TINFO ,"start OOM testing for mlocked pages." );oom (MLOCK , lite, retcode, allow_sigkill);/* @@ -229,14 +230,14 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)* run to run, which isn't reliable for oom03 cgroup test. */ if (access (PATH_KSM ,F_OK ) ==-1 || lite ==1 ) { -tst_resm (TINFO ,"KSM is not configed or lite == 1, " +tst_res (TINFO ,"KSM is not configed or lite == 1, " "skip OOM test for KSM pags" ); }else { -tst_resm (TINFO ,"start OOM testing for KSM pages." ); -SAFE_FILE_SCANF (cleanup,PATH_KSM "run" ,"%d" , &ksm_run_orig); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"1" ); +tst_res (TINFO ,"start OOM testing for KSM pages." ); +SAFE_FILE_SCANF (PATH_KSM "run" ,"%d" , &ksm_run_orig); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" );oom (KSM , lite, retcode, allow_sigkill); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"%d" , ksm_run_orig); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"%d" , ksm_run_orig); } }@@ -247,8 +248,8 @@ static int max_page_sharing;void save_max_page_sharing (void ) {if (access (PATH_KSM "max_page_sharing" ,F_OK ) ==0 ) -SAFE_FILE_SCANF (NULL ,PATH_KSM "max_page_sharing" , -"%d" , &max_page_sharing); +SAFE_FILE_SCANF (PATH_KSM "max_page_sharing" , +"%d" , &max_page_sharing); }void restore_max_page_sharing (void )@@ -264,11 +265,11 @@ static void check(char *path, long int value)long actual_val;snprintf (fullpath,BUFSIZ ,PATH_KSM "%s" , path); -SAFE_FILE_SCANF (cleanup, fullpath,"%ld" , &actual_val); +SAFE_FILE_SCANF (fullpath,"%ld" , &actual_val); -tst_resm (TINFO ,"%s is %ld." , path, actual_val); +tst_res (TINFO ,"%s is %ld." , path, actual_val);if (actual_val != value) -tst_resm (TFAIL ,"%s is not %ld." , path, value); +tst_res (TFAIL ,"%s is not %ld." , path, value); }static void wait_ksmd_done (void )@@ -282,17 +283,10 @@ static void wait_ksmd_done(void)sleep (10 ); count++; -SAFE_FILE_SCANF (cleanup,PATH_KSM "pages_shared" , -"%ld" , &pages_shared); - -SAFE_FILE_SCANF (cleanup,PATH_KSM "pages_sharing" , -"%ld" , &pages_sharing); - -SAFE_FILE_SCANF (cleanup,PATH_KSM "pages_volatile" , -"%ld" , &pages_volatile); - -SAFE_FILE_SCANF (cleanup,PATH_KSM "pages_unshared" , -"%ld" , &pages_unshared); +SAFE_FILE_SCANF (PATH_KSM "pages_shared" ,"%ld" , &pages_shared); +SAFE_FILE_SCANF (PATH_KSM "pages_sharing" ,"%ld" , &pages_sharing); +SAFE_FILE_SCANF (PATH_KSM "pages_volatile" ,"%ld" , &pages_volatile); +SAFE_FILE_SCANF (PATH_KSM "pages_unshared" ,"%ld" , &pages_unshared); if (pages_shared != old_pages_shared || pages_sharing != old_pages_sharing ||@@ -307,7 +301,7 @@ static void wait_ksmd_done(void) } } -tst_resm (TINFO ,"ksm daemon takes %ds to scan all mergeable pages" , +tst_res (TINFO ,"ksm daemon takes %ds to scan all mergeable pages" , count *10 ); }@@ -318,7 +312,7 @@ static void group_check(int run, int pages_shared, int pages_sharing,/* wait for ksm daemon to scan all mergeable pages. */ wait_ksmd_done (); -tst_resm (TINFO ,"check!" ); +tst_res (TINFO ,"check!" );check ("run" , run);check ("pages_shared" , pages_shared);check ("pages_sharing" , pages_sharing);
testcases/kernel/mem/lib/mem.c static void verify(char **memory, char value, int proc, · line 333
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +1
-1@@ -336,16 +330,16 @@ static void verify(char **memory, char value, int proc, s =malloc ((end - start) * (end2 - start2));if (s ==NULL ) -tst_brkm (TBROK |TERRNO , tst_exit,"malloc" ); +tst_brk (TBROK |TERRNO ,"malloc" );
And SAFE_MALLOC()
Quoted 44 lines
testcases/kernel/mem/lib/mem.c +7
-7-tst_resm (TINFO ,"child %d verifies memory content." , proc); +tst_res (TINFO ,"child %d verifies memory content." , proc);memset (s, value, (end - start) * (end2 - start2));if (memcmp (memory[start], s, (end - start) * (end2 - start2)) !=0 )for (j = start; j < end; j++)for (i = start2; i < end2; i++)if (memory[j][i] != value) -tst_resm (TFAIL ,"child %d has %c at " +tst_res (TFAIL ,"child %d has %c at " "%d,%d,%d." , proc, memory[j][i], proc, j, i);@@ -354,9 +348,9 @@ static void verify(char **memory, char value, int proc,void write_memcg (void ) { -SAFE_FILE_PRINTF (NULL ,MEMCG_LIMIT ,"%ld" ,TESTMEM ); +SAFE_FILE_PRINTF (MEMCG_LIMIT ,"%ld" ,TESTMEM ); -SAFE_FILE_PRINTF (NULL ,MEMCG_PATH_NEW "/tasks" ,"%d" ,getpid ()); +SAFE_FILE_PRINTF (MEMCG_PATH_NEW "/tasks" ,"%d" ,getpid ()); }struct ksm_merge_data {@@ -370,14 +364,14 @@ static void ksm_child_memset(int child_num, int size, int total_unit,int i =0 , j;int unit = size / total_unit; -tst_resm (TINFO ,"child %d continues..." , child_num); +tst_res (TINFO ,"child %d continues..." , child_num);if (ksm_merge_data.mergeable_size == size *MB ) { -tst_resm (TINFO ,"child %d allocates %d MB filled with '%c'" , +tst_res (TINFO ,"child %d allocates %d MB filled with '%c'" , child_num, size, ksm_merge_data.data); }else { -tst_resm (TINFO ,"child %d allocates %d MB filled with '%c'" +tst_res (TINFO ,"child %d allocates %d MB filled with '%c'" " except one page with 'e'" , child_num, size, ksm_merge_data.data); }
testcases/kernel/mem/lib/mem.c static void create_ksm_child(int child_num, int size, int unit, · line 406
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +1
-1@@ -409,16 +403,16 @@ static void create_ksm_child(int child_num, int size, int unit, memory[j] =mmap (NULL , unit *MB ,PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 );if (memory[j] ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , tst_exit,"mmap" ); +tst_brk (TBROK |TERRNO ,"mmap" );
And SAFE_MMAP()
Quoted 35 lines
testcases/kernel/mem/lib/mem.c +6
-6#ifdef HAVE_MADV_MERGEABLE if (madvise (memory[j], unit *MB ,MADV_MERGEABLE ) ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"madvise" ); +tst_brk (TBROK |TERRNO ,"madvise" );#endif } -tst_resm (TINFO ,"child %d stops." , child_num); +tst_res (TINFO ,"child %d stops." , child_num);if (raise (SIGSTOP ) ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"kill" ); +tst_brk (TBROK |TERRNO ,"kill" );fflush (stdout);for (j =0 ; j <4 ; j++) {@@ -428,9 +422,9 @@ static void create_ksm_child(int child_num, int size, int unit,fflush (stdout); -tst_resm (TINFO ,"child %d stops." , child_num); +tst_res (TINFO ,"child %d stops." , child_num);if (raise (SIGSTOP ) ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"kill" ); +tst_brk (TBROK |TERRNO ,"kill" );if (ksm_merge_data[j].mergeable_size < size *MB ) { verify(memory, 'e', child_num, total_unit - 1,@@ -443,19 +437,19 @@ static void create_ksm_child(int child_num, int size, int unit, } } -tst_resm (TINFO ,"child %d finished." , child_num); +tst_res (TINFO ,"child %d finished." , child_num); }
testcases/kernel/mem/lib/mem.c static void create_ksm_child(int child_num, int size, int unit, · line 450
Quoted 10 lines
testcases/kernel/mem/lib/mem.c +2
-2static void stop_ksm_children (int *child,int num) {int k, status; -tst_resm (TINFO ,"wait for all children to stop." ); +tst_res (TINFO ,"wait for all children to stop." );for (k =0 ; k < num; k++) {if (waitpid (child[k], &status,WUNTRACED ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"waitpid" ); +tst_brk (TBROK |TERRNO ,"waitpid" );
Again SAFE_WAITPID()
Quoted 7 lines
testcases/kernel/mem/lib/mem.c +1
-1if (!WIFSTOPPED (status)) -tst_brkm (TBROK , cleanup,"child %d was not stopped" , k); +tst_brk (TBROK ,"child %d was not stopped" , k); } }
testcases/kernel/mem/lib/mem.c static void resume_ksm_children(int *child, int num) · line 463
Quoted 9 lines
testcases/kernel/mem/lib/mem.c +2
-2@@ -463,10 +457,10 @@ static void resume_ksm_children(int *child, int num) {int k; -tst_resm (TINFO ,"resume all children." ); +tst_res (TINFO ,"resume all children." );for (k =0 ; k < num; k++) {if (kill (child[k],SIGCONT ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"kill child[%d]" , k); +tst_brk (TBROK |TERRNO ,"kill child[%d]" , k);
And SAFE_KILL()
testcases/kernel/mem/lib/mem.c void create_same_memory(int size, int num, int unit) · line 500
Quoted 9 lines
testcases/kernel/mem/lib/mem.c +1
-1}fflush (stdout); }@@ -503,13 +497,13 @@ void create_same_memory(int size, int num, int unit) child =malloc (num *sizeof (int ));if (child ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"malloc" ); +tst_brk (TBROK |TERRNO ,"malloc" );
Again SAFE_MALLOC()
Quoted 67 lines
testcases/kernel/mem/lib/mem.c +13
-15for (i =0 ; i < num; i++) {fflush (stdout);switch (child[i] =fork ()) {case -1 : -tst_brkm (TBROK |TERRNO , cleanup,"fork" ); +tst_brk (TBROK |TERRNO ,"fork" );case 0 :if (i ==0 ) {create_ksm_child (i, size, unit, ksm_data0);@@ -529,14 +523,12 @@ void create_same_memory(int size, int num, int unit)stop_ksm_children (child, num); -tst_resm (TINFO ,"KSM merging..." ); +tst_res (TINFO ,"KSM merging..." );if (access (PATH_KSM "max_page_sharing" ,F_OK ) ==0 ) -SAFE_FILE_PRINTF (cleanup,PATH_KSM "max_page_sharing" , -"%ld" , size * pages * num); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"1" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "pages_to_scan" ,"%ld" , - size * pages * num); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "sleep_millisecs" ,"0" ); +SAFE_FILE_PRINTF (PATH_KSM "max_page_sharing" ,"%ld" , size * pages * num); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" ); +SAFE_FILE_PRINTF (PATH_KSM "pages_to_scan" ,"%ld" , size * pages * num); +SAFE_FILE_PRINTF (PATH_KSM "sleep_millisecs" ,"0" );resume_ksm_children (child, num);group_check (1 ,2 , size * num * pages -2 ,0 ,0 ,0 , size * pages * num);@@ -555,19 +547,19 @@ void create_same_memory(int size, int num, int unit)stop_ksm_children (child, num); -tst_resm (TINFO ,"KSM unmerging..." ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"2" ); +tst_res (TINFO ,"KSM unmerging..." ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" );resume_ksm_children (child, num);group_check (2 ,0 ,0 ,0 ,0 ,0 , size * pages * num); -tst_resm (TINFO ,"stop KSM." ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"0" ); +tst_res (TINFO ,"stop KSM." ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"0" );group_check (0 ,0 ,0 ,0 ,0 ,0 , size * pages * num);while (waitpid (-1 , &status,WUNTRACED |WCONTINUED ) >0 )if (WEXITSTATUS (status) !=0 ) -tst_resm (TFAIL ,"child exit status is %d" , +tst_res (TFAIL ,"child exit status is %d" ,WEXITSTATUS (status)); }@@ -586,9 +578,9 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages) ret =get_allowed_nodes_arr (NH_MEMS |NH_CPUS , &num_nodes, &nodes);if (ret !=0 ) -tst_brkm (TBROK |TERRNO , cleanup,"get_allowed_nodes_arr" ); +tst_brk (TBROK |TERRNO ,"get_allowed_nodes_arr" );if (num_nodes <2 ) { -tst_resm (TINFO ,"need NUMA system support" ); +tst_res (TINFO ,"need NUMA system support" );free (nodes);return ; }
testcases/kernel/mem/lib/mem.c void test_ksm_merge_across_nodes(unsigned long nr_pages) · line 596
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +1
-1@@ -601,10 +593,10 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages) memory[i] =mmap (NULL , length,PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 );if (memory[i] ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , tst_exit,"mmap" ); +tst_brk (TBROK |TERRNO ,"mmap" );
Again SAFE_MMAP()
Quoted 119 lines
testcases/kernel/mem/lib/mem.c +22
-23#ifdef HAVE_MADV_MERGEABLE if (madvise (memory[i], length,MADV_MERGEABLE ) ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"madvise" ); +tst_brk (TBROK |TERRNO ,"madvise" );#endif #if HAVE_NUMA_H &&HAVE_LINUX_MEMPOLICY_H &&HAVE_NUMAIF_H \@@ -617,17 +609,17 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)*/ ret =mbind (memory[i], length,MPOL_BIND , nmask,MAXNODES ,0 );if (ret ==-1 ) -tst_brkm (TBROK |TERRNO , tst_exit,"mbind" ); +tst_brk (TBROK |TERRNO ,"mbind" );#endif memset (memory[i],10 , length); } -SAFE_FILE_PRINTF (cleanup,PATH_KSM "sleep_millisecs" ,"0" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "pages_to_scan" ,"%ld" , +SAFE_FILE_PRINTF (PATH_KSM "sleep_millisecs" ,"0" ); +SAFE_FILE_PRINTF (PATH_KSM "pages_to_scan" ,"%ld" , nr_pages * num_nodes);if (access (PATH_KSM "max_page_sharing" ,F_OK ) ==0 ) -SAFE_FILE_PRINTF (cleanup,PATH_KSM "max_page_sharing" , +SAFE_FILE_PRINTF (PATH_KSM "max_page_sharing" ,"%ld" , nr_pages * num_nodes);/* * merge_across_nodes setting can be changed only when there @@ -635,23 +627,23 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)* pages first, then to 1 after changing merge_across_nodes, * to remerge according to the new setting. */ -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"2" ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" );wait_ksmd_done (); -tst_resm (TINFO ,"Start to test KSM with merge_across_nodes=1" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "merge_across_nodes" ,"1" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"1" ); +tst_res (TINFO ,"Start to test KSM with merge_across_nodes=1" ); +SAFE_FILE_PRINTF (PATH_KSM "merge_across_nodes" ,"1" ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" );group_check (1 ,1 , nr_pages * num_nodes -1 ,0 ,0 ,0 , nr_pages * num_nodes); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"2" ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" );wait_ksmd_done (); -tst_resm (TINFO ,"Start to test KSM with merge_across_nodes=0" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "merge_across_nodes" ,"0" ); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"1" ); +tst_res (TINFO ,"Start to test KSM with merge_across_nodes=0" ); +SAFE_FILE_PRINTF (PATH_KSM "merge_across_nodes" ,"0" ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" );group_check (1 , num_nodes, nr_pages * num_nodes - num_nodes,0 ,0 ,0 , nr_pages * num_nodes); -SAFE_FILE_PRINTF (cleanup,PATH_KSM "run" ,"2" ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" );wait_ksmd_done (); }@@ -660,22 +652,22 @@ void check_ksm_options(int *size, int *num, int *unit)if (opt_size) { *size =atoi (opt_sizestr);if (*size <1 ) -tst_brkm (TBROK , cleanup,"size cannot be less than 1." ); +tst_brk (TBROK ,"size cannot be less than 1." ); }if (opt_unit) { *unit =atoi (opt_unitstr);if (*unit > *size) -tst_brkm (TBROK , cleanup, +tst_brk (TBROK ,"unit cannot be greater than size." );if (*size % *unit !=0 ) -tst_brkm (TBROK , cleanup, +tst_brk (TBROK ,"the remainder of division of size by unit is " "not zero." ); }if (opt_num) { *num =atoi (opt_numstr);if (*num <3 ) -tst_brkm (TBROK , cleanup, +tst_brk (TBROK ,"process number cannot be less 3." ); } }@@ -712,7 +704,7 @@ static void gather_node_cpus(char *cpus, long nd)* be taken offline */ if (path_exist (path1)) { -SAFE_FILE_SCANF (cleanup, path1,"%ld" , &online); +SAFE_FILE_SCANF (path1,"%ld" , &online);if (online ==0 )continue ; }@@ -742,13 +734,12 @@ void read_cpuset_files(char *prefix, char *filename, char *retbuf) prefix, filename); fd =open (path,O_RDONLY );if (fd ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup, -"open %s" , path); +tst_brk (TBROK |TERRNO ,"open %s" , path); }else -tst_brkm (TBROK |TERRNO , cleanup,"open %s" , path); +tst_brk (TBROK |TERRNO ,"open %s" , path); }if (read (fd, retbuf,BUFSIZ ) <0 ) -tst_brkm (TBROK |TERRNO , cleanup,"read %s" , path); +tst_brk (TBROK |TERRNO ,"read %s" , path);close (fd); }@@ -770,13 +761,12 @@ void write_cpuset_files(char *prefix, char *filename, char *buf) prefix, filename); fd =open (path,O_WRONLY );if (fd ==-1 )
testcases/kernel/mem/lib/mem.c void write_cpuset_files(char *prefix, char *filename, char *buf) · line 769
Quoted 10 lines
testcases/kernel/mem/lib/mem.c +3
-4-tst_brkm (TBROK |TERRNO , cleanup, -"open %s" , path); +tst_brk (TBROK |TERRNO ,"open %s" , path); }else -tst_brkm (TBROK |TERRNO , cleanup,"open %s" , path); +tst_brk (TBROK |TERRNO ,"open %s" , path); }if (write (fd, buf,strlen (buf)) != (ssize_t )strlen (buf)) -tst_brkm (TBROK |TERRNO , cleanup,"write %s" , path); +tst_brk (TBROK |TERRNO ,"write %s" , path);
And SAFE_WRITE()
Quoted 47 lines
testcases/kernel/mem/lib/mem.c +7
-7close (fd); }@@ -797,12 +787,12 @@ void write_cpusets(long nd)if (strlen (cpus) !=0 ) {write_cpuset_files (CPATH_NEW ,"cpus" , cpus); }else { -tst_resm (TINFO ,"No CPUs in the node%ld; " +tst_res (TINFO ,"No CPUs in the node%ld; " "using only CPU0" , nd);write_cpuset_files (CPATH_NEW ,"cpus" ,"0" ); } -SAFE_FILE_PRINTF (NULL ,CPATH_NEW "/tasks" ,"%d" ,getpid ()); +SAFE_FILE_PRINTF (CPATH_NEW "/tasks" ,"%d" ,getpid ()); }void umount_mem (char *path,char *path_new)@@ -815,53 +805,53 @@ void umount_mem(char *path, char *path_new)sprintf (s,"%s/tasks" , path); fd =open (s,O_WRONLY );if (fd ==-1 ) -tst_resm (TWARN |TERRNO ,"open %s" , s); +tst_res (TWARN |TERRNO ,"open %s" , s);snprintf (s_new,BUFSIZ ,"%s/tasks" , path_new); fp =fopen (s_new,"r" );if (fp ==NULL ) -tst_resm (TWARN |TERRNO ,"fopen %s" , s_new); +tst_res (TWARN |TERRNO ,"fopen %s" , s_new);if ((fd !=-1 ) && (fp !=NULL )) {while (fgets (value,BUFSIZ , fp) !=NULL )if (write (fd, value,strlen (value) -1 ) != (ssize_t )strlen (value) -1 ) -tst_resm (TWARN |TERRNO ,"write %s" , s); +tst_res (TWARN |TERRNO ,"write %s" , s); }if (fd !=-1 )close (fd);if (fp !=NULL )fclose (fp);if (rmdir (path_new) ==-1 ) -tst_resm (TWARN |TERRNO ,"rmdir %s" , path_new); +tst_res (TWARN |TERRNO ,"rmdir %s" , path_new);if (umount (path) ==-1 ) -tst_resm (TWARN |TERRNO ,"umount %s" , path); +tst_res (TWARN |TERRNO ,"umount %s" , path);
testcases/kernel/mem/lib/mem.c void umount_mem(char *path, char *path_new) · line 835
Quoted 10 lines
testcases/kernel/mem/lib/mem.c +2
-2if (rmdir (path) ==-1 ) -tst_resm (TWARN |TERRNO ,"rmdir %s" , path); +tst_res (TWARN |TERRNO ,"rmdir %s" , path); }void mount_mem (char *name,char *fs,char *options,char *path,char *path_new) {if (mkdir (path,0777 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"mkdir %s" , path); +tst_brk (TBROK |TERRNO ,"mkdir %s" , path);
And SAFE_MKDIR()
Quoted 67 lines
testcases/kernel/mem/lib/mem.c +11
-11if (mount (name, path, fs,0 , options) ==-1 ) {if (errno ==ENODEV ) {if (rmdir (path) ==-1 ) -tst_resm (TWARN |TERRNO ,"rmdir %s failed" , +tst_res (TWARN |TERRNO ,"rmdir %s failed" , path); -tst_brkm (TCONF ,NULL , +tst_brk (TCONF ,"file system %s is not configured in kernel" , fs); } -tst_brkm (TBROK |TERRNO , cleanup,"mount %s" , path); +tst_brk (TBROK |TERRNO ,"mount %s" , path); }if (mkdir (path_new,0777 ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"mkdir %s" , path_new); +tst_brk (TBROK |TERRNO ,"mkdir %s" , path_new); }/* shared */ /* Warning: *DO NOT* use this function in child */ -unsigned int get_a_numa_node (void (*cleanup_fn) (void )) +unsigned int get_a_numa_node (void ) {unsigned int nd1, nd2;int ret;@@ -871,24 +861,24 @@ unsigned int get_a_numa_node(void (*cleanup_fn) (void))case 0 :break ;case -3 : -tst_brkm (TCONF , cleanup_fn,"requires a NUMA system." ); +tst_brk (TCONF ,"requires a NUMA system." );default : -tst_brkm (TBROK |TERRNO , cleanup_fn,"1st get_allowed_nodes" ); +tst_brk (TBROK |TERRNO ,"1st get_allowed_nodes" ); } ret =get_allowed_nodes (NH_MEMS |NH_CPUS ,1 , &nd1);switch (ret) {case 0 : -tst_resm (TINFO ,"get node%u." , nd1); +tst_res (TINFO ,"get node%u." , nd1);return nd1;case -3 : -tst_brkm (TCONF , cleanup_fn,"requires a NUMA system that has " +tst_brk (TCONF ,"requires a NUMA system that has " "at least one node with both memory and CPU " "available." );default :break ; } -tst_brkm (TBROK |TERRNO , cleanup_fn,"2nd get_allowed_nodes" ); +tst_brk (TBROK |TERRNO ,"2nd get_allowed_nodes" ); }int path_exist (const char *path, ...)@@ -911,7 +901,7 @@ long read_meminfo(char *item) fp =fopen (PATH_MEMINFO ,"r" );if (fp ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"fopen %s" ,PATH_MEMINFO ); +tst_brk (TBROK |TERRNO ,"fopen %s" ,PATH_MEMINFO );while (fgets (line,BUFSIZ , fp) !=NULL ) {if (sscanf (line,"%64s %ld" , buf, &val) ==2 )
testcases/kernel/mem/lib/mem.c long read_meminfo(char *item) · line 918
Quoted 7 lines
testcases/kernel/mem/lib/mem.c +1
-1@@ -923,7 +913,7 @@ long read_meminfo(char *item) }fclose (fp); -tst_brkm (TBROK , cleanup,"cannot find \"%s\" in %s" , +tst_brk (TBROK ,"cannot find \"%s\" in %s" , item,PATH_MEMINFO ); }
The read_meminfo() function body could be replaced with one call to SAFE_FILE_LINES_SCANF().
Quoted 54 lines
testcases/kernel/mem/lib/mem.c +8
-8@@ -932,15 +922,15 @@ void set_sys_tune(char *sys_file, long tune, int check)long val;char path[BUFSIZ ]; -tst_resm (TINFO ,"set %s to %ld" , sys_file, tune); +tst_res (TINFO ,"set %s to %ld" , sys_file, tune);snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_PRINTF (NULL , path,"%ld" , tune); +SAFE_FILE_PRINTF (path,"%ld" , tune);if (check) { val =get_sys_tune (sys_file);if (val != tune) -tst_brkm (TBROK , cleanup,"%s = %ld, but expect %ld" , +tst_brk (TBROK ,"%s = %ld, but expect %ld" , sys_file, val, tune); } }@@ -951,7 +941,7 @@ long get_sys_tune(char *sys_file)long tune;snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_SCANF (NULL , path,"%ld" , &tune); +SAFE_FILE_SCANF (path,"%ld" , &tune);return tune; }@@ -960,20 +950,20 @@ void update_shm_size(size_t * shm_size) {size_t shmmax; -SAFE_FILE_SCANF (cleanup,PATH_SHMMAX ,"%ld" , &shmmax); +SAFE_FILE_SCANF (PATH_SHMMAX ,"%ld" , &shmmax);if (*shm_size > shmmax) { -tst_resm (TINFO ,"Set shm_size to shmmax: %ld" , shmmax); +tst_res (TINFO ,"Set shm_size to shmmax: %ld" , shmmax); *shm_size = shmmax; } } -int range_is_mapped (void (*cleanup_fn) (void ),unsigned long low,unsigned long high) +int range_is_mapped (unsigned long low,unsigned long high) {FILE *fp; fp =fopen ("/proc/self/maps" ,"r" );if (fp ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup_fn,"Failed to open /proc/self/maps." ); +tst_brk (TBROK |TERRNO ,"Failed to open /proc/self/maps." );while (!feof (fp)) {unsigned long start, end;
testcases/kernel/mem/lib/mem.c int range_is_mapped(void (*cleanup_fn) (void), unsigned long low, unsigned long · line 978
Quoted 8 lines
testcases/kernel/mem/lib/mem.c +1
-1@@ -982,7 +972,7 @@ int range_is_mapped(void (*cleanup_fn) (void), unsigned long low, unsigned long ret =fscanf (fp,"%lx-%lx %*[^\n]\n" , &start, &end);if (ret !=2 ) {fclose (fp); -tst_brkm (TBROK |TERRNO , cleanup_fn,"Couldn't parse /proc/self/maps line." ); +tst_brk (TBROK |TERRNO ,"Couldn't parse /proc/self/maps line." ); }if ((start >= low) && (start < high)) {
Otherwise this looks pretty much fine.
Signature · 2 lines
Cyril Hrubis [email protected]
RFC PATCH 1/13 mem/lib: convert to new API
Quoted 10 lines · Cyril Hrubis
testcases/kernel/mem/lib/mem.c long read_meminfo(char *item) · line 918
Quoted 5 lines
testcases/kernel/mem/lib/mem.c +1
-1-tst_brkm (TBROK , cleanup,"cannot find \"%s\" in %s" , +tst_brk (TBROK ,"cannot find \"%s\" in %s" , item,PATH_MEMINFO ); }The
read_meminfo()function body could be replaced with one call toSAFE_FILE_LINES_SCANF().
I saw this MACRO, but it doesn't work with too much pointers which transfered by multi level function.
This test program is not work:
=======================
#include <stdio.h>
#include "tst_test.h"
long read_meminfo(char *item)
{
long val;
SAFE_FILE_LINES_SCANF("/proc/meminfo", "%s %ld", item, &val);
return val;
}static void do_test(void)
{
long dummy;
dummy = read_meminfo("MemFree:");
tst_res(TPASS, "dummy = %ld", dummy);
}static struct tst_test test = {
.tid = "tst_safe_fileops",
.test_all = do_test,
};
=================================
And, no objection to the rest of comments.
Signature · 3 lines
Regards, Li Wang Email: [email protected]
RFC PATCH 1/13 mem/lib: convert to new API
Hi!
Quoted 6 lines
I saw this MACRO, but it doesn't work with too much pointers which transfered by multi level function.
This test program is not work:
=======================
Quoted 8 lines
#include <
stdio.h>
#include "tst_test.h"long
read_meminfo(char *item){ long val; SAFE_FILE_LINES_SCANF("/proc/meminfo", "%s %ld", item, &val);
This is because the item has to be part of the matching string and not a item to be matched the "%s %ld" string would match first line in the /proc/meminfo. The easiest solution would be turning this into a macro:
#define SAFE_READ_MEMINFO(item) \
({long tst_rval; \
SAFE_FILE_LINES_SCANF("/proc/meminfo", item " %ld",
&tst_rval); \This of course works only when item is compile time string constant, but I doubt that we use it with anything else.
Signature · 2 lines
Cyril Hrubis [email protected]
cover Convert LTP kernel/mem/testcase to New API
In reply to Li WangHi!
Quoted 2 lines
Seems the failed reason in oom02/5 is not testcase issue, it just because New API sets test time in 5mins.
The test_test structure has .timeout variable that, if set, overrides the default timeout. All you need to do is to to measure how long the test takes, then multiply it by something as 2 to be on a safe side and set the .timeout correspondingly.
Signature · 2 lines
Cyril Hrubis [email protected]
cover Convert LTP kernel/mem/testcase to New API
Quoted 8 lines · Cyril Hrubis
Hi!
Quoted 2 lines
Seems the failed reason in oom02/5 is not testcase issue, it just because New API sets test time in 5mins.
The
test_teststructure has .timeout variable that, if set, overrides the default timeout. All you need to do is to to measure how long the test takes, then multiply it by something as 2 to be on a safe side and set the .timeout correspondingly.
Yes, but the problem we face is oom01 spend time is not the same on different memory size machines. So, I'm afraid it is meaningless to measure how long it takes on a fixed system.
Or, how about we just set a big vague number (i.e ".timeout = 3600")?
Signature · 3 lines
Regards, Li Wang Email: [email protected]
cover Convert LTP kernel/mem/testcase to New API
In reply to Cyril Hrubis----- Original Message -----
Quoted 7 lines
From: "Cyril Hrubis" <[email protected]>
To: "Li Wang" <[email protected]>
Cc: [email protected]
Sent: Thursday, 30 March, 2017 5:43:58 PM
Subject: Re: [LTP] [RFC PATCH 00/13] Convert LTPkernel/mem/testcaseto New APIHi!
Quoted 8 lines
Quoted 3 lines
Seems the failed reason in oom02/5 is not testcase issue, it just because New API sets
test time in 5mins.The
test_teststructure has .timeout variable that, if set, overrides the default timeout. All you need to do is to to measure how long the test takes, then multiply it by something as 2 to be on a safe side and set the .timeout correspondingly.
OOM tests depend on amount of RAM+swap, so it's going to vary a lot. I'd say safe side is in order of hours.
Other options that come to mind:
- formula based on amount of RAM and swap
- we measure how long it takes to fill 1GB of RAM/swap, and scale that up
- we run all OOM tests in mem cgroup with fixed mem/swap limit, and set timeout according to worse case / slowest system
Quoted 8 lines
--
Cyril Hrubis
[email protected]--
Mailing list info: https://lists.linux.it/listinfo/ltp
cover Convert LTP kernel/mem/testcase to New API
Quoted 21 lines · Jan Stancek
----- Original Message -----
Quoted 7 lines
From: "Cyril Hrubis" <[email protected]>
To: "Li Wang" <[email protected]>
Cc: [email protected]
Sent: Thursday, 30 March, 2017 5:43:58 PM
Subject: Re: [LTP] [RFC PATCH 00/13] Convert LTPkernel/mem/testcaseto New APIHi!
Quoted 8 lines
Quoted 3 lines
Seems the failed reason in oom02/5 is not testcase issue, it just because New API sets
test time in 5mins.The
test_teststructure has .timeout variable that, if set, overrides the default timeout. All you need to do is to to measure how long the test takes, then multiply it by something as 2 to be on a safe side and set the .timeout correspondingly.
Quoted 8 lines
OOM tests depend on amount of RAM+swap, so it's going to vary a lot. I'd say safe side is in order of hours.
Other options that come to mind:
- formula based on amount of RAM and swap
- we measure how long it takes to fill 1GB of RAM/swap, and scale that up
- we run all OOM tests in mem cgroup with fixed mem/swap limit, and set timeout according to worse case / slowest system
This looks fine. But if we set all OOM tests in mem cgroup, that will make this test range is limited.
How about divide it into two part:
1. OOM test take original way on small (less than 100G) RAM, and we set the .timeout according to the spent time on 100G system.
2. If system RAM large than 100G, we go to the cgroup limited way.
Signature · 3 lines
Regards, Li Wang Email: [email protected]