Exemple #1
0
ATF_TC_BODY (child_pid, tc)
{
    atf_process_stream_t outsb, errsb;

    atf_process_child_t child;

    atf_process_status_t status;

    pid_t pid;

    RE (atf_process_stream_init_capture (&outsb));
    RE (atf_process_stream_init_inherit (&errsb));

    RE (atf_process_fork (&child, child_report_pid, &outsb, &errsb, NULL));
    ATF_CHECK_EQ (read (atf_process_child_stdout (&child), &pid, sizeof (pid)), sizeof (pid));
    printf ("Expected PID: %d\n", (int) atf_process_child_pid (&child));
    printf ("Actual PID: %d\n", (int) pid);
    ATF_CHECK_EQ (atf_process_child_pid (&child), pid);

    RE (atf_process_child_wait (&child, &status));
    atf_process_status_fini (&status);

    atf_process_stream_fini (&outsb);
    atf_process_stream_fini (&errsb);
}
Exemple #2
0
static void capture_stream_process (void *v, atf_process_child_t * c)
{
    struct capture_stream *s = v;

    switch (s->m_base.m_type)
    {
        case stdout_type:
            (void) read_line (atf_process_child_stdout (c), &s->m_msg);
            break;
        case stderr_type:
            (void) read_line (atf_process_child_stderr (c), &s->m_msg);
            break;
        default:
            UNREACHABLE;
    }
}
Exemple #3
0
ATF_TC_BODY (child_wait_eintr, tc)
{
    atf_process_child_t child;

    atf_process_status_t status;

    {
        atf_process_stream_t outsb, errsb;

        RE (atf_process_stream_init_capture (&outsb));
        RE (atf_process_stream_init_inherit (&errsb));
        RE (atf_process_fork (&child, child_spawn_loop_and_wait_eintr, &outsb, &errsb, NULL));
        atf_process_stream_fini (&outsb);
        atf_process_stream_fini (&errsb);
    }

    {
        /* Wait until the child process performs the wait call.  This is
         * racy, because the message we get from it is sent *before*
         * doing the real system call... but I can't figure any other way
         * to do this. */
        char buf[16];

        printf ("Waiting for child to issue wait(2)\n");
        ATF_REQUIRE (read (atf_process_child_stdout (&child), buf, sizeof (buf)) > 0);
        sleep (1);
    }

    printf ("Interrupting child's wait(2) call\n");
    kill (atf_process_child_pid (&child), SIGHUP);

    printf ("Waiting for child's completion\n");
    RE (atf_process_child_wait (&child, &status));
    ATF_REQUIRE (atf_process_status_exited (&status));
    ATF_REQUIRE_EQ (atf_process_status_exitstatus (&status), EXIT_SUCCESS);
    atf_process_status_fini (&status);
}
Exemple #4
0
int
impl::child::stdout_fd(void)
{
    return atf_process_child_stdout(&m_child);
}