コード例 #1
0
ファイル: check.c プロジェクト: 0mp/freebsd
static
void
cleanup_tmpdir(const atf_fs_path_t *dir, const atf_fs_path_t *outfile,
               const atf_fs_path_t *errfile)
{
    {
        atf_error_t err = atf_fs_unlink(outfile);
        if (atf_is_error(err)) {
            INV(atf_error_is(err, "libc") &&
                atf_libc_error_code(err) == ENOENT);
            atf_error_free(err);
        } else
            INV(!atf_is_error(err));
    }

    {
        atf_error_t err = atf_fs_unlink(errfile);
        if (atf_is_error(err)) {
            INV(atf_error_is(err, "libc") &&
                atf_libc_error_code(err) == ENOENT);
            atf_error_free(err);
        } else
            INV(!atf_is_error(err));
    }

    {
        atf_error_t err = atf_fs_rmdir(dir);
        INV(!atf_is_error(err));
    }
}
コード例 #2
0
ATF_TC_BODY(libc_new, tc)
{
    atf_error_t err;

    err = atf_libc_error(ENOMEM, "Test message 1");
    ATF_REQUIRE(atf_error_is(err, "libc"));
    ATF_REQUIRE_EQ(atf_libc_error_code(err), ENOMEM);
    ATF_REQUIRE(strcmp(atf_libc_error_msg(err), "Test message 1") == 0);
    atf_error_free(err);

    err = atf_libc_error(EPERM, "%s message %d", "Test", 2);
    ATF_REQUIRE(atf_error_is(err, "libc"));
    ATF_REQUIRE_EQ(atf_libc_error_code(err), EPERM);
    ATF_REQUIRE(strcmp(atf_libc_error_msg(err), "Test message 2") == 0);
    atf_error_free(err);
}
コード例 #3
0
ファイル: fs.c プロジェクト: cyrilmagsuci/freebsd
atf_error_t
atf_fs_exists(const atf_fs_path_t *p, bool *b)
{
    atf_error_t err;

    err = atf_fs_eaccess(p, atf_fs_access_f);
    if (atf_is_error(err)) {
        if (atf_error_is(err, "libc") && atf_libc_error_code(err) == ENOENT) {
            atf_error_free(err);
            err = atf_no_error();
            *b = false;
        }
    } else
        *b = true;

    return err;
}
コード例 #4
0
ATF_TC_BODY(rmdir_enotempty, tc)
{
    atf_fs_path_t p;
    atf_error_t err;

    RE(atf_fs_path_init_fmt(&p, "test-dir"));

    ATF_REQUIRE(mkdir("test-dir", 0755) != -1);
    ATF_REQUIRE(exists(&p));
    create_file("test-dir/foo", 0644);

    err = atf_fs_rmdir(&p);
    ATF_REQUIRE(atf_is_error(err));
    ATF_REQUIRE(atf_error_is(err, "libc"));
    ATF_REQUIRE_EQ(atf_libc_error_code(err), ENOTEMPTY);
    atf_error_free(err);

    atf_fs_path_fini(&p);
}
コード例 #5
0
ATF_TC_BODY(mkdtemp_err, tc)
{
    atf_error_t err;
    atf_fs_path_t p;

    ATF_REQUIRE(mkdir("dir", 0555) != -1);

    RE(atf_fs_path_init_fmt(&p, "dir/testdir.XXXXXX"));

    err = atf_fs_mkdtemp(&p);
    ATF_REQUIRE(atf_is_error(err));
    ATF_REQUIRE(atf_error_is(err, "libc"));
    ATF_CHECK_EQ(atf_libc_error_code(err), EACCES);
    atf_error_free(err);

    ATF_CHECK(!exists(&p));
    ATF_CHECK(strcmp(atf_fs_path_cstring(&p), "dir/testdir.XXXXXX") == 0);

    atf_fs_path_fini(&p);
}
コード例 #6
0
ATF_TC_BODY(rmdir_eperm, tc)
{
    atf_fs_path_t p;
    atf_error_t err;

    RE(atf_fs_path_init_fmt(&p, "test-dir/foo"));

    ATF_REQUIRE(mkdir("test-dir", 0755) != -1);
    ATF_REQUIRE(mkdir("test-dir/foo", 0755) != -1);
    ATF_REQUIRE(chmod("test-dir", 0555) != -1);
    ATF_REQUIRE(exists(&p));

    err = atf_fs_rmdir(&p);
    if (atf_user_is_root()) {
        ATF_REQUIRE(!atf_is_error(err));
    } else {
        ATF_REQUIRE(atf_is_error(err));
        ATF_REQUIRE(atf_error_is(err, "libc"));
        ATF_REQUIRE_EQ(atf_libc_error_code(err), EACCES);
        atf_error_free(err);
    }

    atf_fs_path_fini(&p);
}
コード例 #7
0
ATF_TC_BODY(eaccess, tc)
{
    const int modes[] = { atf_fs_access_f, atf_fs_access_r, atf_fs_access_w,
                          atf_fs_access_x, 0 };
    const int *m;
    struct tests {
        mode_t fmode;
        int amode;
        int uerror;
        int rerror;
    } tests[] = {
        { 0000, atf_fs_access_r, EACCES, 0 },
        { 0000, atf_fs_access_w, EACCES, 0 },
        { 0000, atf_fs_access_x, EACCES, EACCES },

        { 0001, atf_fs_access_r, EACCES, 0 },
        { 0001, atf_fs_access_w, EACCES, 0 },
        { 0001, atf_fs_access_x, EACCES, 0 },
        { 0002, atf_fs_access_r, EACCES, 0 },
        { 0002, atf_fs_access_w, EACCES, 0 },
        { 0002, atf_fs_access_x, EACCES, EACCES },
        { 0004, atf_fs_access_r, EACCES, 0 },
        { 0004, atf_fs_access_w, EACCES, 0 },
        { 0004, atf_fs_access_x, EACCES, EACCES },

        { 0010, atf_fs_access_r, EACCES, 0 },
        { 0010, atf_fs_access_w, EACCES, 0 },
        { 0010, atf_fs_access_x, 0,      0 },
        { 0020, atf_fs_access_r, EACCES, 0 },
        { 0020, atf_fs_access_w, 0,      0 },
        { 0020, atf_fs_access_x, EACCES, EACCES },
        { 0040, atf_fs_access_r, 0,      0 },
        { 0040, atf_fs_access_w, EACCES, 0 },
        { 0040, atf_fs_access_x, EACCES, EACCES },

        { 0100, atf_fs_access_r, EACCES, 0 },
        { 0100, atf_fs_access_w, EACCES, 0 },
        { 0100, atf_fs_access_x, 0,      0 },
        { 0200, atf_fs_access_r, EACCES, 0 },
        { 0200, atf_fs_access_w, 0,      0 },
        { 0200, atf_fs_access_x, EACCES, EACCES },
        { 0400, atf_fs_access_r, 0,      0 },
        { 0400, atf_fs_access_w, EACCES, 0 },
        { 0400, atf_fs_access_x, EACCES, EACCES },

        { 0, 0, 0, 0 }
    };
    struct tests *t;
    atf_fs_path_t p;
    atf_error_t err;

    RE(atf_fs_path_init_fmt(&p, "the-file"));

    printf("Non-existent file checks\n");
    for (m = &modes[0]; *m != 0; m++) {
        err = atf_fs_eaccess(&p, *m);
        ATF_REQUIRE(atf_is_error(err));
        ATF_REQUIRE(atf_error_is(err, "libc"));
        ATF_REQUIRE_EQ(atf_libc_error_code(err), ENOENT);
        atf_error_free(err);
    }

    create_file(atf_fs_path_cstring(&p), 0000);
    ATF_REQUIRE(chown(atf_fs_path_cstring(&p), geteuid(), getegid()) != -1);

    for (t = &tests[0]; t->amode != 0; t++) {
        const int experr = atf_user_is_root() ? t->rerror : t->uerror;

        printf("\n");
        printf("File mode     : %04o\n", (unsigned int)t->fmode);
        printf("Access mode   : 0x%02x\n", t->amode);

        ATF_REQUIRE(chmod(atf_fs_path_cstring(&p), t->fmode) != -1);

        /* First, existence check. */
        err = atf_fs_eaccess(&p, atf_fs_access_f);
        ATF_REQUIRE(!atf_is_error(err));

        /* Now do the specific test case. */
        printf("Expected error: %d\n", experr);
        err = atf_fs_eaccess(&p, t->amode);
        if (atf_is_error(err)) {
            if (atf_error_is(err, "libc"))
                printf("Error         : %d\n", atf_libc_error_code(err));
            else
                printf("Error         : Non-libc error\n");
        } else
                printf("Error         : None\n");
        if (experr == 0) {
            ATF_REQUIRE(!atf_is_error(err));
        } else {
            ATF_REQUIRE(atf_is_error(err));
            ATF_REQUIRE(atf_error_is(err, "libc"));
            ATF_REQUIRE_EQ(atf_libc_error_code(err), experr);
            atf_error_free(err);
        }
    }

    atf_fs_path_fini(&p);
}
コード例 #8
0
ファイル: process_test.c プロジェクト: 274914765/C
static void child_spawn_loop_and_wait_eintr (void *v)
{
    atf_process_child_t child;

    atf_process_status_t status;

    struct sigaction sighup, old_sighup;

#define RE_ABORT(expr) \
    do { \
        atf_error_t _aux_err = expr; \
        if (atf_is_error(_aux_err)) { \
            atf_error_free(_aux_err); \
            abort(); \
        } \
    } while (0)

    {
        atf_process_stream_t outsb, errsb;

        RE_ABORT (atf_process_stream_init_capture (&outsb));
        RE_ABORT (atf_process_stream_init_inherit (&errsb));
        RE_ABORT (atf_process_fork (&child, child_loop, &outsb, &errsb, NULL));
        atf_process_stream_fini (&outsb);
        atf_process_stream_fini (&errsb);
    }

    sighup.sa_handler = nop_signal;
    sigemptyset (&sighup.sa_mask);
    sighup.sa_flags = 0;
    if (sigaction (SIGHUP, &sighup, &old_sighup) == -1)
        abort ();

    printf ("waiting\n");
    fflush (stdout);

    fprintf (stderr, "Child entering wait(2)\n");
    atf_error_t err = atf_process_child_wait (&child, &status);

    fprintf (stderr, "Child's wait(2) terminated\n");
    if (!atf_is_error (err))
    {
        fprintf (stderr, "wait completed successfully (not interrupted)\n");
        abort ();
    }
    if (!atf_error_is (err, "libc"))
    {
        fprintf (stderr, "wait did not raise libc_error\n");
        abort ();
    }
    if (atf_libc_error_code (err) != EINTR)
    {
        fprintf (stderr, "libc_error is not EINTR\n");
        abort ();
    }
    atf_error_free (err);

    sigaction (SIGHUP, &old_sighup, NULL);

    fprintf (stderr, "Child is killing subchild\n");
    kill (atf_process_child_pid (&child), SIGTERM);

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

#undef RE_ABORT

    exit (EXIT_SUCCESS);
}