int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ void check_functionality(void); /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } if ( get_no_of_hugepages() <= 0 || hugepages_size() <= 0 ) tst_brkm(TBROK, cleanup, "Test cannot be continued owning to sufficient availability of Hugepages on the system"); else huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ; setup(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* * Use TEST macro to make the shmdt() call */ TEST(shmdt((const void *)shared)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s call failed - errno = %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { check_functionality(); } else { tst_resm(TPASS, "call succeeded"); } } /* reattach the shared memory segment in case we are looping */ shared = (int*)shmat(shm_id_1, 0, 0); if (*shared == -1) { tst_brkm(TBROK, cleanup, "memory reattach failed"); } /* also reset pass */ pass = 0; } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ unsigned long huge_pages_shm_to_be_allocated; huge_pages_shm_to_be_allocated = 0; /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* The following loop checks looping state if -i option given */ if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0) tst_brkm(TCONF, NULL, "Not enough available Hugepages"); else huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ; setup2(huge_pages_shm_to_be_allocated); /* local setup */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* * use the TEST() macro to make the call */ TEST(shmget(IPC_PRIVATE, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded when error expected"); continue; } TEST_ERROR_LOG(TEST_ERRNO); switch(TEST_ERRNO) { case ENOSPC: tst_resm(TPASS, "expected failure - errno = " "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_resm(TFAIL, "call failed with an " "unexpected error - %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; } } cleanup(); tst_exit(); }
int main(int ac, char **av) { char *msg; /* message returned from parse_opts */ int pid; void do_child(void); int status; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } if ( get_no_of_hugepages() <= 0 || hugepages_size() <= 0 ) tst_brkm(TBROK, cleanup, "Test cannot be continued owning to sufficient availability of Hugepages on the system"); else huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ; setup(); /* global setup */ if ((pid = fork()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (pid == 0) { /* child */ /* set the user ID of the child to the non root user */ if (setuid(ltp_uid) == -1) { tst_resm(TBROK, "setuid() failed"); exit(1); } do_child(); tst_exit(); /*NOTREACHED*/ } else { /* parent */ /* wait for the child to return */ if (waitpid(pid, &status, 0) == -1) { tst_brkm(TBROK, cleanup, "waitpid failed"); } if(WIFEXITED(status) && WEXITSTATUS(status)==0) tst_resm(TPASS, "Child reported success"); else tst_resm(TFAIL, "Child reported failure"); cleanup(); } return 0; }
int main(int ac, char **av) { char *msg; /* message returned from parse_opts */ int pid; void do_child(void); /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0) tst_brkm(TCONF, cleanup, "Not enough available Hugepages"); else huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ; setup(); /* global setup */ if ((pid = fork()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (pid == 0) { /* child */ /* set the user ID of the child to the non root user */ if (setuid(ltp_uid) == -1) { tst_resm(TBROK, "setuid() failed"); exit(1); } do_child(); } else { /* wait for the child to return */ if (waitpid(pid, NULL, 0) == -1) { tst_brkm(TBROK, cleanup, "waitpid failed"); } /* if it exists, remove the shared memory resource */ rm_shm(shm_id_1); tst_rmdir(); } cleanup (); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int Hflag = 0; int page_sz, map_sz; option_t options[] = { { "H:", &Hflag, &Hopt }, /* Required for location of hugetlbfs */ { NULL, NULL, NULL } /* NULL required to end array */ }; /* Parse standard options given to run the test. */ if ((msg = parse_opts(ac, av, options, &help)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help", msg); if (Hflag == 0) { tst_brkm(TBROK, NULL, "-H option is REQUIRED for this test, use -h for options help"); } page_sz = getpagesize(); map_sz = 2 * 1024 * hugepages_size(); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* Creat a temporary file used for huge mapping */ if ((fildes = open(TEMPFILE, O_RDWR|O_CREAT, 0666)) < 0) { tst_brkm(TBROK|TERRNO, cleanup, "opening %s failed", TEMPFILE); } /* Creat a file used for normal mapping */ if ((nfildes = open("/dev/zero", O_RDONLY, 0666)) < 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; } /* mmap using normal pages and a low memory address */ errno = 0; addr = mmap(LOW_ADDR, page_sz, PROT_READ, MAP_SHARED | MAP_FIXED, nfildes, 0); if (addr == MAP_FAILED) tst_brkm(TBROK, cleanup,"mmap failed on nfildes"); /* Attempt to mmap a huge page into a low memory address */ errno = 0; addr2 = mmap(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); 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"); 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; /* loop counter */ char *msg; /* message returned from parse_opts */ struct shmid_ds buf; unsigned long huge_pages_shm_to_be_allocated; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } setup(); /* global setup */ /* The following loop checks looping state if -i option given */ if ( get_no_of_hugepages() <= 0 || hugepages_size() <= 0 ) tst_brkm(TBROK, cleanup, "Test cannot be continued owning to sufficient availability of Hugepages on the system"); else huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ; for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* * Use TEST macro to make the call */ TEST(shmget(shmkey, huge_pages_shm_to_be_allocated, (SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW))); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s call failed - errno = %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } else { shm_id_1 = TEST_RETURN; if (STD_FUNCTIONAL_TEST) { /* do a STAT and check some info */ if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) { tst_resm(TBROK, "shmctl failed in " "functional test"); continue; } /* check the seqment size */ if (buf.shm_segsz != huge_pages_shm_to_be_allocated) { 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, "couldn't remove shared memory"); } else { shm_id_1 = -1; } } cleanup(); /*NOTREACHED*/ return 0; }