restructuring work done, and adding about 400 testcases
diff --git a/testcases/kernel/syscalls/waitpid/waitpid09.c b/testcases/kernel/syscalls/waitpid/waitpid09.c
new file mode 100644
index 0000000..f4be2a7
--- /dev/null
+++ b/testcases/kernel/syscalls/waitpid/waitpid09.c
@@ -0,0 +1,304 @@
+/*
+ *
+ * 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * NAME
+ * waitpid09.c
+ *
+ * DESCRIPTION
+ * Check ability of parent to wait until child returns, and that the
+ * child's process id is returned through the waitpid. Check that
+ * waitpid returns immediately if no child is present.
+ *
+ * ALGORITHM
+ * case 0:
+ * Parent forks a child and waits. Parent should do nothing
+ * further until child returns. The pid of the forked child
+ * should match the returned value from the waitpid.
+ *
+ * case 1:
+ * Parent calls a waitpid with no children waiting. Waitpid
+ * should return a -1 since there are no children to wait for.
+ *
+ * USAGE: <for command-line>
+ * waitpid09 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
+ * where, -c n : Run n copies concurrently.
+ * -e : Turn on errno logging.
+ * -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
+ * 07/2001 John George
+ * -Ported
+ *
+ * Restrictions
+ * None
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "waitpid09";
+int TST_TOTAL = 1;
+int intintr;
+
+/* 0 terminated list of expected errnos */
+int exp_enos[] = {10,0};
+
+extern int Tst_count;
+
+void setup(void);
+void cleanup(void);
+void inthandlr();
+
+
+main(int argc, char **argv)
+{
+ int lc; /* loop counter */
+ char *msg; /* message returned from parse_opts */
+
+ int fail, pid, status, ret;
+
+ /* parse standard options */
+ if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) !=
+ (char *)NULL) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ /*NOTREACHED*/
+ }
+
+ setup();
+
+ if ((pid = fork()) < 0) {
+ tst_brkm(TFAIL, cleanup, "Fork Failed");
+ /*NOTREACHED*/
+ } else if (pid == 0) {
+ /*
+ * Child:
+ * Set up to catch SIGINT. The kids will wait till a
+ * SIGINT has been received before they proceed.
+ */
+ if ((int)sigset(SIGINT, inthandlr) < 0) {
+ tst_brkm(TFAIL, cleanup, "sigset SIGINT failed,"
+ " errno = %d", errno);
+ /*NOTREACHED*/
+ }
+
+ /* check for looping state if -i option is given */
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ /* reset Tst_count in case we are looping */
+ Tst_count = 0;
+
+ intintr = 0;
+
+ fail = 0;
+ if ((pid = fork()) < 0) {
+ tst_brkm(TFAIL, cleanup, "Fork failed.");
+ /*NOTREACHED*/
+ } else if (pid == 0) { /* child */
+ do_exit();
+ } else { /* parent */
+
+ /*
+ *Check that waitpid with WNOHANG returns zero
+ */
+ while (((ret = waitpid(pid, &status, WNOHANG))
+ != 0) || (errno == EINTR)) {
+ if (ret == -1) {
+ continue;
+ }
+ tst_resm(TFAIL, "return value for "
+ "WNOHANG expected 0 got %d",
+ ret);
+ fail = 1;
+ }
+
+ /* send SIGINT to child to tell it to proceed */
+ if (kill(pid, SIGINT) < 0) {
+ tst_resm(TFAIL, "Kill of child failed, "
+ "errno = %d", errno);
+ fail = 1;
+ }
+
+ while (((ret = waitpid(pid, &status, 0)) != -1)
+ || (errno == EINTR)) {
+ if (ret == -1) {
+ continue;
+ }
+
+ if (ret != pid) {
+ tst_resm(TFAIL, "Expected %d "
+ "got %d as proc id of "
+ "child", pid, ret);
+ fail = 1;
+ }
+
+ if (status != 0) {
+ tst_resm(TFAIL, "status value "
+ "got %d expected 0",
+ status);
+ fail = 1;
+ }
+ }
+ }
+
+ if ((pid = fork()) < 0) {
+ tst_brkm(TFAIL, cleanup, "Second fork failed.");
+ /*NOTREACHED*/
+ } else if (pid == 0) { /* child */
+ exit(0);
+ } else { /* parent */
+ /* Give the child time to startup and exit */
+ sleep(2);
+
+ while (((ret = waitpid(pid, &status, WNOHANG))
+ != -1) || (errno == EINTR)) {
+ if (ret == -1) {
+ continue;
+ }
+
+ if (ret != pid) {
+ tst_resm(TFAIL, "proc id %d "
+ "and retval %d do not "
+ "match", pid, ret);
+ fail = 1;
+ }
+
+ if (status != 0) {
+ tst_resm(TFAIL, "non zero "
+ "status received %d",
+ status);
+ fail = 1;
+ }
+ }
+ }
+ if (fail) {
+ tst_resm(TFAIL, "case 1 FAILED");
+ } else {
+ tst_resm(TPASS, "case 1 PASSED");
+ }
+
+ fail = 0;
+ ret = waitpid(pid, &status, 0);
+
+ if (ret != -1) {
+ tst_resm(TFAIL, "Expected -1 got %d", ret);
+ fail = 1;
+ }
+ TEST_ERROR_LOG(errno);
+ if (errno != ECHILD) {
+ tst_resm(TFAIL, "Expected ECHILD got %d",
+ errno);
+ fail = 1;
+ }
+
+ ret = waitpid(pid, &status, WNOHANG);
+ if (ret != -1) {
+ tst_resm(TFAIL, "WNOHANG: Expected -1 got %d",
+ ret);
+ fail = 1;
+ }
+ TEST_ERROR_LOG(errno);
+ if (errno != ECHILD) {
+ tst_resm(TFAIL, "WNOHANG: Expected ECHILD got "
+ "%d", errno);
+ fail = 1;
+ }
+
+ if (fail) {
+ tst_resm(TFAIL, "case 2 FAILED");
+ } else {
+ tst_resm(TPASS, "case 2 PASSED");
+ }
+
+ }
+ cleanup();
+ /*NOTREACHED*/
+ } else { /* parent */
+ /* wait for the child to return */
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) != 0) {
+ tst_brkm(TBROK, cleanup, "child returned bad "
+ "status");
+ /*NOTREACHED*/
+ }
+ }
+}
+
+/*
+ * setup()
+ * performs all ONE TIME setup for this test
+ */
+void
+setup(void)
+{
+ /* Set up the expected error numbers for -e option */
+ TEST_EXP_ENOS(exp_enos);
+
+ /* Pause if that option was specified
+ * TEST_PAUSE contains the code to fork the test with the -c option.
+ */
+ TEST_PAUSE;
+}
+
+/*
+ * cleanup()
+ * performs all ONE TIME cleanup for this test at
+ * completion or premature exit
+ */
+void
+cleanup(void)
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+ /*NOTREACHED*/
+}
+void
+inthandlr()
+{
+ intintr++;
+}
+
+int
+wait_for_parent()
+{
+ int testvar;
+ while (!intintr) {
+ testvar = 0;
+ }
+}
+
+int
+do_exit()
+{
+ wait_for_parent();
+ exit(0);
+}