/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register long long i; register int j, k, l, m; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); i = llabs(MININT) + (long long)MININT; if (i != 0) { fprintf(temp, "abs of minimum integer failed."); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); i = llabs(0); if (i != 0) { fprintf(temp, "abs(0) failed, returned %lld\n", i); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); for (m = 1; m >= 0; m <<= 1) { j = ~m; k = j + 1; l = abs(k); if (l != m) local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ 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[]) { 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(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, j; double r1, r2, x; char buf[100]; setup(); /* temp file is now open */ pi = 4.0 * atan(1.0); /*--------------------------------------------------------------*/ blenter(); for (i = 0; i < 30; i++) for (j = 0; j < 30; j++) { sprintf(buf, "%*.*f", i, j, pi); if (checkbuf(buf, i, j)) { fprintf(temp, "output conversion incorrect."); fprintf(temp, "%*.*f = '%s'", i, j, pi, buf); local_flag = FAILED; } r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } x = fabs(r1 - r2); if (x > ERR) { fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\terr value is %f\n", x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ blenter(); x = 1.0 - exp(-100.0); /* 1.0 - very small number */ sprintf(buf, "%f", x); r1 = atof(buf); if (r1 != 1.0) { fprintf(temp, "\tsprintf small # failed\n"); fprintf(temp, "\t printed '%s', expected 1.0\n", buf); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); for (i = 1; i < 200; i++) { x = 100.0 / (double)i; sprintf(buf, "%f", x); r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } /* * Order subtraction to produce a positive number. * Then subtrace "fudge" factor which should give us * a negative number, as the result fo subtraction should * always be smaller than the fudge factor. */ if (r1 > r2) x = r1 - r2 - 1e-10; else x = r2 - r1 - 1e-10; if (x > 0.0) { fprintf(temp, "\tx = %.15f = %e\n", x, x); fprintf(temp, "\titeration %d\n", i); fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\tcompare fails, %.15f vs %.15f\n", r1, r2); fprintf(temp, "\tbuf = '%s'\n", buf); x = r1 - r2; if (x == 0.0) fprintf(temp, "\tx == 0.0\n"); else fprintf(temp, "\tx != 0.0\n"); fprintf(temp, "\tx = %.15f = %e\n", x, x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ blenter(); for (i = -1; i > -200; i--) { x = 100.0 / (double)i; sprintf(buf, "%f", x); r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } /* * Same ordering of subtraction as above. */ if (r1 > r2) x = r1 - r2 - 1e-10; else x = r2 - r1 - 1e-10; if (x > 0.0) { fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\tcompare fails, %.15f vs %.15f\n", r1, r2); x = r1 - r2; if (x == 0.0) fprintf(temp, "\tx == 0.0)\n"); else fprintf(temp, "\tx != 0.0\n"); fprintf(temp, "\tx = %.15f = %e\n", x, x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ 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 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!! */ }
void fail_exit(void) { local_flag = FAILED; blexit(); anyfail(); }
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; 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(); }