Fix testcases 1-3. Fix compile with remainder.
Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
diff --git a/testcases/kernel/syscalls/writev/writev01.c b/testcases/kernel/syscalls/writev/writev01.c
index 8b12e59..cde34e3 100644
--- a/testcases/kernel/syscalls/writev/writev01.c
+++ b/testcases/kernel/syscalls/writev/writev01.c
@@ -25,7 +25,7 @@
* Testcase to check the basic functionality of writev(2) system call.
*
* ALGORITHM
- * Create a IO vector, and attempt to writev() various components of it.
+ * Create a IO vector, and attempt to writev various components of it.
*
* USAGE: <for command-line>
* writev01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
@@ -117,12 +117,10 @@
int fd[4], in_sighandler;
int pfd[2]; /* pipe fd's */
char *buf_list[NBUFS];
-int fail;
void sighandler(int);
-long l_seek(int, long, int);
int fill_mem(char *, int, int);
-int init_buffs(char *[]);
+void init_buffs(char *[]);
void setup(void);
void cleanup(void);
@@ -136,19 +134,13 @@
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
- /* parse standard options */
- if ((msg = parse_opts(argc, argv, NULL, NULL)) !=
- NULL) {
+ if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- }
- /* 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;
@@ -158,63 +150,40 @@
fd[1] = -1; /* Invalid file descriptor */
- if (signal(SIGTERM, sighandler) == SIG_ERR) {
- perror("signal: SIGTERM");
- cleanup();
- }
+ if (signal(SIGTERM, sighandler) == SIG_ERR)
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "signal(SIGTERM, ..) failed");
- if (signal(SIGPIPE, sighandler) == SIG_ERR) {
- perror("signal: SIGPIPE");
- cleanup();
- }
+ if (signal(SIGPIPE, sighandler) == SIG_ERR)
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "signal(SIGPIPE, ..) failed");
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();
- } 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();
- }
+ if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "open(.., O_WRONLY|O_CREAT, ..) failed");
+ else
+ if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1)
+ tst_brkm(TBROK|TERRNO, cleanup, "write failed");
- if (close(fd[0]) < 0) {
- tst_resm(TFAIL, "close failed: errno: %d", errno);
- cleanup();
- }
+ if (close(fd[0]) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "close failed");
- if ((fd[0] = open(f_name, O_RDWR, 0666)) < 0) {
- tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
- f_name, errno);
- cleanup();
- }
-//block1: /* given vector length -1, writev() return EINVAL. */
- tst_resm(TINFO, "Enter Block 1");
- fail = 0;
+ if ((fd[0] = open(f_name, O_RDWR, 0666)) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open failed");
+//block1: /* given vector length -1, writev return EINVAL. */
+ tst_resm(TPASS, "Enter Block 1");
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 {
+ if (TEST_RETURN == -1) {
+ if (TEST_ERRNO == EINVAL)
+ tst_resm(TPASS, "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");
- }
+ } else
+ tst_resm(TFAIL, "writev failed to fail");
tst_resm(TINFO, "Exit block 1");
//block2:
@@ -222,249 +191,145 @@
* 1. it is not using the wr_iovec initialized
* 2. read() and following message is not consistent
*/
- tst_resm(TINFO, "Enter block 2");
- fail = 0;
+ tst_resm(TPASS, "Enter block 2");
- if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
- TEST_ERROR_LOG(errno);
- tst_resm(TBROK, "block2: 1st lseek failed");
- fail = 1;
- }
+ if (lseek(fd[0], CHUNK * 6, 0) == -1)
+ tst_resm(TBROK|TERRNO, "block2: 1st lseek failed");
if ((ret = writev(fd[0], (wr_iovec + 6), 3)) == CHUNK) {
- if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
- TEST_ERROR_LOG(errno);
- tst_resm(TFAIL, "block2: 2nd lseek failed");
- fail = 1;
- }
- if ((nbytes = read(fd[0], buf_list[0], CHUNK)) != CHUNK) {
- perror("read error");
- tst_resm(TFAIL, "expected nbytes = 1024, "
- "got = %d", nbytes);
- fail = 1;
- } else if (memcmp((buf_list[0] + CHUNK * 6),
+ if (lseek(fd[0], CHUNK * 6, 0) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "block2: 2nd lseek failed");
+ if ((nbytes = read(fd[0], buf_list[0], CHUNK)) !=
+ CHUNK)
+ tst_resm(TFAIL, "read failed; expected nbytes "
+ "= 1024, got = %d", nbytes);
+ else if (memcmp((buf_list[0] + CHUNK * 6),
(buf_list[2] + CHUNK * 6),
- CHUNK) != 0) {
- tst_resm(TFAIL, "Error: writev() over "
+ CHUNK) != 0)
+ tst_resm(TFAIL, "writev over "
"wrote %s", f_name);
- fail = 1;
- }
- } else {
- tst_resm(TFAIL, "writev() failed unexpectedly");
- fail = 1;
- }
- if (fail) {
- tst_resm(TINFO, "block 2 FAILED");
- } else {
- tst_resm(TINFO, "block 2 PASSED");
- }
+ } else
+ tst_resm(TFAIL|TERRNO, "writev failed unexpectedly");
tst_resm(TINFO, "Exit block 2");
-//block3: /* given 1 bad vector buffer with good ones, writev() success */
- tst_resm(TINFO, "Enter block 3");
- fail = 0;
+//block3: /* given 1 bad vector buffer with good ones, writev success */
+ tst_resm(TPASS, "Enter block 3");
- if (lseek(fd[0], CHUNK * 6, 0) < 0) {
- TEST_ERROR_LOG(errno);
- tst_resm(TFAIL, "block3: 1st lseek failed");
- fail = 1;
- }
- if ((nbytes = writev(fd[0], (wr_iovec + 6), 3)) < 0) {
- TEST_ERROR_LOG(errno);
- if (errno == EFAULT) {
+ if (lseek(fd[0], CHUNK * 6, 0) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "block3: 1st lseek failed");
+ if ((nbytes = writev(fd[0], (wr_iovec + 6), 3)) == -1) {
+ if (errno == EFAULT)
tst_resm(TFAIL, "Got EFAULT");
- fail = 1;
- }
}
- if (l_seek(fd[0], 0, 0) < 0) {
- TEST_ERROR_LOG(errno);
- tst_resm(TFAIL, "block3: 2nd lseek failed");
- fail = 1;
- }
+ if (lseek(fd[0], 0, 0) == -1)
+ tst_brkm(TBROK, cleanup, "block3: 2nd lseek failed");
if ((nbytes = read(fd[0], buf_list[0], K_1)) != K_1) {
- perror("read error");
- tst_resm(TFAIL, "expected nbytes = 1024, got = %d",
- nbytes);
- fail = 1;
+ tst_resm(TFAIL|TERRNO,
+ "read failed; expected nbytes = 1024, got = %d",
+ nbytes);
} else if (memcmp((buf_list[0] + CHUNK * 6),
- (buf_list[2] + CHUNK * 6), CHUNK * 3) != 0) {
- tst_resm(TFAIL, "Error: writev() over wrote %s",
- f_name);
- fail = 1;
- }
+ (buf_list[2] + CHUNK * 6), CHUNK * 3) != 0)
+ tst_resm(TFAIL, "writev overwrote file");
- if (fail) {
- tst_resm(TINFO, "block 3 FAILED");
- } else {
- tst_resm(TINFO, "block 3 PASSED");
- }
tst_resm(TINFO, "Exit block 3");
-//block4: /* given bad file discriptor, writev() return EBADF. */
- tst_resm(TINFO, "Enter block 4");
- fail = 0;
+//block4: /* given bad file discriptor, writev return EBADF. */
+ tst_resm(TPASS, "Enter block 4");
TEST(writev(fd[1], (wr_iovec + 9), 1));
- if (TEST_RETURN < 0) {
- TEST_ERROR_LOG(TEST_ERRNO);
- if (TEST_ERRNO == EBADF) {
- tst_resm(TINFO, "Received EBADF as expected");
- } else {
+ if (TEST_RETURN == -1) {
+ if (TEST_ERRNO == EBADF)
+ tst_resm(TPASS, "Received EBADF as expected");
+ else
tst_resm(TFAIL, "expected errno = EBADF, "
"got %d", TEST_ERRNO);
- fail = 1;
- }
- } else {
- tst_resm(TFAIL, "Error: writev() returned a "
+ } else
+ tst_resm(TFAIL, "writev returned a "
"positive value");
- fail = 1;
- }
- if (fail) {
- tst_resm(TINFO, "block 4 FAILED");
- } else {
- tst_resm(TINFO, "block 4 PASSED");
- }
tst_resm(TINFO, "Exit block 4");
-//block5: /* given invalid vector count, writev() return EINVAL */
- tst_resm(TINFO, "Enter block 5");
- fail = 0;
+//block5: /* given invalid vector count, writev return EINVAL */
+ tst_resm(TPASS, "Enter block 5");
TEST(writev(fd[0], (wr_iovec + 10), -1));
- if (TEST_RETURN < 0) {
- TEST_ERROR_LOG(TEST_ERRNO);
- if (TEST_ERRNO == EINVAL) {
- tst_resm(TINFO, "Received EINVAL as expected");
- } else {
+ if (TEST_RETURN == -1) {
+ if (TEST_ERRNO == EINVAL)
+ tst_resm(TPASS, "Received EINVAL as expected");
+ else
tst_resm(TFAIL, "expected errno = EINVAL, "
"got %d", TEST_ERRNO);
- fail = 1;
- }
- } else {
- tst_resm(TFAIL, "Error: writev() returned a "
+ } else
+ tst_resm(TFAIL, "writev returned a "
"positive value");
- fail = 1;
- }
- if (fail) {
- tst_resm(TINFO, "block 5 FAILED");
- } else {
- tst_resm(TINFO, "block 5 PASSED");
- }
tst_resm(TINFO, "Exit block 5");
-//block6: /* given no buffer vector, writev() success */
- tst_resm(TINFO, "Enter block 6");
- fail = 0;
+//block6: /* given no buffer vector, writev success */
+ tst_resm(TPASS, "Enter block 6");
TEST(writev(fd[0], (wr_iovec + 11), 0));
- if (TEST_RETURN < 0) {
- TEST_ERROR_LOG(TEST_ERRNO);
- tst_resm(TFAIL, "writev() failed with unexpected errno "
- "%d", TEST_ERRNO);
- fail = 1;
- } else {
- tst_resm(TPASS, "writev() wrote 0 iovectors");
- }
+ if (TEST_RETURN == -1)
+ tst_resm(TFAIL|TTERRNO, "writev failed");
+ else
+ tst_resm(TPASS, "writev wrote 0 iovectors");
- if (fail) {
- tst_resm(TINFO, "block 6 FAILED");
- } else {
- tst_resm(TINFO, "block 6 PASSED");
- }
tst_resm(TINFO, "Exit block 6");
//block7:
/* given 4 vectors, 2 are NULL, 1 with 0 length and 1 with fixed length,
- * writev() success writing fixed length.
+ * writev success writing fixed length.
*/
- tst_resm(TINFO, "Enter block 7");
- fail = 0;
+ tst_resm(TPASS, "Enter block 7");
- l_seek(fd[0], CHUNK * 12, 0);
- if ((ret = writev(fd[0], (wr_iovec + 12), 4)) != CHUNK) {
- tst_resm(TFAIL, "writev() failed writing %d bytes, "
+ if (lseek(fd[0], CHUNK * 12, 0) == -1)
+ tst_resm(TBROK, "lseek failed");
+ else if ((ret = writev(fd[0], (wr_iovec + 12), 4)) != CHUNK)
+ tst_resm(TFAIL, "writev failed writing %d bytes, "
"followed by two NULL vectors", CHUNK);
- fail = 1;
- } else {
+ else
tst_resm(TPASS, "writev passed writing %d bytes, "
"followed by two NULL vectors", CHUNK);
- }
- if (fail) {
- tst_resm(TINFO, "block 7 FAILED");
- } else {
- tst_resm(TINFO, "block 7 PASSED");
- }
tst_resm(TINFO, "Exit block 7");
-//block8: /* try to write to a closed pipe, writev() return EPIPE. */
- tst_resm(TINFO, "Enter block 8");
- fail = 0;
+//block8: /* try to write to a closed pipe, writev return EPIPE. */
+ tst_resm(TPASS, "Enter block 8");
- if (pipe(pfd) < 0) {
- TEST_ERROR_LOG(errno);
- perror("pipe");
- tst_resm(TFAIL, "pipe failed: errno = %d", errno);
- fail = 1;
- } else {
- if (close(pfd[0]) < 0) {
- TEST_ERROR_LOG(errno);
- perror("close");
- tst_resm(TFAIL, "close failed: errno = %d",
- errno);
- fail = 1;
- } else if ((writev(pfd[1], (wr_iovec + 12), 1)
- < 0) && in_sighandler) {
- TEST_ERROR_LOG(errno);
- if (errno == EPIPE) {
- tst_resm(TINFO, "Received EPIPE as "
+ if (pipe(pfd) == -1)
+ tst_resm(TFAIL|TERRNO, "pipe failed");
+ else {
+ if (close(pfd[0]) == -1)
+ tst_resm(TFAIL|TERRNO, "close failed");
+ else if (writev(pfd[1], (wr_iovec + 12), 1) == -1 &&
+ in_sighandler) {
+ if (errno == EPIPE)
+ tst_resm(TPASS, "Received EPIPE as "
"expected");
- } else {
- tst_resm(TFAIL, "expected errno = "
- "EPIPE, got %d", errno);
- fail = 1;
- }
- } else {
- tst_resm(TFAIL, "Error: writev() returned a "
- "positive value");
- fail = 1;
- }
- }
- if (fail) {
- tst_resm(TINFO, "block 8 FAILED");
- } else {
- tst_resm(TINFO, "block 8 PASSED");
+ else
+ tst_resm(TFAIL|TERRNO,
+ "didn't get EPIPE");
+ } else
+ tst_resm(TFAIL, "writev returned a positive "
+ "value");
}
tst_resm(TINFO, "Exit block 8");
}
- close(fd[0]);
- close(fd[1]);
cleanup();
tst_exit();
}
-/*
- * setup()
- * performs all ONE TIME setup for this test
- */
void setup(void)
{
- tst_sig(FORK, DEF_HANDLER, cleanup);
+ tst_sig(FORK, sighandler, cleanup);
- /* Set up the expected error numbers for -e option */
TEST_EXP_ENOS(exp_enos);
- /* Pause if that option was specified.
- * TEST_PAUSE contains the code to fork the test with the -i option.
- * You want to make sure you do this before you create your temporary
- * directory.
- */
TEST_PAUSE;
- /* Create a unique temporary directory and chdir() to it. */
tst_tmpdir();
strcpy(name, DATA_FILE);
@@ -472,35 +337,30 @@
bad_addr = mmap(0, 1, PROT_NONE,
MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
- if (bad_addr == MAP_FAILED) {
- printf("mmap failed\n");
- }
+ if (bad_addr == MAP_FAILED)
+ tst_brkm(TBROK|TERRNO, cleanup, "mmap failed");
wr_iovec[7].iov_base = bad_addr;
}
-/*
- * cleanup()
- * performs all ONE TIME cleanup for this test at
- * completion or premature exit
- */
void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
- if (unlink(f_name) < 0) {
- tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
- f_name, errno);
- }
+ if (munmap(bad_addr, 1) == -1)
+ tst_resm(TBROK|TERRNO, "munmap failed");
+
+ close(fd[0]);
+ close(fd[1]);
+
+ if (unlink(f_name) == -1)
+ tst_resm(TBROK|TERRNO, "unlink failed");
+
tst_rmdir();
}
-int init_buffs(char *pbufs[])
+void init_buffs(char *pbufs[])
{
int i;
@@ -517,11 +377,9 @@
break;
default:
- tst_resm(TFAIL, "Error detected: init_buffs()");
- cleanup();
- }
+ tst_brkm(TBROK, cleanup, "error detected: init_buffs");
+ }
}
- return 0;
}
int fill_mem(char *c_ptr, int c1, int c2)
@@ -545,29 +403,11 @@
break;
case SIGPIPE:
- ++in_sighandler;
+ in_sighandler++;
return;
default:
- tst_resm(TFAIL, "sighandler() received invalid "
- "signal:%d", sig);
+ tst_resm(TFAIL, "sighandler received invalid signal:%d", sig);
break;
}
-
- if (unlink(f_name) < 0) {
- tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
- f_name, errno);
- tst_exit();
- }
- exit(sig);
}
-
-long l_seek(int fdesc, long offset, int whence)
-{
- if (lseek(fdesc, offset, whence) < 0) {
- perror("lseek");
- tst_resm(TFAIL, "lseek Failed : errno = %d", errno);
- fail = 1;
- }
- return 0;
-}
\ No newline at end of file