Example #1
0
ATF_TC_BODY(get, tc)
{
    const struct varnames *v;

    /* Unset all known environment variables and make sure the built-in
     * values do not match the bogus value we will use for testing. */
    unset_all();
    __atf_config_reinit();
    for (v = all_vars; v->lc != NULL; v++)
        ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0);

    /* Test the behavior of empty values. */
    for (v = all_vars; v->lc != NULL; v++) {
        unset_all();
        if (strcmp(atf_config_get(v->lc), "") != 0) {
            RE(atf_env_set(v->uc, ""));
            __atf_config_reinit();
            if (v->can_be_empty)
                ATF_CHECK(strlen(atf_config_get(v->lc)) == 0);
            else
                ATF_CHECK(strlen(atf_config_get(v->lc)) > 0);
        }
    }

    /* Check if every variable is recognized individually. */
    for (v = all_vars; v->lc != NULL; v++) {
        unset_all();
        RE(atf_env_set(v->uc, test_value));
        __atf_config_reinit();
        compare_one(v->lc, test_value);
    }
}
Example #2
0
static
void
compare_one(const char *var, const char *expvalue)
{
    const struct varnames *v;

    printf("Checking that %s is set to %s\n", var, expvalue);

    for (v = all_vars; v->lc != NULL; v++) {
        if (strcmp(v->lc, var) == 0)
            ATF_CHECK_STREQ(atf_config_get(v->lc), test_value);
        else
            ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0);
    }
}
Example #3
0
static void
sigbus_action(int signo, siginfo_t *info, void *ptr)
{

	printf("si_addr = %p\n", info->si_addr);
	sig_debug(signo, info, (ucontext_t *)ptr);

	ATF_REQUIRE_EQ(info->si_signo, SIGBUS);
	ATF_REQUIRE_EQ(info->si_errno, 0);
	ATF_REQUIRE_EQ(info->si_code, BUS_ADRALN);

	if (strcmp(atf_config_get("atf_arch"), "i386") == 0 ||
	    strcmp(atf_config_get("atf_arch"), "x86_64") == 0) {
		atf_tc_expect_fail("x86 architecture does not correctly "
		    "report the address where the unaligned access occured");
	}
	ATF_REQUIRE_EQ(info->si_addr, (volatile void *)addr);

	atf_tc_pass();
	/* NOTREACHED */
}
Example #4
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);
}
Example #5
0
static
atf_error_t
append_config_var(const char *var, atf_list_t *argv)
{
    atf_error_t err;
    atf_list_t words;

    err = atf_text_split(atf_config_get(var), " ", &words);
    if (atf_is_error(err))
        goto out;

    atf_list_append_list(argv, &words);

out:
    return err;
}
Example #6
0
ATF_TC_BODY(sigbus_adraln, tc)
{
	const char *arch = atf_config_get("atf_arch");
	struct sigaction sa;

	if (strcmp(arch, "alpha") == 0) {
		int rv, val;
		size_t len = sizeof(val);
		rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len,
			NULL, 0);
		ATF_REQUIRE(rv == 0);
		if (val == 0)
			atf_tc_skip("SIGBUS signal not enabled for"
				    " unaligned accesses");

	}

	sa.sa_flags = SA_SIGINFO;
	sa.sa_sigaction = sigbus_action;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGBUS, &sa, NULL);

	/* Enable alignement checks for x86. 0x40000 is PSL_AC. */
#if defined(__i386__)
	__asm__("pushf; orl $0x40000, (%esp); popf");
#elif defined(__amd64__)
	__asm__("pushf; orl $0x40000, (%rsp); popf");
#endif

	addr = calloc(2, sizeof(int));
	ATF_REQUIRE(addr != NULL);

	if (isQEMU())
		atf_tc_expect_fail("QEMU fails to trap unaligned accesses");

	/* Force an unaligned access */
	addr++;
	printf("now trying to access unaligned address %p\n", addr);
	ATF_REQUIRE_EQ(*(volatile int *)addr, 0);

	atf_tc_fail("Test did not fault as expected");
}
Example #7
0
ATF_TC_BODY(sigfpe_int, tc)
{
	struct sigaction sa;
	long l = strtol("0", NULL, 10);

	if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0)
		atf_tc_skip("Test not valid on powerpc");
	if (sigsetjmp(sigfpe_int_env, 0) == 0) {
		sa.sa_flags = SA_SIGINFO;
		sa.sa_sigaction = sigfpe_int_action;
		sigemptyset(&sa.sa_mask);
		sigaction(SIGFPE, &sa, NULL);
#ifdef _FLOAT_IEEE754
		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
#endif
		printf("%ld\n", 1 / l);
	}
	if (intdiv_signalled == 0)
		atf_tc_fail("FPE signal handler was not invoked");
}
Example #8
0
bool
build_check_c_o(const char *path)
{
    bool success;
    atf_dynstr_t iflag;
    const char *optargs[4];

    RE(atf_dynstr_init_fmt(&iflag, "-I%s", atf_config_get("atf_includedir")));

    optargs[0] = atf_dynstr_cstring(&iflag);
    optargs[1] = "-Wall";
    optargs[2] = "-Werror";
    optargs[3] = NULL;

    RE(atf_check_build_c_o(path, "test.o", optargs, &success));

    atf_dynstr_fini(&iflag);

    return success;
}
Example #9
0
static
void
build_check_c_o_aux(const char *path, const char *failmsg)
{
    bool success;
    atf_dynstr_t iflag;
    const char *optargs[2];

    RE(atf_dynstr_init_fmt(&iflag, "-I%s", atf_config_get("atf_includedir")));

    optargs[0] = atf_dynstr_cstring(&iflag);
    optargs[1] = NULL;

    RE(atf_check_build_c_o(path, "test.o", optargs, &success));

    atf_dynstr_fini(&iflag);

    if (!success)
        atf_tc_fail(failmsg);
}
Example #10
0
ATF_TC_BODY(sigfpe_flt, tc)
{
	struct sigaction sa;
	double d = strtod("0", NULL);

	if (isQEMU())
		atf_tc_skip("Test does not run correctly under QEMU");
	if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0)
		atf_tc_skip("Test not valid on powerpc");
	if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
		sa.sa_flags = SA_SIGINFO;
		sa.sa_sigaction = sigfpe_flt_action;
		sigemptyset(&sa.sa_mask);
		sigaction(SIGFPE, &sa, NULL);
#ifdef _FLOAT_IEEE754
		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
#endif
		printf("%g\n", 1 / d);
	}
	if (fltdiv_signalled == 0)
		atf_tc_fail("FPE signal handler was not invoked");
}
Example #11
0
//
// Adds all predefined standard build-time variables to the m_variables
// map, considering the values a user may have provided in the environment.
//
// Can only be called once during the program's lifetime.
//
static
void
init_variables(void)
{
    PRE(m_variables.empty());

    m_variables["atf_arch"] = atf_config_get("atf_arch");
    m_variables["atf_build_cc"] = atf_config_get("atf_build_cc");
    m_variables["atf_build_cflags"] = atf_config_get("atf_build_cflags");
    m_variables["atf_build_cpp"] = atf_config_get("atf_build_cpp");
    m_variables["atf_build_cppflags"] = atf_config_get("atf_build_cppflags");
    m_variables["atf_build_cxx"] = atf_config_get("atf_build_cxx");
    m_variables["atf_build_cxxflags"] = atf_config_get("atf_build_cxxflags");
    m_variables["atf_confdir"] = atf_config_get("atf_confdir");
    m_variables["atf_includedir"] = atf_config_get("atf_includedir");
    m_variables["atf_libdir"] = atf_config_get("atf_libdir");
    m_variables["atf_libexecdir"] = atf_config_get("atf_libexecdir");
    m_variables["atf_machine"] = atf_config_get("atf_machine");
    m_variables["atf_pkgdatadir"] = atf_config_get("atf_pkgdatadir");
    m_variables["atf_shell"] = atf_config_get("atf_shell");
    m_variables["atf_workdir"] = atf_config_get("atf_workdir");

    POST(!m_variables.empty());
}