Esempio n. 1
2
static void
h_check(int test)
{
	struct sigaction sa;
	jmp_buf jb;
	sigjmp_buf sjb;
	sigset_t ss;
	int i, x;

	myself = pthread_self();
	i = getpid();

	if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE)
		expectsignal = 0;
	else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE)
		expectsignal = 1;
	else
		atf_tc_fail("unknown test");

	sa.sa_handler = aborthandler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	REQUIRE_ERRNO(sigaction(SIGABRT, &sa, NULL) != -1);
	REQUIRE_ERRNO(sigemptyset(&ss) != -1);
	REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1);
	REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1);
	ATF_REQUIRE(myself == pthread_self());

	if (test == TEST_SETJMP)
		x = setjmp(jb);
	else if (test == TEST_U_SETJMP)
		x = _setjmp(jb);
	else 
		x = sigsetjmp(sjb, !expectsignal);

	if (x != 0) {
		ATF_REQUIRE(myself == pthread_self());
		ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
		kill(i, SIGABRT);
		ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed");
		ATF_REQUIRE(myself == pthread_self());
		atf_tc_pass();
	}

	ATF_REQUIRE(myself == pthread_self());
	REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1);

	if (test == TEST_SETJMP)
		longjmp(jb, i);
	else if (test == TEST_U_SETJMP)
		_longjmp(jb, i);
	else 
		siglongjmp(sjb, i);

	atf_tc_fail("jmp failed");
}
Esempio n. 2
1
static void
aborthandler(int signo __unused)
{
	ATF_REQUIRE(myself == pthread_self());
	ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded");
	atf_tc_pass();
}
Esempio n. 3
0
void
print_shmid_ds(struct shmid_ds *sp, mode_t mode)
{
	uid_t uid = geteuid();
	gid_t gid = getegid();

	printf("PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\n",
	    sp->shm_perm.uid, sp->shm_perm.gid,
	    sp->shm_perm.cuid, sp->shm_perm.cgid,
	    sp->shm_perm.mode & 0777);

	printf("segsz %lu, lpid %d, cpid %d, nattch %u\n",
	    (u_long)sp->shm_segsz, sp->shm_lpid, sp->shm_cpid,
	    sp->shm_nattch);

	printf("atime: %s", ctime(&sp->shm_atime));
	printf("dtime: %s", ctime(&sp->shm_dtime));
	printf("ctime: %s", ctime(&sp->shm_ctime));

	/*
	 * Sanity check a few things.
	 */

	ATF_REQUIRE_MSG(sp->shm_perm.uid == uid && sp->shm_perm.cuid == uid,
	    "uid mismatch");

	ATF_REQUIRE_MSG(sp->shm_perm.gid == gid && sp->shm_perm.cgid == gid,
	    "gid mismatch");

	ATF_REQUIRE_MSG((sp->shm_perm.mode & 0777) == mode, "mode mismatch");
}
Esempio n. 4
0
void
print_semid_ds(struct semid_ds *sp, mode_t mode)
{
	uid_t uid = geteuid();
	gid_t gid = getegid();

	printf("PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\n",
	    sp->sem_perm.uid, sp->sem_perm.gid,
	    sp->sem_perm.cuid, sp->sem_perm.cgid,
	    sp->sem_perm.mode & 0777);

	printf("nsems %u\n", sp->sem_nsems);

	printf("otime: %s", ctime(&sp->sem_otime));
	printf("ctime: %s", ctime(&sp->sem_ctime));

	/*
	 * Sanity check a few things.
	 */

	ATF_REQUIRE_MSG(sp->sem_perm.uid == uid && sp->sem_perm.cuid == uid,
	    "uid mismatch");

	ATF_REQUIRE_MSG(sp->sem_perm.gid == gid && sp->sem_perm.cgid == gid,
	    "gid mismatch");

	ATF_REQUIRE_MSG((sp->sem_perm.mode & 0777) == mode,
	    "mode mismatch %o != %o", (sp->sem_perm.mode & 0777), mode);
}
Esempio n. 5
0
void
print_msqid_ds(struct msqid_ds *mp, mode_t mode)
{
	uid_t uid = geteuid();
	gid_t gid = getegid();

	printf("PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\n",
	    mp->msg_perm.uid, mp->msg_perm.gid,
	    mp->msg_perm.cuid, mp->msg_perm.cgid,
	    mp->msg_perm.mode & 0777);

	printf("qnum %lu, qbytes %lu, lspid %d, lrpid %d\n",
	    mp->msg_qnum, (u_long)mp->msg_qbytes, mp->msg_lspid,
	    mp->msg_lrpid);

	printf("stime: %s", ctime(&mp->msg_stime));
	printf("rtime: %s", ctime(&mp->msg_rtime));
	printf("ctime: %s", ctime(&mp->msg_ctime));

	/*
	 * Sanity check a few things.
	 */

	ATF_REQUIRE_MSG(mp->msg_perm.uid == uid && mp->msg_perm.cuid == uid,
	    "uid mismatch");

	ATF_REQUIRE_MSG(mp->msg_perm.gid == gid && mp->msg_perm.cgid == gid,
	    "gid mismatch");

	ATF_REQUIRE_MSG((mp->msg_perm.mode & 0777) == mode, "mode mismatch");
}
Esempio n. 6
0
ATF_TC_BODY(symbol_lookup_fail, tc)
{
	char symname[32];
	GElf_Sym sym;
	struct proc_handle *phdl;
	prmap_t *map;
	int error;

	phdl = start_prog(tc, false);

	/* Initialize the rtld_db handle. */
	(void)proc_rdagent(phdl);

	map = proc_name2map(phdl, target_prog_file);
	ATF_REQUIRE_MSG(map != NULL, "failed to look up map for '%s'",
	    target_prog_file);

	/*
	 * We shouldn't be able to find symbols at the beginning of a mapped
	 * file.
	 */
	error = proc_addr2sym(phdl, map->pr_vaddr, symname, sizeof(symname),
	    &sym);
	ATF_REQUIRE_MSG(error != 0, "unexpectedly found a symbol");

	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");

	proc_free(phdl);
}
Esempio n. 7
0
ATF_TC_BODY(fork_wait__signals, tc)
{
    ATF_REQUIRE_MSG(LAST_SIGNO > 10, "LAST_SIGNO as detected by configure is "
                    "suspiciously low");

    int signo;
    for (signo = 1; signo <= LAST_SIGNO; signo++) {
        if (signo == SIGKILL || signo == SIGSTOP) {
            // Ignore immutable signals.
            continue;
        }
        if (signo == SIGCHLD) {
            // If we were to reset SIGCHLD to SIG_IGN (which is different than
            // not touching the signal at all, leaving it at its default value),
            // our child process will not become a zombie and the call to
            // kyua_run_wait will fail.  Avoid this.
            continue;
        }

        struct sigaction sa;
        sa.sa_handler = SIG_IGN;
        sigemptyset(&sa.sa_mask);
        sa.sa_flags = 0;
        printf("Ignoring signal %d\n", signo);
        ATF_REQUIRE(sigaction(signo, &sa, NULL) != -1);
    }

    ATF_REQUIRE_MSG(fork_check(NULL, check_signals, NULL),
                    "Signals not reset to their default state");
}
Esempio n. 8
0
ATF_TC_BODY(fork, tc)
{
	pthread_t p;
	pid_t fork_pid;

	parent = getpid();

	PTHREAD_REQUIRE(pthread_create(&p, NULL, print_pid, NULL));

	fork_pid = fork();
	ATF_REQUIRE(fork_pid != -1);

	if (fork_pid) {
		int status;

		PTHREAD_REQUIRE(pthread_join(p, NULL));
		ATF_REQUIRE_MSG(thread_survived, "thread did not survive in parent");

		waitpid(fork_pid, &status, 0);
		ATF_REQUIRE_MSG(WIFEXITED(status), "child died wrongly");
		ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child");
	} else {
		sleep(5);
#ifdef __FreeBSD__
		_exit(thread_survived ? 1 : 0);
#else
		exit(thread_survived ? 1 : 0);
#endif
	}
}
Esempio n. 9
0
File: t_sysv.c Progetto: wieck/minix
key_t get_ftok(int id)
{
    int fd;
    char token_key[64], token_dir[64];
    char *tmpdir;
    key_t key;

    strlcpy(token_key, "/tmp/t_sysv.XXXXXX", sizeof(token_key));
    tmpdir = mkdtemp(token_key);
    ATF_REQUIRE_MSG(tmpdir != NULL, "mkdtemp() failed: %d", errno);

    strlcpy(token_dir, tmpdir, sizeof(token_dir));
    strlcpy(token_key, tmpdir, sizeof(token_key));
    strlcat(token_key, "/token_key", sizeof(token_key));

    /* Create the file, since ftok() requires it to exist! */

    fd = open(token_key, O_RDWR | O_CREAT | O_EXCL);
    if (fd == -1) {
        rmdir(tmpdir);
        atf_tc_fail("open() of temp file failed: %d", errno);
        return (key_t)-1;
    } else
        close(fd);

    key = ftok(token_key, id);

    ATF_REQUIRE_MSG(unlink(token_key) != -1, "unlink() failed: %d", errno);
    ATF_REQUIRE_MSG(rmdir(token_dir) != -1, "rmdir() failed: %d", errno);

    return key;
}
Esempio n. 10
0
static void *
run(void *param)
{
	struct timespec ts, to, te;
	clockid_t clck;
	pthread_condattr_t attr;
	pthread_cond_t cond;
	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
	int ret = 0;


	clck = *(clockid_t *)param;
	pthread_condattr_init(&attr);
	pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */
	pthread_cond_init(&cond, &attr);

	ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);

	ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0);
	to = ts;

	if (debug)
		printf("started: %lld.%09ld sec\n", (long long)to.tv_sec,
		    to.tv_nsec);

	ts.tv_sec += WAITTIME;	/* Timeout wait */

	switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) {
	case ETIMEDOUT:
		/* Timeout */
		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
		timespecsub(&te, &to, &to);
		if (debug) {
			printf("timeout: %lld.%09ld sec\n",
			    (long long)te.tv_sec, te.tv_nsec);
			printf("elapsed: %lld.%09ld sec\n",
			    (long long)to.tv_sec, to.tv_nsec);
		}
		if (isQEMU()) {
			double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec;
			ATF_REQUIRE(to_seconds >= WAITTIME * 0.9);
			/* Loose upper limit because of qemu timing bugs */
			ATF_REQUIRE(to_seconds < WAITTIME * 2.5);
		} else {
			ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
		}
		break;
	default:
		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));
	}

	ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)),
	    "pthread_mutex_unlock: %s", strerror(ret));
	pthread_exit(&ret);
}
Esempio n. 11
0
ATF_TC_BODY(aio_fifo_test, tc)
{
	int error, read_fd = -1, write_fd = -1;
	struct aio_fifo_arg arg;
	char pathname[PATH_MAX];
	struct aio_context ac;

	ATF_REQUIRE_KERNEL_MODULE("aio");
	ATF_REQUIRE_UNSAFE_AIO();

	/*
	 * In theory, mkstemp() can return a name that is then collided with.
	 * Because this is a regression test, we treat that as a test failure
	 * rather than retrying.
	 */
	strcpy(pathname, PATH_TEMPLATE);
	ATF_REQUIRE_MSG(mkstemp(pathname) != -1,
	    "mkstemp failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(unlink(pathname) == 0,
	    "unlink failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(mkfifo(pathname, 0600) != -1,
	    "mkfifo failed: %s", strerror(errno));
	arg.afa_pathname = pathname;
	arg.afa_read_fd = -1;
	arg.afa_write_fd = -1;

	read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
	if (read_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("read_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_read_fd = read_fd;

	write_fd = open(pathname, O_WRONLY);
	if (write_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("write_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_write_fd = write_fd;

	aio_context_init(&ac, read_fd, write_fd, FIFO_LEN,
	    FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_fifo_cleanup(&arg);
}
Esempio n. 12
0
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");
}
Esempio n. 13
0
ATF_TC_BODY(perror_test, tc)
{
	char buf[512], lbuf[512];
	int i;
	char *s;

	strcpy(tmpfil, "perror.XXXXXXXX");
	ATF_REQUIRE(mkstemp(tmpfil) >= 0);
	/* Reopen stderr on a file descriptor other than 2. */
	fclose(stderr);
	for (i = 0; i < 3; i++)
		dup(0);
	ATF_REQUIRE(freopen(tmpfil, "r+", stderr) != NULL);

	/*
	 * Test that perror() doesn't call strerror() (4.4BSD bug),
	 * the two ways of omitting a program name, and the formatting when
	 * a program name is specified.
	 */
	s = strerror(ENOENT);
	ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0,
	    "message obtained was: %s", s);
	errno = EPERM;
	perror(NULL);
	perror("");
	perror("perror_test");
	ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0,
	    "message obtained was: %s", s);

	/*
	 * Read it back to check...
	 */
	rewind(stderr);
	s = fgets(lbuf, sizeof(lbuf), stderr);
	ATF_REQUIRE(s != NULL);
	ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0,
	    "message obtained was: %s", s);
	s = fgets(lbuf, sizeof(lbuf), stderr);
	ATF_REQUIRE(s != NULL);
	ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0,
	    "message obtained was: %s", s);
	s = fgets(lbuf, sizeof(lbuf), stderr);
	ATF_REQUIRE(s != NULL);
	ATF_REQUIRE_MSG(
	    strcmp(s, "perror_test: Operation not permitted\n") == 0,
	    "message obtained was: %s", s);
	s = fgets(lbuf, sizeof(lbuf), stderr);
	ATF_REQUIRE(s == NULL);
	fclose(stderr);

}
Esempio n. 14
0
ATF_TC_BODY(data_string_new, tc) {
    struct data_string new_string;
    const char *src = "Really? Latin? ... geeks";
    int len_arg = 0;
    const char *error;

    /* Case 1: Call with an invalid data_string pointer, should fail */
    if (data_string_new(NULL, src, len_arg, MDL)) {
        atf_tc_fail("case 1: call should have failed");
    }

    /* Case 2: Passing in NULL src should fail */
    if (data_string_new(&new_string, NULL, 10, MDL)) {
        atf_tc_fail("case 2: did not return success");
    }

    /* Case 3: Call with valid params, length includes NULL */
    len_arg = strlen(src) + 1;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 3: did not return success");
    }

    error = checkString(&new_string, src);
    ATF_REQUIRE_MSG((error == NULL), "case 3: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 4: Call with valid params, length does not include NULL */
    len_arg = 7;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 4: did not return success");
    }

    error = checkString(&new_string, "Really?");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 5: Call with valid params, source string is "" */
    len_arg = 0;
    if (data_string_new(&new_string, "", len_arg, MDL) == 0) {
        atf_tc_fail("case 5: did not return success");
    }

    error = checkString(&new_string, "");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


}
Esempio n. 15
0
ATF_TC_BODY(listen_low_port, tc)
{
	int sd, val;

	sd = socket(AF_INET, SOCK_STREAM, 0);
#ifdef	__FreeBSD__
	ATF_REQUIRE_MSG(sd != -1, "socket failed: %s", strerror(errno));
#endif

	val = IP_PORTRANGE_LOW;
	if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
	    sizeof(val)) == -1)
		atf_tc_fail("setsockopt failed: %s", strerror(errno));

	if (listen(sd, 5) == -1) {
		int serrno = errno;
		atf_tc_fail("listen failed: %s%s",
		    strerror(serrno),
		    serrno != EACCES ? "" :
		    " (see http://mail-index.netbsd.org/"
		    "source-changes/2007/12/16/0011.html)");
	}

	close(sd);
}
Esempio n. 16
0
ATF_TC_BODY(fork_wait__core_size, tc)
{
    struct rlimit rl;
    rl.rlim_cur = 0;
    rl.rlim_max = RLIM_INFINITY;
    if (setrlimit(RLIMIT_CORE, &rl) == -1)
        atf_tc_skip("Failed to lower the core size limit");

    kyua_run_params_t run_params;
    kyua_run_params_init(&run_params);

    pid_t pid;
    kyua_error_t error = kyua_run_fork(&run_params, &pid);
    if (!kyua_error_is_set(error) && pid == 0)
        abort();

    ATF_REQUIRE(!kyua_error_is_set(error));
    int status; bool timed_out;
    error = kyua_run_wait(pid, &status, &timed_out);
    if (kyua_error_is_set(error))
        atf_tc_fail("wait failed; unexpected problem during exec?");

    ATF_REQUIRE(!timed_out);
    ATF_REQUIRE(WIFSIGNALED(status));
    ATF_REQUIRE_MSG(WCOREDUMP(status), "Core not dumped as expected");
}
Esempio n. 17
0
ATF_TC_BODY(positional_wide, tc)
{

	swprintf(wbuf1, nitems(wbuf1),
	    L"|xx %1$s %2$s %3$s %4$s\n"
	    "|xx %5$s %6$s %7$s %8$s\n"
	    "|xx %9$s %10$s %11$s %12$s\n"
	    "|xx %13$s %14$s %15$s %16$s\n"
	    "|xx %17$s %18$s %19$s %20$s\n"
	    "|xx %21$s %22$s %23$s %24$s\n"
	    "|xx %25$s %26$s %27$s %28$s\n"
	    "|xx %29$s %30$s %31$s %32$s\n"
	    "|xx %33$s %34$s %35$s %36$s\n"
	    "|xx %37$s %38$s %39$s %40$s\n"
	    "|xx %41$s %42$s %43$s %44$s\n"
	    "|xx %45$d %46$ld %47$lld %48$d %49$lld\n",
	    "01", "02", "03", "04", "05", "06",
	    "07", "08", "09", "10", "11", "12",
	    "13", "14", "15", "16", "17", "18",
	    "19", "20", "21", "22", "23", "24",
	    "25", "26", "27", "28", "29", "30",
	    "31", "32", "33", "34", "35", "36",
	    "37", "38", "39", "40", "41", "42",
	    "43", "44", 45, -1L, 1LL, -1, 1LL
	    );
	temp = correct;
	mbsrtowcs(wbuf2, &temp, nitems(wbuf2), NULL);
	ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
	    "buffers didn't match");
}
static void
h_pass(const char *buf, const char *fmt, int len,
    int tm_sec, int tm_min, int tm_hour, int tm_mday,
    int tm_mon, int tm_year, int tm_wday, int tm_yday)
{
	struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
	const char *ret, *exp;

	exp = buf + len;
	ret = strptime(buf, fmt, &tm);

	ATF_REQUIRE_MSG(ret == exp,
	    "strptime(\"%s\", \"%s\", tm): incorrect return code: "
	    "expected: %p, got: %p", buf, fmt, exp, ret);

#define H_REQUIRE_FIELD(field)						\
		ATF_REQUIRE_MSG(tm.field == field,			\
		    "strptime(\"%s\", \"%s\", tm): incorrect %s: "	\
		    "expected: %d, but got: %d", buf, fmt,		\
		    ___STRING(field), field, tm.field)

	H_REQUIRE_FIELD(tm_sec);
	H_REQUIRE_FIELD(tm_min);
	H_REQUIRE_FIELD(tm_hour);
	H_REQUIRE_FIELD(tm_mday);
	H_REQUIRE_FIELD(tm_mon);
	H_REQUIRE_FIELD(tm_year);
	H_REQUIRE_FIELD(tm_wday);
	H_REQUIRE_FIELD(tm_yday);

#undef H_REQUIRE_FIELD
}
Esempio n. 19
0
ATF_TC_BODY(positional_normal, tc)
{

	/* Test positional arguments */
	snprintf(buf, sizeof buf,
	    "|xx %1$s %2$s %3$s %4$s\n"
	    "|xx %5$s %6$s %7$s %8$s\n"
	    "|xx %9$s %10$s %11$s %12$s\n"
	    "|xx %13$s %14$s %15$s %16$s\n"
	    "|xx %17$s %18$s %19$s %20$s\n"
	    "|xx %21$s %22$s %23$s %24$s\n"
	    "|xx %25$s %26$s %27$s %28$s\n"
	    "|xx %29$s %30$s %31$s %32$s\n"
	    "|xx %33$s %34$s %35$s %36$s\n"
	    "|xx %37$s %38$s %39$s %40$s\n"
	    "|xx %41$s %42$s %43$s %44$s\n"
	    "|xx %45$d %46$ld %47$lld %48$d %49$lld\n",
	    "01", "02", "03", "04", "05", "06",
	    "07", "08", "09", "10", "11", "12",
	    "13", "14", "15", "16", "17", "18",
	    "19", "20", "21", "22", "23", "24",
	    "25", "26", "27", "28", "29", "30",
	    "31", "32", "33", "34", "35", "36",
	    "37", "38", "39", "40", "41", "42",
	    "43", "44", 45, -1L, 1LL, -1, 1LL
	    );
	ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
	    "buffers didn't match");
}
Esempio n. 20
0
static void
ztest1(const char *name, const char *fmt, long value)
{
	struct tm tm;
	char *rv;

	memset(&tm, 0, sizeof(tm));
	if ((rv = strptime(name, fmt, &tm)) == NULL) 
		tm.tm_gmtoff = -1;
	else if (rv == name && fmt[1] == 'Z')
		value = 0;

	switch (value) {
	case -2:
		value = -timezone;
		break;
	case -1:
		if (fmt[1] == 'Z')
			value = 0;
		break;
	default:
		break;
	}

	ATF_REQUIRE_MSG(tm.tm_gmtoff == value,
	    "strptime(\"%s\", \"%s\", &tm): "
	    "expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
	    name, fmt, value, tm.tm_gmtoff);
	printf("%s %s %ld\n", name, fmt, tm.tm_gmtoff);
}
Esempio n. 21
0
ATF_TC_BODY(swapcontext1, tc)
{
	pthread_t thread;

#if defined(__FreeBSD__) && defined(__mips__)
	/*
	 * MIPS modifies TLS pointer in set_mcontext(), so
	 * swapping contexts obtained from different threads
	 * gives us different pthread_self() return value.
	 */
	atf_tc_skip("Platform is not supported.");
#endif

	oself = (void *)&val1;
	nself = (void *)&val2;

	printf("Testing if swapcontext() alters pthread_self()\n");

#ifdef	__FreeBSD__
	ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s",
	    strerror(errno));
#else
	PTHREAD_REQUIRE(getcontext(&nctx));
#endif
	PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL));
	PTHREAD_REQUIRE(pthread_join(thread, NULL));
}
Esempio n. 22
0
static void
mainfunc(void)
{
	printf("Testing if swapcontext() alters TLS pointer if _UC_TLSBASE "
	       "is %s\n", (alter_tlsbase) ? "left set" : "cleared");

	_lwp_setprivate(&val1);
	printf("before swapcontext TLS pointer = %p\n", &val1);

	ATF_REQUIRE(getcontext(&nctx) == 0);

	nctx.uc_stack.ss_sp = stack;
	nctx.uc_stack.ss_size = sizeof(stack);

#ifndef _UC_TLSBASE
	ATF_REQUIRE_MSG(0, "_UC_TLSBASE is not defined");
#else /* _UC_TLSBASE */
	ATF_REQUIRE(nctx.uc_flags & _UC_TLSBASE);
	if (!alter_tlsbase)
		nctx.uc_flags &= ~_UC_TLSBASE;
#endif /* _UC_TLSBASE */

	makecontext(&nctx, swapfunc, 0);

	_lwp_setprivate(&val2);
	otls = _lwp_getprivate();
	printf("before swapcontext TLS pointer = %p\n", otls);
	ATF_REQUIRE(swapcontext(&octx, &nctx) == 0);

	printf("Test completed\n");
}
Esempio n. 23
0
ATF_TC_BODY(regcomp_too_big, tc)
{
	regex_t re;
	struct rlimit limit;
	int e;

	limit.rlim_cur = limit.rlim_max = 64 * 1024 * 1024;
	ATF_REQUIRE(setrlimit(RLIMIT_VMEM, &limit) != -1);
	for (size_t i = 0; i < __arraycount(tests); i++) {
		char *d = (*tests[i].pattern)(REGEX_MAXSIZE);
		e = regcomp(&re, d, tests[i].type);
		if (e) {
			char ebuf[1024];
			(void)regerror(e, &re, ebuf, sizeof(ebuf));
			ATF_REQUIRE_MSG(e == REG_ESPACE,
			    "regcomp returned %d (%s) for pattern %zu [%s]", e, ebuf,
			    i, d);
			free(d);
			continue;
		}
		free(d);
		(void)regexec(&re, "aaaaaaaaaaa", 0, NULL, 0);
		regfree(&re);
	}
}
Esempio n. 24
0
/** Prints the contents of a file to stdout.
 *
 * \param name The name of the file to be printed.
 * \param prefix An string to be prepended to every line of the printed
 *     file. */
void
atf_utils_cat_file(const char *name, const char *prefix)
{
    const int fd = open(name, O_RDONLY);
    ATF_REQUIRE_MSG(fd != -1, "Cannot open %s", name);

    char buffer[1024];
    ssize_t count;
    bool continued = false;
    while ((count = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
        buffer[count] = '\0';

        if (!continued)
            printf("%s", prefix);

        char *iter = buffer;
        char *end;
        while ((end = strchr(iter, '\n')) != NULL) {
            *end = '\0';
            printf("%s\n", iter);

            iter = end + 1;
            if (iter != buffer + count)
                printf("%s", prefix);
            else
                continued = false;
        }
        if (iter < buffer + count) {
            printf("%s", iter);
            continued = true;
        }
    }
    ATF_REQUIRE(count == 0);
}
Esempio n. 25
0
ATF_TC_BODY(positional_precision, tc)
{

	snprintf(buf, sizeof buf, "%2$.*4$s %2$.*3$s %1$s",
		 "BSD", "bsd", 2, 1);
	ATF_REQUIRE_MSG(strcmp(buf, correct2) == 0,
	    "buffers didn't match");
}
Esempio n. 26
0
static void
aio_timeout_stop(void)
{

	ATF_REQUIRE_MSG(signal(SIGALRM, NULL) != SIG_ERR,
	    "failed to reset SIGALRM handler to default: %s", strerror(errno));
	alarm(0);
}
static void
h_fail(const char *buf, const char *fmt)
{
	struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };

	ATF_REQUIRE_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", "
	    "\"%s\", &tm) should fail, but it didn't", buf, fmt);
}
Esempio n. 28
0
ATF_TC_BODY(aio_md_test, tc)
{
	int error, fd, mdctl_fd, unit;
	char pathname[PATH_MAX];
	struct aio_md_arg arg;
	struct aio_context ac;
	struct md_ioctl mdio;

	ATF_REQUIRE_KERNEL_MODULE("aio");

	mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
	ATF_REQUIRE_MSG(mdctl_fd != -1,
	    "opening /dev/%s failed: %s", MDCTL_NAME, strerror(errno));

	bzero(&mdio, sizeof(mdio));
	mdio.md_version = MDIOVERSION;
	mdio.md_type = MD_MALLOC;
	mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
	mdio.md_mediasize = GLOBAL_MAX;
	mdio.md_sectorsize = 512;

	arg.ama_mdctl_fd = mdctl_fd;
	arg.ama_unit = -1;
	arg.ama_fd = -1;
	if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
		error = errno;
		aio_md_cleanup(&arg);
		errno = error;
		atf_tc_fail("ioctl MDIOCATTACH failed: %s", strerror(errno));
	}

	arg.ama_unit = unit = mdio.md_unit;
	snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
	fd = open(pathname, O_RDWR);
	ATF_REQUIRE_MSG(fd != -1,
	    "opening %s failed: %s", pathname, strerror(errno));
	arg.ama_fd = fd;

	aio_context_init(&ac, fd, fd, MD_LEN, MD_TIMEOUT,
	    aio_md_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_md_cleanup(&arg);
}
Esempio n. 29
0
ATF_TC_BODY(ptm, tc)
{
	struct stat stm, sts;
	struct ptmget ptm;
	int fdm;
	struct group *gp;

	if ((fdm = open("/dev/ptm", O_RDWR)) == -1) {
		if (errno == ENOENT || errno == ENODEV)
			atf_tc_skip("/dev/ptm: %s", strerror(errno));
		atf_tc_fail("/dev/ptm: %s", strerror(errno));
	}

	REQUIRE_ERRNO(fstat(fdm, &stm), -1);
	ATF_REQUIRE_EQ(major(stm.st_rdev), 165);
	REQUIRE_ERRNO(ioctl(fdm, TIOCPTMGET, &ptm), -1);

	ATF_REQUIRE_MSG(strncmp(ptm.cn, "/dev/pty", 8) == 0
		|| strncmp(ptm.cn, "/dev/null", 9) == 0,
		"bad master name: %s", ptm.cn);

	ATF_REQUIRE_MSG(strncmp(ptm.sn, "/dev/tty", 8) == 0
		|| strncmp(ptm.sn, "/dev/pts/", 9) == 0,
		"bad slave name: %s", ptm.sn);

	if (strncmp(ptm.cn, "/dev/null", 9) != 0) {
		REQUIRE_ERRNO(fstat(ptm.cfd, &stm), -1);
		REQUIRE_ERRNO(stat(ptm.cn, &sts), -1);
		ATF_REQUIRE_EQ(stm.st_rdev, sts.st_rdev);
	}

	REQUIRE_ERRNO(fstat(ptm.sfd, &stm), -1);
	REQUIRE_ERRNO(stat(ptm.sn, &sts), -1);
	ATF_REQUIRE_EQ(stm.st_rdev, sts.st_rdev);

	ATF_REQUIRE_EQ_MSG(sts.st_uid, getuid(), "bad slave uid");

	ATF_REQUIRE_MSG((gp = getgrnam("tty")) != NULL,
	    "cannot find `tty' group");
	ATF_REQUIRE_EQ_MSG(sts.st_gid, gp->gr_gid, "bad slave grid");

	(void)close(ptm.sfd);
	(void)close(ptm.cfd);
	(void)close(fdm);
}
Esempio n. 30
0
static void
aio_timeout_start(int seconds)
{

	aio_timedout = 0;
	ATF_REQUIRE_MSG(signal(SIGALRM, aio_timeout_signal) != SIG_ERR,
	    "failed to set SIGALRM handler: %s", strerror(errno));
	alarm(seconds);
}