int main(int ac, char **av) { char *msg; /* message returned from parse_opts */ void *child_stack; /* stack for child */ int status, child_pid; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); if ((child_stack = malloc(CHILD_STACK_SIZE)) == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); Tst_count = 0; TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack)); again: child_pid = wait(&status); /* check return code */ if (TEST_RETURN == child_pid) tst_resm(TPASS, "clone returned %ld", TEST_RETURN); else if (TEST_RETURN == -1) tst_resm(TFAIL|TTERRNO, "clone failed for pid = %d", child_pid); else goto again; free(child_stack); cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ void *child_stack; /* stack for child */ int status, child_pid; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } /* perform global setup for test */ setup(); /* Allocate stack for child */ if ((child_stack = (void *)malloc(CHILD_STACK_SIZE)) == NULL) { tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); } /* check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; /* * Call clone(2) */ TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack)); again: if ((child_pid = wait(&status)) == -1) tst_brkm(TBROK|TERRNO, cleanup, "wait() failed"); /* check return code */ if (TEST_RETURN == child_pid) { tst_resm(TPASS, "clone() returned %ld", TEST_RETURN); } else if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "clone() returned %ld for child %d", TEST_RETURN, child_pid); } else goto again; } /* End for TEST_LOOPING */ free(child_stack); /* cleanup and exit */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc, ind; /* loop counter */ char *msg; /* message returned from parse_opts */ void *test_stack; /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "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; for (ind = 0; ind < TST_TOTAL; ind++) { if (test_cases[ind].child_stack == NULL) { test_stack = (void *)NULL; } else if (*test_cases[ind].child_stack == NULL) { tst_resm(TWARN, "Can not allocate stack for" "child, skipping test case"); continue; } else { test_stack = child_stack; } /* * call the system call with the TEST() macro */ TEST(ltp_clone(0,test_cases[ind].child_fn, NULL, CHILD_STACK_SIZE, test_stack)); if ((TEST_RETURN == -1) && (TEST_ERRNO == test_cases[ind].exp_errno)) { tst_resm(TPASS, "expected failure; Got %s", test_cases[ind].err_desc); } else { tst_resm(TFAIL|TTERRNO, "Call failed to produce expected error; " "expected errno %d and result -1; got result %ld", test_cases[ind].exp_errno, TEST_RETURN); } TEST_ERROR_LOG(TEST_ERRNO); } } cleanup(); tst_exit(); }
static long clone_child(const struct test_case *t, int use_tst) { TEST(ltp_clone(t->flags, t->do_child, NULL, CHILD_STACK_SIZE, child_stack, &ptid, NULL, &ctid)); if (TEST_RETURN == -1) { if (use_tst) { tst_brkm(TBROK | TTERRNO, cleanup, "%s clone() failed", t->name); } else { printf("%s clone() failed, errno: %d", t->name, TEST_ERRNO); exit(1); } } return TEST_RETURN; }
int main(int ac, char **av) { int lc, ind; char *msg; void *test_stack; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (ind = 0; ind < TST_TOTAL; ind++) { if (test_cases[ind].child_stack == NULL) { test_stack = (void *)NULL; } else if (*test_cases[ind].child_stack == NULL) { tst_resm(TWARN, "Can not allocate stack for" "child, skipping test case"); continue; } else { test_stack = child_stack; } TEST(ltp_clone(0, test_cases[ind].child_fn, NULL, CHILD_STACK_SIZE, test_stack)); if ((TEST_RETURN == -1) && (TEST_ERRNO == test_cases[ind].exp_errno)) { tst_resm(TPASS, "expected failure; Got %s", test_cases[ind].err_desc); } else { tst_resm(TFAIL | TTERRNO, "Call failed to produce expected error; " "expected errno %d and result -1; got result %ld", test_cases[ind].exp_errno, TEST_RETURN); } TEST_ERROR_LOG(TEST_ERRNO); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; void *child_stack; /* stack for child */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* Allocate stack for child */ if ((child_stack = (void *) malloc(CHILD_STACK_SIZE)) == NULL) { tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); } /* * Call clone(2) */ child_pid = ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack); wait(NULL); free(child_stack); } if (fail == FALSE) tst_resm(TPASS, "Use of return() in child did not cause SIGSEGV"); else { tst_resm(TFAIL, "Use of return() in child caused SIGSEGV"); } cleanup(); tst_exit(); }
/*********************************************************************** * ltp_clone_malloc: also does the memory allocation for clone with a * caller-specified size. ***********************************************************************/ int ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg), void *arg, size_t stack_size) { void *stack; int ret; int saved_errno; if ((stack = malloc(stack_size)) == NULL) return -1; ret = ltp_clone(clone_flags, fn, arg, stack_size, stack); if (ret == -1) { saved_errno = errno; free(stack); errno = saved_errno; } return ret; }
int main(int ac, char **av) { int lc, status; void *child_stack; tst_parse_opts(ac, av, NULL, NULL); setup(); child_stack = malloc(CHILD_STACK_SIZE); if (child_stack == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE, child_stack)); if ((TEST_RETURN != -1) && (child_exited)) tst_resm(TPASS, "Test Passed"); else tst_resm(TFAIL, "Test Failed"); if ((wait(&status)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d", status); child_exited = 0; } free(child_stack); cleanup(); tst_exit(); }
static void test_flag(int clone_flag, int ns_flag, int (*fn) (void *arg)) { void *child_stack; int ret, status; child_stack = malloc(CHILD_STACK_SIZE); if (child_stack == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); tst_resm(TINFO, "creating child with clone_flag=0x%x, ns_flag=0x%x", clone_flag, ns_flag); ret = ltp_clone(SIGCHLD|clone_flag, fn, &ns_flag, CHILD_STACK_SIZE, child_stack); if (ret == -1) tst_brkm(TBROK|TERRNO, cleanup, "ltp_clone"); if (waitpid(ret, &status, 0) == -1) tst_brkm(TBROK|TERRNO, cleanup, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child returns %d", status); else tst_resm(TPASS, "child finished succesfully"); free(child_stack); }
int main(int ac, char **av) { void *child_stack; int status, child_pid; tst_parse_opts(ac, av, NULL, NULL); setup(); child_stack = malloc(CHILD_STACK_SIZE); if (child_stack == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); tst_count = 0; TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack)); if (TEST_RETURN == -1) tst_resm(TFAIL | TTERRNO, "clone failed"); child_pid = wait(&status); if (child_pid == -1) tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d", status); if (TEST_RETURN == child_pid) tst_resm(TPASS, "clone returned %ld", TEST_RETURN); else tst_resm(TFAIL, "clone returned %ld, wait returned %d", TEST_RETURN, child_pid); free(child_stack); cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ void *child_stack; /* stack for child */ char buff[10]; int child_pid; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } /* perform global setup for test */ setup(); /* Allocate stack for child */ if ((child_stack = (void *)malloc(CHILD_STACK_SIZE)) == NULL) { tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); } /* check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; /* Open a pipe */ if ((pipe(pfd)) == -1) { tst_brkm(TBROK|TERRNO, cleanup, "pipe() failed"); } /* * Call clone(2) */ TEST(ltp_clone(0, child_fn, NULL, CHILD_STACK_SIZE, child_stack)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "clone() failed"); cleanup(); } /* close write end from parent */ if ((close(pfd[1])) == -1) { tst_brkm(TBROK|TERRNO, cleanup, "close(pfd[1]) failed"); } /* Read pid from read end */ if ((read(pfd[0], buff, sizeof(buff))) == -1) { tst_brkm(TBROK|TERRNO, cleanup, "read from pipe failed"); } /* Close read end from parent */ if ((close(pfd[0])) == -1) { tst_resm(TWARN|TERRNO, "close(pfd[0]) failed"); } /* Get child's pid from pid string */ child_pid = atoi(buff); if (TEST_RETURN == child_pid) { tst_resm(TPASS, "Test passed"); } else { tst_resm(TFAIL, "Test failed"); } } /* End for TEST_LOOPING */ free(child_stack); /* cleanup and exit */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; void *child_stack; int status, i; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); child_stack = malloc(CHILD_STACK_SIZE); if (child_stack == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { if (test_setup() != 0) { tst_resm(TWARN, "test_setup() failed," "skipping this test case"); continue; } /* Test the system call */ TEST(ltp_clone(test_cases[i].flags, child_fn, NULL, CHILD_STACK_SIZE, child_stack)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "clone() failed"); /* Cleanup & continue with next test case */ test_cleanup(); continue; } /* Wait for child to finish */ if ((wait(&status)) == -1) { tst_resm(TWARN | TERRNO, "wait failed; skipping testcase"); /* Cleanup & continue with next test case */ test_cleanup(); continue; } if (WTERMSIG(status)) tst_resm(TWARN, "child exitied with signal %d", WTERMSIG(status)); /* * Check the return value from child function and * parent function. If both functions returned * successfully, test passed, else failed */ if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && test_cases[i].parent_fn()) tst_resm(TPASS, "Test Passed"); else tst_resm(TFAIL, "Test Failed"); /* Do test specific cleanup */ test_cleanup(); } } free(child_stack); cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ void *child_stack; /* stack for child */ int status, i; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } /* perform global setup for test */ setup(); /* Allocate stack for child */ if ((child_stack = (void *)malloc(CHILD_STACK_SIZE)) == NULL) { tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); } /* check looping state if -c option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { /*Do test specific setup */ if (!(test_setup())) { tst_resm(TWARN, "test_setup() failed," "skipping this test case"); continue; } /* Test the system call */ TEST(ltp_clone(test_cases[i].flags, child_fn, NULL, CHILD_STACK_SIZE, child_stack)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "clone() failed"); /* Cleanup & continue with next test case */ test_cleanup(); continue; } /* Wait for child to finish */ if ((wait(&status)) < 0) { tst_resm(TWARN|TERRNO, "wait() failed, skipping this" " test case"); /* Cleanup & continue with next test case */ test_cleanup(); continue; } if (WTERMSIG(status)) { tst_resm(TWARN, "child exitied with signal %d", WTERMSIG(status)); } /* * Check the return value from child function and * parent function. If both functions returned * successfully, test passed, else failed */ if ((WIFEXITED(status)) && (WEXITSTATUS(status)) && (test_cases[i].parent_fn())) { tst_resm(TPASS, "Test Passed"); } else { tst_resm(TFAIL, "Test Failed"); } /* Do test specific cleanup */ test_cleanup(); } } /* End for TEST_LOOPING */ free(child_stack); /* cleanup and exit */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; void *child_stack; char buff[10]; int child_pid, status; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* Allocate stack for child */ child_stack = malloc(CHILD_STACK_SIZE); if (child_stack == NULL) tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if ((pipe(pfd)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "pipe failed"); TEST(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE, child_stack)); if (TEST_RETURN == -1) tst_brkm(TFAIL | TTERRNO, cleanup, "clone() failed"); /* close write end from parent */ if ((close(pfd[1])) == -1) tst_brkm(TBROK | TERRNO, cleanup, "close(pfd[1]) failed"); /* Read pid from read end */ if ((read(pfd[0], buff, sizeof(buff))) == -1) tst_brkm(TBROK | TERRNO, cleanup, "read from pipe failed"); /* Close read end from parent */ if ((close(pfd[0])) == -1) tst_resm(TWARN | TERRNO, "close(pfd[0]) failed"); /* Get child's pid from pid string */ child_pid = atoi(buff); if (TEST_RETURN == child_pid) tst_resm(TPASS, "Test passed"); else tst_resm(TFAIL, "Test failed"); if ((wait(&status)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d", status); } free(child_stack); cleanup(); tst_exit(); }