static void cleanup(void) { close(fildes); free(dummy); tst_rmdir(); }
static void cleanup(void) { close(fd); tst_rmdir(); }
int main(int argc, char *argv[]) { char *progname; int fd; int c; extern char *optarg; unsigned nprocs = 0; unsigned procno; pid_t *pidarray=NULL; pid_t pid; pid_t wr_pid = 0; uchar_t *buf=NULL; unsigned int seed; int pagesize = sysconf(_SC_PAGE_SIZE); int alarmtime = 0; struct sigaction sa; unsigned i; int write_cnt; uchar_t data; int no_prob = 0; int wait_stat; time_t t; #ifdef LARGE_FILE off64_t bytes_left; #else /* LARGE_FILE */ off_t bytes_left; #endif /* LARGE_FILE */ progname = *argv; tst_tmpdir(); if (argc < 2) { (void)fprintf(stderr, "usage: %s %s\n", progname, usage); exit(1); } while ((c = getopt(argc, argv, "S:omdlrf:p:t:w:s:")) != -1) { switch (c) { case 'd': debug = 1; break; case 't': alarmtime = atoi(optarg) * 60; break; case 'p': nprocs = atoi(optarg); break; case 'l': leavefile = 1; break; case 's': sleeptime = atoi(optarg); if (sleeptime < 0) { (void)fprintf(stderr, "error: negative " "sleeptime\n"); anyfail(); } break; case 'w': growsize = atoi(optarg); if (growsize < 0) { (void)fprintf(stderr, "error: negative write " "size\n"); anyfail(); } break; case 'f': #ifdef LARGE_FILE filesize = atoll(optarg); #else /* LARGE_FILE */ filesize = atoi(optarg); #endif /* LARGE_FILE */ if (filesize < 0) { (void)fprintf(stderr, "error: negative " "filesize\n"); anyfail(); } break; case 'r': randloops = 1; break; case 'm': dosync = 1; break; case 'o': do_offset = 1; break; case 'S': #ifdef LARGE_FILE sparseoffset = atoll(optarg); #else /* LARGE_FILE */ sparseoffset = atoi(optarg); #endif /* LARGE_FILE */ if (sparseoffset % pagesize != 0) { fprintf(stderr, "sparseoffset must be pagesize multiple\n"); anyfail(); } break; default: (void)fprintf(stderr, "usage: %s %s\n", progname, usage); anyfail(); } } if (nprocs > 255) { (void)fprintf(stderr, "invalid nprocs %d - (range 0-255)\n", nprocs); anyfail(); } (void)time(&t); //(void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port (void)sprintf(filename, "%sout.%d", progname, getpid()); seed = initrand(); pattern = seed & 0xff; if (debug) { #ifdef LARGE_FILE (void)printf("creating file <%s> with %Ld bytes, pattern %d\n", filename, filesize, pattern); #else /* LARGE_FILE */ (void)printf("creating file <%s> with %ld bytes, pattern %d\n", filename, filesize, pattern); #endif /* LARGE_FILE */ if (alarmtime) (void)printf("running for %d minutes\n", alarmtime/60); else (void)printf("running with no time limit\n"); } /* * Plan for death by signal. User may have specified * a time limit, in which case set an alarm and catch SIGALRM. * Also catch and cleanup with SIGINT, SIGQUIT, and SIGTERM. */ sa.sa_handler = finish; sa.sa_flags = 0; if (sigemptyset(&sa.sa_mask)) { perror("sigempty error"); goto cleanup; } if (sigaction(SIGINT, &sa, 0) == -1) { perror("sigaction error SIGINT"); goto cleanup; } if (alarmtime) { if (sigaction(SIGALRM, &sa, 0) == -1) { perror("sigaction error"); goto cleanup; } (void)alarm(alarmtime); } /* If we get a SIGQUIT or SIGTERM, clean up and exit immediately. */ sa.sa_handler = clean_up_file; if (sigaction(SIGQUIT, &sa, 0) == -1) { perror("sigaction error SIGQUIT"); goto cleanup; } if (sigaction(SIGTERM, &sa, 0) == -1) { perror("sigaction error SIGTERM"); goto cleanup; } #ifdef LARGE_FILE if ((fd = open64(filename, O_CREAT|O_TRUNC|O_RDWR, 0664)) == -1) { #else /* LARGE_FILE */ if ((fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, 0664)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } if ((buf = (uchar_t *)malloc(pagesize+growsize)) == NULL || (pidarray = (pid_t *)malloc(nprocs*sizeof(pid_t))) == NULL) { perror("malloc error"); anyfail(); } for (i = 0; i < nprocs; i++) *(pidarray+i) = 0; for (i = 0, data = 0; i < pagesize; i++) { *(buf+i) = (data + pattern) & 0xff; if (++data == nprocs) data = 0; } for (data = 0; i < pagesize+growsize; i++) { *(buf+i) = (data + pattern) & 0xff; if (++data == nprocs) data = 0; } #ifdef LARGE_FILE if (lseek64(fd, sparseoffset, SEEK_SET) < 0) { #else /* LARGE_FILE */ if (lseek(fd, sparseoffset, SEEK_SET) < 0) { #endif /* LARGE_FILE */ perror("lseek"); anyfail(); } for (bytes_left = filesize; bytes_left; bytes_left -= c) { write_cnt = min(pagesize, bytes_left); if ((c = write(fd, (char *)buf, write_cnt)) != write_cnt) { if (c == -1) { perror("write error"); } else { (void)fprintf(stderr, "write: wrote %d of %d " "bytes\n", c, write_cnt); } (void)close(fd); (void)unlink(filename); anyfail(); } } (void)close(fd); /* * Fork off mmap children. */ for (procno = 0; procno < nprocs; procno++) { switch (pid = fork()) { case -1: perror("fork error"); goto cleanup; case 0: child_mapper(filename, procno, nprocs); exit(0); default: pidarray[procno] = pid; } } /* * Now fork off an additional process to continually * write to (and grow) the file. */ if ((wr_pid = fork()) == -1) { perror("fork error"); goto cleanup; } else if (wr_pid == 0) { /* child */ child_writer(filename, buf); exit(0); } /* * Now wait for children and refork them as needed. */ while (!finished) { pid = wait(&wait_stat); /* * Block signals while processing child exit. */ if (sighold(SIGALRM) || sighold(SIGINT)) { perror("sighold error"); goto cleanup; } if (pid != -1) { /* * Check exit status, then refork with the * appropriate procno. */ if (!WIFEXITED(wait_stat) || WEXITSTATUS(wait_stat) != 0) { (void)fprintf(stderr, "child exit with err " "<x%x>\n", wait_stat); goto cleanup; } for (i = 0; i < nprocs; i++) if (pid == pidarray[i]) break; if (i == nprocs) { if (pid == wr_pid) { (void)fprintf(stderr, "writer child unexpected exit <x%x>\n", wait_stat); wr_pid = 0; } else (void)fprintf(stderr, "unknown child " "pid %d, <x%x>\n", pid, wait_stat); goto cleanup; } if ((pid = fork()) == -1) { perror("fork error"); pidarray[i] = 0; goto cleanup; } else if (pid == 0) { /* child */ child_mapper(filename, i, nprocs); exit(0); } else pidarray[i] = pid; } else { /* * wait returned an error. If EINTR, then * normal finish, else it's an unexpected * error... */ if (errno != EINTR || !finished) { perror("unexpected wait error"); goto cleanup; } } if (sigrelse(SIGALRM) || sigrelse(SIGINT)) { perror("sigrelse error"); goto cleanup; } } /* * Finished! Check the file for sanity, then kill all * the children and done!. */ (void)alarm(0); no_prob = 1; cleanup: for (i = 0; i < nprocs; i++) (void)kill(pidarray[i], SIGKILL); (void)kill(wr_pid, SIGKILL); while (wait(&wait_stat) != -1 || errno != ECHILD) continue; if (no_prob) { /* only check file if no errors */ if (!fileokay(filename, buf)) { (void)fprintf(stderr, "file data incorrect!\n"); (void)printf(" leaving file <%s>\n", filename); anyfail(); } else { (void)printf("file data okay\n"); if (!leavefile) (void)unlink(filename); } } else (void)printf(" leaving file <%s>\n", filename); (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port ok_exit(); return 0; } /* * Child process that reads/writes map. The child stats the file * to determine the size, maps the size of the file, then reads/writes * its own locations on random pages of the map (its locations being * determined based on nprocs & procno). After a specific number of * iterations, it exits. */ void child_mapper(char *file, unsigned procno, unsigned nprocs) { #ifdef LARGE_FILE struct stat64 statbuf; off64_t filesize; off64_t offset; #else /* LARGE_FILE */ struct stat statbuf; off_t filesize; off_t offset; #endif /* LARGE_FILE */ size_t validsize; size_t mapsize; caddr_t maddr, paddr; int fd; int pagesize = sysconf(_SC_PAGE_SIZE); unsigned randpage; unsigned int seed; unsigned loopcnt; unsigned nloops; unsigned mappages; unsigned mapflags; unsigned i; mapflags = MAP_SHARED; seed = initrand(); /* initialize random seed */ #ifdef LARGE_FILE if ((fd = open64(file, O_RDWR)) == -1) { #else /* LARGE_FILE */ if ((fd = open(file, O_RDWR)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } #ifdef LARGE_FILE if (fstat64(fd, &statbuf) == -1) { #else /* LARGE_FILE */ if (fstat(fd, &statbuf) == -1) { #endif /* LARGE_FILE */ perror("stat error"); anyfail(); } filesize = statbuf.st_size; if (statbuf.st_size - sparseoffset > SIZE_MAX) { fprintf(stderr, "size_t overflow when setting up map\n"); anyfail(); } mapsize = (size_t)(statbuf.st_size - sparseoffset); mappages = roundup(mapsize, pagesize) / pagesize; offset = sparseoffset; if (do_offset) { int pageoffset = lrand48() % mappages; int byteoffset = pageoffset * pagesize; offset += byteoffset; mapsize -= byteoffset; mappages -= pageoffset; } #ifdef LARGE_FILE if ((maddr = mmap64(0, mapsize, PROT_READ|PROT_WRITE, mapflags, fd, offset)) == (caddr_t)-1) { #else /* LARGE_FILE */ if ((maddr = mmap(0, mapsize, PROT_READ|PROT_WRITE, mapflags, fd, offset)) == (caddr_t)-1) { #endif /* LARGE_FILE */ perror("mmap error"); anyfail(); } (void)close(fd); nloops = (randloops) ? (lrand48() % MAXLOOPS) : MAXLOOPS; if (debug) { #ifdef LARGE_FILE (void)printf("child %d (pid %ld): seed %d, fsize %Ld, " "mapsize %d, off %Ld, loop %d\n", procno, getpid(), seed, filesize, mapsize, offset/pagesize, nloops); #else /* LARGE_FILE */ (void)printf("child %d (pid %d): seed %d, fsize %ld, " "mapsize %ld, off %ld, loop %d\n", procno, getpid(), seed, filesize, (long)mapsize, offset/pagesize, nloops); #endif /* LARGE_FILE */ } /* * Now loop read/writing random pages. */ for (loopcnt = 0; loopcnt < nloops; loopcnt++) { randpage = lrand48() % mappages; paddr = maddr + (randpage * pagesize); /* page address */ if (randpage < mappages - 1 || !(mapsize % pagesize)) validsize = pagesize; else validsize = mapsize % pagesize; /* * Because one child is mapping file in extend mode, * it may be padded with zeros at end. So we can't * do an exact check -- accept known pattern OR zeros. */ for (i = procno; i < validsize; i += nprocs) { if (*((unsigned char *)(paddr+i)) != ((procno + pattern) & 0xff) && *((unsigned char *)(paddr+i)) != 0) { (void)fprintf(stderr, "child %d: invalid data " "<x%x>", procno, *((unsigned char *)(paddr+i))); (void)fprintf(stderr, " at pg %d off %d, exp " "<x%x>\n", randpage, i, (procno+pattern)&0xff); anyfail(); } /* * Now write it. */ *(paddr+i) = (procno + pattern) & 0xff; } } if (dosync) { /* * Exercise msync() as well! */ randpage = lrand48() % mappages; paddr = maddr + (randpage * pagesize); /* page address */ if (msync(paddr, (mappages - randpage)*pagesize, MS_SYNC) == -1) { perror("msync error"); anyfail(); } } exit(0); } /* * child_writer * The child process that continually (and slowly!!) grows * the file. The purpose of this is to exercise the code * supporting mapping of fragments. The map children are * constantly reforking and will pick up the map changes, etc. * This process executes until signalled (i.e. has no exit!) * unless error. */ void child_writer(char *file, uchar_t *buf) /* buf already set up in main */ { int fd; #ifdef LARGE_FILE struct stat64 statbuf; off64_t off; #else /* LARGE_FILE */ struct stat statbuf; off_t off; #endif /* LARGE_FILE */ int pagesize = sysconf(_SC_PAGE_SIZE); uchar_t *p; int cnt; #ifdef LARGE_FILE if ((fd = open64(file, O_RDWR)) == -1) { #else /* LARGE_FILE */ if ((fd = open(file, O_RDWR)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } #ifdef LARGE_FILE if ((off = lseek64(fd, 0, SEEK_END)) == -1) { #else /* LARGE_FILE */ if ((off = lseek(fd, 0, SEEK_END)) == -1) { #endif /* LARGE_FILE */ perror("lseek error"); anyfail(); } for (;;) { #ifdef LARGE_FILE if (fstat64(fd, &statbuf) == -1) { #else /* LARGE_FILE */ if (fstat(fd, &statbuf) == -1) { #endif /* LARGE_FILE */ perror("fstat error"); anyfail(); } #ifdef LARGE_FILE if (debug) (void)printf("writer %d bytes at off %Ld, size %Ld\n", growsize, off, statbuf.st_size); #else /* LARGE_FILE */ if (debug) (void)printf("writer %d bytes at off %ld, size %ld\n", growsize, off, statbuf.st_size); #endif /* LARGE_FILE */ /* * Write some number of bytes, then sleep some * number of seconds... * Need to keep track of our offset so write the * right bytes. */ p = buf + (off % pagesize); if ((cnt = write(fd, p, growsize)) != growsize) { if (cnt == -1) perror("write error"); else (void)fprintf(stderr, "wrote %d of %d bytes\n", cnt, growsize); anyfail(); } off += growsize; (void)sleep(sleeptime); if (dosync) { if (fsync(fd) == -1) { perror("fsync error"); anyfail(); } } } } /* * Make sure file has all the correct data. */ int fileokay(char *file, uchar_t *expbuf) { #ifdef LARGE_FILE struct stat64 statbuf; #else /* LARGE_FILE */ struct stat statbuf; #endif /* LARGE_FILE */ size_t mapsize; uchar_t *readbuf; unsigned mappages; unsigned pagesize = sysconf(_SC_PAGE_SIZE); int fd; int cnt; unsigned i, j; #ifdef LARGE_FILE if ((fd = open64(file, O_RDONLY)) == -1) { #else /* LARGE_FILE */ if ((fd = open(file, O_RDONLY)) == -1) { #endif /* LARGE_FILE */ perror("open error"); anyfail(); } #ifdef LARGE_FILE if (fstat64(fd, &statbuf) == -1) { #else /* LARGE_FILE */ if (fstat(fd, &statbuf) == -1) { #endif /* LARGE_FILE */ perror("stat error"); anyfail(); } #ifdef LARGE_FILE if (lseek64(fd, sparseoffset, SEEK_SET) < 0) { #else /* LARGE_FILE */ if (lseek(fd, sparseoffset, SEEK_SET) < 0) { #endif /* LARGE_FILE */ perror("lseek"); exit(1); } readbuf = (uchar_t *)malloc(pagesize); if (statbuf.st_size - sparseoffset > SIZE_MAX) { fprintf(stderr, "size_t overflow when setting up map\n"); exit(1); } mapsize = (size_t)(statbuf.st_size - sparseoffset); mappages = roundup(mapsize, pagesize) / pagesize; for (i = 0; i < mappages; i++) { cnt = read(fd, (char *)readbuf, pagesize); if (cnt == -1) { perror("read error"); return(0); } else if (cnt != pagesize) { /* * Okay if at last page in file... */ if ((i * pagesize) + cnt != mapsize) { (void)fprintf(stderr, "read %d of %ld bytes\n", (i*pagesize)+cnt, (long)mapsize); return(0); } } /* * Compare read bytes of data. * May have zeros from map extend... */ for (j = 0; j < cnt; j++) { if (expbuf[j] != readbuf[j] && readbuf[j] != 0) { (void)fprintf(stderr, "read bad data: exp %c got %c", expbuf[j], readbuf[j]); #ifdef LARGE_FILE (void)fprintf(stderr, ", pg %d off %d, " "(fsize %Ld)\n", i, j, statbuf.st_size); #else /* LARGE_FILE */ (void)fprintf(stderr, ", pg %d off %d, " "(fsize %ld)\n", i, j, statbuf.st_size); #endif /* LARGE_FILE */ return(0); } } } return(1); } /*ARGSUSED*/ void finish(int sig) { finished++; /* finish nicely and check the file contents */ } /*ARGSUSED*/ void clean_up_file(int sig) { if (!leavefile) (void)unlink(filename); exit(1); } unsigned int initrand(void) { unsigned int seed; /* * Initialize random seed... Got this from a test written * by scooter: * Use srand/rand to diffuse the information from the * time and pid. If you start several processes, then * the time and pid information don't provide much * variation. */ srand((unsigned int)getpid()); seed = rand(); srand((unsigned int)time((time_t *)0)); seed = (seed ^ rand()) % 100000; srand48((long int)seed); return (seed); } /***** LTP Port *****/ void ok_exit() { tst_resm(TPASS, "Test passed\n"); tst_rmdir(); tst_exit(); } int anyfail() { tst_resm(TFAIL, "Test failed\n"); tst_rmdir(); tst_exit(); return(0); }
static void cleanup(void) { semctl(sem_id, 0, IPC_RMID); tst_rmdir(); }
/***** LTP Port *****/ void ok_exit() { tst_resm(TPASS, "Test passed\n"); tst_rmdir(); tst_exit(); }
/*--------------------------------------------------------------------*/ int main(int argc, char **argv) { /***** BEGINNING OF MAIN. *****/ int core; int pid, npid; int nsig, exno, nexno, status; /*SIGIOT is 6, but since linux doesn't have SIGEMT, just using SIGIOT for place filling */ int signum[15]; int j; int ret_val = 0; #ifdef UCLINUX const char *msg; #endif signum[1] = SIGHUP; signum[2] = SIGINT; signum[3] = SIGQUIT; signum[4] = SIGILL; signum[5] = SIGTRAP; signum[6] = SIGABRT; signum[7] = SIGIOT; signum[8] = SIGFPE; signum[9] = SIGKILL; signum[10] = SIGBUS; signum[11] = SIGSEGV; signum[12] = SIGSYS; signum[13] = SIGPIPE; signum[14] = SIGALRM; #ifdef UCLINUX if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); maybe_run_child(&do_child, "dd", &temp, &sig); #endif setup(); // tempdir(); /* move to new directory */ blenter(); exno = 1; unlink("core"); for (j = 1; j < sizeof(signum) / sizeof(*signum); j++) { sig = signum[j]; if (sig != SIGKILL) #ifndef BCS if (sig != SIGSTOP) #endif if (sigset(sig, SIG_DFL) == SIG_ERR) { fprintf(temp, "\tsigset(%d,,) fails\n", sig); local_flag = FAILED; fail_exit(); } fflush(temp); pid = FORK_OR_VFORK(); if (pid < 0) { forkfail(); } /* * Child process sleeps for up to 3 minutes giving the * parent process a chance to kill it. */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "dd", temp, sig) < 0) { tst_resm(TBROK, "self_exec FAILED - " "terminating test."); tst_exit(); tst_exit(); } #else do_child(); #endif } /* * Parent process sends signal to child. */ //fprintf(temp, "Testing signal %d\n", sig); 12/12/02 kill(pid, sig); npid = wait(&status); if (npid != pid) { fprintf(temp, "wait error: unexpected pid returned\n"); ret_val = 1; } /* 12/20/02. nsig = status & 0177; core = status & 0200; nexno = (status & 0xff00) >> 8; */ /***** LTP Port *****/ nsig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif nexno = WIFEXITED(status); /***** ** ** *****/ //printf("nsig=%x, core=%x, status=%x\n", nsig,core, status); 12/12/2002 /* to check if the core dump bit has been set, bit # 7 */ /***** LTP Port *****/ /* 12/12/02: [email protected] * SIGILL when is not caught or not ignored it causes * a core dump and program termination. So moved the condition to * else part of the program. * SIGQUIT like SIGABRT normally causes a program to quit and * and dumps core. So moved the condition to else part of the * program. */ /***** ** ** *****/ if (core) { if ((sig == 1) || (sig == 2) /*|| (sig == 3) || */ /*(sig == 4) */ || (sig == 9) || (sig == 13) || (sig == 14) || (sig == 15)) { fprintf(temp, "signal error: core dump bit set for exception number %d\n", sig); ret_val = 1; } } else { if ((sig == 3) || (sig == 4) || (sig == 5) || (sig == 6) || (sig == 7) || (sig == 8) || (sig == 10) || (sig == 11) || (sig == 12)) { fprintf(temp, "signal error: core dump bit not set for exception number %d\n", sig); ret_val = 1; } } /* nsig is the signal number returned by wait */ if (nsig != sig) { fprintf(temp, "wait error: unexpected signal %d returned, expected %d\n", nsig, sig); ret_val = 1; } /* nexno is the exit number returned by wait */ if (nexno != 0) { fprintf(temp, "signal error: unexpected exit number %d returned, expected 0\n", nexno); ret_val = 1; } } unlink("core"); fflush(temp); if (ret_val) local_flag = FAILED; unlink("core"); tst_rmdir(); /*--------------------------------------------------------------------*/ anyfail(); tst_exit(); }
int main(int ac, char **av) { int fd, i; int tlen = 0; struct sigaction act; int lc; char *msg; struct statvfs fs; /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); tst_exit(); } #ifdef UCLINUX maybe_run_child(&dochild, "dddd", filename, &recstart, &reclen, &ppid); #endif local_flag = PASSED; tst_tmpdir(); if (statvfs(".", &fs) == -1) { tst_resm(TFAIL | TERRNO, "statvfs failed"); tst_rmdir(); tst_exit(); } if ((fs.f_flag & MS_MANDLOCK) == 0) { tst_resm(TCONF, "The filesystem where /tmp is mounted does" " not support mandatory locks. Cannot run this test."); tst_rmdir(); tst_exit(); } for (lc = 0; TEST_LOOPING(lc); lc++) { setvbuf(stdin, 0, _IOLBF, BUFSIZ); setvbuf(stdout, 0, _IOLBF, BUFSIZ); setvbuf(stderr, 0, _IOLBF, BUFSIZ); ppid = getpid(); srand(ppid); sigemptyset(&set); act.sa_handler = (void (*)())usr1hndlr; act.sa_mask = set; act.sa_flags = 0; if (sigaction(SIGUSR1, &act, 0)) { tst_resm(TBROK, "Sigaction for SIGUSR1 failed"); tst_rmdir(); tst_exit(); } /* end if */ if (sigaddset(&set, SIGUSR1)) { tst_resm(TBROK, "sigaddset for SIGUSR1 failed"); tst_rmdir(); tst_exit(); } if (sigprocmask(SIG_SETMASK, &set, 0)) { tst_resm(TBROK, "sigprocmask for SIGUSR1 failed"); tst_rmdir(); tst_exit(); } for (i = 0; i < iterations; i++) { sprintf(filename, "%s.%d.%d\n", progname, ppid, i); if ((fd = open(filename, O_CREAT | O_RDWR, 02666)) < 0) { tst_resm(TBROK, "parent error opening/creating %s", filename); cleanup(); } /* end if */ if (chown(filename, geteuid(), getegid()) == -1) { tst_resm(TBROK, "parent error chowning %s", filename); cleanup(); } /* end if */ if (chmod(filename, 02666) == -1) { tst_resm(TBROK, "parent error chmoding %s", filename); cleanup(); } /* end if */ do { if (write(fd, buffer, BUFSIZE) < 0) { tst_resm(TBROK, "parent write failed to %s", filename); cleanup(); } tlen += BUFSIZE; } while (tlen < len); close(fd); reclen = RECLEN; /* * want at least RECLEN bytes BEFORE AND AFTER the * record lock. */ recstart = RECLEN + rand() % (len - 3 * RECLEN); if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); if ((cpid = FORK_OR_VFORK()) < 0) { unlink(filename); tst_resm(TINFO, "System resource may be too low, fork() malloc()" " etc are likely to fail."); tst_resm(TBROK, "Test broken due to inability of fork."); tst_rmdir(); tst_exit(); } if (cpid == 0) { #ifdef UCLINUX if (self_exec (av[0], "dddd", filename, recstart, reclen, ppid) < -1) { unlink(filename); tst_resm(TBROK, "self_exec failed."); tst_rmdir(); tst_exit(); } #else dochild(); #endif /* never returns */ } if (sync_pipe_wait(sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); doparent(); /* child should already be dead */ unlink(filename); } if (local_flag == PASSED) tst_resm(TPASS, "Test passed."); else tst_resm(TFAIL, "Test failed."); tst_rmdir(); tst_exit(); } /* end for */ tst_exit(); }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { int fildes; int ret = 0; char pbuf[BUFSIZ]; int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int fail_count = 0; /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); tst_exit(); } tst_tmpdir(); local_flag = PASSED; sprintf(tempfile, "open09.%d", getpid()); /*--------------------------------------------------------------------*/ for (lc = 0; TEST_LOOPING(lc); lc++) { local_flag = PASSED; //block0: if ((fildes = creat(tempfile, 0600)) == -1) { tst_resm(TBROK, "\t\t\tcan't create '%s'", tempfile); tst_exit(); } else { close(fildes); if ((fildes = open(tempfile, 1)) == -1) { tst_resm(TFAIL, "\t\t\topen failed"); tst_exit(); } } ret = read(fildes, pbuf, 1); if (ret != -1) { tst_resm(TFAIL, "read should not succeed"); local_flag = FAILED; } close(fildes); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block0."); } else { tst_resm(TFAIL, "Test failed in block0."); fail_count++; } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block1: if ((fildes = open(tempfile, 0)) == -1) { tst_resm(TFAIL, "\t\t\topen failed"); local_flag = FAILED; } else { ret = write(fildes, pbuf, 1); if (ret != -1) { tst_resm(TFAIL, "writeshould not succeed"); local_flag = FAILED; } } close(fildes); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block1."); } else { tst_resm(TFAIL, "Test failed in block1."); fail_count++; } /*--------------------------------------------------------------------*/ unlink(tempfile); tst_rmdir(); if (fail_count == 0) { tst_resm(TPASS, "Test passed."); } else { tst_resm(TFAIL, "Test failed due to above failures."); } } /* end for */ tst_exit(); }
extern void cleanup() { /* Remove tmp dir and all files in it */ TEST_CLEANUP; tst_rmdir(); }
int main(int argc, char *argv[]) { int pid; sigset_t set; struct sigaction act, oact; int term(); int al(); void dochild1(); void dochild2(); #ifdef UCLINUX tst_parse_opts(argc, argv, NULL, NULL); maybe_run_child(&dochild1, "n", 1); maybe_run_child(&dochild2, "n", 2); #endif sigemptyset(&set); act.sa_handler = (void (*)())term; act.sa_mask = set; act.sa_flags = 0; if (sigaction(SIGTERM, &act, &oact)) { tst_brkm(TBROK, NULL, "Sigaction(SIGTERM)"); } sigemptyset(&set); act.sa_handler = (void (*)())al; act.sa_mask = set; act.sa_flags = 0; if (sigaction(SIGALRM, &act, 0)) { tst_brkm(TBROK, NULL, "Sigaction(SIGALRM)"); } parent_pid = getpid(); tst_tmpdir(); /*--------------------------------------------------------------*/ pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TBROK, NULL, "fork() returned %d", pid); } if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "n", 1) < 0) { tst_resm(TBROK, "self_exec failed"); } #else dochild1(); #endif } kidpid[0] = pid; pid = FORK_OR_VFORK(); if (pid < 0) { (void)kill(kidpid[0], SIGTERM); (void)unlink("./rename14"); tst_brkm(TBROK, NULL, "fork() returned %d", pid); } if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "n", 1) < 0) { tst_resm(TBROK, "self_exec failed"); } #else dochild2(); #endif } kidpid[1] = pid; alarm(RUNTIME); /* Collect child processes. */ /* Wait for timeout */ pause(); kill(kidpid[0], SIGTERM); kill(kidpid[1], SIGTERM); waitpid(kidpid[0], NULL, 0); waitpid(kidpid[1], NULL, 0); unlink("./rename14"); unlink("./rename14xyz"); (local_flag == PASSED) ? tst_resm(TPASS, "Test Passed") : tst_resm(TFAIL, "Test Failed"); tst_rmdir(); tst_exit(); }
void cleanup(void) { free(testfile3); tst_rmdir(); }
int main(int ac, char **av) { int lc; char *msg; int results; /* Disable test if the version of the kernel is less than 2.6.17 */ if (((results = tst_kvercmp(2, 6, 17)) < 0)) { tst_resm(TINFO, "This test can only run on kernels that are "); tst_resm(TINFO, "2.6.17 and higher"); exit(0); } /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL))) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); tst_tmpdir(); if (tst_fs_type(cleanup, ".") == TST_NFS_MAGIC) { tst_brkm(TCONF, cleanup, "Cannot do splice on a file on NFS filesystem"); } tst_rmdir(); /* * check looping state if -c option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call splice_test */ TEST(splice_test()); /* check return code */ if (TEST_RETURN < 0) { if (TEST_RETURN != -1) { TEST_ERRNO = -TEST_RETURN; } TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "splice() Failed, errno=%d : %s", 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, "splice() returned %ld", TEST_RETURN); } } } /* * cleanup and exit */ cleanup(); return (0); }
static void cleanup(void) { tst_rmdir(); tst_exit(); }
void cleanup(void) { rm_shm(shm_id_1); tst_rmdir(); }
static void cleanup(void) { TEST_CLEANUP; unlink(testfile); tst_rmdir(); }
int main(int ac, char *av[]) { FILE *stream; char buf[30]; char *junk="abcdefghijklmnopqrstuvwxyz"; long pos; off_t opos; int lc; char *msg; /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); tst_exit(); } local_flag = PASSED; tst_tmpdir(); for (lc = 0; TEST_LOOPING(lc); lc++) { sprintf(tempfile1, "stream03.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if ((stream=fopen(tempfile1, "a+")) == NULL) { tst_resm(TBROK,"fopen(%s) a+ failed: %s", tempfile1, strerror(errno)); tst_exit(); } /* make sure offset of zero at start */ pos=ftell(stream); if (pos != 0) { tst_resm(TFAIL,"file pointer descrepancy 1"); local_flag = FAILED; } /* write something and check */ if (fwrite(junk, sizeof(*junk), strlen(junk), stream) == 0) { tst_resm(TFAIL,"fwrite failed: %s", strerror(errno)); tst_exit(); } pos=ftell(stream); if (pos != strlen(junk)) { tst_resm(TFAIL, "strlen(junk)=%zi: file pointer descrepancy 2 (pos=%li)", strlen(junk), pos); local_flag = FAILED; } /* rewind and check */ rewind(stream); pos = ftell(stream); if (pos != 0) { tst_resm(TFAIL,"file pointer descrepancy 3 (pos=%li, wanted pos=0)", pos); local_flag = FAILED; } /* seek from current position and then check */ if (fseek(stream,strlen(junk), 1) != 0) { tst_resm(TFAIL, "fseek failed: %s", strerror(errno)); tst_exit(); } pos = ftell(stream); if (pos != strlen(junk)) { tst_resm(TFAIL, "strlen(junk)=%zi: file pointer descrepancy 4 (pos=%li)", strlen(junk), pos); local_flag = FAILED; } /* seek from end of file and then check */ if (fseek(stream, 0, 2) != 0) { tst_resm(TFAIL, "fseek failed: %s", strerror(errno)); tst_exit(); } pos = ftell(stream); if (pos != strlen(junk)) { tst_resm(TFAIL,"strlen(junk)=%zi: file pointer descrepancy 5 (pos=%li)", strlen(junk), pos); local_flag = FAILED; } /* rewind with seek and then check */ if (fseek(stream, 0, 0) != 0) { tst_resm(TFAIL,"fseek failed: %s", strerror(errno)); tst_exit(); } pos = ftell(stream); if (pos != 0) { tst_resm(TFAIL,"file pointer descrepancy 6 (pos=%li, wanted pos=0)", pos); local_flag = FAILED; } /* read till EOF, do getc and then check ftell */ while (fgets(buf, sizeof(buf), stream)); pos=ftell(stream); getc(stream); pos=ftell(stream); if (pos != strlen(junk)) { tst_resm(TFAIL,"strlen(junk)=%zi: file pointer descrepancy 7 (pos=%li)", strlen(junk), pos); local_flag = FAILED; } fclose(stream); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block0."); } else { tst_resm(TFAIL, "Test failed in block0."); } local_flag = PASSED; unlink(tempfile1); /*--------------------------------------------------------------------*/ //block1: if ((stream = fopen(tempfile1, "a+")) == NULL) { tst_resm(TFAIL,"fopen(%s) a+ failed: %s", tempfile1, strerror(errno)); tst_exit(); } /* make sure offset of zero at start */ opos = ftello(stream); if (opos != 0) { tst_resm(TFAIL,"file pointer descrepancy 1 (opos=%"PRId64", wanted opos=0)", (int64_t)opos); local_flag = FAILED; } /* write something and check */ if (fwrite(junk, sizeof(*junk), strlen(junk), stream) == 0) { tst_resm(TFAIL, "fwrite failed: %s", strerror(errno)); tst_exit(); } opos = ftello(stream); if (opos != strlen(junk)) { tst_resm(TFAIL, "strlen(junk)=%zi: file pointer descrepancy 2 (opos=%"PRId64")", strlen(junk), (int64_t)opos); local_flag = FAILED; } /* rewind and check */ rewind(stream); opos = ftello(stream); if (opos != 0) { tst_resm(TFAIL,"file pointer descrepancy 3 (opos=%"PRId64", wanted opos=0)", (int64_t)opos); local_flag = FAILED; } /* seek from current position and then check */ if (fseeko(stream, strlen(junk), 1) != 0) { tst_resm(TFAIL,"fseeko failed: %s", strerror(errno)); tst_exit(); } opos = ftello(stream); if (opos != strlen(junk)) { tst_resm(TFAIL,"strlen(junk)=%zi: file pointer descrepancy 4 (opos=%"PRId64")", strlen(junk), (int64_t)opos); local_flag = FAILED; } /* seek from end of file and then check */ if (fseeko(stream, 0, 2) != 0) { tst_resm(TFAIL,"fseeko failed: %s", strerror(errno)); tst_exit(); } opos = ftello(stream); if (opos != strlen(junk)) { tst_resm(TFAIL,"strlen(junk)=%zi: file pointer descrepancy 5 (opos=%"PRId64")", strlen(junk), (int64_t)opos); local_flag = FAILED; } /* rewind with seek and then check */ if (fseeko(stream, 0, 0) != 0) { tst_resm(TFAIL,"fseeko failed: %s", strerror(errno)); tst_exit(); } opos = ftello(stream); if (opos != 0) { tst_resm(TFAIL,"file pointer descrepancy 6 (opos=%"PRId64", wanted opos=0)", (int64_t)opos); local_flag = FAILED; } /* read till EOF, do getc and then check ftello */ while (fgets(buf, sizeof(buf), stream)); opos=ftello(stream); getc(stream); opos=ftello(stream); if (opos != strlen(junk)) { tst_resm(TFAIL,"strlen(junk)=%zi: file pointer descrepancy 7 (opos=%li)", strlen(junk), opos); local_flag = FAILED; } fclose(stream); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block1."); } else { tst_resm(TFAIL, "Test failed in block1."); } unlink(tempfile1); } tst_rmdir(); tst_exit(); }
static void cleanup(void) { close(fd); TEST_CLEANUP; tst_rmdir(); }
int main(int argc, char *argv[]) { int opt = 0; pid_t pid; char *bin_path, *ltproot; void *exit_value; pthread_attr_t newattr; pthread_t sig_hand; size_t stacksize = 2093056; int th_num; int retvalend = 0; int retval = 0; int error = 0; /*int time=1; */ int i; /* Generate test ID from invocation name */ if ((TCID = strrchr(argv[0], '/')) != NULL) TCID++; else TCID = argv[0]; ltproot = getenv("LTPROOT"); if (ltproot == NULL || strlen(ltproot) == 0) { tst_brkm(TBROK, NULL, "You must set $LTPROOT before executing this test"); } bin_path = malloc(strlen(ltproot) + 16); if (bin_path == NULL) { tst_brkm(TBROK | TERRNO, NULL, "malloc failed"); } sprintf(bin_path, "%s/testcases/bin", ltproot); tst_tmpdir(); setbuf(stdout, NULL); setbuf(stderr, NULL); datadir[0] = '.'; datadir[1] = '\0'; if (argc != 1) { while ((opt = getopt(argc, argv, "vn:l:D:?")) != EOF) { switch (opt) { case 'D': strncpy(datadir, optarg, PATH_MAX); break; case 'l': num_loops = atoi(optarg); break; case 'n': num_threads = atoi(optarg); break; case 'v': ++debug; /* verbose mode */ break; default: fprintf(stderr, "usage: %s [-n number_of_threads] [-v]\n", argv[0]); fprintf(stderr, "[-l number_of_loops] "); fprintf(stderr, "[-D DATAs absolute path]\n"); exit(1); } } } switch (pid = fork()) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork failed"); case 0: generate(datadir, bin_path); exit(0); default: waitpid(pid, NULL, 0); } SAFE_FREE(bin_path); if (debug) { tst_resm(TINFO, "%s: will run for %d loops; using %s as a data directory", argv[0], num_loops, datadir); } if (num_threads <= 0) { tst_resm(TWARN, "num_threads undefined or incorrect, using \"1\""); num_threads = 1; } if (nb_func * num_threads > PTHREAD_THREADS_MAX - 2) while (nb_func * num_threads > PTHREAD_THREADS_MAX - 2) num_threads--; if (debug) tst_resm(TINFO, "%s: will run %d functions, %d threads per function", argv[0], nb_func, num_threads); retval = pthread_mutex_init(&sig_mutex, NULL); if (retval != 0) sys_error("main : mutex_init(&sig_mutex) FAILED", __LINE__); retval = pthread_create(&sig_hand, NULL, handle_signals, NULL); if (retval != 0) sys_error("main : create(&sig_hand) FAILED", __LINE__); /* * Start all calculation threads... */ threads = malloc(nb_func * num_threads * sizeof(pthread_t)); if (threads == NULL) tst_brkm(TFAIL | TERRNO, cleanup, "malloc failed"); tabcom = malloc((sizeof(TH_DATA *) * nb_func * num_threads)); if (!tabcom) tst_brkm(TFAIL | TERRNO, cleanup, "malloc failed"); tabcour = tabcom; retval = pthread_attr_init(&newattr); if (retval != 0) sys_error("main : attr_init(&newattr) FAILED", __LINE__); if (pthread_attr_setstacksize(&newattr, stacksize)) sys_error("main: pthread_attr_setstacksize failed", __LINE__); retval = pthread_attr_setdetachstate(&newattr, PTHREAD_CREATE_JOINABLE); if (retval != 0) sys_error("main : attr_setdetachstate(&newattr) FAILED", __LINE__); /* run the nb_func functions on num_threads */ indice = 0; for (i = 0; i < nb_func; i++) { for (th_num = 0; th_num < num_threads; th_num++) { /* allocate struct of commucation with the thread */ pcom = calloc(1, sizeof(TH_DATA)); if (pcom == NULL) tst_brkm(TFAIL | TERRNO, cleanup, "calloc failed"); *tabcour = (TH_DATA *) pcom; tabcour++; /* * update structure of communication */ pcom->th_num = th_num; pcom->th_func = th_func[i]; pthread_mutex_lock(&sig_mutex); if (sig_cancel) { /* stop processing right now! */ pthread_mutex_unlock(&sig_mutex); goto finished; } retval = pthread_create(&threads[indice], &newattr, thread_code, (void *)pcom); if (retval != 0) sys_error("main : create FAILED", __LINE__); indice++; pthread_mutex_unlock(&sig_mutex); } /* num_threads */ } /* for i */ /*alarm(60*time); *//* start all threads for TEST_time */ /* * Wait for the threads finish their task * pthread_join () will block */ finished: if (debug) { tst_resm(TINFO, "initial thread: Waiting for %d threads to finish", indice); } tabcour = tabcom; for (th_num = 0; th_num < indice; th_num++) { retvalend = pthread_join(threads[th_num], &exit_value); if (retvalend != 0) sys_error("finish : join FAILED", __LINE__); /* test the result in TH_DATA : communication buffer */ pcom = *tabcour++; if (pcom->th_result != 0) { error++; tst_resm(TFAIL, "thread %d (%s) terminated unsuccessfully %d " "errors/%d loops\n%s", th_num, pcom->th_func.fident, pcom->th_nerror, pcom->th_nloop, pcom->detail_data); } else if (debug) { tst_resm(TINFO, "thread %d (%s) terminated successfully %d loops", th_num, pcom->th_func.fident, pcom->th_nloop - 1); } SAFE_FREE(pcom); } pthread_cancel(sig_hand); pthread_join(sig_hand, NULL); SAFE_FREE(tabcom); SAFE_FREE(threads); tst_rmdir(); if (error) exit(1); else exit(0); return 0; }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { FILE *stream; char *junk = "abcdefghijklmnopqrstuvwxyz"; char *inbuf; int ret; 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); tst_tmpdir(); for (lc = 0; TEST_LOOPING(lc); lc++) { local_flag = PASSED; sprintf(tempfile1, "stream04.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if ((stream = fopen(tempfile1, "a+")) == NULL) { tst_resm(TFAIL | TERRNO, "fopen(%s) a+ failed", tempfile1); tst_rmdir(); tst_exit(); } /* write something and check */ if ((ret = fwrite(junk, sizeof(*junk), strlen(junk), stream)) == 0) { tst_resm(TFAIL, "fwrite failed: %s", strerror(errno)); tst_rmdir(); tst_exit(); } if ((size_t) ret != strlen(junk)) { tst_resm(TFAIL, "strlen(junk) = %zi != return value from fwrite = %zi", strlen(junk), ret); local_flag = FAILED; } fclose(stream); if ((stream = fopen(tempfile1, "r+")) == NULL) { tst_resm(TFAIL, "fopen(%s) r+ failed: %s", tempfile1, strerror(errno)); tst_rmdir(); tst_exit(); } if ((inbuf = (char *)malloc(strlen(junk))) == 0) { tst_resm(TBROK, "test failed because of malloc: %s", strerror(errno)); tst_rmdir(); tst_exit(); } if ((ret = fread(inbuf, sizeof(*junk), strlen(junk), stream)) == 0) { tst_resm(TFAIL, "fread failed: %s", strerror(errno)); tst_rmdir(); tst_exit(); } if ((size_t) ret != strlen(junk)) { tst_resm(TFAIL, "strlen(junk) = %zi != return value from fread = %zi", strlen(junk), ret); local_flag = FAILED; } fclose(stream); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed."); } else { tst_resm(TFAIL, "Test failed."); } /*--------------------------------------------------------------------*/ unlink(tempfile1); } /* end for */ tst_rmdir(); tst_exit(); }
void cleanup(void) { unlink(filename); tst_rmdir(); }
void cleanup(void) { tst_rmdir(); TEST_CLEANUP; }
int anyfail() { tst_resm(TFAIL, "Test failed\n"); tst_rmdir(); tst_exit(); }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { FILE *stream; char buf[10]; int nr, fd; 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); tst_tmpdir(); local_flag = PASSED; for (lc = 0; TEST_LOOPING(lc); lc++) { local_flag = PASSED; sprintf(tempfile, "stream05.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if ((stream = fopen(tempfile, "a+")) == NULL) { tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile, strerror(errno)); tst_exit(); } fprintf(stream, "a"); fclose(stream); if ((stream = fopen(tempfile, "r+")) == NULL) { tst_resm(TFAIL, "fopen(%s) r+ failed: %s", tempfile, strerror(errno)); tst_exit(); } /* check that ferror returns zero */ if (ferror(stream) != 0) { tst_resm(TFAIL, "ferror did not return zero: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block0."); } else { tst_resm(TFAIL, "Test failed in block0."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block1: /* check that fileno returns valid file descriptor */ fd = fileno(stream); if ((nr = read(fd, buf, 1)) < 0) { tst_resm(TFAIL, "read failed: %s", strerror(errno)); tst_exit(); } if (nr != 1) { tst_resm(TFAIL, "read did not read right number"); local_flag = FAILED; } if (buf[0] != 'a') { tst_resm(TFAIL, "read returned bad values"); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block1."); } else { tst_resm(TFAIL, "Test failed in block1."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block2: /* read to EOF and ensure feof returns non-zero */ fclose(stream); if ((stream = fopen(tempfile, "r+")) == NULL) { tst_resm(TFAIL, "fopen(%s) r+ failed: %s", tempfile, strerror(errno)); tst_exit(); } if (feof(stream) != 0) { tst_resm(TFAIL, "feof returned non-zero when it should not: %s", strerror(errno)); local_flag = FAILED; } fread(buf, 1, 2, stream); /* read to EOF */ if (feof(stream) == 0) { tst_resm(TFAIL, "feof returned zero when it should not: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block2."); } else { tst_resm(TFAIL, "Test failed in block2."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block3: /* ensure clearerr works */ clearerr(stream); if (feof(stream) != 0) { tst_resm(TFAIL, "clearerr failed: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block3."); } else { tst_resm(TFAIL, "Test failed in block3."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block4: /* test fopen "b" flags -- should be allowed but ignored */ (void)fclose(stream); if ((stream = fopen(tempfile, "rb")) == NULL) { tst_resm(TFAIL, "fopen(%s) rb failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); if ((stream = fopen(tempfile, "wb")) == NULL) { tst_resm(TFAIL, "fopen(%s) wb failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); if ((stream = fopen(tempfile, "ab")) == NULL) { tst_resm(TFAIL, "fopen(%s) ab failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); if ((stream = fopen(tempfile, "rb+")) == NULL) { tst_resm(TFAIL, "fopen(%s) rb+ failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); if ((stream = fopen(tempfile, "wb+")) == NULL) { tst_resm(TFAIL, "fopen(%s) wb+ failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); if ((stream = fopen(tempfile, "ab+")) == NULL) { tst_resm(TFAIL, "fopen(%s) ab+ failed: %s", tempfile, strerror(errno)); tst_exit(); } (void)fclose(stream); tst_resm(TPASS, "Test passed in block4."); /*--------------------------------------------------------------------*/ unlink(tempfile); } /* end for */ tst_rmdir(); tst_exit(); tst_exit(); }
static void cleanup(void) { munmap(maddr, mapsize); close(fd); tst_rmdir(); }
static void cleanup(void) { TEST_CLEANUP; tst_rmdir(); }
static void cleanup(void) { unlink(testfile); tst_rmdir(); }
void cleanup(void) { tst_rmdir(); }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { FILE *stream; int fd; int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* * parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); tst_exit(); /*NOTREACHED*/ } local_flag = PASSED; tst_tmpdir(); for (lc = 0; TEST_LOOPING(lc); lc++) { sprintf(tempfile1, "stream1.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if(mknod(tempfile1, (S_IFIFO|0666), 0) != 0) { tst_resm(TFAIL,"\tmknod failed in block0\n"); local_flag = FAILED; goto block1; } if((stream=fopen(tempfile1,"w+")) == NULL) { tst_resm(TFAIL,"\tfopen w+ failed for pipe file\n"); local_flag = FAILED; } else { fclose(stream); } if((stream=fopen(tempfile1,"a+")) == NULL) { tst_resm(TFAIL,"\tfopen a+ failed\n"); local_flag = FAILED; } else { fclose(stream); unlink(tempfile1); } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block0.\n"); } else { tst_resm(TFAIL, "Test failed in block0.\n"); } local_flag = PASSED; /*--------------------------------------------------------------------*/ block1 : if(( fd = open("/dev/tty",O_WRONLY)) >= 0 ) { close(fd); if(( stream = fopen("/dev/tty","w"))==NULL) { tst_resm(TFAIL,"\tfopen write failed for /dev/tty\n"); local_flag = FAILED; } else { fclose(stream); } } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block1.\n"); } else { tst_resm(TFAIL, "Test failed in block1.\n"); } /*--------------------------------------------------------------------*/ } /* end for */ tst_rmdir(); tst_exit(); return(0); }
/* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { TEST_CLEANUP; tst_rmdir(); }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { FILE *stream; char buf[10]; int i; int lc; char *msg; /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); local_flag = PASSED; tst_tmpdir(); for (lc = 0; TEST_LOOPING(lc); lc++) { sprintf(tempfile1, "stream011.%d", getpid()); sprintf(tempfile2, "stream012.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if ((stream = fopen(tempfile1, "a+")) == NULL) { tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1, strerror(errno)); tst_exit(); } fwrite("a", 1, 1, stream); if ((stream = freopen(tempfile2, "a+", stream)) == NULL) { tst_brkm(TFAIL | TERRNO, NULL, "freopen(%s) a+ failed", tempfile2); } fwrite("a", 1, 1, stream); fclose(stream); /* now check that a single "a" is in each file */ if ((stream = fopen(tempfile1, "r")) == NULL) { tst_brkm(TFAIL | TERRNO, NULL, "fopen(%s) r failed", tempfile1); } else { for (i = 0; i < 10; i++) buf[i] = 0; fread(buf, 1, 1, stream); if ((buf[0] != 'a') || (buf[1] != 0)) { tst_resm(TFAIL, "bad contents in %s", tempfile1); local_flag = FAILED; } fclose(stream); } if ((stream = fopen(tempfile2, "r")) == NULL) { tst_brkm(TFAIL | TERRNO, NULL, "fopen(%s) r failed", tempfile2); } else { for (i = 0; i < 10; i++) buf[i] = 0; fread(buf, 1, 1, stream); if ((buf[0] != 'a') || (buf[1] != 0)) { tst_resm(TFAIL, "bad contents in %s", tempfile2); local_flag = FAILED; } fclose(stream); } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed."); } else { tst_resm(TFAIL, "Test failed."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ unlink(tempfile1); unlink(tempfile2); } /* end for */ tst_rmdir(); tst_exit(); }