コード例 #1
0
ファイル: c_helpers.c プロジェクト: 274914765/C
ATF_TC_BODY (cleanup_sigterm, tc)
{
    char *nofile;

    touch (atf_tc_get_config_var (tc, "tmpfile"));
    kill (getpid (), SIGTERM);

    RE (atf_text_format (&nofile, "%s.no", atf_tc_get_config_var (tc, "tmpfile")));
    touch (nofile);
    free (nofile);
}
コード例 #2
0
ファイル: main.c プロジェクト: indianpoptart/xbps
ATF_TC_BODY(pkgdb_get_pkg_revdeps_test, tc)
{
	struct xbps_handle xh;
	xbps_array_t res;
	xbps_string_t pstr;
	const char *tcsdir, *str;
	const char *eout = "four-0.1_1\ntwo-0.1_1\n";
	unsigned int i;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	xh.flags = XBPS_FLAG_DEBUG;
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	res = xbps_pkgdb_get_pkg_revdeps(&xh, "mixed");
	ATF_REQUIRE_EQ(xbps_object_type(res), XBPS_TYPE_ARRAY);

	pstr = xbps_string_create();
	for (i = 0; i < xbps_array_count(res); i++) {
		xbps_array_get_cstring_nocopy(res, i, &str);
		xbps_string_append_cstring(pstr, str);
		xbps_string_append_cstring(pstr, "\n");
	}
	ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), eout);
}
コード例 #3
0
ファイル: main.c プロジェクト: indianpoptart/xbps
ATF_TC_BODY(pkgdb_get_virtualpkg_test, tc)
{
	xbps_dictionary_t pkgd;
	struct xbps_handle xh;
	const char *tcsdir, *pkgver;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	xh.flags = XBPS_FLAG_DEBUG;
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed>0");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed<2");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed-0.1_1");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
}
コード例 #4
0
ファイル: run_test.c プロジェクト: s5unty/kyua
ATF_TC_BODY(work_directory__env_tmpdir, tc)
{
    char* tmpdir;
    RE(kyua_fs_make_absolute("worktest", &tmpdir));
    ATF_REQUIRE(mkdir(tmpdir, 0755) != -1);
    RE(kyua_env_set("TMPDIR", tmpdir));

    char* work_directory;
    RE(kyua_run_work_directory_enter("template.XXXXXX", getuid(), getgid(),
                                     &work_directory));

    {
        char* template_test;
        RE(kyua_fs_concat(&template_test, atf_tc_get_config_var(tc, "srcdir"),
                          "worktest", "template.XXXXXX", NULL));
        ATF_REQUIRE(access(template_test, X_OK) == -1);
        free(template_test);
    }

    ATF_REQUIRE(access(work_directory, X_OK) != -1);

    ATF_REQUIRE(rmdir(tmpdir) == -1);  // Not yet empty.
    RE(kyua_run_work_directory_leave(&work_directory));
    ATF_REQUIRE(rmdir(tmpdir) != -1);
    free(tmpdir);
}
コード例 #5
0
ファイル: proc_test.c プロジェクト: mulichao/freebsd
/*
 * Run the test program. If the sig parameter is set to true, the test program
 * will deliver SIGUSR1 to itself during execution.
 */
static struct proc_handle *
start_prog(const struct atf_tc *tc, bool sig)
{
	char *argv[3];
	struct proc_handle *phdl;
	int error;

	asprintf(&argv[0], "%s/%s", atf_tc_get_config_var(tc, "srcdir"),
	    target_prog_file);
	ATF_REQUIRE(argv[0] != NULL);

	if (sig) {
		argv[1] = strdup("-s");
		argv[2] = NULL;
	} else {
		argv[1] = NULL;
	}

	error = proc_create(argv[0], argv, NULL, NULL, &phdl);
	ATF_REQUIRE_EQ_MSG(error, 0, "failed to run '%s'", target_prog_file);
	ATF_REQUIRE(phdl != NULL);

	free(argv[0]);
	free(argv[1]);

	return (phdl);
}
コード例 #6
0
ファイル: main.c プロジェクト: DirectorX/xbps
ATF_TC_BODY(find_all_orphans_test, tc)
{
	struct xbps_handle xh;
	xbps_array_t res;
	xbps_dictionary_t pkgd;
	xbps_string_t pstr;
	const char *pkgver, *tcsdir;
	unsigned int i;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	pstr = xbps_string_create();
	res = xbps_find_pkg_orphans(&xh, NULL);
	for (i = 0; i < xbps_array_count(res); i++) {
		pkgd = xbps_array_get(res, i);
		xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
		xbps_string_append_cstring(pstr, pkgver);
		xbps_string_append_cstring(pstr, "\n");
	}
	printf("%s", xbps_string_cstring_nocopy(pstr));

	ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), expected_output_all);
}
コード例 #7
0
void
get_process_helpers_path(const atf_tc_t *tc, const bool is_detail,
                         atf_fs_path_t *path)
{
    RE(atf_fs_path_init_fmt(path, "%s/%sprocess_helpers",
                            atf_tc_get_config_var(tc, "srcdir"),
                            is_detail ? "" : "detail/"));
}
コード例 #8
0
ファイル: libcam_test.c プロジェクト: mulichao/freebsd
static const char *
get_cam_test_device(const atf_tc_t *tc)
{
	const char *cam_test_device;

	cam_test_device = atf_tc_get_config_var(tc, "cam_test_device");

	return (cam_test_device);
}
コード例 #9
0
ファイル: test_helpers.c プロジェクト: gosudream/netbsd-src
void
build_check_c_o(const atf_tc_t *tc, const char *sfile, const char *failmsg)
{
    atf_fs_path_t path;

    RE(atf_fs_path_init_fmt(&path, "%s/%s",
                            atf_tc_get_config_var(tc, "srcdir"), sfile));
    build_check_c_o_aux(atf_fs_path_cstring(&path), failmsg);
    atf_fs_path_fini(&path);
}
コード例 #10
0
bool
build_check_c_o_srcdir(const atf_tc_t *tc, const char *sfile)
{
    atf_fs_path_t path;

    RE(atf_fs_path_init_fmt(&path, "%s/%s",
                            atf_tc_get_config_var(tc, "srcdir"), sfile));
    const bool result = build_check_c_o(atf_fs_path_cstring(&path));
    atf_fs_path_fini(&path);
    return result;
}
コード例 #11
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(fork_stop, tc)
{
    FILE *f;
    const char *dfstr, *pfstr;

    dfstr = atf_tc_get_config_var(tc, "donefile");
    pfstr = atf_tc_get_config_var(tc, "pidfile");

    f = fopen(pfstr, "w");
    if (f == NULL)
        atf_tc_fail("Failed to create pidfile %s", pfstr);
    fprintf(f, "%d", (int)getpid());
    fclose(f);
    printf("Wrote pid file\n");

    printf("Waiting for done file\n");
    while (access(dfstr, F_OK) != 0)
        usleep(10000);
    printf("Exiting\n");
}
コード例 #12
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(srcdir_exists, tc)
{
    atf_fs_path_t p;
    bool b;

    RE(atf_fs_path_init_fmt(&p, "%s/datafile",
                            atf_tc_get_config_var(tc, "srcdir")));
    RE(atf_fs_exists(&p, &b));
    atf_fs_path_fini(&p);
    if (!b)
        atf_tc_fail("Cannot find datafile");
}
コード例 #13
0
ファイル: run_test.c プロジェクト: s5unty/kyua
ATF_TC_BODY(fork_wait__unprivileged_group, tc)
{
    const struct passwd* pw = getpwnam(atf_tc_get_config_var(
        tc, "unprivileged-user"));
    ATF_REQUIRE_MSG(pw != NULL, "Cannot find unprivileged user");

    kyua_run_params_t run_params;
    kyua_run_params_init(&run_params);
    run_params.unprivileged_group = pw->pw_gid;

    ATF_REQUIRE_MSG(fork_check(&run_params, check_gid_not_root, NULL),
                    "Subprocess is still running with GID set to root");
}
コード例 #14
0
ファイル: t_parser.c プロジェクト: Henauxg/minix
static void set_env(atf_tc_t *tc)
{
        char *dir;

        asprintf(&dir, "%s/%s/", atf_tc_get_config_var(tc, "srcdir"),
            "parser_tests");

        if (dir == NULL)
            exit(-1);

        setenv(SASLC_ENV_CONFIG, dir, 1);
        free(dir);
}
コード例 #15
0
ファイル: t_truncate.c プロジェクト: 2trill2spill/freebsd
ATF_TC_BODY(truncate_err, tc)
{
	char buf[PATH_MAX];

	errno = 0;
	ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1);

	errno = 0;
	ATF_REQUIRE_ERRNO(EISDIR, truncate("/etc", 999) == -1);

	errno = 0;
	ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1);

	errno = 0;
	snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned",
	    atf_tc_get_config_var(tc, "srcdir"));
	ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1);
}
コード例 #16
0
ファイル: run_test.c プロジェクト: s5unty/kyua
ATF_TC_BODY(work_directory__permissions, tc)
{
    const struct passwd* pw = getpwnam(atf_tc_get_config_var(
        tc, "unprivileged-user"));

    printf("%d %d %d %d\n", getuid(), getgid(), pw->pw_uid, pw->pw_gid);

    char* work_directory;
    RE(kyua_run_work_directory_enter("template.XXXXXX", pw->pw_uid, pw->pw_gid,
                                     &work_directory));

    struct stat sb;
    ATF_REQUIRE(stat(work_directory, &sb) != -1);
    ATF_REQUIRE_EQ(pw->pw_uid, sb.st_uid);
    ATF_REQUIRE_EQ(pw->pw_gid, sb.st_gid);

    RE(kyua_run_work_directory_leave(&work_directory));
}
コード例 #17
0
ファイル: tc_test.c プロジェクト: jaredmcneill/netbsd-src
ATF_TC_BODY(config, tcin)
{
    atf_tc_t tc;
    const char *const config[] = { "test-var", "test-value", NULL };

    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
                   ATF_TC_BODY_NAME(empty), NULL, NULL));
    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var"));
    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
    atf_tc_fini(&tc);

    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
                   ATF_TC_BODY_NAME(empty), NULL, config));
    ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var"));
    ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"),
                     "test-value") == 0);
    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2"));
    ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"),
                     "def-value") == 0);
    atf_tc_fini(&tc);
}
コード例 #18
0
ファイル: main.c プロジェクト: indianpoptart/xbps
ATF_TC_BODY(pkgdb_pkg_reverts_test, tc)
{
	struct xbps_handle xh;
	const char *tcsdir;
	xbps_dictionary_t pkgd;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	xh.flags = XBPS_FLAG_DEBUG;
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	pkgd = xbps_pkgdb_get_pkg(&xh, "reverts");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);

	ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.2_1"), 0);
	ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.3_1"), 1);
	ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.4_1"), 1);
	ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.5_1"), 0);
}
コード例 #19
0
ファイル: t_truncate.c プロジェクト: 2asoft/freebsd
ATF_TC_BODY(truncate_err, tc)
{
#ifndef __NetBSD__
	char buf[PATH_MAX];
#endif

	errno = 0;
	ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1);

	errno = 0;
	ATF_REQUIRE_ERRNO(EISDIR, truncate("/etc", 999) == -1);

	errno = 0;
	ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1);

	errno = 0;
#ifdef __NetBSD__
	ATF_REQUIRE_ERRNO(EACCES, truncate("/usr/bin/fpr", 999) == -1);
#else
	snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned",
	    atf_tc_get_config_var(tc, "srcdir"));
	ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1);
#endif
}
コード例 #20
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(cleanup_fail, tc)
{
    touch(atf_tc_get_config_var(tc, "tmpfile"));
    atf_tc_fail("On purpose");
}
コード例 #21
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_CLEANUP(cleanup_pass, tc)
{
    if (atf_tc_get_config_var_as_bool(tc, "cleanup"))
        safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
}
コード例 #22
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(cleanup_pass, tc)
{
    touch(atf_tc_get_config_var(tc, "tmpfile"));
}
コード例 #23
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(config_multi_value, tc)
{
    ATF_REQUIRE(atf_tc_has_config_var(tc, "test"));
    ATF_REQUIRE(strcmp(atf_tc_get_config_var(tc, "test"), "foo bar") == 0);
}
コード例 #24
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_BODY(config_empty, tc)
{
    ATF_REQUIRE(atf_tc_has_config_var(tc, "test"));
    ATF_REQUIRE(strlen(atf_tc_get_config_var(tc, "test")) == 0);
}
コード例 #25
0
ファイル: c_helpers.c プロジェクト: AlexZhao/freebsd
ATF_TC_CLEANUP(cleanup_sigterm, tc)
{
    safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
}
コード例 #26
0
ファイル: atf_helpers.c プロジェクト: Bhudipta/minix
/// Prints a configuration variable if it exists.
///
/// \param tc Caller test case.
/// \param part Identifier for the part of the test case.
/// \param name Name of the configuration variable.
static void
print_config_var(const atf_tc_t* tc, const char* part, const char* name)
{
    if (atf_tc_has_config_var(tc, name))
        printf("%s %s %s\n", part, name, atf_tc_get_config_var(tc, name));
}