void check_thp_options(int *nr_children, int *nr_thps) { if (opt_nr_children) *nr_children = SAFE_STRTOL(NULL, opt_nr_children_str, 0, LONG_MAX); if (opt_nr_thps) *nr_thps = SAFE_STRTOL(NULL, opt_nr_thps_str, 0, LONG_MAX); }
int main(int ac, char **av) { const char *msg; int status; pid_t pid; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); setup(); switch (pid = fork()) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork"); case 0: if (setuid(ltp_uid) == -1) tst_brkm(TBROK | TERRNO, cleanup, "setuid"); do_child(); tst_exit(); default: if (waitpid(pid, &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; const char *msg; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 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++) { TEST(shmctl(*(TC[i].shmid), TC[i].cmd, TC[i].sbuf)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "shmctl succeeded " "unexpectedly"); continue; } if (TEST_ERRNO == TC[i].error) tst_resm(TPASS | TTERRNO, "shmctl failed " "as expected"); else tst_resm(TFAIL | TTERRNO, "shmctl failed " "unexpectedly - expect errno = " "%d, got", TC[i].error); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, options, &help); if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if (shmdt(shared) == -1) { tst_resm(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"); /* also reset pass */ pass = 0; } cleanup(); tst_exit(); }
int main(int ac, char **av) { pid_t pid; int status; tst_parse_opts(ac, av, options, NULL); if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); setup(); switch (pid = fork()) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork"); case 0: /* set the user ID of the child to the non root user */ if (setuid(ltp_uid) == -1) tst_brkm(TBROK | TERRNO, cleanup, "setuid"); do_child(); tst_exit(); default: if (waitpid(pid, &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; TEST(shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "shmget succeeded unexpectedly"); continue; } if (TEST_ERRNO == ENOSPC) tst_resm(TPASS | TTERRNO, "shmget failed as expected"); else tst_resm(TFAIL | TTERRNO, "shmget failed unexpectedly " "- expect errno=ENOSPC, got"); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { char *msg; int lc; msg = parse_opts(argc, argv, options, &usage); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #if __WORDSIZE == 32 tst_brkm(TCONF, NULL, "test is not designed for 32-bit system."); #endif if (R_flag) overcommit_ratio = SAFE_STRTOL(NULL, R_opt, 0, LONG_MAX); else overcommit_ratio = DEFAULT_OVER_RATIO; setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; overcommit_memory_test(); } cleanup(); tst_exit(); }
static void setup(void) { tst_require_root(); nr_iovecs = nflag ? SAFE_STRTOL(NULL, nr_opt, 1, IOV_MAX) : 10; bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, NUM_LOCAL_VECS, LONG_MAX) : 100000; #if !defined(__NR_process_vm_readv) tst_brkm(TCONF, NULL, "process_vm_readv does not exist " "on your system"); #endif semid = init_sem(1); srand(time(NULL)); TEST_PAUSE; }
long get_sys_tune(char *sys_file) { char buf[BUFSIZ], path[BUFSIZ]; snprintf(path, BUFSIZ, "%s%s", PATH_SYSVM, sys_file); read_file(path, buf); return SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX); }
static void _wait_ksmd_done(void) { char buf[BUFSIZ]; long pages_shared, pages_sharing, pages_volatile, pages_unshared; long old_pages_shared = 0, old_pages_sharing = 0; long old_pages_volatile = 0, old_pages_unshared = 0; int changing = 1, count = 0; while (changing) { sleep(10); count++; read_file(PATH_KSM "pages_shared", buf); pages_shared = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); read_file(PATH_KSM "pages_sharing", buf); pages_sharing = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); read_file(PATH_KSM "pages_volatile", buf); pages_volatile = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); read_file(PATH_KSM "pages_unshared", buf); pages_unshared = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); if (pages_shared != old_pages_shared || pages_sharing != old_pages_sharing || pages_volatile != old_pages_volatile || pages_unshared != old_pages_unshared) { old_pages_shared = pages_shared; old_pages_sharing = pages_sharing; old_pages_volatile = pages_volatile; old_pages_unshared = pages_unshared; } else { changing = 0; } } tst_resm(TINFO, "ksm daemon takes %ds to scan all mergeable pages", count * 10); }
int main(int ac, char **av) { int lc; char *msg; #if __WORDSIZE == 32 tst_brkm(TCONF, NULL, "This test is only for 64bit"); #endif msg = parse_opts(ac, av, options, &help); if (msg) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); if (!Hflag) { tst_tmpdir(); Hopt = get_tst_tmpdir(); } if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); setup(); map_sz = read_meminfo("Hugepagesize:") * 1024; for (lc = 0; TEST_LOOPING(lc); lc++) { fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666); if (fildes < 0) tst_brkm(TBROK | TERRNO, cleanup, "open %s", TEMPFILE); Tst_count = 0; /* Attempt to mmap into highmem addr, should get ENOMEM */ addr = mmap(HIGH_ADDR, map_sz, PROT_READ, MAP_SHARED | MAP_FIXED, fildes, 0); if (addr != MAP_FAILED) { tst_resm(TFAIL, "mmap into high region " "succeeded unexpectedly"); goto fail; } if (errno != ENOMEM) tst_resm(TFAIL | TERRNO, "mmap into high region " "failed unexpectedly - expect " "errno=ENOMEM, got"); else tst_resm(TPASS | TERRNO, "mmap into high region " "failed as expected"); fail: close(fildes); } cleanup(); tst_exit(); }
static void _check(char *path, long int value) { FILE *fp; char buf[BUFSIZ], fullpath[BUFSIZ]; long actual_val; snprintf(fullpath, BUFSIZ, "%s%s", PATH_KSM, path); read_file(fullpath, buf); actual_val = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); tst_resm(TINFO, "%s is %ld.", path, actual_val); if (actual_val != value) tst_resm(TFAIL, "%s is not %ld.", path, value); }
void setup(void) { save_nr_hugepages(); if (!Hopt) Hopt = tst_get_tmpdir(); SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL); 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()); }
int main(int argc, char *argv[]) { int lc; long seconds; tst_parse_opts(argc, argv, options, &help); setup(); seconds = tflag ? SAFE_STRTOL(NULL, t_opt, 1, LONG_MAX) : 15; for (lc = 0; TEST_LOOPING(lc); lc++) reproduce(seconds); tst_resm(TPASS, "finished after %ld seconds", seconds); cleanup(); tst_exit(); }
static void setup(void) { tst_require_root(); /* Just a sanity check of the existence of syscall */ ltp_syscall(__NR_process_vm_writev, getpid(), NULL, 0UL, NULL, 0UL, 0UL); bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, 1, LONG_MAX - PADDING_SIZE * 2) : 100000; tst_tmpdir(); TST_CHECKPOINT_INIT(cleanup); TEST_PAUSE; }
int main(int ac, char **av) { 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; /* 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_brkm(TBROK | TERRNO, cleanup, "shmget #main"); 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) (); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; int shm_id_2 = -1; 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++) { /* If this key is existent, just remove it */ if (*TC[i].skey == -1) { shm_id_2 = shmget(*(TC[i].skey), 0, 0); if (shm_id_2 != -1) shmctl(shm_id_2, IPC_RMID, NULL); } TEST(shmget(*(TC[i].skey), TC[i].size_coe * shm_size, TC[i].flags)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "shmget succeeded " "unexpectedly"); continue; } if (TEST_ERRNO == TC[i].error) tst_resm(TPASS | TTERRNO, "shmget failed " "as expected"); else tst_resm(TFAIL | TTERRNO, "shmget failed " "unexpectedly - expect errno=%d, " "got", TC[i].error); } } cleanup(); tst_exit(); }
void setup(void) { long hpage_size; char buf[BUFSIZ]; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size; read_file(PATH_SHMMNI, buf); orig_shmmni = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); snprintf(buf, BUFSIZ, "%ld", hugepages / 2); write_file(PATH_SHMMNI, buf); /* * Use a while loop to create the maximum number of memory segments. * If the loop exceeds MAXIDS, then break the test and cleanup. */ num_shms = 0; shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); while (shm_id_1 != -1) { shm_id_arr[num_shms++] = shm_id_1; if (num_shms == MAXIDS) tst_brkm(TBROK, cleanup, "The maximum number of " "shared memory ID's has been reached. " "Please increase the MAXIDS value in " "the test."); shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); } if (errno != ENOSPC) tst_brkm(TBROK | TERRNO, cleanup, "shmget #setup"); TEST_PAUSE; }
static void setup(void) { if (opt_fsizestr) testfile_size = SAFE_STRTOL(opt_fsizestr, 1, INT_MAX); if (access(PROC_IO_FNAME, F_OK)) tst_brk(TCONF, "Requires " PROC_IO_FNAME); has_file(DROP_CACHES_FNAME, 1); has_file(MEMINFO_FNAME, 1); /* check if readahead is supported */ tst_syscall(__NR_readahead, 0, 0, 0); pagesize = getpagesize(); setup_readahead_length(); tst_res(TINFO, "readahead length: %d", readahead_length); setup_overlay(); }
void setup(void) { long hpage_size; save_nr_hugepages(); if (nr_opt) hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(); shmkey2 = shmkey + 1; 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 #setup"); }
static void setup(void) { long mem_total, swap_total; struct rlimit lim; if (access(PATH_SYSVM "overcommit_memory", F_OK) == -1 || access(PATH_SYSVM "overcommit_ratio", F_OK) == -1) tst_brk(TCONF, "The system " "can't support to test %s", TCID); if (R_opt) overcommit_ratio = SAFE_STRTOL(R_opt, 0, LONG_MAX); else overcommit_ratio = DEFAULT_OVER_RATIO; old_overcommit_memory = get_sys_tune("overcommit_memory"); old_overcommit_ratio = get_sys_tune("overcommit_ratio"); mem_total = SAFE_READ_MEMINFO("MemTotal:"); tst_res(TINFO, "MemTotal is %ld kB", mem_total); swap_total = SAFE_READ_MEMINFO("SwapTotal:"); tst_res(TINFO, "SwapTotal is %ld kB", swap_total); sum_total = mem_total + swap_total; commit_limit = SAFE_READ_MEMINFO("CommitLimit:"); tst_res(TINFO, "CommitLimit is %ld kB", commit_limit); SAFE_GETRLIMIT(RLIMIT_AS, &lim); if (lim.rlim_cur != RLIM_INFINITY) { lim.rlim_cur = RLIM_INFINITY; lim.rlim_max = RLIM_INFINITY; tst_res(TINFO, "Increasing RLIM_AS to INFINITY"); SAFE_SETRLIMIT(RLIMIT_AS, &lim); } set_sys_tune("overcommit_ratio", overcommit_ratio, 1); }
int main(int ac, char **av) { int lc, i; tst_parse_opts(ac, av, options, &help); 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"); } } cleanup(); tst_exit(); }
static void setup(void) { long hpage_size; save_nr_hugepages(); if (nr_opt) hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX); SAFE_FILE_SCANF(PATH_SHMMNI, "%ld", &orig_shmmni); set_sys_tune("nr_hugepages", hugepages, 1); SAFE_FILE_PRINTF(PATH_SHMMNI, "%ld", hugepages / 2); hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024; shm_size = hpage_size; /* * Use a while loop to create the maximum number of memory segments. * If the loop exceeds MAXIDS, then break the test and cleanup. */ num_shms = 0; shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); while (shm_id_1 != -1) { shm_id_arr[num_shms++] = shm_id_1; if (num_shms == MAXIDS) tst_brk(TBROK, "The maximum number of " "shared memory ID's has been reached. " "Please increase the MAXIDS value in " "the test."); shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); } if (errno != ENOSPC) tst_brk(TBROK | TERRNO, "shmget #setup"); }
static void setup(void) { if (opt_nchild) nchild = SAFE_STRTOL(opt_nchild, 1, INT_MAX); }
int main(int argc, char *argv[]) { struct rusage usage; unsigned long ulast, udelta, slast, sdelta; int i, lc; char *msg; char msg_string[BUFSIZ]; msg = parse_opts(argc, argv, child_options, fusage); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #if (__powerpc__) || (__powerpc64__) || (__s390__) || (__s390x__) tst_brkm(TCONF, NULL, "This test is not designed for current system"); #endif setup(); if (opt_factor) factor_nr = SAFE_STRTOL(cleanup, factor_str, 0, FACTOR_MAX); tst_resm(TINFO, "Using %ld as multiply factor for max [us]time " "increment (1000+%ldus)!", factor_nr, BIAS_MAX * factor_nr); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; i = 0; SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage); tst_resm(TINFO, "utime:%12luus; stime:%12luus", usage.ru_utime.tv_usec, usage.ru_stime.tv_usec); ulast = usage.ru_utime.tv_usec; slast = usage.ru_stime.tv_usec; while (i < RECORD_MAX) { SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage); udelta = usage.ru_utime.tv_usec - ulast; sdelta = usage.ru_stime.tv_usec - slast; if (udelta > 0 || sdelta > 0) { i++; tst_resm(TINFO, "utime:%12luus; stime:%12luus", usage.ru_utime.tv_usec, usage.ru_stime.tv_usec); if (udelta > 1000 + (BIAS_MAX * factor_nr)) { sprintf(msg_string, "utime increased > %ldus:", 1000 + BIAS_MAX * factor_nr); tst_brkm(TFAIL, cleanup, msg_string, " delta = %luus", udelta); } if (sdelta > 1000 + (BIAS_MAX * factor_nr)) { sprintf(msg_string, "stime increased > %ldus:", 1000 + BIAS_MAX * factor_nr); tst_brkm(TFAIL, cleanup, msg_string, " delta = %luus", sdelta); } } ulast = usage.ru_utime.tv_usec; slast = usage.ru_stime.tv_usec; busyloop(100000); } } tst_resm(TPASS, "Test Passed"); cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int lc; pid_t pid; long maxrss_self, maxrss_children, delta; long consume_nr, grand_consume_nr, self_nr, child_nr; struct rusage ru; tst_parse_opts(argc, argv, child_options, usage); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if (opt_consume) { consume_nr = SAFE_STRTOL(cleanup, consume_str, 0, LONG_MAX); tst_resm(TINFO, "child allocate %ldMB", consume_nr); consume(consume_nr); } if (opt_grand) { grand_consume_nr = SAFE_STRTOL(cleanup, grand_consume_str, 0, LONG_MAX); tst_resm(TINFO, "grandchild allocate %ldMB", grand_consume_nr); switch (pid = fork()) { case -1: tst_brkm(TBROK, cleanup, "fork"); case 0: consume(grand_consume_nr); exit(0); default: break; } while (waitpid(-1, &pid, WUNTRACED | WCONTINUED) > 0) if (WEXITSTATUS(pid) != 0) tst_brkm(TBROK | TERRNO, cleanup, "child exit status is not 0"); } if (opt_show) { SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru); maxrss_self = ru.ru_maxrss; SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru); maxrss_children = ru.ru_maxrss; tst_resm(TINFO, "exec.self = %ld, exec.children = %ld", maxrss_self, maxrss_children); if (opt_self) { self_nr = SAFE_STRTOL(cleanup, self_str, 0, LONG_MAX); delta = maxrss_self - self_nr; if (delta >= -DELTA_MAX && delta <= DELTA_MAX) tst_resm(TPASS, "initial.self ~= exec.self"); else tst_resm(TFAIL, "initial.self !~= exec.self"); } if (opt_child) { child_nr = SAFE_STRTOL(cleanup, child_str, 0, LONG_MAX); delta = maxrss_children - child_nr; if (delta >= -DELTA_MAX && delta <= DELTA_MAX) tst_resm(TPASS, "initial.children ~= exec.children"); else tst_resm(TFAIL, "initial.children !~= exec.children"); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; int Hflag = 0; long page_sz, map_sz; int sflag = 0; option_t options[] = { {"H:", &Hflag, &Hopt}, {"s:", &sflag, &nr_opt}, {NULL, NULL, NULL} }; tst_parse_opts(ac, av, options, &help); check_hugepage(); if (!Hflag) { tst_tmpdir(); Hopt = tst_get_tmpdir(); } if (sflag) hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX); page_sz = getpagesize(); map_sz = read_meminfo("Hugepagesize:") * 1024 * 2; setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* Creat a temporary file used for huge mapping */ fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666); if (fildes < 0) tst_brkm(TBROK | TERRNO, cleanup, "opening %s failed", TEMPFILE); /* Creat a file used for normal mapping */ nfildes = open("/dev/zero", O_RDONLY, 0666); if (nfildes < 0) tst_brkm(TBROK | TERRNO, cleanup, "opening /dev/zero failed"); tst_count = 0; /* * Call mmap on /dev/zero 5 times */ for (i = 0; i < 5; i++) { addr = mmap(0, 256 * 1024 * 1024, PROT_READ, MAP_SHARED, nfildes, 0); addrlist[i] = addr; } while (range_is_mapped(cleanup, low_addr, low_addr + map_sz) == 1) { low_addr = low_addr + 0x10000000; if (low_addr < LOW_ADDR) tst_brkm(TBROK | TERRNO, cleanup, "no empty region to use"); } /* mmap using normal pages and a low memory address */ addr = mmap((void *)low_addr, page_sz, PROT_READ, MAP_SHARED | MAP_FIXED, nfildes, 0); if (addr == MAP_FAILED) tst_brkm(TBROK | TERRNO, cleanup, "mmap failed on nfildes"); while (range_is_mapped(cleanup, low_addr2, low_addr2 + map_sz) == 1) { low_addr2 = low_addr2 + 0x10000000; if (low_addr2 < LOW_ADDR2) tst_brkm(TBROK | TERRNO, cleanup, "no empty region to use"); } /* Attempt to mmap a huge page into a low memory address */ addr2 = mmap((void *)low_addr2, map_sz, PROT_READ | PROT_WRITE, MAP_SHARED, fildes, 0); #if __WORDSIZE == 64 /* 64-bit process */ if (addr2 == MAP_FAILED) { tst_resm(TFAIL | TERRNO, "huge mmap failed unexpectedly" " with %s (64-bit)", TEMPFILE); close(fildes); continue; } else { tst_resm(TPASS, "huge mmap succeeded (64-bit)"); } #else /* 32-bit process */ if (addr2 == MAP_FAILED) tst_resm(TFAIL | TERRNO, "huge mmap failed unexpectedly" " with %s (32-bit)", TEMPFILE); else if (addr2 > 0) { tst_resm(TCONF, "huge mmap failed to test the scenario"); close(fildes); continue; } else if (addr == 0) tst_resm(TPASS, "huge mmap succeeded (32-bit)"); #endif /* Clean up things in case we are looping */ for (i = 0; i < 5; i++) { if (munmap(addrlist[i], 256 * 1024 * 1024) == -1) tst_resm(TBROK | TERRNO, "munmap of addrlist[%d] failed", i); } #if __WORDSIZE == 64 if (munmap(addr2, map_sz) == -1) tst_brkm(TFAIL | TERRNO, NULL, "huge munmap failed"); #endif if (munmap(addr, page_sz) == -1) tst_brkm(TFAIL | TERRNO, NULL, "munmap failed"); close(fildes); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; int Hflag = 0; int sflag = 0; int huge_pagesize = 0; option_t options[] = { {"H:", &Hflag, &Hopt}, {"s:", &sflag, &nr_opt}, {NULL, NULL, NULL} }; tst_parse_opts(ac, av, options, &help); 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 huge 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 */ freepages = read_meminfo("HugePages_Free:"); beforetest = freepages; /* Note the size of huge page size BEFORE testing */ huge_pagesize = read_meminfo("Hugepagesize:"); tst_resm(TINFO, "Size of huge pages is %d KB", huge_pagesize); #if __WORDSIZE == 32 tst_resm(TINFO, "Total amount of free huge pages is %d", freepages); tst_resm(TINFO, "Max number allowed for 1 mmap file in" " 32-bits is 128"); if (freepages > 128) freepages = 128; #endif mapsize = (long long)freepages *huge_pagesize * 1024; addr = mmap(NULL, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, fildes, 0); sleep(2); if (addr == MAP_FAILED) { tst_resm(TFAIL | TERRNO, "mmap() Failed on %s", TEMPFILE); close(fildes); continue; } else { tst_resm(TPASS, "Succeeded mapping file using %ld pages", freepages); /* 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, mapsize) != 0) tst_brkm(TFAIL | TERRNO, NULL, "munmap failed"); close(fildes); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int Hflag = 0; long page_sz = 0; int sflag = 0; option_t options[] = { { "H:", &Hflag, &Hopt }, { "s:", &sflag, &nr_opt }, { NULL, NULL, NULL } }; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s," "use -help", msg); if (!Hflag) { tst_tmpdir(); Hopt = get_tst_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 */ 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); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; struct shmid_ds buf; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 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 { if (STD_FUNCTIONAL_TEST) { /* 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"); } else { tst_resm(TPASS, "call succeeded"); } } /* * 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; } cleanup(); tst_exit(); }