本文整理汇总了C++中ATF_REQUIRE_MSG函数的典型用法代码示例。如果您正苦于以下问题:C++ ATF_REQUIRE_MSG函数的具体用法?C++ ATF_REQUIRE_MSG怎么用?C++ ATF_REQUIRE_MSG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ATF_REQUIRE_MSG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_shmid_ds
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");
}
示例2: ATF_TC_BODY
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);
}
示例3: print_msqid_ds
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");
}
示例4: print_semid_ds
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);
}
示例5: ATF_TC_BODY
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");
}
示例6: ATF_TC_BODY
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
}
}
示例7: get_ftok
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;
}
示例8: h_check
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");
}
示例9: run
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);
}
示例10: ATF_TC_BODY
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);
}
示例11: ATF_TC_BODY
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);
}
示例12: ATF_TC_BODY
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);
}
示例13: ATF_TC_BODY
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");
}
示例14: h_pass
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
}
示例15: ztest1
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);
}