Esempio n. 1
0
int main(int argc, char **argv)
{
	int lc;
	char *msg;
	int fail = 0;
	int pid;
	int status;

	msg = parse_opts(argc, argv, NULL, NULL);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#ifdef UCLINUX
	argv0 = argv[0];

	maybe_run_child(&do_child_1, "n", 1);
	maybe_run_child(&do_child_2_uclinux, "n", 2);
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		pid = FORK_OR_VFORK();
		if (pid < 0) {
			tst_resm(TINFO, "Fork Failed, may be OK under stress");
			exit(pid);
		} else if (pid == 0) {
			/*
			 * Child:
			 * Set up to catch SIGINT.  The kids will wait till a
			 * SIGINT has been received before they proceed.
			 */
#ifdef UCLINUX
			if (self_exec(argv[0], "n", 1) < 0) {
				tst_resm(TINFO, "self_exec failed");
				exit(pid);
			}
#else
			do_child_1();
#endif
		} else {	/* parent */
			fail = 0;
			waitpid(pid, &status, 0);
			if (WEXITSTATUS(status) != 0) {
				tst_resm(TFAIL, "child returned bad status");
				fail = 1;
			}
			if (fail)
				tst_resm(TFAIL, "%s FAILED", TCID);
			else
				tst_resm(TPASS, "%s PASSED", TCID);
		}
	}

	cleanup();
	tst_exit();
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* Parse standard options given to run the test. */
	msg = parse_opts(argc, argv, (option_t *) NULL, NULL);
	if (msg != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	argv0 = argv[0];
	maybe_run_child(&do_child, "dd", &sfd, &ufd);
#endif

	setup();

	TEST_EXP_ENOS(exp_enos);

	/* Check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		Tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			tdat[testno].setup();

			/* setup common to all tests */

			iov[0].iov_base = tdat[testno].buf;
			iov[0].iov_len = tdat[testno].buflen;
			msgdat.msg_name = tdat[testno].from;
			msgdat.msg_namelen = tdat[testno].fromlen;
			msgdat.msg_iov = tdat[testno].iov;
			msgdat.msg_iovlen = tdat[testno].iovcnt;
			msgdat.msg_control = control;
			msgdat.msg_controllen = controllen;
			msgdat.msg_flags = 0;

			TEST(recvmsg(s, tdat[testno].msg, tdat[testno].flags));
			if (TEST_RETURN >= 0)
				TEST_RETURN = 0;	/* all nonzero equal here */
			if (TEST_RETURN != tdat[testno].retval ||
			    (TEST_RETURN < 0 &&
			     TEST_ERRNO != tdat[testno].experrno)) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				TEST_ERROR_LOG(TEST_ERRNO);
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();
	/*NOT REACHED */
	return 0;
}				/* End main */
Esempio n. 3
0
int main(int ac, char **av)
{
	int i;
	int lc;
	char *msg;		/* parse_opts() return message */

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "");
#endif

	setup();

	/*
	 * The following loop checks looping state if -c option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			do_sendfile(testcases[i].protection,
				    testcases[i].pass_unmapped_buffer);
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 4
0
int main(int ac, char **av)
{
	char *msg;
	pid_t pid;
	int status;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();		/* global setup */

	pid = FORK_OR_VFORK();
	if (pid == -1)
		tst_brkm(TBROK, cleanup, "Fork failed");
	else if (pid == 0)
		do_master_child(av);

	if (waitpid(pid, &status, 0) == -1)
		tst_resm(TBROK | TERRNO, "waitpid failed");
	else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
		tst_resm(TFAIL, "child exited abnormally");
	else
		tst_resm(TPASS, "received expected errno(EPERM)");
	cleanup();
	tst_exit();
}
Esempio n. 5
0
int main(int ac, char **av)
{
	int i;
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "");
#endif

	setup();

	/*
	 * The following loop checks looping state if -c option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			do_sendfile(testcases[i].protection,
				    testcases[i].pass_unmapped_buffer);
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 6
0
int main(int ac, char **av)
{
	int lc;
	char *msg;		/* parse_opts() return message */

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "");
#endif

	setup();

	/*
	 * The following loop checks looping state if -c option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		do_sendfile();
	}
	cleanup();

	tst_exit();
}
Esempio n. 7
0
int main(int ac, char **av)
{
	int i;
	int lc;			/* loop counter */
	char *msg;		/* parse_opts() return message */

	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	 /*NOTREACHED*/}
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "");
#endif

	setup();

	/*
	 * The following loop checks looping state if -c option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			do_sendfile(testcases[i].offset, i);
		}
	}
	cleanup();

	 /*NOTREACHED*/ return 0;
}
Esempio n. 8
0
int main(int ac, char **av)
{
	int lc;				/* loop counter */
	char *msg;			/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}

#ifdef UCLINUX
	maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
#endif

	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;

		/*
		 * fork a child that will attempt to read a non-existent
		 * message from the queue
		 */
		if ((c_pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "could not fork");
		}

		if (c_pid == 0) {		/* child */
			/*
			 * Attempt to read a message without IPC_NOWAIT.
			 * With no message to read, the child sleeps.
			 */
#ifdef UCLINUX
			if (self_exec(av[0], "d", msg_q_1) < 0) {
				tst_brkm(TBROK, cleanup, "could not self_exec");
			}
#else
			do_child();
#endif
		} else {			/* parent */
			usleep(250000);

			/* send a signal that must be caught to the child */
			if (kill(c_pid, SIGHUP) == -1) {
				tst_brkm(TBROK, cleanup, "kill failed");
			}

			waitpid(c_pid, NULL, 0);
		}
	}

	cleanup();

	/*NOTREACHED*/
	return(0);
}
Esempio n. 9
0
/***********************************************************************
 *   M A I N
 ***********************************************************************/
int main(int argc, char **argv)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* gcc -Wall complains about sig_caught not being ref'd because of the
	   external declarations. */
	sig_caught = FALSE;

	/*
	 * parse standard options
	 */
	if ((msg =
	     parse_opts(argc, argv, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	}
#ifdef UCLINUX
	maybe_run_child(&child, "dd", &pipe_fd[1], &pipe_fd2[0]);
#endif

	/*
	 * perform global setup for test
	 */
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * fork off a child process
		 */
		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_brkm(TBROK|TERRNO, cleanup, "fork() failed");

		} else if (pid > 0) {
			parent();

		} else {
#ifdef UCLINUX
			if (self_exec(argv[0], "dd", pipe_fd[1], pipe_fd2[0]) <
			    0) {
				tst_brkm(TBROK|TERRNO, cleanup, "self_exec() failed");
			}
#else
			child();
#endif
		}

	}

	cleanup();
	tst_exit();

}				/* end main */
Esempio n. 10
0
int main(int ac, char *av[])
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* Parse standard options given to run the test. */
	msg = parse_opts(ac, av, (option_t *) NULL, NULL);
	if (msg != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "d", &sfd);
#endif

	setup();

	TEST_EXP_ENOS(exp_enos);

	/* Check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); ++lc) {

		Tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			tdat[testno].setup();

			TEST(sendto(s, tdat[testno].buf, tdat[testno].buflen,
				    tdat[testno].flags,
				    (const struct sockaddr *)tdat[testno].to,
				    tdat[testno].tolen));

			if (TEST_RETURN > 0)
				TEST_RETURN = 0;	/* all success equal */

			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_RETURN != tdat[testno].retval ||
			    (TEST_RETURN < 0 &&
			     TEST_ERRNO != tdat[testno].experrno)) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();

	 /*NOTREACHED*/ return 0;
}
Esempio n. 11
0
int main(int ac, char **av)
{
    int lc;
    pid_t c_pid;

    tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
    maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
#endif

    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;

        /*
         * fork a child that will attempt to write a message
         * to the queue without IPC_NOWAIT
         */
        if ((c_pid = FORK_OR_VFORK()) == -1) {
            tst_brkm(TBROK, cleanup, "could not fork");
        }

        if (c_pid == 0) {	/* child */
            /*
             * Attempt to write another message to the full queue.
             * Without the IPC_NOWAIT flag, the child sleeps
             */

#ifdef UCLINUX
            if (self_exec(av[0], "d", msg_q_1) < 0) {
                tst_brkm(TBROK, cleanup, "could not self_exec");
            }
#else
            do_child();
#endif
        } else {
            TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');

            /* send a signal that must be caught to the child */
            if (kill(c_pid, SIGHUP) == -1)
                tst_brkm(TBROK, cleanup, "kill failed");

            waitpid(c_pid, NULL, 0);
        }
    }

    cleanup();

    tst_exit();
}
Esempio n. 12
0
File: shmctl01.c Progetto: 1587/ltp
int main(int argc, char *argv[])
{
	int lc;
	int i;

	tst_parse_opts(argc, argv, NULL, NULL);
#ifdef UCLINUX
	argv0 = argv[0];
	maybe_run_child(do_child, "ddd", &stat_i, &stat_time, &shm_id_1);
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		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,
				  IPC_CREAT | IPC_EXCL | SHM_RW);
		if (shm_id_1 == -1)
			tst_brkm(TBROK, cleanup, "couldn't create the shared"
				 " memory segment");

		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) ();

			TEST(shmctl(*(TC[i].shmid), TC[i].cmd, TC[i].arg));

			if (TEST_RETURN == -1) {
				tst_resm(TFAIL, "%s call failed - errno "
					 "= %d : %s", TCID, TEST_ERRNO,
					 strerror(TEST_ERRNO));
				continue;
			}
			(*TC[i].func_test) (TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
Esempio n. 13
0
File: kill09.c Progetto: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	char *msg;
	int status;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		if ((fork_pid = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "fork failed");

		if (fork_pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0) {
				tst_brkm(TBROK, cleanup,
					 "self_exec of child failed");
			}
#else
			do_child();
#endif
		}

		TEST(kill(fork_pid, SIGKILL));
		if (TEST_RETURN == -1)
			tst_resm(TFAIL | TTERRNO, "kill(.., SIGKILL) failed");
		else {

			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS,
					 "kill(%d, SIGKILL) returned %ld",
					 fork_pid, TEST_RETURN);
			}
		}

		waitpid(0, &status, WNOHANG);

	}

	cleanup();
	tst_exit();
}
Esempio n. 14
0
int main(int ac, char *av[])
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* Parse standard options given to run the test. */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	argv0 = av[0];
	maybe_run_child(&do_child, "d", &sfd);
#endif

	setup();

	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); ++lc) {

		Tst_count = 0;

		for (testno = 0; testno < TST_TOTAL; ++testno) {
			tdat[testno].setup();

			TEST(send
			     (s, tdat[testno].buf, tdat[testno].buflen,
			      tdat[testno].flags));

			if (TEST_RETURN != -1) {
				tst_resm(TFAIL, "call succeeded unexpectedly");
				continue;
			}

			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_ERRNO != tdat[testno].experrno) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 15
0
File: pause03.c Progetto: kraj/ltp
int main(int ac, char **av)
{
	int lc;
	int status;

	tst_parse_opts(ac, av, NULL, NULL);
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		if ((cpid = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");

		if (cpid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed");
#else
			do_child();
#endif
		}

		TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S');

		kill(cpid, SIGKILL);

		SAFE_WAIT(NULL, &status);

		if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
			tst_resm(TPASS, "pause() did not return after SIGKILL");
			continue;
		}

		if (WIFSIGNALED(status)) {
			tst_resm(TFAIL, "child killed by %s unexpectedly",
			         tst_strsig(WTERMSIG(status)));
			continue;
		}

		tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status));
	}

	cleanup();
	tst_exit();

}
Esempio n. 16
0
int main(int argc, char *argv[])
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* Parse standard options given to run the test. */
	msg = parse_opts(argc, argv, NULL, NULL);
	if (msg != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}
#ifdef UCLINUX
	argv0 = argv[0];
	maybe_run_child(&do_child, "d", &sfd);
#endif

	/* set up expected errnos */
	TEST_EXP_ENOS(exp_enos);

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		Tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			tdat[testno].setup();

			TEST(connect
			     (s, tdat[testno].sockaddr, tdat[testno].salen));
			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_RETURN != tdat[testno].retval ||
			    (TEST_RETURN < 0 &&
			     TEST_ERRNO != tdat[testno].experrno)) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();

	tst_exit();
 }
Esempio n. 17
0
int main(int ac, char **av)
{
	int lc, pid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

#ifdef UCLINUX
	maybe_run_child(&dochild, "sdd", filename, &recstart, &reclen);
#endif

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		sprintf(filename, MOUNT_DIR"%s.%d.%d\n", TCID, getpid(), lc);

		if (tst_fill_file(filename, 0, 1024, 8)) {
			tst_brkm(TBROK, cleanup,
			         "Failed to create test file '%s'", filename);
		}

		SAFE_CHMOD(cleanup, filename, 02666);

		reclen = RECLEN;
		/*
		 * want at least RECLEN bytes BEFORE AND AFTER the
		 * record lock.
		 */
		recstart = RECLEN + rand() % (len - 3 * RECLEN);

		if ((pid = FORK_OR_VFORK()) < 0)
			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");

		if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "sdd", filename, recstart,
			              reclen) < -1) {
				tst_brkm(TBROK, cleanup, "self_exec() failed");
			}
#else
			dochild();
#endif
		}

		doparent();
	}

	cleanup();
	tst_exit();
}
Esempio n. 18
0
int main(int argc, char *argv[])
{
	int lc;
	char *msg;

	/* Parse standard options given to run the test. */
	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#ifdef UCLINUX
	argv0 = argv[0];
	maybe_run_child(&do_child, "d", &sfd);
#endif

	setup();

	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		Tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			tdat[testno].setup();

			TEST(recvfrom(s, tdat[testno].buf, tdat[testno].buflen,
				      tdat[testno].flags, tdat[testno].from,
				      tdat[testno].salen));
			if (TEST_RETURN >= 0)
				TEST_RETURN = 0;	/* all nonzero equal here */
			if (TEST_RETURN != tdat[testno].retval ||
			    (TEST_RETURN < 0 &&
			     TEST_ERRNO != tdat[testno].experrno)) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				TEST_ERROR_LOG(TEST_ERRNO);
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 19
0
int main(int ac, char **av)
{

	int lc, i;		/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* 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);
	}
#ifdef UCLINUX
	maybe_run_child(&child_func, "");
#endif

	/* perform global setup for test */
	setup();

	/* 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;

		for (i = 0; i < TST_TOTAL; ++i) {

			test_setup(i, av[0]);
			TEST(capset(test_cases[i].headerp,
				    test_cases[i].datap));

			if ((TEST_RETURN == -1) && (TEST_ERRNO ==
						    test_cases[i].exp_errno)) {
				tst_resm(TPASS, "capset() returned -1,"
					 " errno: %s", test_cases[i].errdesc);
			} else {
				tst_resm(TFAIL|TTERRNO, "Test Failed, capset() returned %ld",
					 TEST_RETURN);
			}
			TEST_ERROR_LOG(TEST_ERRNO);
		}
	}			/* End for TEST_LOOPING */

	/* cleanup and exit */
	cleanup();

	 /*NOTREACHED*/ return 0;

}				/* End main */
Esempio n. 20
0
File: recv01.c Progetto: 1587/ltp
int main(int argc, char *argv[])
{
	int lc;

	tst_parse_opts(argc, argv, NULL, NULL);
#ifdef UCLINUX
	argv0 = argv[0];
	maybe_run_child(&do_child, "d", &sfd);
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			if ((tst_kvercmp(3, 17, 0) < 0)
			    && (tdat[testno].flags & MSG_ERRQUEUE)
			    && (tdat[testno].type & SOCK_STREAM)) {
				tst_resm(TCONF, "skip MSG_ERRQUEUE test, "
						"it's supported from 3.17");
				continue;
			}

			tdat[testno].setup();
			TEST(recv(s, tdat[testno].buf, tdat[testno].buflen,
				  tdat[testno].flags));
			if (TEST_RETURN > 0)
				TEST_RETURN = 0;	/* all nonzero equal here */
			if (TEST_RETURN != tdat[testno].retval ||
			    (TEST_RETURN < 0 &&
			     TEST_ERRNO != tdat[testno].experrno)) {
				tst_resm(TFAIL, "%s ; returned"
					 " %ld (expected %d), errno %d (expected"
					 " %d)", tdat[testno].desc,
					 TEST_RETURN, tdat[testno].retval,
					 TEST_ERRNO, tdat[testno].experrno);
			} else {
				tst_resm(TPASS, "%s successful",
					 tdat[testno].desc);
			}
			tdat[testno].cleanup();
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 21
0
int main(int ac, char **av)
{

	int lc, i;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	maybe_run_child(&child_func, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

#ifdef UCLINUX
		i = 2;
#else
		i = 0;
#endif

		for (; i < TST_TOTAL; i++) {

			test_setup(i, av[0]);
			TEST(ltp_syscall(__NR_capset, test_cases[i].headerp,
				     test_cases[i].datap));

			if (TEST_RETURN == -1 &&
			    TEST_ERRNO == test_cases[i].exp_errno) {
				tst_resm(TPASS, "capset() returned -1,"
					 " errno: %s", test_cases[i].errdesc);
			} else {
				tst_resm(TFAIL | TTERRNO,
					 "Test Failed, capset() returned %ld",
					 TEST_RETURN);
			}
		}
	}

	cleanup();

	tst_exit();

}
Esempio n. 22
0
File: sighold02.c Progetto: kraj/ltp
int main(int ac, char **av)
{
	int sig;
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
		} else if (pid > 0) {
			TST_SAFE_CHECKPOINT_WAIT(NULL, 0);

			for (sig = 1; sig < NUMSIGS; sig++) {
				if (skip_sig(sig))
					continue;
				SAFE_KILL(NULL, pid, sig);
			}

			TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
			tst_record_childstatus(cleanup, pid);
		} else {

#ifdef UCLINUX
			if (self_exec(av[0], "") < 0) {
				tst_brkm(TBROK | TERRNO, NULL,
					 "self_exec() failed");
			}
#else
			do_child();
#endif
		}
	}

	cleanup();
	tst_exit();
}
Esempio n. 23
0
File: execve04.c Progetto: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	pid_t pid;
	char *argv[2] = {TEST_APP, NULL};
	char *env[1] = {NULL};

	tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork failed");
		} else if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed");
#else
			do_child();
#endif
		}

		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);

		TEST(execve(TEST_APP, argv, env));

		if (TEST_ERRNO != ETXTBSY)
			tst_resm(TFAIL | TTERRNO, "execve succeeded, expected failure");
		else
			tst_resm(TPASS | TTERRNO, "execve failed as expected");

		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
		SAFE_WAIT(cleanup, NULL);
	}

	cleanup();
	tst_exit();
}
Esempio n. 24
0
File: kill11.c Progetto: 1587/ltp
int main(int argc, char **argv)
{
	int lc;
	unsigned int i;

	tst_parse_opts(argc, argv, NULL, NULL);

#ifdef UCLINUX
	maybe_run_child(&do_child, "dd", &sig);
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		for (i = 0; i < ARRAY_SIZE(tcases); i++)
			verify_kill(tcases + i);
	}

	tst_rmdir();
	tst_exit();
}
Esempio n. 25
0
File: kill08.c Progetto: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t pid1, pid2;
	int exno, status, nsig, i;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	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;
		status = 1;
		exno = 1;

		/* Fork a process and set the process group so that */
		/* it is different from this one.  Fork 5 more children. */

		pid1 = FORK_OR_VFORK();
		if (pid1 < 0) {
			tst_brkm(TBROK, cleanup, "Fork of first child failed");
		} else if (pid1 == 0) {
			setpgrp();
			for (i = 0; i < 5; i++) {
				pid2 = FORK_OR_VFORK();
				if (pid2 < 0) {
					tst_brkm(TBROK, cleanup, "Fork failed");
				} else if (pid2 == 0) {
#ifdef UCLINUX
					if (self_exec(av[0], "") < 0) {
						tst_brkm(TBROK, cleanup,
							 "self_exec of "
							 "child failed");
					}
#else
					do_child();
#endif
				}
			}
			/* Kill all processes in this process group */
			TEST(kill(0, TEST_SIG));
			pause();
			exit(exno);
		} else {
			waitpid(pid1, &status, 0);
			if (TEST_RETURN != 0) {
				tst_brkm(TFAIL, cleanup, "%s failed - errno = "
					 "%d : %s", TCID, TEST_ERRNO,
					 strerror(TEST_ERRNO));
			}
		}

		if (STD_FUNCTIONAL_TEST) {
			/*
			 * Check to see if the process was terminated with the
			 * expected signal.
			 */
			nsig = WTERMSIG(status);
			if (nsig == TEST_SIG) {
				tst_resm(TPASS, "received expected signal %d",
					 nsig);
			} else {
				tst_resm(TFAIL,
					 "expected signal %d received %d",
					 TEST_SIG, nsig);
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}
	}
	cleanup();

	tst_exit();
}
Esempio n. 26
0
File: semop05.c Progetto: Nan619/ltp
int main(int ac, char **av)
{
    int lc;
    int i;
    pid_t pid;
    void do_child();

    tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
    maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1);
#endif

    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 (i = 0; i < TST_TOTAL; i++) {

            /* initialize the s_buf buffer */
            s_buf.sem_op = TC[i].op;
            s_buf.sem_flg = TC[i].flg;
            s_buf.sem_num = TC[i].num;

            /* initialize all of the primitive semaphores */
            if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)
                    == -1) {
                tst_brkm(TBROK, cleanup, "semctl() failed");
            }

            if ((pid = FORK_OR_VFORK()) == -1) {
                tst_brkm(TBROK, cleanup, "could not fork");
            }

            if (pid == 0) {	/* child */

#ifdef UCLINUX
                if (self_exec(av[0], "dd", i, sem_id_1) < 0) {
                    tst_brkm(TBROK, cleanup,
                             "could not self_exec");
                }
#else
                do_child(i);
#endif
            } else {
                TST_PROCESS_STATE_WAIT(cleanup, pid, 'S');

                /*
                 * If we are testing for EIDRM then remove
                 * the semaphore, else send a signal that
                 * must be caught as we are testing for
                 * EINTR.
                 */
                if (TC[i].error == EIDRM) {
                    /* remove the semaphore resource */
                    rm_sema(sem_id_1);
                } else {
                    if (kill(pid, SIGHUP) == -1) {
                        tst_brkm(TBROK, cleanup,
                                 "kill failed");
                    }
                }

                /* let the child carry on */
                waitpid(pid, NULL, 0);
            }

            /*
             * recreate the semaphore resource if needed
             */
            if (TC[i].error == EINTR) {
                continue;
            }

            if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |
                                   IPC_EXCL | SEM_RA)) == -1) {
                tst_brkm(TBROK, cleanup, "couldn't recreate "
                         "semaphore");
            }
        }
    }

    cleanup();

    tst_exit();
}
Esempio n. 27
0
int main(int ac, char **av)
{
	int kid_count, ret_val, status, nkids;
	int i, j, k, found;
	int fork_kid_pid[MAXKIDS], wait_kid_pid[MAXKIDS];
	int runtime;		/* time(sec) to run this process */

	int lc;
	char *msg;

	msg = parse_opts(ac, av, NULL, NULL);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#ifdef UCLINUX
	argv0 = av[0];

	maybe_run_child(&do_exit, "n", 1);
	maybe_run_child(&do_compute, "n", 2);
	maybe_run_child(&do_fork, "n", 3);
	maybe_run_child(&do_sleep, "n", 4);
	maybe_run_child(&do_mkdir, "n", 5);
#endif

	/*
	 * process the arg -- If there is one arg, it is the
	 * number of seconds to run.  If there is no arg the program
	 * defaults to 60 sec runtime.
	 */
	if (ac == 2) {
		if (sscanf(av[1], "%d", &runtime) != 1)
			tst_resm(TFAIL, "%s is an invalid argument", av[1]);
	} else {
		runtime = 60;
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset tst_count in case we are looping */
		tst_count = 0;
		fail = 0;

		if (signal(SIGALRM, alrmhandlr) == SIG_ERR) {
			tst_resm(TFAIL, "signal SIGALRM failed.  errno = %d",
				 errno);

		}
		alrmintr = 0;

		/*
		 * Set up to catch SIGINT. The kids will wait till a SIGINT
		 * has been received before they proceed.
		 */
		if (signal(SIGINT, inthandlr) == SIG_ERR) {
			tst_resm(TFAIL, "signal SIGINT failed.  errno = %d",
				 errno);

		}
		intintr = 0;

		/* Turn on the real time interval timer. */
		if ((alarm(runtime)) < 0)
			tst_resm(TFAIL, "alarm failed.  errno = %d", errno);

		/* Run the test over and over until the timer expires */
		for (;;) {
			if (alrmintr)
				break;

			/*
			 * Fork 8 kids. There will be 4 sets of 2 processes
			 * doing the same thing. Save all kid pid's in an
			 * array for future use. The kids will first wait for
			 * the parent to send SIGINT. Then will proceed to
			 * their assigned tasks.
			 */
			kid_count = 0;
			/*
			 * Clearing the intinitr flag here for all the children.
			 * So that we may not miss any signals !
			 */
			intintr = 0;
			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 0 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 1) < 0)
					tst_resm(TFAIL, "self_exec 0 failed");
#else
				do_exit();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 0 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 1 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 1) < 0)
					tst_resm(TFAIL, "self_exec 1 failed");
#else
				do_exit();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 1 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 2 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 2) < 0)
					tst_resm(TFAIL, "self_exec 2 failed");
#else
				do_compute();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 2 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 3 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 2) < 0)
					tst_resm(TFAIL, "self_exec 3 failed");
#else
				do_compute();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 3 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 4 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 3) < 0)
					tst_resm(TFAIL, "self_exec 4 failed");
#else
				do_fork();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 4 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 5 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 3) < 0)
					tst_resm(TFAIL, "self_exec 5 failed");
#else
				do_fork();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 5 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 6 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 4) < 0)
					tst_resm(TFAIL, "self_exec 6 failed");
#else
				do_sleep();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 6 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			ret_val = FORK_OR_VFORK();
			if (ret_val == 0) {	/* child 7 */
#ifdef UCLINUX
				if (self_exec(argv0, "n", 4) < 0)
					tst_resm(TFAIL, "self_exec 7 failed");
#else
				do_sleep();
#endif
			}
			if (ret_val < 0) {
				tst_resm(TFAIL, "Fork kid 7 failed. errno = "
					 "%d", errno);

			}

			/* parent */
			fork_kid_pid[kid_count++] = ret_val;

			nkids = kid_count;

			/*
			 * Now send all the kids a SIGINT to tell them to
			 * proceed. We sleep for a while first to allow the
			 * children to initialize their "intintr" variables
			 * and get set up.
			 */
			sleep(15);

			for (i = 0; i < nkids; i++) {
				if (kill(fork_kid_pid[i], SIGINT) < 0) {
					tst_resm(TFAIL, "Kill of child %d "
						 "failed, errno = %d", i,
						 errno);
				}
			}

			/* Wait till all kids have terminated. */
			kid_count = 0;
			errno = 0;
			for (i = 0; i < nkids; i++) {
				while (((ret_val = waitpid(fork_kid_pid[i],
							   &status, 0)) != -1)
				       || (errno == EINTR)) {
					if (ret_val == -1)
						continue;

					wait_kid_pid[kid_count++] = ret_val;
				}
			}

			/*
			 * Check that for every entry in the fork_kid_pid
			 * array, there is a matching pid in the
			 * wait_kid_pid array.
			 */
			for (i = 0; i < MAXKIDS; i++) {
				found = 0;
				for (j = 0; j < MAXKIDS; j++) {
					if (fork_kid_pid[i] == wait_kid_pid[j]) {
						found = 1;
						break;
					}
				}
				if (!found) {
					tst_resm(TFAIL, "Did not find a "
						 "wait_kid_pid for the "
						 "fork_kid_pid of %d",
						 fork_kid_pid[i]);
					for (k = 0; k < nkids; k++) {
						tst_resm(TFAIL,
							 "fork_kid_pid[%d] = "
							 "%d", k,
							 fork_kid_pid[k]);
					}
					for (k = 0; k < kid_count; k++) {
						tst_resm(TFAIL,
							 "wait_kid_pid[%d] = "
							 "%d", k,
							 wait_kid_pid[k]);
					}
					fail = 1;
				}
			}
		}

		/* Kill kids and remove file from do_mkdir */
		rmdir("waitpid14.ttt.ttt");

		if (fail)
			tst_resm(TFAIL, "Test FAILED");
		else
			tst_resm(TPASS, "Test PASSED");
	}

	cleanup();
	tst_exit();
}
Esempio n. 28
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int i;
	pid_t pid;
	void do_child();

	/* parse standard options */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1);
#endif

	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 (i = 0; i < TST_TOTAL; i++) {

			if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_create failed");

			/* initialize the s_buf buffer */
			s_buf.sem_op = TC[i].op;
			s_buf.sem_flg = TC[i].flg;
			s_buf.sem_num = TC[i].num;

			/* initialize all of the primitive semaphores */
			if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)
			    == -1) {
				tst_brkm(TBROK, cleanup, "semctl() failed");
			}

			if ((pid = FORK_OR_VFORK()) == -1) {
				tst_brkm(TBROK, cleanup, "could not fork");
			}

			if (pid == 0) {	/* child */

#ifdef UCLINUX
				if (self_exec(av[0], "dd", i, sem_id_1) < 0) {
					tst_brkm(TBROK, cleanup,
						 "could not self_exec");
				}
#else
				do_child(i);
#endif
			} else {	/* parent */

				if (sync_pipe_wait(sync_pipes) == -1)
					tst_brkm(TBROK, cleanup,
						 "sync_pipe_wait failed: %d",
						 errno);

				if (sync_pipe_close(sync_pipes, PIPE_NAME) ==
				    -1)
					tst_brkm(TBROK, cleanup,
						 "sync_pipe_close failed: %d",
						 errno);

				/* After son has been created, give it a chance to execute the
				 * semop command before we continue. Without this sleep, on SMP machine
				 * the father rm_sema/kill could be executed before the son semop.
				 */
				sleep(1);

				/*
				 * If we are testing for EIDRM then remove
				 * the semaphore, else send a signal that
				 * must be caught as we are testing for
				 * EINTR.
				 */
				if (TC[i].error == EIDRM) {
					/* remove the semaphore resource */
					rm_sema(sem_id_1);
				} else {
					if (kill(pid, SIGHUP) == -1) {
						tst_brkm(TBROK, cleanup,
							 "kill failed");
					}
				}

				/* let the child carry on */
				waitpid(pid, NULL, 0);
			}

			/*
			 * recreate the semaphore resource if needed
			 */
			if (TC[i].error == EINTR) {
				continue;
			}

			if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |
					       IPC_EXCL | SEM_RA)) == -1) {
				tst_brkm(TBROK, cleanup, "couldn't recreate "
					 "semaphore");
			}
		}
	}

	cleanup();

	tst_exit();
}
Esempio n. 29
0
int main(int argc, char **argv)
{
    int lc;
    char *msg;

    int pid, npid, sig, nsig;
    int exno, nexno, status;

    msg = parse_opts(argc, argv, NULL, NULL);
    if (msg != NULL)
        tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
    maybe_run_child(&do_child, "");
#endif

    setup();

    /* 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;

        exno = 1;
        sig = SIGFPE;

        pid = FORK_OR_VFORK();

        if (pid == 0) {
#ifdef UCLINUX
            self_exec(argv[0], "");
            /* No fork() error check is done so don't check here */
#else
            do_child();
#endif
        } else {
            kill(pid, sig);
            errno = 0;
            while (((npid = waitpid(pid, &status, 0)) != -1) ||
                    (errno == EINTR)) {
                if (errno == EINTR)
                    continue;

                if (npid != pid) {
                    tst_resm(TFAIL, "waitpid error: "
                             "unexpected pid returned");
                } else {
                    tst_resm(TPASS,
                             "recieved expected pid");
                }

                nsig = WTERMSIG(status);

                /*
                 * nsig is the signal number returned by
                 * waitpid
                 */
                if (nsig != sig) {
                    tst_resm(TFAIL, "waitpid error: "
                             "unexpected signal returned");
                } else {
                    tst_resm(TPASS, "recieved expected "
                             "signal");
                }

                /*
                 * nexno is the exit number returned by
                 * waitpid
                 */
                nexno = WEXITSTATUS(status);
                if (nexno != 0) {
                    tst_resm(TFAIL, "signal error: "
                             "unexpected exit number "
                             "returned");
                } else {
                    tst_resm(TPASS, "recieved expected "
                             "exit value");
                }
            }
        }
    }

    cleanup();
    tst_exit();
}
Esempio n. 30
0
File: kill04.c Progetto: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t pid, fake_pid;
	int exno, status, fake_status, nsig;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();		/* global setup */

	TEST_EXP_ENOS(exp_enos);

	/* 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;
		status = 1;
		exno = 1;
		pid = FORK_OR_VFORK();
		if (pid < 0) {
			tst_brkm(TBROK, cleanup, "Fork failed");
		} else if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0) {
				tst_brkm(TBROK, cleanup,
					 "self_exec of child failed");
			}
#else
			do_child();
#endif
		} else {
			fake_pid = FORK_OR_VFORK();
			if (fake_pid < 0) {
				tst_brkm(TBROK, cleanup, "Second fork failed");
			} else if (fake_pid == 0) {
#ifdef UCLINUX
				if (self_exec(av[0], "") < 0) {
					tst_brkm(TBROK, cleanup,
						 "second self_exec "
						 "of child failed");
				}
#else
				do_child();
#endif
			}
			kill(fake_pid, TEST_SIG);
			waitpid(fake_pid, &fake_status, 0);
			TEST(kill(fake_pid, TEST_SIG));
			kill(pid, TEST_SIG);
			waitpid(pid, &status, 0);
		}

		if (TEST_RETURN != -1) {
			tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s "
				 "Expected a return value of -1 got %ld",
				 TCID, TEST_ERRNO, strerror(TEST_ERRNO),
				 TEST_RETURN);
		}

		if (STD_FUNCTIONAL_TEST) {
			/*
			 * Check to see if the errno was set to the expected
			 * value of 3 : ESRCH
			 */
			nsig = WTERMSIG(status);
			TEST_ERROR_LOG(TEST_ERRNO);
			if (TEST_ERRNO == ESRCH) {
				tst_resm(TPASS, "errno set to %d : %s, as "
					 "expected", TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				tst_resm(TFAIL, "errno set to %d : %s expected "
					 "%d : %s", TEST_ERRNO,
					 strerror(TEST_ERRNO), 3, strerror(3));
			}
		}
	}
	cleanup();

	tst_exit();
}