Ejemplo n.º 1
0
ATF_TC_BODY(exec_exitstatus, tc)
{
    {
        atf_check_result_t result;
        do_exec(tc, "exit-success", &result);
        ATF_CHECK(atf_check_result_exited(&result));
        ATF_CHECK(!atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS);
        atf_check_result_fini(&result);
    }

    {
        atf_check_result_t result;
        do_exec(tc, "exit-failure", &result);
        ATF_CHECK(atf_check_result_exited(&result));
        ATF_CHECK(!atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_FAILURE);
        atf_check_result_fini(&result);
    }

    {
        atf_check_result_t result;
        do_exec(tc, "exit-signal", &result);
        ATF_CHECK(!atf_check_result_exited(&result));
        ATF_CHECK(atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_termsig(&result) == SIGKILL);
        atf_check_result_fini(&result);
    }
}
Ejemplo n.º 2
0
ATF_TC_BODY(exec_stdout_stderr, tc)
{
    atf_check_result_t result1, result2;
    const char *out1, *out2;
    const char *err1, *err2;

    do_exec_with_arg(tc, "stdout-stderr", "result1", &result1);
    ATF_CHECK(atf_check_result_exited(&result1));
    ATF_CHECK(atf_check_result_exitcode(&result1) == EXIT_SUCCESS);

    do_exec_with_arg(tc, "stdout-stderr", "result2", &result2);
    ATF_CHECK(atf_check_result_exited(&result2));
    ATF_CHECK(atf_check_result_exitcode(&result2) == EXIT_SUCCESS);

    out1 = atf_check_result_stdout(&result1);
    out2 = atf_check_result_stdout(&result2);
    err1 = atf_check_result_stderr(&result1);
    err2 = atf_check_result_stderr(&result2);

    ATF_CHECK(strstr(out1, "check.XXXXXX") == NULL);
    ATF_CHECK(strstr(out2, "check.XXXXXX") == NULL);
    ATF_CHECK(strstr(err1, "check.XXXXXX") == NULL);
    ATF_CHECK(strstr(err2, "check.XXXXXX") == NULL);

    ATF_CHECK(strstr(out1, "/check") != NULL);
    ATF_CHECK(strstr(out2, "/check") != NULL);
    ATF_CHECK(strstr(err1, "/check") != NULL);
    ATF_CHECK(strstr(err2, "/check") != NULL);

    ATF_CHECK(strstr(out1, "/stdout") != NULL);
    ATF_CHECK(strstr(out2, "/stdout") != NULL);
    ATF_CHECK(strstr(err1, "/stderr") != NULL);
    ATF_CHECK(strstr(err2, "/stderr") != NULL);

    ATF_CHECK(strcmp(out1, out2) != 0);
    ATF_CHECK(strcmp(err1, err2) != 0);

#define CHECK_LINES(path, outname, resname) \
    do { \
        int fd = open(path, O_RDONLY); \
        ATF_CHECK(fd != -1); \
        check_line(fd, "Line 1 to " outname " for " resname); \
        check_line(fd, "Line 2 to " outname " for " resname); \
        close(fd); \
    } while (false)

    CHECK_LINES(out1, "stdout", "result1");
    CHECK_LINES(out2, "stdout", "result2");
    CHECK_LINES(err1, "stderr", "result1");
    CHECK_LINES(err2, "stderr", "result2");

#undef CHECK_LINES

    atf_check_result_fini(&result2);
    atf_check_result_fini(&result1);
}
Ejemplo n.º 3
0
ATF_TC_BODY(exec_array, tc)
{
    atf_fs_path_t process_helpers;
    atf_check_result_t result;

    get_process_helpers_path(tc, false, &process_helpers);

    const char *argv[4];
    argv[0] = atf_fs_path_cstring(&process_helpers);
    argv[1] = "echo";
    argv[2] = "test-message";
    argv[3] = NULL;

    RE(atf_check_exec_array(argv, &result));

    ATF_CHECK(atf_check_result_exited(&result));
    ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS);

    {
        const char *path = atf_check_result_stdout(&result);
        int fd = open(path, O_RDONLY);
        ATF_CHECK(fd != -1);
        check_line(fd, "test-message");
        close(fd);
    }

    atf_check_result_fini(&result);
    atf_fs_path_fini(&process_helpers);
}
Ejemplo n.º 4
0
ATF_TC_BODY(exec_unknown, tc)
{
    const char *argv[2];
    argv[0] = "/foo/bar/non-existent";
    argv[1] = NULL;

    atf_check_result_t result;
    RE(atf_check_exec_array(argv, &result));
    ATF_CHECK(atf_check_result_exited(&result));
    ATF_CHECK(atf_check_result_exitcode(&result) == 127);
    atf_check_result_fini(&result);
}
Ejemplo n.º 5
0
ATF_TC_BODY(exec_unknown, tc)
{
    char buf[1024];
    snprintf(buf, sizeof(buf), "%s/non-existent",
             atf_config_get("atf_workdir"));

    const char *argv[2];
    argv[0] = buf;
    argv[1] = NULL;

    atf_check_result_t result;
    RE(atf_check_exec_array(argv, &result));
    ATF_CHECK(atf_check_result_exited(&result));
    ATF_CHECK(atf_check_result_exitcode(&result) == 127);
    atf_check_result_fini(&result);
}
Ejemplo n.º 6
0
ATF_TC_BODY(exec_cleanup, tc)
{
    atf_fs_path_t out, err;
    atf_check_result_t result;
    bool exists;

    do_exec(tc, "exit-success", &result);
    RE(atf_fs_path_init_fmt(&out, "%s", atf_check_result_stdout(&result)));
    RE(atf_fs_path_init_fmt(&err, "%s", atf_check_result_stderr(&result)));

    RE(atf_fs_exists(&out, &exists)); ATF_CHECK(exists);
    RE(atf_fs_exists(&err, &exists)); ATF_CHECK(exists);
    atf_check_result_fini(&result);
    RE(atf_fs_exists(&out, &exists)); ATF_CHECK(!exists);
    RE(atf_fs_exists(&err, &exists)); ATF_CHECK(!exists);

    atf_fs_path_fini(&err);
    atf_fs_path_fini(&out);
}
Ejemplo n.º 7
0
impl::check_result::~check_result(void)
{
    atf_check_result_fini(&m_result);
}