示例#1
0
ATF_TC_BODY(shm_remap, tc)
{
	char *shm_buf;
	int shmid_remap;

	pgsize = sysconf(_SC_PAGESIZE);

	shmkey = get_ftok(4160);
	ATF_REQUIRE_MSG(shmkey != (key_t)-1, "get_ftok failed");

	ATF_REQUIRE_MSG((shmid_remap = shmget(shmkey, pgsize,
	    IPC_CREAT | 0640)) != -1, "shmget: %d", errno);
	write_int("shmid_remap", shmid_remap);

	ATF_REQUIRE_MSG((shm_buf = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
	    MAP_ANON | MAP_PRIVATE, -1, 0)) != MAP_FAILED, "mmap: %d", errno);

	ATF_REQUIRE_MSG(shmat(shmid_remap, shm_buf, 0) == (void *)-1,
	    "shmat without MAP_REMAP succeeded");
	ATF_REQUIRE_MSG(shmat(shmid_remap, shm_buf, SHM_REMAP) == shm_buf,
	    "shmat(SHM_REMAP): %d", errno);
}
示例#2
0
文件: t_sysv.c 项目: wieck/minix
ATF_TC_BODY(msg, tc)
{
    struct sigaction sa;
    struct msqid_ds m_ds;
    struct mymsg m;
    sigset_t sigmask;
    int loop;
    int c_status;

    /*
     * Install a SIGSYS handler so that we can exit gracefully if
     * System V Message Queue support isn't in the kernel.
     */
    did_sigsys = 0;
    sa.sa_handler = sigsys_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    ATF_REQUIRE_MSG(sigaction(SIGSYS, &sa, NULL) != -1,
                    "sigaction SIGSYS: %d", errno);

    /*
     * Install a SIGCHLD handler to deal with all possible exit
     * conditions of the receiver.
     */
    did_sigchild = 0;
    child_count = 0;
    sa.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    ATF_REQUIRE_MSG(sigaction(SIGCHLD, &sa, NULL) != -1,
                    "sigaction SIGCHLD: %d", errno);

    msgkey = get_ftok(4160);
    ATF_REQUIRE_MSG(msgkey != (key_t)-1, "get_ftok failed");

    sender_msqid = msgget(msgkey, IPC_CREAT | 0640);
    ATF_REQUIRE_MSG(sender_msqid != -1, "msgget: %d", errno);

    if (did_sigsys) {
        atf_tc_skip("SYSV Message Queue not supported");
        return;
    }

    ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds) != -1,
                    "msgctl IPC_STAT 1: %d", errno);

    print_msqid_ds(&m_ds, 0640);

    m_ds.msg_perm.mode = (m_ds.msg_perm.mode & ~0777) | 0600;

    ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_SET, &m_ds) != -1,
                    "msgctl IPC_SET: %d", errno);

    memset(&m_ds, 0, sizeof(m_ds));

    ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds) != -1,
                    "msgctl IPC_STAT 2: %d", errno);

    ATF_REQUIRE_MSG((m_ds.msg_perm.mode & 0777) == 0600,
                    "IPC_SET of mode didn't hold");

    print_msqid_ds(&m_ds, 0600);

    switch ((child_pid = fork())) {
    case -1:
        atf_tc_fail("fork: %d", errno);
        return;

    case 0:
        child_count++;
        receiver();
        break;

    default:
        break;
    }

    for (loop = 0; loop < maxloop; loop++) {
        /*
         * Send the first message to the receiver and wait for the ACK.
         */
        m.mtype = MTYPE_1;
        strcpy(m.mtext, m1_str);
        ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, sizeof(m), 0) != -1,
                        "sender: msgsnd 1: %d", errno);

        ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, sizeof(m),
                               MTYPE_1_ACK, 0) == sizeof(m),
                        "sender: msgrcv 1 ack: %d", errno);

        print_msqid_ds(&m_ds, 0600);

        /*
         * Send the second message to the receiver and wait for the ACK.
         */
        m.mtype = MTYPE_2;
        strcpy(m.mtext, m2_str);
        ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, sizeof(m), 0) != -1,
                        "sender: msgsnd 2: %d", errno);

        ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, sizeof(m),
                               MTYPE_2_ACK, 0) == sizeof(m),
                        "sender: msgrcv 2 ack: %d", errno);
    }

    /*
     * Wait for child to finish
     */
    sigemptyset(&sigmask);
    (void) sigsuspend(&sigmask);

    /*
     * ...and any other signal is an unexpected error.
     */
    if (did_sigchild) {
        c_status = child_status;
        if (c_status < 0)
            atf_tc_fail("waitpid: %d", -c_status);
        else if (WIFEXITED(c_status) == 0)
            atf_tc_fail("child abnormal exit: %d", c_status);
        else if (WEXITSTATUS(c_status) != 0)
            atf_tc_fail("c status: %d", WEXITSTATUS(c_status));
        else {
            ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds)
                            != -1, "msgctl IPC_STAT: %d", errno);

            print_msqid_ds(&m_ds, 0600);
            atf_tc_pass();
        }
    } else
        atf_tc_fail("sender: received unexpected signal");
}
示例#3
0
ATF_TC_BODY(shm, tc)
{
	struct sigaction sa;
	struct shmid_ds s_ds;
	sigset_t sigmask;
	char *shm_buf;
	int sender_shmid;
	int c_status;

	/*
	 * Install a SIGSYS handler so that we can exit gracefully if
	 * System V Shared Memory support isn't in the kernel.
	 */
	did_sigsys = 0;
	sa.sa_handler = sigsys_handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	ATF_REQUIRE_MSG(sigaction(SIGSYS, &sa, NULL) != -1,
	    "sigaction SIGSYS: %d", errno);

	/*
	 * Install a SIGCHLD handler to deal with all possible exit
	 * conditions of the sharer.
	 */
	did_sigchild = 0;
	child_count = 0;
	sa.sa_handler = sigchld_handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	ATF_REQUIRE_MSG(sigaction(SIGCHLD, &sa, NULL) != -1,
	    "sigaction SIGCHLD: %d", errno);

	pgsize = sysconf(_SC_PAGESIZE);

	shmkey = get_ftok(4160);
	ATF_REQUIRE_MSG(shmkey != (key_t)-1, "get_ftok failed");

	ATF_REQUIRE_MSG((sender_shmid = shmget(shmkey, pgsize,
					       IPC_CREAT | 0640)) != -1,
	    "shmget: %d", errno);
	write_int("sender_shmid", sender_shmid);

	ATF_REQUIRE_MSG(shmctl(sender_shmid, IPC_STAT, &s_ds) != -1,
	    "shmctl IPC_STAT: %d", errno);

	print_shmid_ds(&s_ds, 0640);

	s_ds.shm_perm.mode = (s_ds.shm_perm.mode & ~0777) | 0600;

	ATF_REQUIRE_MSG(shmctl(sender_shmid, IPC_SET, &s_ds) != -1,
	    "shmctl IPC_SET: %d", errno);

	memset(&s_ds, 0, sizeof(s_ds));

	ATF_REQUIRE_MSG(shmctl(sender_shmid, IPC_STAT, &s_ds) != -1,
	    "shmctl IPC_STAT: %d", errno);

	ATF_REQUIRE_MSG((s_ds.shm_perm.mode & 0777) == 0600,
	    "IPC_SET of mode didn't hold");

	print_shmid_ds(&s_ds, 0600);

	shm_buf = shmat(sender_shmid, NULL, 0);
	ATF_REQUIRE_MSG(shm_buf != (void *) -1, "sender: shmat: %d", errno);

	/*
	 * Write the test pattern into the shared memory buffer.
	 */
	strcpy(shm_buf, m2_str);

	switch ((child_pid = fork())) {
	case -1:
		atf_tc_fail("fork: %d", errno);
		return;

	case 0:
		sharer();
		break;

	default:
		break;
	}

	/*
	 * Wait for child to finish
	 */
	sigemptyset(&sigmask);
	(void) sigsuspend(&sigmask);

	if (did_sigchild) {
		c_status = child_status;
		if (c_status < 0)
			atf_tc_fail("waitpid: %d", -c_status);
		else if (WIFEXITED(c_status) == 0)
			atf_tc_fail("c abnormal exit: %d", c_status);
		else if (WEXITSTATUS(c_status) != 0)
			atf_tc_fail("c status: %d", WEXITSTATUS(c_status));
		else {
			ATF_REQUIRE_MSG(shmctl(sender_shmid, IPC_STAT,
					       &s_ds) != -1,
			    "shmctl IPC_STAT: %d", errno);

			print_shmid_ds(&s_ds, 0600);
			atf_tc_pass();
		}
	} else
		atf_tc_fail("sender: received unexpected signal");
}
示例#4
0
ATF_TC_BODY(sem, tc)
{
	struct sigaction sa;
	union semun sun;
	struct semid_ds s_ds;
	sigset_t sigmask;
	int sender_semid;
	int i;
	int c_status;

	/*
	 * Install a SIGSYS handler so that we can exit gracefully if
	 * System V Semaphore support isn't in the kernel.
	 */
	did_sigsys = 0;
	sa.sa_handler = sigsys_handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	ATF_REQUIRE_MSG(sigaction(SIGSYS, &sa, NULL) != -1,
	    "sigaction SIGSYS: %d", errno);

	/*
	 * Install a SIGCHLD handler to deal with all possible exit
	 * conditions of the receiver.
	 */
	did_sigchild = 0;
	child_count = 0;
	sa.sa_handler = sigchld_handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	ATF_REQUIRE_MSG(sigaction(SIGCHLD, &sa, NULL) != -1,
	    "sigaction SIGCHLD: %d", errno);

	semkey = get_ftok(4160);
	ATF_REQUIRE_MSG(semkey != (key_t)-1, "get_ftok failed");

	sender_semid = semget(semkey, 1, IPC_CREAT | 0640);
	ATF_REQUIRE_MSG(sender_semid != -1, "semget: %d", errno);
	write_int("sender_semid", sender_semid);

	if (did_sigsys) {
		atf_tc_skip("SYSV Semaphore not supported");
		return;
	}
	
	sun.buf = &s_ds;
	ATF_REQUIRE_MSG(semctl(sender_semid, 0, IPC_STAT, sun) != -1,
	    "semctl IPC_STAT: %d", errno);

	print_semid_ds(&s_ds, 0640);

	s_ds.sem_perm.mode = (s_ds.sem_perm.mode & ~0777) | 0600;

	sun.buf = &s_ds;
	ATF_REQUIRE_MSG(semctl(sender_semid, 0, IPC_SET, sun) != -1,
	    "semctl IPC_SET: %d", errno);

	memset(&s_ds, 0, sizeof(s_ds));

	sun.buf = &s_ds;
	ATF_REQUIRE_MSG(semctl(sender_semid, 0, IPC_STAT, sun) != -1,
	    "semctl IPC_STAT: %d", errno);

	ATF_REQUIRE_MSG((s_ds.sem_perm.mode & 0777) == 0600,
	    "IPC_SET of mode didn't hold");

	print_semid_ds(&s_ds, 0600);

	for (child_count = 0; child_count < 5; child_count++) {
		switch ((child_pid = fork())) {
		case -1:
			atf_tc_fail("fork: %d", errno);
			return;

		case 0:
			waiter();
			break;

		default:
			break;
		}
	}

	/*
	 * Wait for all of the waiters to be attempting to acquire the
	 * semaphore.
	 */
	for (;;) {
		i = semctl(sender_semid, 0, GETNCNT);
		if (i == -1)
			atf_tc_fail("semctl GETNCNT: %d", i);
		if (i == 5)
			break;
	}

	/*
	 * Now set the thundering herd in motion by initializing the
	 * semaphore to the value 1.
	 */
	sun.val = 1;
	ATF_REQUIRE_MSG(semctl(sender_semid, 0, SETVAL, sun) != -1,
	    "sender: semctl SETVAL to 1: %d", errno);

	/*
	 * Wait for all children to finish
	 */
	sigemptyset(&sigmask);
	for (;;) {
		(void) sigsuspend(&sigmask);
		if (did_sigchild) {
			c_status = child_status;
			if (c_status < 0)
				atf_tc_fail("waitpid: %d", -c_status);
			else if (WIFEXITED(c_status) == 0)
				atf_tc_fail("c abnormal exit: %d", c_status);
			else if (WEXITSTATUS(c_status) != 0)
				atf_tc_fail("c status: %d",
				    WEXITSTATUS(c_status));
			else {
				sun.buf = &s_ds;
				ATF_REQUIRE_MSG(semctl(sender_semid, 0,
						    IPC_STAT, sun) != -1,
				    "semctl IPC_STAT: %d", errno);

				print_semid_ds(&s_ds, 0600);
				atf_tc_pass();
			}
			if (child_count <= 0)
				break;
			did_sigchild = 0;
		} else {
			atf_tc_fail("sender: received unexpected signal");
			break;
		}
	}
}