本文整理汇总了C++中TEST_ERROR_LOG函数的典型用法代码示例。如果您正苦于以下问题:C++ TEST_ERROR_LOG函数的具体用法?C++ TEST_ERROR_LOG怎么用?C++ TEST_ERROR_LOG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TEST_ERROR_LOG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
int nbytes, ret;
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
/* parse standard options */
if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) !=
(char *)NULL) {
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
/*NOTREACHED*/
}
/* set "tstdir", and "testfile" vars */
setup();
/* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping */
Tst_count = 0;
buf_list[0] = buf1;
buf_list[1] = buf2;
buf_list[2] = buf3;
buf_list[3] = (char *)NULL;
fd[1] = -1; /* Invalid file descriptor */
if (signal(SIGTERM, sighandler) == SIG_ERR) {
perror("signal: SIGTERM");
cleanup();
/*NOTREACHED*/
}
if (signal(SIGPIPE, sighandler) == SIG_ERR) {
perror("signal: SIGPIPE");
cleanup();
/*NOTREACHED*/
}
init_buffs(buf_list);
if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) {
tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
f_name, errno);
cleanup();
/*NOTREACHED*/
}
else if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1) {
tst_resm(TFAIL,
"write failed: nbytes = %d, " "errno = %d",
nbytes, errno);
cleanup();
/*NOTREACHED*/
}
if (close(fd[0]) < 0) {
tst_resm(TFAIL, "close failed: errno: %d", errno);
cleanup();
/*NOTREACHED*/
}
if ((fd[0] = open(f_name, O_RDWR, 0666)) < 0) {
tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
f_name, errno);
cleanup();
/*NOTREACHED*/
}
//block1: /* given vector length -1, writev() return EINVAL. */
tst_resm(TINFO, "Enter Block 1");
fail = 0;
TEST(writev(fd[0], wr_iovec, 1));
if (TEST_RETURN < 0) {
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO == EINVAL) {
tst_resm(TINFO, "Received EINVAL as expected");
} else {
tst_resm(TFAIL, "Expected errno = EINVAL, "
"got %d", TEST_ERRNO);
fail = 1;
}
} else {
tst_resm(TFAIL, "writev() failed to fail");
fail = 1;
}
if (fail) {
tst_resm(TINFO, "block 1 FAILED");
} else {
tst_resm(TINFO, "block 1 PASSED");
}
tst_resm(TINFO, "Exit block 1");
//block2:
/* This testcases doesn't look like what it intent to do
* 1. it is not using the wr_iovec initialized
* 2. read() and following message is not consistent
*/
//.........这里部分代码省略.........
示例2: main
int main(int ac, char **av)
{
int lc;
const char *msg;
int val; /* value for SETVAL */
int i;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup(); /* global setup */
/* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset tst_count in case we are looping */
tst_count = 0;
val = 1;
for (i = 0; i < TST_TOTAL; i++) {
/* initialize the s_buf buffer */
s_buf.sem_op = TC[i].op;
s_buf.sem_flg = TC[i].flg;
s_buf.sem_num = TC[i].num;
/* initialize all the primitive semaphores */
TC[i].get_arr.val = val--;
if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].get_arr)
== -1) {
tst_brkm(TBROK, cleanup, "semctl() failed");
}
/*
* make the call with the TEST macro
*/
TEST(semop(sem_id_1, &s_buf, 1));
if (TEST_RETURN != -1) {
tst_resm(TFAIL, "call succeeded unexpectedly");
continue;
}
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO == TC[i].error) {
tst_resm(TPASS,
"expected failure - errno = %d"
" : %s", TEST_ERRNO,
strerror(TEST_ERRNO));
} else {
tst_resm(TFAIL, "unexpected error - "
"%d : %s", TEST_ERRNO,
strerror(TEST_ERRNO));
}
}
}
cleanup();
tst_exit();
}
示例3: main
int main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
int exec_return; /* return from do_exec */
int **tcp; /* testcase pointer (pointer to FD) */
char **tcd; /* testcase description pointer */
/***************************************************************
* parse standard options, and exit if there is an error
***************************************************************/
if ((msg = parse_opts(ac, av, options, &help)) != (char *)NULL) {
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
tst_exit();
}
if (fflag) /* -F option */
File1 = fopt;
if (Tflag) { /* -T option */
exit(test_open(Topt));
}
/***************************************************************
* perform global setup for test
***************************************************************/
setup(av[0]);
/***************************************************************
* check looping state if -c option given
***************************************************************/
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping. */
Tst_count = 0;
for (tcp = testfds, tcd = testfdtypes; *tcp; tcp++, tcd++) {
TEST(fcntl(**tcp, F_SETFD, FD_CLOEXEC));
/* check return code */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"fcntl(%s[%d], F_SETFD, FD_CLOEXEC) Failed, errno=%d : %s",
*tcd, **tcp, TEST_ERRNO,
strerror(TEST_ERRNO));
} else {
/*************************************************************
* only perform functional verification if flag set
* (-f not given)
*************************************************************/
if (STD_FUNCTIONAL_TEST) {
exec_return =
do_exec(subprog_path, **tcp, *tcd);
switch (exec_return) {
case -1:
tst_resm(TBROK,
"fork failed. Errno %s [%d]",
strerror(errno),
errno);
break;
case 1:
tst_resm(TBROK,
"waitpid return was 0%o",
stat_loc);
break;
case 2:
tst_resm(TBROK, "exec failed"); /* errno was in child */
break;
case 0:
tst_resm(TPASS,
"%s child exited 0, indicating that the file was closed",
*tcd);
break;
default:
tst_resm(TFAIL,
"%s child exited non-zero, %d",
*tcd, exec_return);
break;
}
}
}
}
} /* End for TEST_LOOPING */
/***************************************************************
* cleanup and exit
***************************************************************/
cleanup();
return 0;
} /* End main */
示例4: main
int main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
int i;
/* Disable test if the version of the kernel is less than 2.6.16 */
if((tst_kvercmp(2,6,16)) < 0)
{
tst_resm(TWARN, "This test can only run on kernels that are ");
tst_resm(TWARN, "2.6.16 and higher");
exit(0);
}
/***************************************************************
* parse standard options
***************************************************************/
if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL)
tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
/***************************************************************
* perform global setup for test
***************************************************************/
setup();
/***************************************************************
* check looping state if -c option given
***************************************************************/
for (lc = 0; TEST_LOOPING(lc); lc++) {
setup_every_copy();
/* reset Tst_count in case we are looping. */
Tst_count = 0;
/*
* Call fchmodat
*/
for (i = 0; i < TST_TOTAL; i++) {
TEST(myfchmodat(fds[i], filenames[i], 0600));
/* check return code */
if (TEST_ERRNO == expected_errno[i]) {
/***************************************************************
* only perform functional verification if flag set (-f not given)
***************************************************************/
if (STD_FUNCTIONAL_TEST) {
/* No Verification test, yet... */
tst_resm(TPASS,
"fchmodat() returned the expected errno %d: %s",
TEST_ERRNO,
strerror(TEST_ERRNO));
}
} else {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"fchmodat() Failed, errno=%d : %s",
TEST_ERRNO, strerror(TEST_ERRNO));
}
}
} /* End for TEST_LOOPING */
/***************************************************************
* cleanup and exit
***************************************************************/
cleanup();
return (0);
} /* End main */
示例5: do_master_child
/*
* do_master_child()
*/
void do_master_child()
{
int lc;
int pid;
int status;
for (lc = 0; TEST_LOOPING(lc); lc++) {
int tst_fd;
/* Reset tst_count in case we are looping */
tst_count = 0;
if (setresuid(0, ltpuser->pw_uid, 0) == -1) {
perror("setfsuid failed");
exit(1);
}
/* Test 1: Check the process with new uid cannot open the file
* with RDWR permissions.
*/
TEST(tst_fd = open(testfile, O_RDWR));
if (TEST_RETURN != -1) {
printf("open succeeded unexpectedly\n");
close(tst_fd);
exit(1);
}
if (TEST_ERRNO == EACCES) {
printf("open failed with EACCES as expected\n");
} else {
perror("open failed unexpectedly");
exit(1);
}
/* Test 2: Check a son process cannot open the file
* with RDWR permissions.
*/
pid = FORK_OR_VFORK();
if (pid < 0)
tst_brkm(TBROK, cleanup, "Fork failed");
if (pid == 0) {
int tst_fd2;
/* Test to open the file in son process */
TEST(tst_fd2 = open(testfile, O_RDWR));
if (TEST_RETURN != -1) {
printf("call succeeded unexpectedly\n");
close(tst_fd2);
exit(1);
}
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO == EACCES) {
printf("open failed with EACCES as expected\n");
exit(0);
} else {
printf("open failed unexpectedly\n");
exit(1);
}
} else {
/* Wait for son completion */
if (waitpid(pid, &status, 0) == -1) {
perror("waitpid failed");
exit(1);
}
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
exit(WEXITSTATUS(status));
}
/* Test 3: Fallback to initial uid and check we can again open
* the file with RDWR permissions.
*/
tst_count++;
if (setresuid(0, 0, 0) == -1) {
perror("setfsuid failed");
exit(1);
}
TEST(tst_fd = open(testfile, O_RDWR));
if (TEST_RETURN == -1) {
perror("open failed unexpectedly");
exit(1);
} else {
printf("open call succeeded\n");
close(tst_fd);
}
}
exit(0);
}
示例6: main
/***********************************************************************
* Main
***********************************************************************/
int
main(int ac, char **av)
{
int lc; /* loop counter */
const char *msg; /* message returned from parse_opts */
struct stat fbuf, lbuf;
int cnt;
int nlinks;
char lname[255];
Tst_nobuf=1;
/***************************************************************
* parse standard options
***************************************************************/
if ( (msg=parse_opts(ac, av, options, &help)) != (char *) NULL ) {
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
tst_exit();
}
if ( Nflag ) {
if (sscanf(Nlinkarg, "%i", &Nlinks) != 1 ) {
tst_brkm(TBROK, NULL, "--N option arg is not a number");
tst_exit();
}
if ( Nlinks > 1000 ) {
tst_resm(TWARN, "--N option arg > 1000 - may get errno:%d (EMLINK)",
EMLINK);
}
}
/***************************************************************
* perform global setup for test
***************************************************************/
setup();
/* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
/***************************************************************
* check looping state if -c option given
***************************************************************/
for (lc=0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping. */
Tst_count=0;
if ( Nlinks )
nlinks = Nlinks;
else
/* min of 10 links and max of a 100 links */
nlinks = (lc%90)+10;
for(cnt=1; cnt < nlinks; cnt++) {
sprintf(lname, "%s%d", Basename, cnt);
/*
* Call link(2)
*/
TEST(link(Fname, lname));
/* check return code */
if ( TEST_RETURN == -1 ) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_brkm(TFAIL, cleanup, "link(%s, %s) Failed, errno=%d : %s",
Fname, lname, TEST_ERRNO, strerror(TEST_ERRNO));
}
}
/***************************************************************
* only perform functional verification if flag set (-f not given)
***************************************************************/
if ( STD_FUNCTIONAL_TEST ) {
stat(Fname, &fbuf);
for(cnt=1; cnt < nlinks; cnt++) {
sprintf(lname, "%s%d", Basename, cnt);
stat(lname, &lbuf);
if ( fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 ||
(fbuf.st_nlink != lbuf.st_nlink) ) {
tst_resm(TFAIL,
"link(%s, %s[1-%d]) ret %d for %d files, stat values do not match %d %d",
Fname, Basename, nlinks, TEST_RETURN, nlinks,
fbuf.st_nlink, lbuf.st_nlink);
break;
}
}
if ( cnt >= nlinks ) {
tst_resm(TPASS,
"link(%s, %s[1-%d]) ret %d for %d files, stat linkcounts match %d",
Fname, Basename, nlinks, TEST_RETURN, nlinks,
fbuf.st_nlink);
}
}
else
//.........这里部分代码省略.........
示例7: main
int main(int ac, char **av)
{
struct stat stat_buf; /* stat(2) struct contents */
int lc, i; /* loop counter */
char *msg; /* message returned from parse_opts */
off_t file_length2; /* test file length */
off_t file_length1; /* test file length */
int rbytes; /* bytes read from testfile */
int read_len = 0; /* total no. of bytes read from testfile */
int err_flag = 0; /* error indicator flag */
/* Parse standard options given to run the test. */
msg = parse_opts(ac, av, (option_t *) NULL, NULL);
if (msg != (char *)NULL) {
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
tst_exit();
}
/* Perform global setup for test */
setup();
/* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
/* Check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* Reset Tst_count in case we are looping. */
Tst_count = 0;
/*
* Call truncate(2) to truncate a test file to a
* specified length (TRUNC_LEN1).
*/
TEST(truncate(TESTFILE, TRUNC_LEN1));
/* check return code of truncate(2) */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"truncate(%s, %d) Failed, errno=%d : %s",
TESTFILE, TRUNC_LEN1, TEST_ERRNO,
strerror(TEST_ERRNO));
} else {
/*
* Perform functional verification if test
* executed without (-f) option.
*/
if (STD_FUNCTIONAL_TEST) {
/*
* Get the testfile information using
* stat(2).
*/
if (stat(TESTFILE, &stat_buf) < 0) {
tst_brkm(TFAIL, cleanup, "stat(2) of "
"%s failed after 1st truncate, "
"error:%d", TESTFILE, errno);
/*NOTREACHED*/}
file_length1 = stat_buf.st_size;
/*
* Set the file pointer of testfile to the
* beginning of the file.
*/
if (lseek(fd, 0, SEEK_SET) < 0) {
tst_brkm(TFAIL, cleanup, "lseek(2) on "
"%s failed after 1st truncate, "
"error:%d", TESTFILE, errno);
/*NOTREACHED*/}
/* Read the testfile from the beginning. */
while ((rbytes = read(fd, tst_buff,
sizeof(tst_buff))) > 0) {
read_len += rbytes;
}
/*
* Execute truncate(2) again to truncate
* testfile to a size TRUNC_LEN2.
*/
TEST(truncate(TESTFILE, TRUNC_LEN2));
/* check return code of truncate(2) */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL, "truncate of %s to "
"size %d Failed, errno=%d : %s",
TESTFILE, TRUNC_LEN2,
TEST_ERRNO,
strerror(TEST_ERRNO));
}
/*
* Get the testfile information using
* stat(2)
*/
if (stat(TESTFILE, &stat_buf) < 0) {
tst_brkm(TFAIL, cleanup, "stat(2) of "
"%s failed after 2nd truncate, "
"error:%d", TESTFILE, errno);
/*NOTREACHED*/}
//.........这里部分代码省略.........
示例8: main
int main(int ac, char **av)
{
int lc;
char *msg;
int count, rval, fd;
size_t size = 0;
char *dir_name = NULL;
struct dirent *dirp;
struct stat *sbuf;
char *newfile;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
if ((dir_name = getcwd(dir_name, size)) == NULL)
tst_brkm(TBROK, cleanup, "Can not get current "
"directory name");
if ((dirp = malloc(sizeof(struct dirent))) == NULL)
tst_brkm(TBROK, cleanup, "malloc failed");
count = (int)sizeof(struct dirent);
/* set up some space for a file name */
if ((newfile = malloc(sizeof(char) * 20)) == NULL)
tst_brkm(TBROK, cleanup, "newfile malloc failed");
if ((rval = sprintf(newfile, "getdents03.%d", getpid())) < 0)
tst_brkm(TBROK, cleanup, "sprintf failed");
if ((fd = open(newfile, O_CREAT | O_RDWR, 0777)) == -1)
tst_brkm(TBROK|TERRNO, cleanup, "open of file failed");
/* set up some space for the stat buffer */
if ((sbuf = malloc(sizeof(struct stat))) == NULL)
tst_brkm(TBROK, cleanup, "stat malloc failed");
/* make sure fd is not a directory */
if ((rval = fstat(fd, sbuf)) == -1)
tst_brkm(TBROK, cleanup, "fstat failed");
if (S_ISDIR(sbuf->st_mode))
tst_brkm(TBROK, cleanup, "fd is a directory");
rval = getdents(fd, dirp, count);
/*
* Calling with a non directory file descriptor should give
* an ENOTDIR error.
*/
if (rval < 0) {
TEST_ERROR_LOG(errno);
switch (errno) {
case ENOTDIR:
tst_resm(TPASS,
"getdents failed as expected with ENOTDIR");
break;
default:
tst_resm(TFAIL|TERRNO,
"getdents failed unexpectedly");
break;
}
} else
tst_resm(TFAIL, "getdents call succeeded unexpectedly");
free(dir_name);
dir_name = NULL;
free(dirp);
if ((rval = close(fd)) == -1)
tst_brkm(TBROK, cleanup, "fd close failed");
if ((rval = unlink(newfile)) == -1)
tst_brkm(TBROK, cleanup, "file unlink failed");
}
cleanup();
tst_exit();
}
示例9: main
int main(int ac, char **av)
{
int lc;
char *msg;
int fails;
int kid_status, wait_status;
msg = parse_opts(ac, av, NULL, NULL);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
fails = 0;
TEST(fork());
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
if (STD_FUNCTIONAL_TEST) {
tst_resm(TFAIL, "fork() Failed, errno=%d : %s",
TEST_ERRNO, strerror(TEST_ERRNO));
tst_resm(TBROK, "unable to continue");
}
}
if (TEST_RETURN == 0) {
/* child */
if (STD_FUNCTIONAL_TEST)
child_pid();
exit(KIDEXIT);
} else {
/* parent */
if (STD_FUNCTIONAL_TEST) {
tst_resm(TPASS, "fork() returned %ld",
TEST_RETURN);
}
/* wait for the child to complete */
wait_status = waitpid(TEST_RETURN, &kid_status, 0);
if (STD_FUNCTIONAL_TEST) {
if (wait_status == TEST_RETURN) {
if (kid_status != KIDEXIT << 8) {
tst_resm(TBROK,
"incorrect child status returned on wait(): %d",
kid_status);
fails++;
}
} else {
tst_resm(TBROK,
"wait() for child status failed with %d errno: %d : %s",
wait_status, errno,
strerror(errno));
fails++;
}
if (fails == 0) {
/* verification tests */
parent_pid();
}
} /* STD_FUNCTIONAL_TEST */
} /* TEST_RETURN */
}
cleanup();
tst_exit();
}
示例10: main
int main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
/***************************************************************
* parse standard options
***************************************************************/
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
/***************************************************************
* perform global setup for test
***************************************************************/
setup();
/*
* check if the current filesystem is nfs
*/
if (tst_is_cwd_nfs()) {
tst_brkm(TCONF, cleanup,
"Cannot do fcntl on a file located on an NFS filesystem");
}
/*
* check if the current filesystem is tmpfs
*/
if (tst_is_cwd_tmpfs()) {
tst_brkm(TCONF, cleanup,
"Cannot do fcntl on a file located on an TMPFS filesystem");
}
/*
* check if the current filesystem is ramfs
*/
if (tst_is_cwd_ramfs()) {
tst_brkm(TCONF, cleanup,
"Cannot do fcntl on a file located on an RAMFS filesystem");
}
/* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
/***************************************************************
* check looping state if -c option given
***************************************************************/
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
#ifdef F_SETLEASE
/*
* Call fcntl(2) with F_SETLEASE & F_WRLCK argument on fname
*/
TEST(fcntl(fd, F_SETLEASE, F_WRLCK));
/* check return code */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"fcntl(%s, F_SETLEASE, F_WRLCK) Failed, errno=%d : %s",
fname, TEST_ERRNO, strerror(TEST_ERRNO));
} else {
if (STD_FUNCTIONAL_TEST) {
TEST(fcntl(fd, F_GETLEASE));
if (TEST_RETURN != F_WRLCK)
tst_resm(TFAIL,
"fcntl(%s, F_GETLEASE) did not return F_WRLCK, returned %ld",
fname, TEST_RETURN);
else {
TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
if (TEST_RETURN != 0)
tst_resm(TFAIL,
"fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld",
fname, TEST_RETURN);
else
tst_resm(TPASS,
"fcntl(%s, F_SETLEASE, F_WRLCK)",
fname);
}
}
}
#else
tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
#endif
}
/***************************************************************
* cleanup and exit
***************************************************************/
cleanup();
tst_exit();
}
示例11: main
int main(int ac, char **av)
{
int lc;
char *msg;
pid_t pid, pid1;
int retval = 3, status;
char *argv[1], *env[1];
if ((msg = parse_opts(ac, av, options, &help)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
maybe_run_child(&do_child_1, "nS", 1, &test_app);
#endif
if (!Fflag)
tst_brkm(TBROK, NULL,
"You must specify an executable file with the -F option.");
setup(*av);
TEST_EXP_ENOS(exp_enos);
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
if (sync_pipe_create(start_sync_pipes, PIPE_NAME_START) == -1)
tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
if (sync_pipe_create(end_sync_pipes, PIPE_NAME_END) == -1)
tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
/*
* to test whether execve(2) sets ETXTBSY when a second
* child process attempts to execve the executable opened
* by the first child process
*/
if ((pid = FORK_OR_VFORK()) == -1)
tst_brkm(TBROK, cleanup, "fork #1 failed");
else if (pid == 0) {
#ifdef UCLINUX
if (self_exec(av[0], "nS", 1, test_app) < 0)
tst_brkm(TBROK, cleanup, "self_exec failed");
#else
do_child_1();
#endif
}
if (sync_pipe_wait(start_sync_pipes) == -1)
tst_brkm(TBROK, cleanup, "sync_pipe_wait failed");
if (sync_pipe_close(start_sync_pipes, PIPE_NAME_START) == -1)
tst_brkm(TBROK, cleanup, "sync_pipe_close failed");
if ((pid1 = FORK_OR_VFORK()) == -1)
tst_brkm(TBROK, cleanup, "fork #2 failed");
if (pid1 == 0) {
retval = 3;
argv[0] = 0;
env[0] = 0;
/* do not interfere with end synchronization of first
* child */
sync_pipe_close(end_sync_pipes, PIPE_NAME_END);
TEST(execve(test_app, argv, env));
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO != ETXTBSY) {
retval = 1;
perror("didn't get ETXTBSY\n");
} else
printf("execve failed with ETXTBSY as "
"expected\n");
exit(retval);
}
/* wait for the child to finish */
if (waitpid(pid1, &status, 0) == -1)
tst_brkm(TBROK|TERRNO, cleanup, "waitpid failed");
if (WIFEXITED(status) && WEXITSTATUS(status) == 3)
tst_resm(TPASS, "execve failed as expected");
else
tst_resm(TFAIL, "execve succeeded, expected failure");
/* terminate first child */
sync_pipe_notify(end_sync_pipes);
(void) waitpid(pid, NULL, 0);
}
cleanup();
tst_exit();
}
示例12: main
int main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
pid_t pid, fake_pid;
int exno, status, fake_status, nsig;
/* parse standard options */
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
}
#ifdef UCLINUX
maybe_run_child(&do_child, "");
#endif
setup(); /* global setup */
TEST_EXP_ENOS(exp_enos);
/* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping */
Tst_count = 0;
status = 1;
exno = 1;
pid = FORK_OR_VFORK();
if (pid < 0) {
tst_brkm(TBROK, cleanup, "Fork failed");
} else if (pid == 0) {
#ifdef UCLINUX
if (self_exec(av[0], "") < 0) {
tst_brkm(TBROK, cleanup,
"self_exec of child failed");
}
#else
do_child();
#endif
} else {
fake_pid = FORK_OR_VFORK();
if (fake_pid < 0) {
tst_brkm(TBROK, cleanup, "Second fork failed");
} else if (fake_pid == 0) {
#ifdef UCLINUX
if (self_exec(av[0], "") < 0) {
tst_brkm(TBROK, cleanup,
"second self_exec "
"of child failed");
}
#else
do_child();
#endif
}
kill(fake_pid, TEST_SIG);
waitpid(fake_pid, &fake_status, 0);
TEST(kill(fake_pid, TEST_SIG));
kill(pid, TEST_SIG);
waitpid(pid, &status, 0);
}
if (TEST_RETURN != -1) {
tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s "
"Expected a return value of -1 got %ld",
TCID, TEST_ERRNO, strerror(TEST_ERRNO),
TEST_RETURN);
}
if (STD_FUNCTIONAL_TEST) {
/*
* Check to see if the errno was set to the expected
* value of 3 : ESRCH
*/
nsig = WTERMSIG(status);
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO == ESRCH) {
tst_resm(TPASS, "errno set to %d : %s, as "
"expected", TEST_ERRNO,
strerror(TEST_ERRNO));
} else {
tst_resm(TFAIL, "errno set to %d : %s expected "
"%d : %s", TEST_ERRNO,
strerror(TEST_ERRNO), 3, strerror(3));
}
}
}
cleanup();
tst_exit();
}
示例13: main
int main(int ac, char **av)
{
int lc;
const char *msg;
/***************************************************************
* parse standard options
***************************************************************/
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
/***************************************************************
* perform global setup for test
***************************************************************/
setup();
/* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
/***************************************************************
* check looping state if -c option given
***************************************************************/
for (lc = 0; TEST_LOOPING(lc); lc++) {
int type;
for (type = 0; type < 2; type++) {
tst_count = 0;
flocks.l_type = type ? F_RDLCK : F_WRLCK;
/*
* Call fcntl(2) with F_SETLKW flocks.l_type = F_UNLCK argument on fname
*/
TEST(fcntl(fd, F_SETLKW, &flocks));
/* check return code */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"fcntl(%s, F_SETLKW, &flocks) flocks.l_type = %s Failed, errno=%d : %s",
fname, type ? "F_RDLCK" : "F_WRLCK",
TEST_ERRNO, strerror(TEST_ERRNO));
} else {
/***************************************************************
* only perform functional verification if flag set (-f not given)
***************************************************************/
if (STD_FUNCTIONAL_TEST) {
/* No Verification test, yet... */
tst_resm(TPASS,
"fcntl(%s, F_SETLKW, &flocks) flocks.l_type = %s returned %ld",
fname,
type ? "F_RDLCK" : "F_WRLCK",
TEST_RETURN);
}
}
flocks.l_type = F_UNLCK;
/*
* Call fcntl(2) with F_SETLKW flocks.l_type = F_UNLCK argument on fname
*/
TEST(fcntl(fd, F_SETLKW, &flocks));
/* check return code */
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO);
tst_resm(TFAIL,
"fcntl(%s, F_SETLKW, &flocks) flocks.l_type = F_UNLCK Failed, errno=%d : %s",
fname, TEST_ERRNO,
strerror(TEST_ERRNO));
} else {
/***************************************************************
* only perform functional verification if flag set (-f not given)
***************************************************************/
if (STD_FUNCTIONAL_TEST) {
/* No Verification test, yet... */
tst_resm(TPASS,
"fcntl(%s, F_SETLKW, &flocks) flocks.l_type = F_UNLCK returned %ld",
fname, TEST_RETURN);
}
}
}
}
/***************************************************************
* cleanup and exit
***************************************************************/
cleanup();
tst_exit();
}
示例14: main
int main(int ac, char **av)
{
int lc;
const char *msg;
struct itimerval *value, *ovalue;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
}
setup(); /* global setup */
/* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset tst_count in case we are looping */
tst_count = 0;
/* allocate some space for timer structures */
if ((value = (struct itimerval *)malloc((size_t)
sizeof(struct
itimerval))) ==
NULL) {
tst_brkm(TBROK, cleanup, "value malloc failed");
}
if ((ovalue = (struct itimerval *)malloc((size_t)
sizeof(struct
itimerval))) ==
NULL) {
tst_brkm(TBROK, cleanup, "value malloc failed");
}
/* set up some reasonable values */
value->it_value.tv_sec = 30;
value->it_value.tv_usec = 0;
value->it_interval.tv_sec = 0;
value->it_interval.tv_usec = 0;
/*
* issue the system call with the TEST() macro
* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2
*/
/* make the first value negative to get a failure */
TEST(setitimer(-ITIMER_PROF, value, ovalue));
if (TEST_RETURN == 0) {
tst_resm(TFAIL, "call failed to produce expected error "
"- errno = %d - %s", TEST_ERRNO,
strerror(TEST_ERRNO));
continue;
}
TEST_ERROR_LOG(TEST_ERRNO);
switch (TEST_ERRNO) {
case EINVAL:
tst_resm(TPASS, "expected failure - errno = %d - %s",
TEST_ERRNO, strerror(TEST_ERRNO));
break;
default:
tst_resm(TFAIL, "call failed to produce expected error "
"- errno = %d - %s", TEST_ERRNO,
strerror(TEST_ERRNO));
}
/*
* clean up things in case we are looping
*/
free(value);
free(ovalue);
value = NULL;
ovalue = NULL;
}
cleanup();
tst_exit();
}
示例15: main
int main(int ac, char **av)
{
int lc;
char *msg;
int rval, fd;
int count;
size_t size = 0;
char *dir_name = NULL;
struct dirent *dirp;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
if ((dir_name = getcwd(dir_name, size)) == NULL)
tst_brkm(TBROK, cleanup, "Can not get current "
"directory name");
if ((dirp = malloc(sizeof(struct dirent))) == NULL)
tst_brkm(TBROK, cleanup, "malloc failed");
/* Set count to be very small. The result should be EINVAL */
count = 1;
if ((fd = open(dir_name, O_RDONLY)) == -1)
tst_brkm(TBROK, cleanup, "open of directory failed");
rval = getdents(fd, dirp, count);
/*
* Hopefully we get an error due to the small buffer.
*/
if (rval < 0) {
TEST_ERROR_LOG(errno);
switch (errno) {
case EINVAL:
tst_resm(TPASS,
"getdents failed with EINVAL as expected");
break;
default:
tst_resm(TFAIL|TERRNO,
"getdents call failed unexpectedly");
break;
}
} else
tst_resm(TFAIL, "getdents passed unexpectedly");
free(dir_name);
dir_name = NULL;
free(dirp);
if ((rval = close(fd)) == -1)
tst_brkm(TBROK, cleanup, "fd close failed");
}
cleanup();
tst_exit();
}