示例#1
0
文件: msgsnd05.c 项目: Nan619/ltp
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();
}
示例#2
0
文件: mtest01.c 项目: yaneurabeya/ltp
static void mem_test(void)
{
	pid_t pid;
	int i = 0, pid_cntr = 0;
	unsigned long long alloc_bytes = alloc_maxbytes;
	const char *write_msg = "";

	if (dowrite)
		write_msg = "(and written to) ";

	/* to make mtest01 support -i N */
	children_done = 0;

	do {
		pid = SAFE_FORK();
		if (pid == 0) {
			alloc_bytes = MIN(ALLOC_THRESHOLD, alloc_bytes);
			child_loop_alloc(alloc_bytes);
		}

		pid_list[pid_cntr++] = pid;

		if (alloc_bytes <= ALLOC_THRESHOLD)
			break;

		alloc_bytes -= ALLOC_THRESHOLD;
	} while (pid_cntr < max_pids);

	/* wait in the loop for all children finish allocating */
	while (children_done < pid_cntr) {
		if (tst_timeout_remaining() < STOP_THRESHOLD) {
			tst_res(TWARN,
				"the remaininig time is not enough for testing");

			break;
		}

		usleep(100000);
	}

	if (children_done < pid_cntr) {
		tst_res(TFAIL, "kbytes allocated %sless than expected %llu",
				write_msg, alloc_maxbytes / 1024);
	} else {
		tst_res(TPASS, "%llu kbytes allocated %s",
				alloc_maxbytes / 1024, write_msg);
	}

	for (i = 0; i < pid_cntr; i++) {
		TST_PROCESS_STATE_WAIT(pid_list[i], 'T');
		kill(pid_list[i], SIGCONT);
	}
}
示例#3
0
文件: pause03.c 项目: 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();

}
示例#4
0
文件: semctl01.c 项目: 1587/ltp
/*
 * cnt_setup() - set up for the GETNCNT and GETZCNT commands with semctl()
 */
static void cnt_setup(int opval)
{
	int pid, i;

	sops.sem_num = SEM4;
	sops.sem_flg = 0;

	/*
	 * if seting up for GETZCNT, the semaphore value needs to be positive
	 */
	if (opval == 0) {
		/* initialize the semaphore value to ONE */
		sops.sem_op = ONE;
		if (semop(sem_id_1, &sops, 1) == -1)
			tst_brkm(TBROK, cleanup, "semop #1 failed - cnt_setup");
	}

	/* set the correct operation */
	sops.sem_op = opval;
	for (i = 0; i < NCHILD; i++) {
		/* fork five children to wait */
		pid = FORK_OR_VFORK();
		if (pid == -1)
			tst_brkm(TBROK, cleanup, "fork failed in cnt_setup");

		if (pid == 0) {
#ifdef UCLINUX
			sem_op = sops.sem_op;
			if (self_exec(argv0, "ndd", 2, sem_id_1, sem_op) < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed "
					 "in cnt_setup");
#else
			child_cnt();
#endif
		} else {
			TST_PROCESS_STATE_WAIT(cleanup, pid, 'S');
			/* save the pid so we can kill it later */
			pid_arr[i] = pid;
		}
	}
}
示例#5
0
文件: shmctl01.c 项目: 1587/ltp
/*
 * stat_setup() - Set up for the IPC_STAT command with shmctl().
 *		  Make things interesting by forking some children
 *		  that will either attach or inherit the shared memory.
 */
void stat_setup(void)
{
	void *set_shmat();
	pid_t pid;

	/*
	 * The first time through, let the children attach the memory.
	 * The second time through, attach the memory first and let
	 * the children inherit the memory.
	 */

	if (stat_time == SECOND)
		/*
		 * use the global "set_shared" variable here so that
		 * it can be removed in the stat_func() routine.
		 */
		set_shared = set_shmat();

	tst_flush();
	for (stat_i = 0; stat_i < N_ATTACH; stat_i++) {
		pid = FORK_OR_VFORK();
		if (pid == -1)
			tst_brkm(TBROK, cleanup, "could not fork");

		if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(argv0, "ddd", stat_i, stat_time,
				      shm_id_1) < 0)
				tst_brkm(TBROK, cleanup, "could not self_exec");
#else
			do_child();
#endif

		} else {
			/* save the child's pid for cleanup later */
			pid_arr[stat_i] = pid;
			TST_PROCESS_STATE_WAIT(cleanup, pid, 'S');
		}
	}
}
示例#6
0
文件: wait401.c 项目: kraj/ltp
static void run(void)
{
	pid_t pid;
	int status = 1;
	struct rusage rusage;

	pid = SAFE_FORK();
	if (!pid) {
		TST_PROCESS_STATE_WAIT(getppid(), 'S');
		exit(0);
	}

	TEST(wait4(pid, &status, 0, &rusage));
	if (TST_RET == -1) {
		tst_res(TFAIL | TERRNO, "wait4() failed");
		return;
	}

	if (TST_RET != pid) {
		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
			TST_RET, pid);
	} else {
		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
	}

	if (!WIFEXITED(status)) {
		tst_res(TFAIL, "WIFEXITED() not set in status (%s)",
		        tst_strstatus(status));
		return;
	}

	tst_res(TPASS, "WIFEXITED() is set in status");

	if (WEXITSTATUS(status))
		tst_res(TFAIL, "WEXITSTATUS() != 0 but %i", WEXITSTATUS(status));
	else
		tst_res(TPASS, "WEXITSTATUS() == 0");

}
示例#7
0
文件: semctl01.c 项目: 1587/ltp
/*
 * pid_setup() - set up for the GETPID command with semctl()
 */
static void pid_setup(void)
{
	int pid;

	/*
	 * Fork a child to do a semop that will pass.
	 */
	pid = FORK_OR_VFORK();
	if (pid == -1)
		tst_brkm(TBROK, cleanup, "fork failed in pid_setup()");

	if (pid == 0) {		/* child */
#ifdef UCLINUX
		if (self_exec(argv0, "nd", 1, sem_id_1) < 0)
			tst_brkm(TBROK, cleanup, "self_exec failed "
				 "in pid_setup()");
#else
		child_pid();
#endif
	} else {
		pid_arr[SEM2] = pid;
		TST_PROCESS_STATE_WAIT(cleanup, pid, 'Z');
	}
}
示例#8
0
文件: semop05.c 项目: 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();
}
示例#9
0
文件: pause02.c 项目: Nan619/ltp-ddt
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;

		cpid = FORK_OR_VFORK();
		switch (cpid) {
		case -1:
			tst_brkm(TBROK, cleanup, "fork() failed");
		break;
		case 0:
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed");
#else
			do_child();
#endif
		break;
		default:
		break;
		}

		/*
		 * Wait for child to enter pause().
		 */
		TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S');

		/*
		 * Send the SIGINT signal now, so that child
		 * returns from pause and resumes execution.
		 */
		kill(cpid, SIGINT);

		wait(&status);

		if (WIFEXITED(status)) {
			if (WEXITSTATUS(status) == 0)
				tst_resm(TPASS, "pause was interrupted correctly");
			else
				tst_resm(TFAIL, "pause was interrupted but the "
				                "retval and/or errno was wrong");
			continue;
		}

		if (WIFSIGNALED(status)) {
			switch (WTERMSIG(status)) {
			case SIGALRM:
				tst_resm(TFAIL, "Timeout: SIGINT wasn't recieved by child");
			break;
			default:
				tst_resm(TFAIL, "Child killed by signal");
			}

			continue;
		}
			
		tst_resm(TFAIL, "Pause was not interrupted");
	}

	cleanup();
	tst_exit();
}