8000 minix/test/test19.c at v3.1.3b · lukegithub/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
521 lines (454 loc) · 14.3 KB

test19.c

File metadata and controls

521 lines (454 loc) · 14.3 KB
if (close(pipefd[1]) >= 0) e(5);
if (read(pipefd[0], buf2, 1) != 0) e(6);
if (close(pipefd[0]) != 0) e(7);
/* Test O_NONBLOCK on pipes. */
if (pipe(pipefd) < 0) e(8);
if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0) e(9);
if (read(pipefd[0], buf2, 1) != -1) e(10);
if (errno != EAGAIN) e(11);
if (close(pipefd[0]) != 0) e(12);
if (close(pipefd[1]) != 0) e(13);
/* Test read and lseek. */
if ( (fd = creat("T19.g1", 0777)) != 3) e(14); /* create test file */
if (write(fd, buf, 512) != 512) e(15);
errno = 3000;
if (read(fd, buf2, 512) != -1) e(16);
if (errno != EBADF) e(17);
if (close(fd) != 0) e(18);
if ( (fd = open("T19.g1", O_RDWR)) != 3) e(19);
if (read(fd, buf2, 512) != 512) e(20);
if (read(fd, buf2, 512) != 0) e(21);
if (lseek(fd, 100L, SEEK_SET) != 100L) e(22);
if (read(fd, buf2, 512) != 412) e(23);
if (lseek(fd, 1000L, SEEK_SET) != 1000L) e(24);
/* Test write. */
if (lseek(fd, -1000L, SEEK_CUR) != 0) e(25);
if (write(fd, buf, 512) != 512) e(26);
if (lseek(fd, 2L, SEEK_SET) != 2) e(27);
if (write(fd, buf, 3) != 3) e(28);
if (lseek(fd, -2L, SEEK_CUR) != 3) e(29);
if (write(fd, &buf[30], 1) != 1) e(30);
if (lseek(fd, 2L, SEEK_CUR) != 6) e(31);
if (write(fd, &buf[60], 1) != 1) e(32);
if (lseek(fd, -512L, SEEK_END) != 0) e(33);
if (read(fd, buf2, 8) != 8) e(34);
errno = 4000;
if (buf2[0] != 0 || buf2[1] != 1 || buf2[2] != 0 || buf2[3] != 30) e(35);
if (buf2[4] != 2 || buf2[5] != 5 || buf2[6] != 60 || buf2[7] != 7) e(36);
/* Turn the O_APPEND flag on. */
if (fcntl(fd, F_SETFL, O_APPEND) != 0) e(37);
if (lseek(fd, 0L, SEEK_SET) != 0) e(38);
if (write(fd, &buf[100], 1) != 1) e(39);
if (lseek(fd, 0L, SEEK_SET) != 0) e(40);
if (read(fd, buf2, 10) != 10) e(41);
if (buf2[0] != 0) e(42);
if (lseek(fd, -1L, SEEK_END) != 512) e(43);
if (read(fd, buf2, 10) != 1) e(44);
if (buf2[0] != 100) e(45);
if (close(fd) != 0) e(46);
/* Now try write with O_NONBLOCK. */
if (pipe(pipefd) != 0) e(47);
if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) e(48);
if (write(pipefd[1], buf, 512) != 512) e(49);
if (write(pipefd[1], buf, 512) != 512) e(50);
errno = 0;
for (i = 1; i < 20; i++) {
n = write(pipefd[1], buf, 512);
if (n == 512) continue;
if (n != -1 || errno != EAGAIN) {e(51); break;}
}
if (read(pipefd[0], buf, 512) != 512) e(52);
if (close(pipefd[0]) != 0) e(53);
/* Write to a pipe with no reader. This should generate a signal. */
signal(SIGPIPE, pipecatcher);
errno = 0;
if (write(pipefd[1], buf, 1) != -1) e(54);
if (errno != EPIPE) e(55);
if (pipesigs != passes + 1) e(56); /* we should have had the sig now */
if (close(pipefd[1]) != 0) e(57);
errno = 0;
if (write(100, buf, 512) != -1) e(58);
if (errno != EBADF) e(59);
if (unlink("T19.g1") != 0) e(60);
}
void clraa()
{
int i;
for (i = 0; i < 100; i++) aa[i] = 0;
}
void pipecatcher(s)
int s; /* it is supposed to have an arg */
{
pipesigs++;
}
void e(n)
int n;
{
int err_num = errno; /* save errno in case printf clobbers it */
printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
fflush(stdout); /* aargh! Most results go to stdout and are
* messed up by perror going to stderr.
* Should replace perror by printf and strerror
* in all the tests.
*/
errno = err_num; /* restore errno, just in case */
perror("");
if (errct++ > MAX_ERROR) {
printf("Too many errors; test aborted\n");
chdir("..");
system("rm -rf DIR*");
exit(1);
}
}
void quit()
{
chdir("..");
system("rm -rf DIR*");
if (errct == 0) {
printf("ok\n");
exit(0);
} else {
printf("%d errors\n", errct);
exit(1);
}
}
0