/* * func_stat() - check the functionality of the IPC_STAT command with shmctl() * by looking at the pid of the creator, the segement size, * the number of attaches and the mode. */ void func_stat() { int fail = 0; pid_t pid; /* check perm, pid, nattach and size */ pid = getpid(); if (buf.shm_cpid != pid) { tst_resm(TFAIL, "creator pid is incorrect"); fail = 1; } if (!fail && buf.shm_segsz != HUGE_SHM_SIZE) { tst_resm(TFAIL, "segment size is incorrect"); fail = 1; } /* * The first time through, only the children attach the memory, so * the attaches equal N_ATTACH + stat_time (0). The second time * through, the parent attaches the memory and the children inherit * that memory so the attaches equal N_ATTACH + stat_time (1). */ if (!fail && buf.shm_nattch != N_ATTACH + stat_time) { tst_resm(TFAIL, "# of attaches is incorrect - %d", buf.shm_nattch); fail = 1; } /* use MODE_MASK to make sure we are comparing the last 9 bits */ if (!fail && (buf.shm_perm.mode & MODE_MASK) != ((SHM_RW) & MODE_MASK)) { tst_resm(TFAIL, "segment mode is incorrect"); fail = 1; } stat_cleanup(); /* save the change time for use in the next test */ save_time = buf.shm_ctime; if (fail) { return; } tst_resm(TPASS, "pid, size, # of attaches and mode are correct " "- pass #%d", stat_time); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; 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); } 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; /* 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. */ if ((shm_id_1 = shmget(shmkey, HUGE_SHM_SIZE, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW)) == -1) { tst_brkm(TBROK, cleanup, "couldn't create the shared" " memory segment"); } /* loop through the test cases */ 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)(); } /* * Use TEST macro to make the call */ TEST(shmctl(shm_id_1, TC[i].cmd, &buf)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s call failed - errno " "= %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } if (STD_FUNCTIONAL_TEST) { (*TC[i].func_test)(); } else { tst_resm(TPASS, "call succeeded"); /* now perform command related cleanup */ switch(TC[i].cmd) { case IPC_STAT: stat_cleanup(); break; case IPC_RMID: shm_id_1 = -1; break; } } } } cleanup(); /*NOTREACHED*/ return(0); }
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; /* 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; } if (STD_FUNCTIONAL_TEST) { (*TC[i].func_test) (); } else { tst_resm(TPASS, "shmctl call succeeded"); /* now perform command related cleanup */ switch (TC[i].cmd) { case IPC_STAT: stat_cleanup(); break; case IPC_RMID: shm_id_1 = -1; break; } } } } cleanup(); tst_exit(); }