/* * Child process that reads/writes map. The child 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(unsigned procno, unsigned nprocs) { uchar_t *paddr; unsigned randpage; unsigned int seed; unsigned loopcnt; unsigned nloops; unsigned i; seed = initrand(); /* initialize random seed */ nloops = (randloops) ? (lrand48() % MAXLOOPS) : MAXLOOPS; if (debug) (void)printf("child %d (pid %d): seed %d, loop %d\n", procno, getpid(), seed, nloops); /* * Now loop read/writing random pages. */ for (loopcnt = 0; loopcnt < nloops; loopcnt++) { randpage = lrand48() % mappages; /* find the page address */ paddr = (uchar_t *)(mapaddr + (randpage * pagesize)); for (i = procno; i < pagesize; i += nprocs) { if (*((unsigned char *)(paddr+i)) != ((procno + pattern) & 0xff)) { (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) { randpage = (unsigned)lrand48() % mappages; paddr = (uchar_t *)mapaddr + (randpage * pagesize); if (msync((caddr_t)paddr, (mappages-randpage)*pagesize, MS_SYNC) == -1) { perror("msync error"); anyfail(); } } exit(0); }
/* * Make sure file has all the correct data. */ int mapokay(uchar_t *expbuf) { uchar_t *ptr; unsigned i, j; ptr = (uchar_t *)mapaddr; for (i = 0; i < mappages; i++) { /* * Compare read bytes of data. */ for (j = 0; j < pagesize; j++) { if (*ptr != expbuf[j]) { (void)fprintf(stderr, "bad map data: exp %c got %c)", expbuf[j], *ptr); (void)fprintf(stderr, ", pg %d off %d\n", i, j); anyfail(); } ptr++; } } return(1); }
/*ARGSUSED*/ int main(int argc, char *argv[]) { caddr_t mmapaddr, munmap_begin; long pagesize = sysconf(_SC_PAGE_SIZE); int i; time_t t; (void)time(&t); //(void)printf("%s: Started %s", argv[0], ctime(&t)); if (sbrk(pagesize - ((u_long)sbrk(0)%(u_long)pagesize))==(char *)-1) { ERROR("couldn't round up brk to a page boundary"); local_flag = FAILED; anyfail(); } /* The brk is now at the begining of a page. */ if ((munmap_begin = mmapaddr = (caddr_t)sbrk(0)) == (caddr_t)-1) { ERROR("couldn't find top of brk"); local_flag = FAILED; anyfail(); } mmapaddr = 0; /* burn level 2 ptes by spacing mmaps 4Meg apart */ /* This should switch to large anonymous swap space granularity */ for (i = 0; i < GRAN_NUMBER; i++) { if (mmap(mmapaddr, pagesize, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0)==(caddr_t)-1) { ERROR("mmap failed"); local_flag = FAILED; anyfail(); } mmapaddr += NPTEPG*pagesize; } /* Free bizillion level2 ptes to switch to small granularity */ if (munmap(munmap_begin, (size_t)(mmapaddr-munmap_begin))) { ERROR("munmap failed"); local_flag = FAILED; anyfail(); } (void)time(&t); //(void)printf("%s: Finished %s", argv[0], ctime(&t)); ok_exit(); tst_exit(); }
int main(int argc, char *argv[]) { caddr_t mmapaddr; size_t pagesize = sysconf(_SC_PAGE_SIZE); time_t t; int sleep_time = 0; if (!argc) { (void)fprintf(stderr, "argc == 0\n"); anyfail(); } if (argc != 2 || !(sleep_time = atoi(argv[1]))) { (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); anyfail(); } (void)time(&t); // (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port if (sbrk(pagesize - ((unsigned long) sbrk(0) & (pagesize - 1))) == (char *)-1) { ERROR("couldn't round up brk"); anyfail(); } if ((mmapaddr = sbrk(0)) == (char *)-1) { ERROR("couldn't find top of brk"); anyfail(); } /* mmapaddr is now on a page boundary after the brk segment */ if (mmap (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0) == (caddr_t) - 1) { ERROR("large mmap failed"); printf("for this test to run, it needs a mmap space of\n"); printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); return 1; } (void)sleep(sleep_time); (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port ok_exit(); tst_exit(); }
static void do_test(caddr_t brk_max, long pagesize) { if (mmap((caddr_t)((long)brk_max - 3*pagesize), (2*pagesize), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE, 0, 0) == (caddr_t)-1) { ERROR("mmap failed"); anyfail(); } /* extend mmap */ if (mmap((caddr_t)((long)brk_max - 2*pagesize), (2*pagesize), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE, 0, 0) == (caddr_t)-1) { ERROR("mmap failed"); anyfail(); } if (sbrk(pagesize) == NEG1) { ERROR("sbrk failed to grow over mmaped region"); anyfail(); } if (sbrk(-pagesize) == NEG1) { ERROR("sbrk failed to shrink back to mmaped region"); anyfail(); } if (sbrk(-pagesize) == NEG1) { ERROR("sbrk failed to shrink over mmaped region more"); anyfail(); } if (sbrk(-pagesize) == NEG1) { ERROR("sbrk failed to shrink some more"); anyfail(); } if (sbrk(2 * pagesize) == NEG1) { ERROR("sbrk failed to change brk segment to original size"); anyfail(); } }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { int fd, ret_val; FILE *fp; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); /* Check that system SEV_LEVEL output is correct */ close(2); /* redirect stderr to file */ fd = creat("fmtfile", 0644); ret_val = fmtmsg(MM_PRINT | MM_SOFT, "LTP:fmtmsg", MM_INFO, "LTP fmtmsg() test1 message, NOT an error", "This is correct output, no action needed", "LTP:msg:001"); close(fd); if (ret_val != 0) { fprintf(temp, "fmtmsg returned %d, expected 0\n\n", ret_val); local_flag = FAILED; } fp = fopen("fmtfile", "r"); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str1), fp); if (strcmp(str1, buf) != 0) { fprintf(temp, "Expected string: %s\n", str1); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } /* Read past spaces in output */ fread(&ch, sizeof(ch), 1, fp); while (isspace(ch)) fread(&ch, sizeof(ch), 1, fp); ungetc(ch, fp); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str2), fp); fclose(fp); if (strcmp(str2, buf) != 0) { fprintf(temp, "Expected string: %s\n", str2); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); /* Check that a system defined SEV_LEVEL cannot get redefined */ ret_val = addseverity(3, "INVALID"); if (ret_val != MM_NOTOK) { fprintf(temp, "addseverity returned %d, expected MM_NOTOK\n", ret_val); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); /* Check that we can define our own */ /* SEV_LEVEL and output is correct */ ret_val = addseverity(5, "LTP_TEST"); if (ret_val != MM_OK) { fprintf(temp, "addseverity returned %d, expected MM_OK\n", ret_val); local_flag = FAILED; } close(2); /* redirect stderr to file */ fd = creat("fmtfile", 0644); ret_val = fmtmsg(MM_PRINT | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5, "LTP fmtmsg() test2 message, NOT an error", "This is correct output, no action needed", "LTP:msg:002"); close(fd); if (ret_val != 0) { fprintf(temp, "fmtmsg returned %d, expected 0\n", ret_val); local_flag = FAILED; } fp = fopen("fmtfile", "r"); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str3), fp); if (strcmp(str3, buf) != 0) { fprintf(temp, "Expected string: %s\n", str3); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } /* Read past spaces in output */ fread(&ch, sizeof(ch), 1, fp); while (isspace(ch)) fread(&ch, sizeof(ch), 1, fp); ungetc(ch, fp); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str4), fp); if (strcmp(str4, buf) != 0) { fprintf(temp, "Expected string: %s\n", str4); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } fclose(fp); remove("fmtfile"); blexit(); /*--------------------------------------------------------------*/ blenter(); /* Test result of writing to /dev/console */ ret_val = fmtmsg(MM_CONSOLE | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5, "LTP fmtmsg() test3 message, NOT an error", "This is correct output, no action needed", "LTP:msg:003"); if (ret_val != MM_OK) { fprintf(temp, "fmtmsg returned %d, expected MM_OK\n", ret_val); fprintf(temp, "failed to write to console\n\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ tst_exit(); }
/*--------------------------------------------------------------------*/ int main(int argc, char **argv) { /***** BEGINNING OF MAIN. *****/ int pid, npid; int nsig, exno, nexno, status; int ret_val = 0; int core; void chsig(); #ifdef UCLINUX tst_parse_opts(argc, argv, NULL, NULL); maybe_run_child(&do_child, "dd", &temp, &sig); #endif setup(); //tempdir(); /* move to new directory */ 12/20/2003 blenter(); exno = 1; if (sigset(SIGCHLD, chsig) == SIG_ERR) { fprintf(temp, "\tsigset failed, errno = %d\n", errno); fail_exit(); } for (sig = 1; sig < 14; sig++) { fflush(temp); chflag = 0; pid = FORK_OR_VFORK(); if (pid < 0) { forkfail(); } if (pid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "dd", temp, sig) < 0) { tst_brkm(TBROK, NULL, "self_exec FAILED - " "terminating test."); } #else do_child(); #endif } else { //fprintf(temp, "Testing signal %d\n", sig); while (!chflag) /* wait for child */ sleep(1); kill(pid, sig); /* child should ignroe this sig */ kill(pid, SIGCHLD); /* child should exit */ #ifdef BCS while ((npid = wait(&status)) != pid || (npid == -1 && errno == EINTR)) ; if (npid != pid) { fprintf(temp, "wait error: wait returned wrong pid\n"); ret_val = 1; } #else while ((npid = waitpid(pid, &status, 0)) != -1 || errno == EINTR) ; #endif /* nsig = status & 0177; core = status & 0200; nexno = (status & 0xff00) >> 8; */ /***** LTP Port *****/ nsig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif nexno = WIFEXITED(status); /***** ** ** *****/ /* nsig is the signal number returned by wait it should be 0, except when sig = 9 */ if ((sig == 9) && (nsig != sig)) { fprintf(temp, "wait error: unexpected signal" " returned when the signal sent was 9" " The status of the process is %d \n", status); ret_val = 1; } if ((sig != 9) && (nsig != 0)) { fprintf(temp, "wait error: unexpected signal " "returned, the status of the process is " "%d \n", status); ret_val = 1; } /* nexno is the exit number returned by wait it should be 1, except when sig = 9 */ if (sig == 9) if (nexno != 0) { fprintf(temp, "signal error: unexpected" " exit number returned when" " signal sent was 9, the status" " of the process is %d \n", status); ret_val = 1; } else; else if (nexno != 1) { fprintf(temp, "signal error: unexpected exit " "number returned,the status of the" " process is %d\n", status); ret_val = 1; } } } if (ret_val) local_flag = FAILED; /*--------------------------------------------------------------------*/ anyfail(); tst_exit(); } /******** END OF MAIN. ********/
void fail_exit(void) { local_flag = FAILED; anyfail(); }
/*ARGSUSED*/ int main(int argc, char *argv[]) { char *brk_max_addr, *hole_addr, *brk_start, *hole_start; size_t pagesize = (size_t)sysconf(_SC_PAGE_SIZE); time_t t; progname = argv[0]; (void)time(&t); // (void)printf("%s: Started %s", argv[0], ctime(&t)); if ((brk_start = sbrk(0)) == NEG1) { ERROR("initial sbrk failed"); anyfail(); } if ((u_long)brk_start % (u_long)pagesize) { if (sbrk(pagesize - ((u_long)brk_start % (u_long)pagesize)) == NEG1) { ERROR("couldn't round up brk to a page boundary"); anyfail(); } } /* The brk is now at the beginning of a page. */ if ((hole_addr = hole_start = sbrk(NUM_SEGS * 2 * pagesize)) == NEG1) { ERROR("couldn't brk large space for segments"); anyfail(); } if ((brk_max_addr = sbrk(0)) == NEG1) { ERROR("couldn't find top of brk"); anyfail(); } do_test((caddr_t)brk_max_addr, pagesize); /* now make holes and repeat test */ while (hole_addr + pagesize < brk_max_addr) { if (munmap(hole_addr, pagesize) == -1) { ERROR("failed to munmap odd hole in brk segment"); anyfail(); } hole_addr += 2 * pagesize; } if (brk_max_addr != sbrk(0)) { ERROR("do_test should leave the top of brk where it began"); anyfail(); } do_test((caddr_t)brk_max_addr, pagesize); /* Shrink brk */ if (sbrk(-NUM_SEGS * pagesize) == NEG1) { ERROR("couldn't brk back over holes"); anyfail(); } if ((brk_max_addr = sbrk(0)) == NEG1) { ERROR("couldn't find top of break again"); anyfail(); } /* sbrked over about half the holes */ hole_addr = hole_start + pagesize; /* munmap the other pages */ while (hole_addr + pagesize < brk_max_addr) { if (munmap(hole_addr, pagesize) == -1) { ERROR("failed to munmap even hole in brk segment"); anyfail(); } hole_addr += 2 * pagesize; } /* munmaped the rest of the brk except a little at the beginning */ if (brk(brk_start) == -1) { ERROR("failed to completely remove brk"); anyfail(); } if (sbrk(pagesize) == NEG1 || sbrk(-pagesize) == NEG1) { ERROR("failed to fiddle with brk at the end"); anyfail(); } /* Ask for a ridiculously large mmap region at a high address */ if (mmap((caddr_t)(1UL << (POINTER_SIZE - 1)) - pagesize, (size_t)((1UL << (POINTER_SIZE - 1)) - pagesize), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, 0, 0) != (caddr_t)-1) { ERROR("really large mmap didn't fail"); anyfail(); } if (errno != ENOMEM && errno != EINVAL) { ERROR("really large mmap didn't set errno = ENOMEM nor EINVAL"); anyfail(); } (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); ok_exit(); tst_exit(); }
/*--------------------------------------------------------------*/ int main(void) { setup(); /* temp file is now open */ npathdats = (sizeof(pathdat) / sizeof(pathdat[0])); ngoods = (sizeof(goodlist) / sizeof(goodlist[0])); nbads = (sizeof(badlist) / sizeof(badlist[0])); nmnem = (sizeof(mnem) / sizeof(mnem[0])); setup_path(); /*---------------- ENTER BLOCK 0 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall recursively descend the\n"); fprintf(temp, "directory hierarchy rooted in path until it has\n"); fprintf(temp, "traversed the whole tree, calling the function fn for\n"); fprintf(temp, "each object in the directory tree, and return 0.\n\n"); #endif test1A(); blexit(); /*--------------- EXIT BLOCK 0 ---------------------------------*/ /*---------------- ENTER BLOCK 1 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when flags contains FTW_PHYS shall\n"); fprintf(temp, "not traverse symbolic links.\n\n"); #endif test2A(); blexit(); /*--------------- EXIT BLOCK 1 ---------------------------------*/ /*---------------- ENTER BLOCK 2 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when flags does not contain FTW_PHYS\n"); fprintf(temp, "shall follow links instead of reporting them and shall\n"); fprintf(temp, "not report the same file twice.\n\n"); #endif test3A(); blexit(); /*--------------- EXIT BLOCK 2 ---------------------------------*/ /*---------------- ENTER BLOCK 3 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when flags contains FTW_DEPTH shall\n"); fprintf(temp, "report all files in a directory before reporting the\n"); fprintf(temp, "directory.\n\n"); #endif test4A(); blexit(); /*--------------- EXIT BLOCK 3 ---------------------------------*/ /*---------------- ENTER BLOCK 4 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when flags does not contain\n"); fprintf(temp, "FTW_DEPTH shall report a directory before reporting\n"); fprintf(temp, "the files in that directory.\n\n"); #endif test5A(); blexit(); /*--------------- EXIT BLOCK 4 ---------------------------------*/ /*---------------- ENTER BLOCK 5 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when flags contains FTW_CHDIR shall\n"); fprintf(temp, "change the current working directory to each directory\n"); fprintf(temp, "as it reports files in that directory.\n\n"); #endif test6A(); blexit(); /*--------------- EXIT BLOCK 5 ---------------------------------*/ /*---------------- ENTER BLOCK 6 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass the path-name of the\n"); fprintf(temp, "current object as the first argument of the function\n"); fprintf(temp, "fn.\n\n"); #endif test7A(); blexit(); /*--------------- EXIT BLOCK 6 ---------------------------------*/ /*---------------- ENTER BLOCK 7 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass a pointer to a stat\n"); fprintf(temp, "structure containing information about the current\n"); fprintf(temp, "object as the second argument to fn.\n\n"); #endif test8A(); blexit(); /*--------------- EXIT BLOCK 7 ---------------------------------*/ /*---------------- ENTER BLOCK 8 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_F as the third\n"); fprintf(temp, "argument of the function fn when the object is a file.\n\n"); #endif test9A(); blexit(); /*--------------- EXIT BLOCK 8 ---------------------------------*/ /*---------------- ENTER BLOCK 9 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_D as the third\n"); fprintf(temp, "argument of the function fn when the object is a\n"); fprintf(temp, "directory.\n\n"); #endif test10A(); blexit(); /*--------------- EXIT BLOCK 9 ---------------------------------*/ /*---------------- ENTER BLOCK 10 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_DP as the third\n"); fprintf(temp, "argument of the function fn when the object is a\n"); fprintf(temp, "directory and subdirectories have been visited.\n\n"); #endif test11A(); blexit(); /*--------------- EXIT BLOCK 10 ---------------------------------*/ /*---------------- ENTER BLOCK 11 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_SL as the third\n"); fprintf(temp, "argument of the function fn when the object is a\n"); fprintf(temp, "symbolic link.\n\n"); #endif test12A(); blexit(); /*--------------- EXIT BLOCK 11 ---------------------------------*/ /*---------------- ENTER BLOCK 12 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_SLN as the third\n"); fprintf(temp, "argument of the function fn when the object is a\n"); fprintf(temp, "symbolic link that does not name an existing file.\n\n"); #endif test13A(); blexit(); /*--------------- EXIT BLOCK 12 ---------------------------------*/ /*---------------- ENTER BLOCK 13 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_DNR as the third\n"); fprintf(temp, "argument of the function fn when the object is a\n"); fprintf(temp, "directory that cannot be read.\n\n"); #endif test14A(); blexit(); /*--------------- EXIT BLOCK 13 ---------------------------------*/ /*---------------- ENTER BLOCK 14 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_NS as the third\n"); fprintf(temp, "argument of the function fn when stat() failed on the\n"); fprintf(temp, "object because of lack of appropriate permission.\n\n"); #endif test15A(); blexit(); /*--------------- EXIT BLOCK 14 ---------------------------------*/ /*---------------- ENTER BLOCK 15 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass a structure which\n"); fprintf(temp, "contains the offset into the pathname of the object\n"); fprintf(temp, "and the depth relative to the root of the walk\n"); fprintf(temp, "starting from 0 as the fourth argument of the function\n"); fprintf(temp, "fn.\n\n"); #endif test16A(); blexit(); /*--------------- EXIT BLOCK 15 ---------------------------------*/ /*---------------- ENTER BLOCK 16 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_SL as the third\n"); fprintf(temp, "argument to the function fn if and only if the\n"); fprintf(temp, "FTW_PHYS flag is included in flags.\n\n"); #endif test17A(); blexit(); /*--------------- EXIT BLOCK 16 ---------------------------------*/ /*---------------- ENTER BLOCK 17 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall pass FTW_SLN as the third\n"); fprintf(temp, "argument to the function fn if and only if the\n"); fprintf(temp, "FTW_PHYS flag is not included in flags.\n\n"); #endif test18A(); blexit(); /*--------------- EXIT BLOCK 17 ---------------------------------*/ /*---------------- ENTER BLOCK 18 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "On a call to int nftw(const char *path, int\n"); fprintf(temp, "(*fn)(const char *, const struct stat *, int, struct\n"); fprintf(temp, "FTW *), int depth, int flags) when the third argument\n"); fprintf(temp, "passed to the function fn is FTW_DNR then the\n"); fprintf(temp, "descendants of the directory shall not be processed.\n\n"); #endif test19A(); blexit(); /*--------------- EXIT BLOCK 18 ---------------------------------*/ /*---------------- ENTER BLOCK 19 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall close any file descriptors or\n"); fprintf(temp, "directory streams used to traverse the directory tree.\n\n"); #endif test20A(); blexit(); /*--------------- EXIT BLOCK 19 ---------------------------------*/ /*---------------- ENTER BLOCK 20 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "On a call to int nftw(const char *path, int\n"); fprintf(temp, "(*fn)(const char *, const struct stat *, int, struct\n"); fprintf(temp, "FTW *), int depth, int flags) depth shall be the\n"); fprintf(temp, "maximum number of file descriptors used for the search.\n\n"); #endif test21A(); blexit(); /*--------------- EXIT BLOCK 20 ---------------------------------*/ /*---------------- ENTER BLOCK 21 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) shall use at most one file\n"); fprintf(temp, "descriptor for each directory level.\n\n"); #endif test22A(); blexit(); /*--------------- EXIT BLOCK 21 ---------------------------------*/ /*---------------- ENTER BLOCK 22 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); fprintf(temp, "depth, int flags) when the function fn returns a\n"); fprintf(temp, "non-zero value shall stop and return the value\n"); fprintf(temp, "returned by fn.\n\n"); #endif test23A(); blexit(); /*--------------- EXIT BLOCK 22 ---------------------------------*/ /*---------------- ENTER BLOCK 23 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "ENAMETOOLONG in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when the length of path exceeds PATH_MAX.\n\n"); #endif test24A(); blexit(); /*--------------- EXIT BLOCK 23 ---------------------------------*/ /*---------------- ENTER BLOCK 24 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "ENAMETOOLONG in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when a component of path exceeds NAME_MAX.\n\n"); #endif test25A(); blexit(); /*--------------- EXIT BLOCK 24 ---------------------------------*/ /*---------------- ENTER BLOCK 25 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "ENOENT in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when path points to a file which does not exist.\n\n"); #endif test26A(); blexit(); /*--------------- EXIT BLOCK 25 ---------------------------------*/ /*---------------- ENTER BLOCK 26 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "ENOENT in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when path points to an empty string.\n\n"); #endif test27A(); blexit(); /*--------------- EXIT BLOCK 26 ---------------------------------*/ /*---------------- ENTER BLOCK 27 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "ENOTDIR in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when path is not a directory.\n\n"); #endif test28A(); blexit(); /*--------------- EXIT BLOCK 27 ---------------------------------*/ /*---------------- ENTER BLOCK 28 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "EACCES in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when search permission is denied for any\n"); fprintf(temp, "component of path.\n\n"); #endif test29A(); blexit(); /*--------------- EXIT BLOCK 28 ---------------------------------*/ /*---------------- ENTER BLOCK 29 --------------------------------*/ blenter(); #ifdef DEBUG fprintf(temp, "EACCES in errno and return -1 on a call to int\n"); fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); fprintf(temp, "flags) when read permission is denied for path.\n\n"); #endif test30A(); blexit(); /*--------------- EXIT BLOCK 29 ---------------------------------*/ cleanup_function(); anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ tst_exit(); /*--------------------------------------------------------------*/ }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register int i; int v1, v2; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); #if defined(SYS_getpid) for (i = 0; i < ITER; i++) { v1 = getpid(); v2 = syscall(SYS_getpid); if (v1 != v2) { fprintf(temp, "\tgetpid syscall failed.\n"); fprintf(temp, "\t iteration %d\n", i); local_flag = FAILED; break; } } #else fprintf(temp, "\tgetpid syscall failed.\n"); fprintf(temp, "\tSYS_getpid not defined\n"); local_flag = FAILED; #endif blexit(); /*--------------------------------------------------------------*/ blenter(); #if defined(SYS_getuid) || defined(SYS_getuid32) for (i = 0; i < ITER; i++) { v1 = getuid(); #if defined(SYS_getuid) v2 = syscall(SYS_getuid); #else v2 = syscall(SYS_getuid32); #endif if (v1 != v2) { fprintf(temp, "\tgetuid syscall failed.\n"); fprintf(temp, "\t iteration %d\n", i); local_flag = FAILED; break; } } #else fprintf(temp, "\tgetuid syscall failed.\n"); fprintf(temp, "\tSYS_getuid and SYS_getuid32 not defined\n"); local_flag = FAILED; #endif blexit(); /*--------------------------------------------------------------*/ blenter(); #if defined(SYS_getgid) || defined(SYS_getgid32) for (i = 0; i < ITER; i++) { v1 = getgid(); #if defined(SYS_getgid) v2 = syscall(SYS_getgid); #else v2 = syscall(SYS_getgid32); #endif if (v1 != v2) { fprintf(temp, "\tgetgid syscall failed.\n"); fprintf(temp, "\t iteration %d\n", i); local_flag = FAILED; break; } } #else fprintf(temp, "\tgetgid syscall failed.\n"); fprintf(temp, "\tSYS_getgid and SYS_getgid32 not defined\n"); local_flag = FAILED; #endif blexit(); /*--------------------------------------------------------------*/ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ }
int main(int argc, char *argv[]) { char *p, *q; tst_parse_opts(argc, argv, NULL, NULL); setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[100]; fill(p); q = &buf[800]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[-1] || p[LEN]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[-1] || q[LEN]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[800]; fill(p); q = &buf[100]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[-1] || p[LEN]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[-1] || q[LEN]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); anyfail(); tst_exit(); }
int main(int argc, char *argv[]) { caddr_t mmapaddr; size_t pagesize = sysconf(_SC_PAGE_SIZE); time_t t; int i; struct sigaction sa; tst_tmpdir(); if (!argc) { (void)fprintf(stderr, "argc == 0\n"); return 1; } if (argc != 1) { (void)fprintf(stderr, "usage: %s\n", argv[0]); return 1; } (void)time(&t); if ((fd = mkstemp(tmpname)) == -1) { ERROR("mkstemp failed"); anyfail(); } sa.sa_handler = cleanup; sa.sa_flags = 0; if (sigemptyset(&sa.sa_mask)) { ERROR("sigemptyset failed"); anyfail(); } CATCH_SIG(SIGINT); CATCH_SIG(SIGQUIT); CATCH_SIG(SIGTERM); if (sbrk(2*pagesize - ((ulong)sbrk(0) & (pagesize-1))) == (char *)-1) { CLEANERROR("couldn't round up brk"); anyfail(); } if ((mmapaddr = sbrk(0)) == (caddr_t)-1) { CLEANERROR("couldn't find top of brk"); anyfail(); } /* Write a page of garbage into the file, so we can mmap it without * asking for PROT_WRITE. */ for (i = pagesize; i; i--) *(mmapaddr-i) = 'a'; if (write(fd, (char *)mmapaddr-pagesize, pagesize) != pagesize) { CLEANERROR("write failed"); anyfail(); } if (mmap(mmapaddr, pagesize, PROT_NONE, MAP_FIXED|MAP_PRIVATE|MAP_FILE, fd, 0) != mmapaddr) { CLEANERROR("couldn't mmap file"); anyfail(); } /* * Since the file is mmapped, mmreg_new and uiomove_phys handle all * I/O */ if (lseek(fd, 0, SEEK_SET) != 0) { CLEANERROR("lseek failed"); anyfail(); } if (read(fd, (char *)mmapaddr, pagesize) != -1) { CLEANERROR("read succeded"); anyfail(); } if (errno != EFAULT) { CLEANERROR("read didn't set errno = EFAULT"); anyfail(); } if (write(fd, (char *)mmapaddr, pagesize) != -1) { CLEANERROR("write succeded"); anyfail(); } if (errno != EFAULT) { CLEANERROR("write didn't set errno = EFAULT"); anyfail(); } if (close(fd) == -1) { CLEANERROR("close failed"); anyfail(); } if (munmap(mmapaddr, pagesize) == -1) { CLEANERROR("munmap failed"); anyfail(); } if (unlink(tmpname) == -1) { ERROR("unlink failed"); anyfail(); } (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); ok_exit(); /* LTP Port */ tst_exit(); }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { char *p, *q; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[100]; q = &buf[800]; fill(p); fill(q); if (memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp fails - should have succeeded.\n"); local_flag = FAILED; } p[LEN - 1] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; p[LEN - 1] = 'a'; p[0] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; p[0] = 'a'; q[LEN - 1] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; q[LEN - 1] = 'a'; q[0] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; q[0] = 'a'; if (memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp fails - should have succeeded.\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[800]; q = &buf[100]; fill(p); fill(q); if (memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp fails - should have succeeded.\n"); local_flag = FAILED; } p[LEN - 1] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; p[LEN - 1] = 'a'; p[0] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; p[0] = 'a'; q[LEN - 1] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; q[LEN - 1] = 'a'; q[0] = 0; if (!memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp succeeded - should have failed.\n"); local_flag = FAILED; }; q[0] = 'a'; if (memcmp(p, q, LEN)) { fprintf(temp, "\tmemcmp fails - should have succeeded.\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ tst_exit(); }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register int i; int status, count, child, kidpid; int core, sig, ex; char *msg; if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child, ""); #endif setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ for (i = 0; i < ITER; i++) { if ((kidpid = FORK_OR_VFORK()) == 0) { #ifdef UCLINUX if (self_exec(argv[0], "")) { terror("self_exec failed (may be OK if under stress)"); if (instress()) ok_exit(); forkfail(); } #else do_child(); #endif } if (kidpid < 0) { terror("Fork failed (may be OK if under stress)"); if (instress()) ok_exit(); forkfail(); } count = 0; while ((child = wait(&status)) > 0) { count++; } if (count != 1) { fprintf(temp, "\twrong # children waited on.\n"); fprintf(temp, "\tgot %d, expected %d\n", count, 1); fail_exit(); } /* sig = status & 0177; core = status & 0200; ex = (status & 0xFF00) >> 8; */ /***** LTP Port *****/ sig = WTERMSIG(status); #ifdef WCOREDUMP core = WCOREDUMP(status); #endif ex = WIFEXITED(status); /**************/ if (!core) { fprintf(temp, "\tChild did not return core bit set!\n"); fprintf(temp, "\t iteration %d, exit stat = 0x%x\n", i, status); fprintf(temp, "\tCore = %d, sig = %d, ex = %d\n", core, sig, ex); local_flag = FAILED; } if (sig != SIGIOT) { fprintf(temp, "\tChild did not exit with SIGIOT (%d)\n", SIGIOT); fprintf(temp, "\t iteration %d, exit stat = 0x%x\n", i, status); fprintf(temp, "\tCore = %d, sig = %d, ex = %d\n", core, sig, ex); local_flag = FAILED; } if (local_flag == FAILED) break; } /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ unlink("core"); anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ return 0; }
/*--------------------------------------------------------------------*/ 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 argc, char **argv) { char *progname; int status; int count = 0; int i, c; char *fname = "test.mmap-corruption"; char *mem; unsigned long alarmtime = 0; struct sigaction sa; void finish(int sig); progname = *argv; while ((c = getopt(argc, argv, ":h:m:s:")) != -1) { switch (c) { case 'h': alarmtime += atoi(optarg) * 60 * 60; break; case 'm': alarmtime += atoi(optarg) * 60; break; case 's': alarmtime += atoi(optarg); break; default: (void)fprintf(stderr, "usage: %s %s\n", progname, usage); anyfail(); } } /* * 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"); exit(1); } if (sigaction(SIGINT, &sa, 0) == -1) { perror("sigaction error SIGINT"); exit(1); } if (alarmtime) { if (sigaction(SIGALRM, &sa, 0) == -1) { perror("sigaction error"); exit(1); } (void)alarm(alarmtime); printf("mmap-corruption will run for=> %ld, seconds\n",alarmtime); } else { //Run for 5 secs only if (sigaction(SIGALRM, &sa, 0) == -1) { perror("sigaction error"); exit(1); } (void)alarm(5); printf("mmap-corruption will run for=> 5, seconds\n"); } /* If we get a SIGQUIT or SIGTERM, clean up and exit immediately. */ sa.sa_handler = finish; if (sigaction(SIGQUIT, &sa, 0) == -1) { perror("sigaction error SIGQUIT"); exit(1); } if (sigaction(SIGTERM, &sa, 0) == -1) { perror("sigaction error SIGTERM"); exit(1); } tst_tmpdir(); while (1) { unlink(fname); int fd = open(fname, O_CREAT | O_EXCL | O_RDWR, 0600); status = ftruncate(fd, kMemSize); mem = mmap(0, kMemSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); // Fill the memory with 1s. memset(mem, 1, kMemSize); for (i = 0; i < kMemSize; i++) { int byte_good = mem[i] != 0; if (!byte_good && ((i % kPageSize) == 0)) { //printf("%d ", i / kPageSize); count++; } } munmap(mem, kMemSize); close(fd); unlink(fname); if (count > 0) { printf("Running %d bad page\n", count); return 1; } count=0; } return 0; }
int main(int argc, char *argv[]) { char *progname; unsigned c; extern char *optarg; unsigned nprocs = 0; unsigned procno; pid_t *pidarray=NULL; pid_t pid; uchar_t *buf, *ptr; unsigned int seed; int alarmtime = 0; struct sigaction sa; unsigned i, j; uchar_t data; int no_prob = 0; time_t t; int wait_stat; progname = *argv; pagesize = sysconf(_SC_PAGE_SIZE); if (argc < 2) { (void)fprintf(stderr, "usage: %s %s\n", progname, usage); anyfail(); } while ((c = getopt(argc, argv, "mdrp:t:s:")) != -1) { switch (c) { case 'd': debug = 1; break; case 't': alarmtime = atoi(optarg) * 60; break; case 'p': nprocs = atoi(optarg); break; case 'm': dosync = 1; break; case 's': mapsize = atoi(optarg); if (mapsize < 0) { (void)fprintf(stderr, "error: negative " "mapsize\n"); anyfail(); } break; case 'r': randloops = 1; break; default: (void)fprintf(stderr, "usage: %s %s\n", progname, usage); anyfail(); } } /* nprocs is unsigned */ 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 seed = initrand(); pattern = seed & 0xff; if (debug) { (void)printf("%s mapsize %d bytes, pattern %d\n", progname, mapsize, pattern); if (alarmtime) (void)printf("running for %d minutes\n", alarmtime/60); else (void)printf("running with no time limit\n"); } if ((mapaddr = mmap(0, mapsize, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, 0, 0)) == (caddr_t)-1) { perror("mmap error"); anyfail(); } if ((buf = (uchar_t *)malloc(pagesize)) == NULL || (pidarray = (pid_t *)malloc(nprocs*sizeof(pid_t))) == NULL) { perror("malloc error"); anyfail(); } for (i = 0; i < nprocs; i++) *(pidarray+i) = 0; /* * Initialize page compare buffer, then initialize map. */ for (i = 0, data = 0; i < pagesize; i++) { *(buf+i) = (data + pattern) & 0xff; if (++data == nprocs) data = 0; } mappages = roundup(mapsize, pagesize)/pagesize; ptr = (uchar_t *)mapaddr; for (i = 0; i < mappages; i++) { for (j = 0; j < pagesize; j++) *ptr++ = *(buf+j); } /* * Fork off mmap children. */ for (procno = 0; procno < nprocs; procno++) { switch (pid = fork()) { case -1: perror("fork error"); goto cleanup; case 0: child_mapper(procno, nprocs); exit(0); default: pidarray[procno] = pid; } } /* * Plan for death by signal. User may have specified * a time limit, in which set an alarm and catch SIGALRM. * Also catch and cleanup with SIGINT. */ sa.sa_handler = finish; sa.sa_flags = 0; if (sigemptyset(&sa.sa_mask)) { perror("sigemptyset error"); goto cleanup; } if (sigaction(SIGINT, &sa, 0) == -1) { perror("sigaction error"); goto cleanup; } if (alarmtime) { if (sigaction(SIGALRM, &sa, 0) == -1) { perror("sigaction error"); goto cleanup; } (void)alarm(alarmtime); } /* * Now wait for children and refork them as needed. */ while (!finished) { do { pid = wait(&wait_stat); } while (pid == -1 && errno == EINTR); /* * 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) { (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(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 map for sanity, then kill all * the children and done!. */ if (sighold(SIGALRM)) { perror("sighold error"); goto cleanup; } (void)alarm(0); no_prob = 1; cleanup: for (i = 0; i < nprocs; i++) (void)kill(pidarray[i], SIGKILL); /* failure? oh well. */ while (wait(&wait_stat) != -1 || errno != ECHILD) continue; if (no_prob) { /* only check file if no errors */ if (!mapokay(buf)) { (void)fprintf(stderr, "map data incorrect!\n"); anyfail(); } else (void)printf("map data okay\n"); } (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP POrt ok_exit(); return(0); }
int main(int argc, char *argv[]) { char *buf; size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE); caddr_t mmapaddr; time_t t; int i, j; struct sigaction sa; #ifdef LARGE_FILE off64_t startoffset; off64_t seekoff; off64_t mapoff; #else /* LARGE_FILE */ off_t startoffset; off_t seekoff; off_t mapoff; #endif /* LARGE_FILE */ if (argc < 2 || argc > 3) { (void)fprintf(stderr, "Usage: %s filename startoffset\n", argv[0]); return 1; } filename = argv[1]; if (argc >= 3) { #ifdef LARGE_FILE startoffset = atoll(argv[2]); #else /* LARGE_FILE */ startoffset = atoi(argv[2]); #endif /* LARGE_FILE */ } else startoffset = pagesize; if (startoffset % pagesize != 0) { fprintf(stderr, "pagesize=%ld\n", (long)pagesize); fprintf(stderr, "startoffset must be a pagesize multiple\n"); anyfail(); //LTP Port } (void)time(&t); // (void)printf("%s: Started %s", argv[0], ctime(&t)); if ((buf = sbrk(6 * pagesize)) == (char *)-1) { ERROR("couldn't allocate buf"); anyfail(); //LTP Port } if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { ERROR("couldn't round up brk"); anyfail(); //LTP Port } if ((mmapaddr = (caddr_t) sbrk(0)) == (caddr_t) - 1) { ERROR("couldn't find top of brk"); anyfail(); //LTP Port } sa.sa_handler = cleanup; sa.sa_flags = 0; if (sigemptyset(&sa.sa_mask)) { ERROR("sigemptyset failed"); anyfail(); //LTP Port } CATCH_SIG(SIGINT); CATCH_SIG(SIGQUIT); CATCH_SIG(SIGTERM); tst_tmpdir(); #ifdef LARGE_FILE if ((rofd = open64(filename, O_RDONLY | O_CREAT, 0777)) == -1) { #else /* LARGE_FILE */ if ((rofd = open(filename, O_RDONLY | O_CREAT, 0777)) == -1) { #endif /* LARGE_FILE */ ERROR("read only open failed"); anyfail(); //LTP Port } #ifdef LARGE_FILE if ((rwfd = open64(filename, O_RDWR)) == -1) { #else /* LARGE_FILE */ if ((rwfd = open(filename, O_RDWR)) == -1) { #endif /* LARGE_FILE */ (void)close(rofd); (void)unlink(filename); ERROR("read/write open failed"); anyfail(); //LTP Port } #ifdef LARGE_FILE seekoff = startoffset + (off64_t) 64 *(off64_t) 6 *(off64_t) pagesize; if (lseek64(rwfd, seekoff, SEEK_SET) != seekoff) { #else /* LARGE_FILE */ seekoff = startoffset + (off_t) 64 *(off_t) 6 *(off_t) pagesize; if (lseek(rwfd, seekoff, SEEK_SET) != seekoff) { #endif /* LARGE_FILE */ CLEANERROR("first lseek failed"); anyfail(); //LTP Port } i = 0; while (i < pagesize && write(rwfd, "b", 1) == 1) i++; if (i != pagesize) { CLEANERROR("write to extend file failed"); anyfail(); //LTP Port } /* The file is now really big, and empty. * Assuming disk blocks are 8k, and logical pages are 4k, there are * two maps per page. In order to test mapping at the beginning and * ends of the block, mapping the whole block, or none of the block * with different mappings on preceding and following blocks, each * 3 blocks with 6 pages can be thought of as a binary number from 0 to * 64 with a bit set for mapped or cleared for unmapped. This number * is represented by i. The value j is used to look at the bits of i * and decided to map the page or not. * NOTE: None of the above assumptions are critical. */ for (i = 0; i < 64; i++) { for (j = 0; j < 6; j++) { if (i & (1 << j)) { #ifdef LARGE_FILE mapoff = startoffset + (off64_t) pagesize *(off64_t) (6 + i + j); if (mmap64(mmapaddr + pagesize * (6 * i + j), pagesize, PROT_READ, MAP_FILE | MAP_PRIVATE | MAP_FIXED, rofd, mapoff) == (caddr_t) - 1) { #else /* LARGE_FILE */ mapoff = startoffset + (off_t) pagesize *(off_t) (6 + i + j); if (mmap(mmapaddr + pagesize * (6 * i + j), pagesize, PROT_READ, MAP_FILE | MAP_PRIVATE | MAP_FIXED, rofd, mapoff) == (caddr_t) - 1) { #endif /* LARGE_FILE */ CLEANERROR("mmap failed"); anyfail(); //LTP Port } } } } /* done mapping */ for (i = 0; i < 6 * pagesize; i++) buf[i] = 'a'; /* write out 6 pages of stuff into each of the 64 six page sections */ #ifdef LARGE_FILE if (lseek64(rwfd, startoffset, SEEK_SET) != startoffset) { #else /* LARGE_FILE */ if (lseek(rwfd, startoffset, SEEK_SET) != startoffset) { #endif /* LARGE_FILE */ CLEANERROR("second lseek failed"); anyfail(); //LTP Port } for (i = 0; i < 64; i++) { if (write(rwfd, buf, 6 * pagesize) != 6 * pagesize) { CLEANERROR("write failed"); anyfail(); //LTP Port } } /* Just finished scribbling all over interwoven mmapped and unmapped * regions. */ for (i = 0; i < 64; i++) { for (j = 0; j < 6; j++) { /* if mmaped && not updated */ if ((i & (1 << j)) && *(mmapaddr + pagesize * (6 * i + j)) != 'a') { CLEANERROR("'a' missing from mmap"); (void)fprintf(stderr, "i=%d\nj=%d\n" "val=0x%x\n", i, j, (int)(* (mmapaddr + pagesize * (6 * i + j)))); anyfail(); //LTP Port } } } /* Just checked to see that each mmapped page at least had an 'a' at * the beginning. */ CLEAN; (void)time(&t); // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port (local_flag == FAILED) ? tst_resm(TFAIL, "Test failed\n") : tst_resm(TPASS, "Test passed\n"); //LTP Port tst_rmdir(); tst_exit(); //LTP Port tst_exit(); } /***** LTP Port *****/ int anyfail(void) { tst_brkm(TFAIL, tst_rmdir, "Test failed\n"); }
int main() { char root[16]; //as pids can get much longer int gen_ret_val, ch_ret_val, level; int ret_val; int generate(), check(); char path_list_string[PATH_STRING_LENGTH + 1]; int status; int len; int term(); slash[0] = '/'; slash[1] = '\0'; strcpy(path_string, "inode"); sprintf(root, "A%d", getpid()); strcat(path_string, root); strcpy(rm_string, "rm -rf "); strcat(rm_string, path_string); setup(); if (signal(SIGTERM, (void (*)())term) == SIG_ERR) { fprintf(temp, "\tSIGTERM signal set failed!, errno=%d\n", errno); fail_exit(); } blenter(); /********************************/ /* */ /* make the root directory for */ /* the tree */ /* */ /********************************/ ret_val = mkdir(path_string, DIRECTORY_MODE); if (ret_val == -1) { perror("mkdir error"); fprintf(temp, "\tcreating directory '%s'\n", path_string); fprintf(temp, "\t\n%s Impossible to create directory %s\n", root, path_string); fail_exit(); } #ifdef PRINT printf("\n%s\n", path_string); #endif /****************************************/ /* */ /* create the "path_list" file, in */ /* which the list of generated paths */ /* will be stored so that they later */ /* may be checked */ /* */ /****************************************/ strcpy(path_list_string, path_string); strcat(path_list_string, slash); strcat(path_list_string, "path_list"); list_id = creat(path_list_string, FILE_MODE); if (list_id == -1) { fprintf(temp, "\t\n%s The path_list file cannot be created, errno=%d \n", root, errno); fail_exit(); } /****************************************/ /* */ /* and store its name in path_list */ /* */ /****************************************/ strcpy(write_string, path_string); len = strlen(write_string); write_string[len++] = 'D'; write_string[len] = '\0'; escrivez(write_string); /****************************************/ /* */ /* generate the directory-file tree */ /* */ /****************************************/ level = 0; #ifdef PRINT printf("\n\t%s\n\n", "GENERATING:"); #endif gen_ret_val = generate(path_string, level); if (gen_ret_val) { fprintf(temp, "Failure occured in generate routine, return value %d\n", gen_ret_val); local_flag = FAILED; } blexit(); blenter(); close(list_id); list_id = open(path_list_string, READ); if (list_id == -1) { fprintf(temp, "\t\n%s The path_list file cannot be opened for reading, errno=%d\n", root, errno); fail_exit(); } list_stream = fdopen(list_id, "r"); /****************************************/ /* */ /* check the directory-file tree */ /* for correctness */ /* */ /****************************************/ #ifdef PRINT printf("\n\t%s\n\n", "CHECKING:"); #endif ch_ret_val = check(); if (ch_ret_val) { fprintf(temp, "Failure occured in check routine, return value %d\n", ch_ret_val); local_flag = FAILED; } status = fclose(list_stream); if (status != 0) { fprintf(temp, "Failed to close list_stream: ret=%d errno=%d (%s)\n", status, errno, strerror(errno)); local_flag = FAILED; } blexit(); /* * Now fork and exec a system call to remove the directory. */ #ifdef DEBUG fprintf(temp, "\nClean up:\trm string = %s\n", rm_string); #endif fflush(stdout); fflush(temp); status = system(rm_string); if (status) { fprintf(temp, "Caution-``%s'' may have failed\n", rm_string); fprintf(temp, "rm command exit status = %d\n", status); } /****************************************/ /* */ /* .....and exit main */ /* */ /****************************************/ anyfail(); /***** NOT REACHED ******/ tst_exit(); }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { char *p, *q; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[100]; fill(p); q = &buf[800]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[-1] || p[LEN]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[-1] || q[LEN]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[800]; fill(p); q = &buf[100]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[-1] || p[LEN]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[-1] || q[LEN]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[800]; fill(p); q = &buf[850]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[-1]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[LEN]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); clearit(); p = &buf[850]; fill(p); q = &buf[800]; memcpy(q, p, LEN); if (checkit(q)) { fprintf(temp, "\tcopy failed - missed data\n"); local_flag = FAILED; } if (p[LEN]) { fprintf(temp, "\tcopy failed - 'to' bounds\n"); local_flag = FAILED; } if (q[-1]) { fprintf(temp, "\tcopy failed - 'from' bounds\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ tst_exit(); }
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); }