int test_nr;
{
char buf[64];
+ int i;
common_test_nr = test_nr;
printf("Test %2d ", test_nr);
e(6666);
quit();
}
+
+ for (i = 3; i < OPEN_MAX; ++i) {
+ /* Close all files except stdin, stdout, and stderr */
+ (void) close(i);
+ }
}
int does_fs_truncate(void)
_VOLATILE int glov, gct;
int errct;
int subtest;
+#include "common.c"
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void test1a, (void));
_PROTOTYPE(void parent1, (int childpid));
_PROTOTYPE(void func, (int s));
_PROTOTYPE(void child1, (void));
-_PROTOTYPE(void e, (int n));
-_PROTOTYPE(void quit, (void));
int main(argc, argv)
int argc;
{
int i, m = 0xFFFF;
- sync();
+ start(1);
if (argc == 2) m = atoi(argv[1]);
- printf("Test 1 ");
- fflush(stdout); /* have to flush for child's benefit */
-
- system("rm -rf DIR_01; mkdir DIR_01");
- chdir("DIR_01");
-
for (i = 0; i < ITERATIONS; i++) {
if (m & 00001) test1a();
if (m & 00002) test1b();
exit(gct);
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g",
"t10h", "t10i", "t10j"};
-int errct;
long prog[300];
int psize;
+#define MAX_ERROR 2
+#include "common.c"
+
_PROTOTYPE(int main, (void));
_PROTOTYPE(void spawn, (int n));
_PROTOTYPE(void mkfiles, (void));
{
int i, n, pid, r;
- printf("Test 10 ");
- fflush(stdout); /* have to flush for child's benefit */
-
- system("rm -rf DIR_10; mkdir DIR_10; cp t10a DIR_10");
- chdir("DIR_10");
-
+ start(10);
+ system("cp ../t10a .");
pid = getpid();
/* Create files t10b ... t10h */
unlink("t10j");
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
char *envp[3] = {"spring", "summer", 0};
char *passwd_file = "/etc/passwd";
+#include "common.c"
+
_PROTOTYPE(int main, (int argc, char *argv[]));
_PROTOTYPE(void test11a, (void));
_PROTOTYPE(void test11b, (void));
_PROTOTYPE(void test11c, (void));
_PROTOTYPE(void test11d, (void));
-_PROTOTYPE(void e, (int n));
int main(argc, argv)
int argc;
if (argc == 2) m = atoi(argv[1]);
- printf("Test 11 ");
- fflush(stdout); /* have to flush for child's benefit */
+ start(11);
+
+ system("cp ../t11a .");
+ system("cp ../t11b .");
if (geteuid() != 0) {
printf("must be setuid root; test aborted\n");
exit(1);
}
-/*
- system("rm -rf DIR_11; mkdir DIR_11");
- chdir("DIR_11");
-*/
-
for (i = 0; i < ITERATIONS; i++) {
if (m & 0001) test11a();
if (m & 0002) test11b();
if (m & 0004) test11c();
if (m & 0010) test11d();
}
- if (errct == 0)
- printf("ok\n");
- else
- printf(" %d errors\n", errct);
-
-/*
- chdir("..");
- system("rm -rf DIR_11");
-*/
- return(0);
+ quit();
+ return(-1);
}
void test11a()
if (unlink("T11.1") != 0) e(7);
}
-void e(n)
-int n;
-{
- int err_num = errno; /* save errno in case printf clobbers it */
-
- printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
- errno = err_num; /* restore errno, just in case */
- perror("");
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- exit(1);
- }
-}
#include <stdio.h>
#define NUM_TIMES 1000
+#define MAX_ERROR 2
-int errct = 0;
+#include "common.c"
_PROTOTYPE(int main, (void));
-_PROTOTYPE(void quit, (void));
int main()
{
register int i;
int k;
- printf("Test 12 ");
- fflush(stdout); /* have to flush for child's benefit */
-
- system("rm -rf DIR_12; mkdir DIR_12");
- chdir("DIR_12");
+ start(12);
for (i = 0; i < NUM_TIMES; i++) switch (fork()) {
case 0: exit(1); break;
return(-1); /* impossible */
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define BLOCK_SIZE 1000
#define NUM_BLOCKS 1000
-int errct = 0;
char buffer[BLOCK_SIZE];
+#define MAX_ERROR 2
+#include "common.c"
+
_PROTOTYPE(int main, (void));
_PROTOTYPE(void quit, (void));
{
int stat_loc, pipefd[2];
register int i;
- pipe(pipefd);
-
- printf("Test 13 ");
- fflush(stdout); /* have to flush for child's benefit */
- system("rm -rf DIR_13; mkdir DIR_13");
- chdir("DIR_13");
+ start(13);
pipe(pipefd);
return(-1); /* impossible */
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define MAX_ERROR 4
char name[20] = {"TMP14."};
-int errct;
int subtest = 1;
+#include "common.c"
+
_PROTOTYPE(int main, (void));
_PROTOTYPE(void e, (int n));
_PROTOTYPE(void quit, (void));
{
int fd0, i, pid;
- printf("Test 14 ");
- fflush(stdout);
-
- system("rm -rf DIR_14; mkdir DIR_14");
- chdir("DIR_14");
+ start(14);
pid = getpid();
sprintf(&name[6], "%x", pid);
return(-1); /* impossible */
}
-void e(n)
-int n;
-{
- int err_num = errno; /* save errno in case printf clobbers it */
-
- printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
- errno = err_num; /* restore errno, just in case */
- perror("");
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- exit(1);
- }
-}
-
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#include <stdlib.h>
#include <stdio.h>
-_PROTOTYPE( int chdir, (char *_path)); /* from <unistd.h> */
#define STREQ(a, b) (strcmp((a), (b)) == 0)
char uctest[] = "\004\203"; /* For testing signedness of chars. */
int charsigned; /* Result. */
+#define MAX_ERROR 2
+#include "common.c"
+
_PROTOTYPE(void check, (int thing, int number));
_PROTOTYPE(void equal, (char *a, char *b, int number));
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void first, (void));
_PROTOTYPE(void second, (void));
-_PROTOTYPE(void quit, (void));
/*
- check - complain if condition is not true
int argc;
char *argv[];
{
- printf("Test 15 ");
- fflush(stdout);
- system("rm -rf DIR_15; mkdir DIR_15");
- chdir("DIR_15");
+ start(15);
+
/* First, establish whether chars are signed. */
if (uctest[0] < uctest[1])
charsigned = 0;
#endif
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define MAX_ERROR 4
-int errct, subtest, passes;
+int subtest, passes;
+
+#include "common.c"
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void test16a, (void));
_PROTOTYPE(void get_times, (char *name, time_t *a, time_t *c, time_t *m));
-_PROTOTYPE(void e, (int n));
-_PROTOTYPE(void quit, (void));
int main(argc, argv)
int argc;
{
int i, m;
+ start(16);
+
m = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
- system("rm -rf DIR_16; mkdir DIR_16");
- chdir("DIR_16");
- printf("Test 16 ");
- fflush(stdout);
for (i = 0; i < 4; i++) {
if (m & 0001) test16a();
passes++;
*m = s.st_mtime;
}
-void e(n)
-int n;
-{
- int err_num = errno; /* save errno in case printf clobbers it */
-
- printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
- errno = err_num; /* restore errno, just in case */
- perror("");
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- exit(1);
- }
-}
-
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
-
#define NOCRASH 1 /* test11(), 2nd pipe */
#define PDPNOHANG 1 /* test03(), write_standards() */
-#define MAXERR 2
+#define MAX_ERROR 2
#define USER_ID 12
#define GROUP_ID 1
/* "test.c", created by Rene Montsma and Menno Wilcke */
+#include "common.c"
+
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void test, (int mask));
_PROTOTYPE(void test01, (void));
_PROTOTYPE(int unlink_alot, (int number));
_PROTOTYPE(void get_new, (char name []));
_PROTOTYPE(void test11, (void));
-_PROTOTYPE(void comp_stats, (struct stat *stbf1, struct stat *stbf2));
-_PROTOTYPE(void comp_inodes, (int m, int m1));
-_PROTOTYPE(void e, (char *string));
_PROTOTYPE(void nlcr, (void));
_PROTOTYPE(void str, (char *s));
-_PROTOTYPE(void err, (int number, char *scall, char *name));
-_PROTOTYPE(void make_and_fill_dirs, (void));
+_PROTOTYPE(void test03, (void));
_PROTOTYPE(void put_file_in_dir, (char *dirname, int mode));
_PROTOTYPE(void init_array, (char *a));
_PROTOTYPE(void clear_array, (char *b));
char *argv[];
{
int n, mask, i;
+ pid_t child;
+
+ start(17);
/* Create filenames for MAXOPEN files, the *filenames[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&filenames[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
- return 1;
+ quit();
}
}
- sync();
-
-#define DIR "DIR17"
- system("rm -rf " DIR);
-
- if(mkdir(DIR, 0755) != 0) {
- perror("mkdir");
- return 1;
- }
-
- if(chdir(DIR) < 0) {
- perror("chdir");
- return 1;
- }
mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
-
- if (fork()) {
- printf("Test 17 ");
- fflush(stdout);
-
- wait(&n);
+ subtest = 0;
+ child = fork();
+ if (child == -1) {
+ e(1);
+ quit();
+ } else if (child == 0) {
+ test(mask);
+ return(0);
+ } else {
+ wait(&n);
clean_up_the_mess();
quit();
- } else {
- test(mask);
- exit(0);
}
return(-1); /* impossible */
}
umask(0); /* not honest, but i always forget */
if (mask & 00001) test01();
- if (mask & 00002) make_and_fill_dirs();
+ if (mask & 00002) test03();
if (mask & 00004) test02();
if (mask & 00010) test08();
if (mask & 00020) test09();
int oldvalue, newvalue, tempvalue;
int nr;
- if ((oldvalue = umask(0777)) != 0) err(0, UMASK, NIL);
+ subtest = 1;
+ if ((oldvalue = umask(0777)) != 0) e(1);
/* Special test: only the lower 9 bits (protection bits) may part- *
* icipate. ~0777 means: 111 000 000 000. Giving this to umask must*
* not change any value. */
- if ((newvalue = umask(~0777)) != 0777) err(1, UMASK, "illegal");
- if (oldvalue == newvalue) err(11, UMASK, "not change mask");
+ if ((newvalue = umask(~0777)) != 0777) e(2);
+ if (oldvalue == newvalue) e(3);
- if ((tempvalue = umask(0)) != 0) err(2, UMASK, "values");
+ if ((tempvalue = umask(0)) != 0) e(4);
/* Now test all possible modes of umask on a file */
for (newvalue = MASK; newvalue >= 0; newvalue -= 0111) {
tempvalue = umask(newvalue);
if (tempvalue != oldvalue) {
- err(1, UMASK, "illegal");
+ e(5);
break; /* no use trying more */
} else if ((nr = creat("file01", 0777)) < 0)
- err(5, CREAT, "'file01'");
+ e(6);
else {
try_close(nr, "'file01'");
if (get_mode("file01") != (MASK & ~newvalue))
- err(7, UMASK, "mode computed");
+ e(7);
try_unlink("file01");
}
oldvalue = newvalue;
/* The loop has terminated with umask(0) */
if ((tempvalue = umask(0)) != 0)
- err(7, UMASK, "umask may influence rest of tests!");
+ e(8);
} /* test01 */
/*****************************************************************************
char a[ARSIZE], b[ARSIZE];
struct stat stbf1;
+ subtest = 2;
mode = 0;
- /* Create twenty files, check filedes */
+
for (n = 0; n < MAXOPEN; n++) {
if (creat(filenames[n], mode) != FF + n)
- err(13, CREAT, filenames[n]);
+ e(1);
else {
if (get_mode(filenames[n]) != mode)
- err(7, CREAT, "mode set while creating many files");
+ e(2);
/* Change mode of file to standard mode, we want to *
* use a lot (20) of files to be opened later, see *
* open_alot(), close_alot(). */
- if (chmod(filenames[n], 0700) != OK) err(5, CHMOD, filenames[n]);
+ if (chmod(filenames[n], 0700) != OK) e(3);
}
mode = (mode + 0100) % 01000;
}
/* Already twenty files opened; opening another has to fail */
if (creat("file02", 0777) != FAIL)
- err(9, CREAT, "created");
+ e(4);
else
- check(CREAT, EMFILE);
+ if (errno != EMFILE) e(5);
/* Close all files: seems blunt, but it isn't because we've *
* checked all fd's already */
- if ((n = close_alot(MAXOPEN)) < MAXOPEN) err(5, CLOSE, "MAXOPEN files");
+ if ((n = close_alot(MAXOPEN)) < MAXOPEN) e(6);
/* Creat 1 file twice; check */
if ((n = creat("file02", 0777)) < 0)
- err(5, CREAT, "'file02'");
+ e(7);
else {
init_array(a);
- if (write(n, a, ARSIZE) != ARSIZE) err(1, WRITE, "bad");
+ if (write(n, a, ARSIZE) != ARSIZE) e(8);
if ((n1 = creat("file02", 0755)) < 0) /* receate 'file02' */
- err(5, CREAT, "'file02' (2nd time)");
+ e(9);
else {
/* Fd should be at the top after recreation */
if (lseek(n1, 0L, SEEK_END) != 0)
- err(11, CREAT, "not truncate file by recreation");
+ e(10);
else {
/* Try to write on recreated file */
clear_array(b);
- if (lseek(n1, 0L, SEEK_SET) != 0)
- err(5, LSEEK, "to top of 2nd fd 'file02'");
- if (write(n1, a, ARSIZE) != ARSIZE)
- err(1, WRITE, "(2) bad");
+ if (lseek(n1, 0L, SEEK_SET) != 0) e(11);
+ if (write(n1, a, ARSIZE) != ARSIZE) e(12);
/* In order to read we've to close and open again */
try_close(n1, "'file02' (2nd creation)");
if ((n1 = open("file02", RW)) < 0)
- err(5, OPEN, "'file02' (2nd recreation)");
+ e(13);
/* Continue */
- if (lseek(n1, 0L, SEEK_SET) != 0)
- err(5, LSEEK, "to top 'file02'(2nd fd) (2)");
- if (read(n1, b, ARSIZE) != ARSIZE)
- err(1, READ, "wrong");
+ if (lseek(n1, 0L, SEEK_SET) != 0) e(14);
+ if (read(n1, b, ARSIZE) != ARSIZE) e(15);
- if (comp_array(a, b, ARSIZE) != OK) err(11, CREAT,
- "not really truncate file by recreation");
+ if (comp_array(a, b, ARSIZE) != OK) e(16);
}
- if (get_mode("file02") != 0777)
- err(11, CREAT, "not maintain mode by recreation");
+ if (get_mode("file02") != 0777) e(17);
try_close(n1, "recreated 'file02'");
}
}
/* Give 'creat' wrong input: dir not searchable */
- if (creat("drw-/file02", 0777) != FAIL)
- err(4, CREAT, "'drw-'");
+ if (creat("drw-/file02", 0777) != FAIL) e(18);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(19);
/* Dir not writable */
- if (creat("dr-x/file02", 0777) != FAIL)
- err(12, CREAT, "'dr-x/file02'");
+ if (creat("dr-x/file02", 0777) != FAIL) e(20);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(21);
/* File not writable */
- if (creat("drwx/r-x", 0777) != FAIL)
- err(11, CREAT, "recreate non-writable file");
+ if (creat("drwx/r-x", 0777) != FAIL) e(22);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(23);
/* Try to creat a dir */
if ((n = creat("dir", 040777)) != FAIL) {
- if (fstat(n, &stbf1) != OK)
- err(5, FSTAT, "'dir'");
+ if (fstat(n, &stbf1) != OK) e(24);
else if (stbf1.st_mode != (mode_t) 0100777)
/* cast because mode is negative :-( */
- err(11, CREAT, "'creat' a new directory");
+ e(25);
Remove(n, "dir");
}
* tricky modes */
/* File is an existing dir */
- if (creat("drwx", 0777) != FAIL)
- err(11, CREAT, "create an existing dir!");
+ if (creat("drwx", 0777) != FAIL) e(26);
else
- check(CREAT, EISDIR);
+ if (errno != EISDIR) e(27);
} /* test02 */
void test08()
{
+ subtest = 8;
+
/* Test chdir to searchable dir */
- if (chdir("drwx") != OK)
- err(5, CHDIR, "to accessible dir");
- else if (chdir("..") != OK)
- err(11, CHDIR, "not return to '..'");
+ if (chdir("drwx") != OK) e(1);
+ else if (chdir("..") != OK) e(2);
/* Check the chdir(".") and chdir("..") mechanism */
- if (chdir("drwx") != OK)
- err(5, CHDIR, "to 'drwx'");
+ if (chdir("drwx") != OK) e(3);
else {
- if (chdir(".") != OK) err(5, CHDIR, "to working dir (.)");
+ if (chdir(".") != OK) e(4);
/* If we still are in 'drwx' , we should be able to access *
* file 'rwx'. */
- if (access("rwx", 0) != OK) err(5, CHDIR, "rightly to '.'");
+ if (access("rwx", 0) != OK) e(5);
/* Try to return to previous dir ('/' !!) */
- if (chdir("././../././d--x/../d--x/././..") != OK)
- err(5, CHDIR, "to motherdir (..)");
+ if (chdir("././../././d--x/../d--x/././..") != OK) e(6);
/* Check whether we are back in '/' */
- if (chdir("d--x") != OK) err(5, CHDIR, "rightly to a '..'");
- }
+ if (chdir("d--x") != OK) e(7);
+ } /* Return to '..' */
+ if (chdir("..") != OK) e(8);
- /* Return to '..' */
- if (chdir("..") != OK) err(5, CHDIR, "to '..'");
-
- if (chdir("././././drwx") != OK)
- err(11, CHDIR, "not follow a path");
- else if (chdir("././././..") != OK)
- err(11, CHDIR, "not return to path");
+ if (chdir("././././drwx") != OK) e(9);
+ else if (chdir("././././..") != OK) e(10);
/* Try giving chdir wrong parameters */
- if (chdir("drwx/rwx") != FAIL)
- err(11, CHDIR, "chdir to a file");
+ if (chdir("drwx/rwx") != FAIL) e(11);
else
- check(CHDIR, ENOTDIR);
+ if (errno != ENOTDIR) e(12);
- if (chdir("drw-") != FAIL)
- err(4, CHDIR, "'/drw-'");
+ if (chdir("drw-") != FAIL) e(13);
else
- check(CHDIR, EACCES);
+ if (errno != EACCES) e(14);
- /* To be sure: return to root */
- /* If (chdir("/") != OK) err(5, CHDIR, "to '/' (2nd time)"); */
} /* test08 */
-/* New page */\f
/*****************************************************************************
* test CHMOD *
****************************************************************************/
{
int n;
+ subtest = 9;
+
/* Prepare file09 */
- if ((n = creat("drwx/file09", 0644)) != FF) err(5, CREAT, "'drwx/file09'");
+ if ((n = creat("drwx/file09", 0644)) != FF) e(1);
try_close(n, "'file09'");
/* Try to chmod a file, check and restore old values, check */
- if (chmod("drwx/file09", 0700) != OK)
- err(5, CHMOD, "'drwx/file09'"); /* set rwx */
+ if (chmod("drwx/file09", 0700) != OK) e(2);
else {
/* Check protection */
- if (get_mode("drwx/file09") != 0700) err(7, CHMOD, "mode");
+ if (get_mode("drwx/file09") != 0700) e(3);
/* Test if chmod accepts just filenames too */
- if (chdir("drwx") != OK)
- err(5, CHDIR, "to '/drwx'");
- else if (chmod("file09", 0177) != OK) /* restore oldies */
- err(5, CHMOD, "'h1'");
+ if (chdir("drwx") != OK) e(4);
+ else if (chmod("file09", 0177) != OK) e(5);
else
/* Check if value has been restored */
- if (get_mode("../drwx/file09") != 0177)
- err(7, CHMOD, "restored mode");
+ if (get_mode("../drwx/file09") != 0177) e(6);
}
/* Try setuid and setgid */
if ((chmod("file09", 04777) != OK) || (get_mode("file09") != 04777))
- err(11, CHMOD, "not set uid-bit");
+ e(7);
if ((chmod("file09", 02777) != OK) || (get_mode("file09") != 02777))
- err(11, CHMOD, "not set gid-bit");
+ e(8);
/* Remove testfile */
try_unlink("file09");
- if (chdir("..") != OK) err(5, CHDIR, "to '..'");
+ if (chdir("..") != OK) e(9);
/* Try to chmod directory */
- if (chmod("d---", 0777) != OK)
- err(5, CHMOD, "dir 'd---'");
+ if (chmod("d---", 0777) != OK) e(10);
else {
- if (get_mode("d---") != 0777) err(7, CHMOD, "protection value");
- if (chmod("d---", 0000) != OK) err(5, CHMOD, "dir 'a' 2nd time");
+ if (get_mode("d---") != 0777) e(11);
+ if (chmod("d---", 0000) != OK) e(12);
/* Check if old value has been restored */
- if (get_mode("d---") != 0000)
- err(7, CHMOD, "restored protection value");
+ if (get_mode("d---") != 0000) e(13);
}
/* Try to make chmod failures */
/* We still are in dir root */
/* Wrong filename */
- if (chmod("non-file", 0777) != FAIL)
- err(3, CHMOD, NIL);
+ if (chmod("non-file", 0777) != FAIL) e(14);
else
- check(CHMOD, ENOENT);
+ if (errno != ENOENT) e(15);
} /* test 09 */
-/* New page */\f
/* "t4.c", created by Rene Montsma and Menno Wilcke */
int n, n1;
char a[ARSIZE], b[ARSIZE], *f, *lf;
+ subtest = 10;
+
f = "anotherfile10";
lf = "linkfile10";
- if ((n = creat(f, 0702)) != FF) /* no other open files */
- err(13, CREAT, f);
+ if ((n = creat(f, 0702)) != FF) e(1); /* no other open files */
else {
/* Now link correctly */
- if (link(f, lf) != OK)
- err(5, LINK, lf);
- else if ((n1 = open(lf, RW)) < 0)
- err(5, OPEN, "'linkfile10'");
+ if (link(f, lf) != OK) e(2);
+ else if ((n1 = open(lf, RW)) < 0) e(3);
else {
init_array(a);
clear_array(b);
/* Write on 'file10' means being able to * read
* through linked filedescriptor */
- if (write(n, a, ARSIZE) != ARSIZE) err(1, WRITE, "bad");
- if (read(n1, b, ARSIZE) != ARSIZE) err(1, READ, "bad");
- if (comp_array(a, b, ARSIZE) != OK) err(8, "r/w", NIL);
+ if (write(n, a, ARSIZE) != ARSIZE) e(4);
+ if (read(n1, b, ARSIZE) != ARSIZE) e(5);
+ if (comp_array(a, b, ARSIZE) != OK) e(6);
/* Clean up: unlink and close (twice): */
Remove(n, f);
/* Check if "linkfile" exists and the info * on it
* is correct ('file' has been deleted) */
- if ((n1 = open(lf, R)) < 0)
- err(5, OPEN, "'linkfile10'");
+ if ((n1 = open(lf, R)) < 0) e(7);
else {
/* See if 'linkfile' still contains 0..511 ? */
clear_array(b);
- if (read(n1, b, ARSIZE) != ARSIZE)
- err(1, READ, "bad");
- if (comp_array(a, b, ARSIZE) != OK)
- err(8, "r/w", NIL);
+ if (read(n1, b, ARSIZE) != ARSIZE) e(8);
+ if (comp_array(a, b, ARSIZE) != OK) e(9);
try_close(n1, "'linkfile10' 2nd time");
try_unlink(lf);
/* Try if unlink fails with incorrect parameters */
/* File does not exist: */
- if (unlink("non-file") != FAIL)
- err(2, UNLINK, "name");
+ if (unlink("non-file") != FAIL) e(10);
else
- check(UNLINK, ENOENT);
+ if (errno != ENOENT) e(11);
/* Dir can't be written */
- if (unlink("dr-x/rwx") != FAIL)
- err(11, UNLINK, "could unlink in non-writable dir.");
+ if (unlink("dr-x/rwx") != FAIL) e(12);
else
- check(UNLINK, EACCES);
+ if (errno != EACCES) e(13);
/* Try to unlink a dir being user */
- if (unlink("drwx") != FAIL)
- err(11, UNLINK, "unlink dir's as user");
+ if (unlink("drwx") != FAIL) e(14);
else
- check(UNLINK, EPERM);
+ if (errno != EPERM) e(15);
/* Try giving link wrong input */
/* First try if link fails with incorrect parameters * name1 does not
* exist. */
- if (link("non-file", "linkfile") != FAIL)
- err(2, LINK, "1st name");
+ if (link("non-file", "linkfile") != FAIL) e(16);
else
- check(LINK, ENOENT);
+ if (errno != ENOENT) e(17);
/* Name2 exists already */
- if (link("drwx/rwx", "drwx/rw-") != FAIL)
- err(2, LINK, "2nd name");
+ if (link("drwx/rwx", "drwx/rw-") != FAIL) e(18);
else
- check(LINK, EEXIST);
+ if (errno != EEXIST) e(19);
/* Directory of name2 not writable: */
- if (link("drwx/rwx", "dr-x/linkfile") != FAIL)
- err(11, LINK, "link non-writable file");
+ if (link("drwx/rwx", "dr-x/linkfile") != FAIL) e(20);
else
- check(LINK, EACCES);
+ if (errno != EACCES) e(21);
/* Try to link a dir, being a user */
- if (link("drwx", "linkfile") != FAIL)
- err(11, LINK, "link a dir without superuser!");
+ if (link("drwx", "linkfile") != FAIL) e(22);
else
- check(LINK, EPERM);
+ if (errno != EPERM) e(23);
/* File has too many links */
if ((n = link_alot("drwx/rwx")) != LINKCOUNT - 1) /* file already has one
* link */
- err(5, LINK, "many files");
- if (unlink_alot(n) != n) err(5, UNLINK, "all linked files");
+ e(24);
+ if (unlink_alot(n) != n) e(25);
} /* test10 */
}
} /* get_new */
-/* New page */\f
/*****************************************************************************
* test PIPE *
int n, fd[2];
char a[ARSIZE], b[ARSIZE];
- if (pipe(fd) != OK)
- err(13, PIPE, NIL);
+ subtest = 11;
+
+ if (pipe(fd) != OK) e(1);
else {
/* Try reading and writing on a pipe */
init_array(a);
clear_array(b);
- if (write(fd[1], a, ARSIZE) != ARSIZE)
- err(5, WRITE, "on pipe");
- else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2))
- err(5, READ, "on pipe (2nd time)");
- else if (comp_array(a, b, (ARSIZE / 2)) != OK)
- err(7, PIPE, "values read/written");
- else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2))
- err(5, READ, "on pipe 2");
- else if (comp_array(&a[ARSIZE / 2], b, (ARSIZE / 2)) != OK)
- err(7, PIPE, "pipe created");
+ if (write(fd[1], a, ARSIZE) != ARSIZE) e(2);
+ else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2)) e(3);
+ else if (comp_array(a, b, (ARSIZE / 2)) != OK) e(4);
+ else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2)) e(5);
+ else if (comp_array(&a[ARSIZE / 2], b, (ARSIZE / 2)) != OK) e(6);
/* Try to let the pipe make a mistake */
- if (write(fd[0], a, ARSIZE) != FAIL)
- err(11, WRITE, "write on fd[0]");
- if (read(fd[1], b, ARSIZE) != FAIL) err(11, READ, "read on fd[1]");
+ if (write(fd[0], a, ARSIZE) != FAIL) e(7);
+ if (read(fd[1], b, ARSIZE) != FAIL) e(8);
try_close(fd[1], "'fd[1]'");
/* Now we shouldn't be able to read, because fd[1] has been closed */
- if (read(fd[0], b, ARSIZE) != END_FILE) err(2, PIPE, "'fd[1]'");
+ if (read(fd[0], b, ARSIZE) != END_FILE) e(9);
try_close(fd[0], "'fd[0]'");
}
- if (pipe(fd) < 0)
- err(5, PIPE, "2nd time");
+ if (pipe(fd) < 0) e(10);
else {
/* Test lseek on a pipe: should fail */
- if (write(fd[1], a, ARSIZE) != ARSIZE)
- err(5, WRITE, "on pipe (2nd time)");
- if (lseek(fd[1], 10L, SEEK_SET) != FAIL)
- err(11, LSEEK, "lseek on a pipe");
+ if (write(fd[1], a, ARSIZE) != ARSIZE) e(11);
+ if (lseek(fd[1], 10L, SEEK_SET) != FAIL) e(12);
else
- check(PIPE, ESPIPE);
+ if (errno != ESPIPE) e(13);
/* Eat half of the pipe: no writing should be possible */
try_close(fd[0], "'fd[0]' (2nd time)");
/* This makes UNIX crash: omit it if pdp or VAX */
#ifndef NOCRASH
- if (write(fd[1], a, ARSIZE) != FAIL)
- err(11, WRITE, "write on wrong pipe");
+ if (write(fd[1], a, ARSIZE) != FAIL) e(14);
else
- check(PIPE, EPIPE);
+ if (errno != EPIPE) e(15);
#endif
try_close(fd[1], "'fd[1]' (2nd time)");
}
* Monix system crashed when we tried to write more then 3584 bytes *
* (3.5K) on a pipe. That's why we try to write only 3.5K in the *
* folowing test. */
- if (pipe(fd) < 0)
- err(5, PIPE, "3rd time");
+ if (pipe(fd) < 0) e(16);
else {
for (n = 0; n < (PIPESIZE / ARSIZE); n++)
- if (write(fd[1], a, ARSIZE) != ARSIZE)
- err(5, WRITE, "on pipe (3rd time) 4K");
+ if (write(fd[1], a, ARSIZE) != ARSIZE) e(17);
try_close(fd[1], "'fd[1]' (3rd time)");
for (n = 0; n < (PIPESIZE / ARSIZE); n++)
- if (read(fd[0], b, ARSIZE) != ARSIZE)
- err(5, READ, "from pipe (3rd time) 4K");
+ if (read(fd[0], b, ARSIZE) != ARSIZE) e(18);
try_close(fd[0], "'fd[0]' (3rd time)");
}
/* Test opening a lot of files */
- if ((n = open_alot()) != MAXOPEN) err(5, OPEN, "MAXOPEN files");
- if (pipe(fd) != FAIL)
- err(9, PIPE, "open");
+ if ((n = open_alot()) != MAXOPEN) e(19);
+ if (pipe(fd) != FAIL) e(20);
else
- check(PIPE, EMFILE);
- if (close_alot(n) != n) err(5, CLOSE, "all opened files");
+ if (errno != EMFILE) e(21);
+ if (close_alot(n) != n) e(22);
} /* test11 */
-/* New page */\f
-void comp_stats(stbf1, stbf2)
-struct stat *stbf1, *stbf2;
-{
- if (stbf1->st_dev != stbf2->st_dev) err(7, "st/fst", "'dev'");
- if (stbf1->st_ino != stbf2->st_ino) err(7, "st/fst", "'ino'");
- if (stbf1->st_mode != stbf2->st_mode) err(7, "st/fst", "'mode'");
- if (stbf1->st_nlink != stbf2->st_nlink) err(7, "st/fst", "'nlink'");
- if (stbf1->st_uid != stbf2->st_uid) err(7, "st/fst", "'uid'");
- if (stbf1->st_gid != stbf2->st_gid) err(7, "st/fst", "'gid'");
- if (stbf1->st_rdev != stbf2->st_rdev) err(7, "st/fst", "'rdev'");
- if (stbf1->st_size != stbf2->st_size) err(7, "st/fst", "'size'");
- if (stbf1->st_atime != stbf2->st_atime) err(7, "st/fst", "'atime'");
- if (stbf1->st_mtime != stbf2->st_mtime) err(7, "st/fst", "'mtime'");
-} /* comp_stats */
-
-/* New page */\f
-
-/* "t5.c", created by Rene Montsma and Menno Wilcke */
-
-void comp_inodes(m, m1)
-int m, m1; /* twee filedes's */
-{
- struct stat stbf1, stbf2;
-
- if (fstat(m, &stbf1) == OK)
- if (fstat(m1, &stbf2) == OK) {
- if (stbf1.st_ino != stbf2.st_ino)
- err(7, DUP, "inode number");
- } else
- err(100, "comp_inodes", "cannot 'fstat' (m1)");
- else
- err(100, "comp_inodes", "cannot 'fstat' (m)");
-} /* comp_inodes */
-
-/* "support.c", created by Rene Montsma and Menno Wilcke */
-
-/* Err, make_and_fill_dirs, init_array, clear_array, comp_array,
+/* Err, test03, init_array, clear_array, comp_array,
try_close, try_unlink, Remove, get_mode, check, open_alot,
close_alot, clean_up_the_mess.
*/
-/***********************************************************************
- * EXTENDED FIONS *
- **********************************************************************/
-/* First extended functions (i.e. not oldfashioned monixcalls.
- e(), nlcr(), octal.*/
-
-void e(string)
-char *string;
-{
- printf("Error: %s ", string);
-}
-
-void nlcr()
-{
- fputs("\n",stdout);
-}
-
-void str(char *s)
-{
- fputs(s,stdout);
-}
-
-/*****************************************************************************
-* *
-* ERR(or) messages *
-* *
-*****************************************************************************/
-void err(number, scall, name)
- /* Give nice error messages */
-
-char *scall, *name;
-int number;
-
-{
- errct++;
- if (errct > MAXERR) {
- printf("Too many errors; test aborted\n");
- quit();
- }
- e("");
- str("\t");
- switch (number) {
- case 0:
- str(scall);
- str(": illegal initial value.");
- break;
- case 1:
- str(scall);
- str(": ");
- str(name);
- str(" value returned.");
- break;
- case 2:
- str(scall);
- str(": accepting illegal ");
- str(name);
- str(".");
- break;
- case 3:
- str(scall);
- str(": accepting non-existing file.");
- break;
- case 4:
- str(scall);
- str(": could search non-searchable dir (");
- str(name);
- str(").");
- break;
- case 5:
- str(scall);
- str(": cannot ");
- str(scall);
- str(" ");
- str(name);
- str(".");
- break;
- case 7:
- str(scall);
- str(": incorrect ");
- str(name);
- str(".");
- break;
- case 8:
- str(scall);
- str(": wrong values.");
- break;
- case 9:
- str(scall);
- str(": accepting too many ");
- str(name);
- str(" files.");
- break;
- case 10:
- str(scall);
- str(": even a superuser can't do anything!");
- break;
- case 11:
- str(scall);
- str(": could ");
- str(name);
- str(".");
- break;
- case 12:
- str(scall);
- str(": could write in non-writable dir (");
- str(name);
- str(").");
- break;
- case 13:
- str(scall);
- str(": wrong filedes returned (");
- str(name);
- str(").");
- break;
- case 100:
- str(scall); /* very common */
- str(": ");
- str(name);
- str(".");
- break;
- default: str("errornumber does not exist!\n");
- }
- nlcr();
-} /* err */
/*****************************************************************************
* *
* *
*****************************************************************************/
-void make_and_fill_dirs()
+void test03()
/* Create 8 dir.'s: "d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", *
* "drw-", "drwx". * Then create 8 files
* in "drwx", and some needed files in other dirs. */
{
int mode, i;
-
+ subtest = 3;
for (i = 0; i < MODES; i++) {
mkdir(mode_dir[i], 0700);
chown(mode_dir[i], USER_ID, GROUP_ID);
chmod_8_dirs(8); /* 8 means; 8 different modes */
-} /* make_and_fill_dirs */
+} /* test03 */
void put_file_in_dir(dirname, mode)
char *dirname;
{
int nr;
- if (chdir(dirname) != OK)
- err(5, CHDIR, "to dirname (put_f_in_dir)");
+ if (chdir(dirname) != OK) e(1);
else {
/* Creat the file */
assert(mode >= 0 && mode < MODES);
- if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0)
- err(13, CREAT, mode_fnames[mode]);
+ if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0) e(2);
else {
try_close(nr, mode_fnames[mode]);
}
- if (chdir("..") != OK)
- err(5, CHDIR, "to previous dir (put_f_in_dir)");
+ if (chdir("..") != OK) e(3);
}
} /* put_file_in_dir */
char *a, *b;
int range;
{
- if ((range < 0) || (range > ARSIZE)) {
- err(100, "comp_array", "illegal range");
+ assert(range >= 0 && range <= ARSIZE);
+ while (range-- && (*a++ == *b++));
+ if (*--a == *--b)
+ return(OK);
+ else
return(FAIL);
- } else {
- while (range-- && (*a++ == *b++));
- if (*--a == *--b)
- return(OK);
- else
- return(FAIL);
- }
} /* comp_array */
void try_close(filedes, name)
int filedes;
char *name;
{
- if (close(filedes) != OK) err(5, CLOSE, name);
+ if (close(filedes) != OK) e(90);
} /* try_close */
void try_unlink(fname)
char *fname;
{
- if (unlink(fname) != 0) err(5, UNLINK, fname);
+ if (unlink(fname) != 0) e(91);
} /* try_unlink */
void Remove(fdes, fname)
struct stat stbf1;
if (stat(name, &stbf1) != OK) {
- err(5, STAT, name);
+ e(92);
return(stbf1.st_mode); /* return a mode which will cause *
* error in the calling function *
* (file/dir bit) */
return(stbf1.st_mode & 07777); /* take last 4 bits */
} /* get_mode */
-/*****************************************************************************
-* *
-* CHECK *
-* *
-*****************************************************************************/
-
-void check(scall, number)
-int number;
-char *scall;
-{
- if (errno != number) {
- e(NIL);
- str("\t");
- str(scall);
- str(": bad errno-value: ");
- put(errno);
- str(" should have been: ");
- put(number);
- nlcr();
- }
-} /* check */
-
-void put(nr)
-int nr;
-{
- switch (nr) {
- case 0: str("unused"); break;
- case 1: str("EPERM"); break;
- case 2: str("ENOENT"); break;
- case 3: str("ESRCH"); break;
- case 4: str("EINTR"); break;
- case 5: str("EIO"); break;
- case 6: str("ENXIO"); break;
- case 7: str("E2BIG"); break;
- case 8: str("ENOEXEC"); break;
- case 9: str("EBADF"); break;
- case 10: str("ECHILD"); break;
- case 11: str("EAGAIN"); break;
- case 12: str("ENOMEM"); break;
- case 13: str("EACCES"); break;
- case 14: str("EFAULT"); break;
- case 15: str("ENOTBLK"); break;
- case 16: str("EBUSY"); break;
- case 17: str("EEXIST"); break;
- case 18: str("EXDEV"); break;
- case 19: str("ENODEV"); break;
- case 20: str("ENOTDIR"); break;
- case 21: str("EISDIR"); break;
- case 22: str("EINVAL"); break;
- case 23: str("ENFILE"); break;
- case 24: str("EMFILE"); break;
- case 25: str("ENOTTY"); break;
- case 26: str("ETXTBSY"); break;
- case 27: str("EFBIG"); break;
- case 28: str("ENOSPC"); break;
- case 29: str("ESPIPE"); break;
- case 30: str("EROFS"); break;
- case 31: str("EMLINK"); break;
- case 32: str("EPIPE"); break;
- case 33: str("EDOM"); break;
- case 34: str("ERANGE"); break;
- }
-}
/*****************************************************************************
* *
for (i = 0; i < MAXOPEN; i++)
if (open(filenames[i], R) == FAIL) break;
- if (i == 0) err(5, "open_alot", "at all");
+ if (i == 0) e(93);
return(i);
} /* open_alot */
int i, count = 0;
if (number > MAXOPEN)
- err(5, "close_alot", "accept this argument");
+ e(94);
else
for (i = FF; i < number + FF; i++)
if (close(i) != OK) count++;
/* Unlink the files in dir 'drwx' */
if (chdir("drwx") != OK)
- err(5, CHDIR, "to 'drwx'");
+ e(95);
else {
for (i = 0; i < MODES; i++) {
try_unlink(mode_fnames[i]);
}
- if (chdir("..") != OK) err(5, CHDIR, "to '..'");
+ if (chdir("..") != OK) e(96);
}
/* Before unlinking files in some dirs, make them writable */
}
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define UTIME "utime"
int errct;
+#define MAX_ERROR 2
/* "decl.c", created by Rene Montsma and Menno Wilcke */
/* "test.c", created by Rene Montsma and Menno Wilcke */
+#include "common.c"
+
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(void test, (void));
_PROTOTYPE(void test01, (void));
(int pattern, struct iovec *iovec, char *buffer, int count));
_PROTOTYPE(static int power, (int base, int exponent));
_PROTOTYPE(void try_access, (char *fname, int mode, int test));
-_PROTOTYPE(void e, (char *string));
-_PROTOTYPE(void nlcr, (void));
-_PROTOTYPE(void str, (char *s));
-_PROTOTYPE(void err, (int number, char *scall, char *name));
_PROTOTYPE(void make_and_fill_dirs, (void));
_PROTOTYPE(void put_file_in_dir, (char *dirname, int mode));
_PROTOTYPE(void init_array, (char *a));
_PROTOTYPE(int close_alot, (int number));
_PROTOTYPE(void clean_up_the_mess, (void));
_PROTOTYPE(void chmod_8_dirs, (int sw));
-_PROTOTYPE(void quit, (void));
/*****************************************************************************
* TEST *
int main(int argc, char **argv)
{
int n, i;
+ pid_t child;
+
+ start(18);
/* Create filenames for MAXOPEN files, the *file[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&file[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
- return 1;
+ quit();
}
}
-#define DIR "DIR18"
- system("rm -rf " DIR);
- if(mkdir(DIR, 0755) != 0) {
- perror("mkdir");
- return 1;
- }
- if(chdir(DIR) != 0) {
- perror("chdir");
- return 1;
- }
-
- if (fork()) {
- printf("Test 18 ");
- fflush(stdout); /* have to flush for child's benefit */
-
+ subtest = 0;
+ child = fork();
+ if (child == -1) {
+ e(1);
+ quit();
+ } else if (child == 0) {
+ test();
+ return(0);
+ } else {
wait(&n);
clean_up_the_mess();
quit();
- } else {
- test();
- exit(0);
}
- return(0);
+ return(-1);
}
void test()
int oldvalue, newvalue, tempvalue;
int nr;
- if ((oldvalue = umask(0777)) != 0) err(0, UMASK, NIL);
+ subtest = 1;
+
+ if ((oldvalue = umask(0777)) != 0) e(1);
/* Special test: only the lower 9 bits (protection bits) may part- *
* icipate. ~0777 means: 111 000 000 000. Giving this to umask must*
* not change any value. */
- if ((newvalue = umask(~0777)) != 0777) err(1, UMASK, "illegal");
- if (oldvalue == newvalue) err(11, UMASK, "not change mask");
+ if ((newvalue = umask(~0777)) != 0777) e(2);
+ if (oldvalue == newvalue) e(3);
- if ((tempvalue = umask(0)) != 0) err(2, UMASK, "values");
+ if ((tempvalue = umask(0)) != 0) e(4);
/* Now test all possible modes of umask on a file */
for (newvalue = MASK; newvalue >= 0; newvalue -= 0111) {
tempvalue = umask(newvalue);
if (tempvalue != oldvalue) {
- err(1, UMASK, "illegal");
+ e(5);
break; /* no use trying more */
} else if ((nr = creat("file01", 0777)) < 0)
- err(5, CREAT, "'file01'");
+ e(6);
else {
try_close(nr, "'file01'");
- if (get_mode("file01") != (MASK & ~newvalue))
- err(7, UMASK, "mode computed");
+ if (get_mode("file01") != (MASK & ~newvalue)) e(7);
try_unlink("file01");
}
oldvalue = newvalue;
}
/* The loop has terminated with umask(0) */
- if ((tempvalue = umask(0)) != 0)
- err(7, UMASK, "umask may influence rest of tests!");
+ if ((tempvalue = umask(0)) != 0) e(8);
} /* test01 */
/*****************************************************************************
char a[ARSIZE], b[ARSIZE];
struct stat stbf1;
+ subtest = 2;
mode = 0;
- /* Create twenty files, check filedes */
+ /* Create MAXOPEN files, check filedes */
for (n = 0; n < MAXOPEN; n++) {
if (creat(file[n], mode) != FF + n)
- err(13, CREAT, file[n]);
+ e(1);
else {
- if (get_mode(file[n]) != mode)
- err(7, CREAT, "mode set while creating many files");
+ if (get_mode(file[n]) != mode) e(2);
/* Change mode of file to standard mode, we want to *
* use a lot (20) of files to be opened later, see *
* open_alot(), close_alot(). */
- if (chmod(file[n], 0700) != OK) err(5, CHMOD, file[n]);
+ if (chmod(file[n], 0700) != OK) e(3);
}
mode = (mode + 0100) % 01000;
}
/* Already twenty files opened; opening another has to fail */
- if (creat("file02", 0777) != FAIL)
- err(9, CREAT, "created");
+ if (creat("file02", 0777) != FAIL) e(4);
else
- check(CREAT, EMFILE);
+ if (errno != EMFILE) e(5);;
+
/* Close all files: seems blunt, but it isn't because we've *
* checked all fd's already */
- if ((n = close_alot(MAXOPEN)) < MAXOPEN) err(5, CLOSE, "MAXOPEN files");
+ if ((n = close_alot(MAXOPEN)) < MAXOPEN) e(6);
/* Creat 1 file twice; check */
- if ((n = creat("file02", 0777)) < 0)
- err(5, CREAT, "'file02'");
+ if ((n = creat("file02", 0777)) < 0) e(7);
else {
init_array(a);
- if (write(n, a, ARSIZE) != ARSIZE) err(1, WRITE, "bad");
+ if (write(n, a, ARSIZE) != ARSIZE) e(8);
- if ((n1 = creat("file02", 0755)) < 0) /* receate 'file02' */
- err(5, CREAT, "'file02' (2nd time)");
+ if ((n1 = creat("file02", 0755)) < 0) e(9);
else {
/* Fd should be at the top after recreation */
- if (lseek(n1, 0L, SEEK_END) != 0)
- err(11, CREAT, "not truncate file by recreation");
+ if (lseek(n1, 0L, SEEK_END) != 0) e(10);
else {
/* Try to write on recreated file */
clear_array(b);
- if (lseek(n1, 0L, SEEK_SET) != 0)
- err(5, LSEEK, "to top of 2nd fd 'file02'");
- if (write(n1, a, ARSIZE) != ARSIZE)
- err(1, WRITE, "(2) bad");
+ if (lseek(n1, 0L, SEEK_SET) != 0) e(11);
+ if (write(n1, a, ARSIZE) != ARSIZE) e(12);
/* In order to read we've to close and open again */
try_close(n1, "'file02' (2nd creation)");
- if ((n1 = open("file02", RW)) < 0)
- err(5, OPEN, "'file02' (2nd recreation)");
+ if ((n1 = open("file02", RW)) < 0) e(13);
/* Continue */
- if (lseek(n1, 0L, SEEK_SET) != 0)
- err(5, LSEEK, "to top 'file02'(2nd fd) (2)");
- if (read(n1, b, ARSIZE) != ARSIZE)
- err(1, READ, "wrong");
+ if (lseek(n1, 0L, SEEK_SET) != 0) e(14);
+ if (read(n1, b, ARSIZE) != ARSIZE) e(15);
- if (comp_array(a, b, ARSIZE) != OK) err(11, CREAT,
- "not really truncate file by recreation");
+ if (comp_array(a, b, ARSIZE) != OK) e(16);
}
- if (get_mode("file02") != 0777)
- err(11, CREAT, "not maintain mode by recreation");
+ if (get_mode("file02") != 0777) e(17);
try_close(n1, "recreated 'file02'");
}
}
/* Give 'creat' wrong input: dir not searchable */
- if (creat("drw-/file02", 0777) != FAIL)
- err(4, CREAT, "'drw-'");
+ if (creat("drw-/file02", 0777) != FAIL) e(18);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(19);
/* Dir not writable */
- if (creat("dr-x/file02", 0777) != FAIL)
- err(12, CREAT, "'dr-x/file02'");
+ if (creat("dr-x/file02", 0777) != FAIL) e(20);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(21);
/* File not writable */
- if (creat("drwx/r-x", 0777) != FAIL)
- err(11, CREAT, "recreate non-writable file");
+ if (creat("drwx/r-x", 0777) != FAIL) e(22);
else
- check(CREAT, EACCES);
+ if (errno != EACCES) e(23);
/* Try to creat a dir */
if ((n = creat("dir", 040777)) != FAIL) {
- if (fstat(n, &stbf1) != OK)
- err(5, FSTAT, "'dir'");
+ if (fstat(n, &stbf1) != OK) e(24);
else if (stbf1.st_mode != (mode_t) 0100777)
/* Cast because mode is negative :-(.
* HACK DEBUG FIXME: this appears to duplicate
* code in test17.c.
*/
- err(11, CREAT, "'creat' a new directory");
+ e(25);
Remove(n, "dir");
}
* tricky modes */
/* File is an existing dir */
- if (creat("drwx", 0777) != FAIL)
- err(11, CREAT, "create an existing dir!");
+ if (creat("drwx", 0777) != FAIL) e(26);
else
- check(CREAT, EISDIR);
+ if (errno != EISDIR) e(27);
} /* test02 */
/*****************************************************************************
int fd[2];
char a[ARSIZE];
+ subtest = 3;
init_array(a);
/* Test write after a CREAT */
- if ((n = creat("file03", 0700)) != FF) /* 'file03' only open file */
- err(13, CREAT, "'file03'");
+ if ((n = creat("file03", 0700)) != FF) e(1);
else {
write_standards(n, a); /* test simple writes, wrong input too */
try_close(n, "'file03'");
}
/* Test write after an OPEN */
- if ((n = open("file03", W)) < 0)
- err(5, OPEN, "'file03'");
+ if ((n = open("file03", W)) < 0) e(2);
else
write_standards(n, a); /* test simple writes, wrong input too */
/* Test write after a DUP */
- if ((n1 = dup(n)) < 0)
- err(5, DUP, "'file03'");
+ if ((n1 = dup(n)) < 0) e(3);
else {
write_standards(n1, a);
try_close(n1, "duplicated fd 'file03'");
Remove(n, "file03");
/* Test write after a PIPE */
- if (pipe(fd) < 0)
- err(5, PIPE, NIL);
+ if (pipe(fd) < 0) e(4);
else {
write_standards(fd[1], a);
try_close(fd[0], "'fd[0]'");
}
/* Last test: does write check protections ? */
- if ((n = open("drwx/r--", R)) < 0)
- err(5, OPEN, "'drwx/r--'");
+ if ((n = open("drwx/r--", R)) < 0) e(5);
else {
- if (write(n, a, ARSIZE) != FAIL)
- err(11, WRITE, "write on non-writ. file");
+ if (write(n, a, ARSIZE) != FAIL) e(6);
else
- check(WRITE, EBADF);
+ if (errno != EBADF) e(7);
try_close(n, "'drwx/r--'");
}
} /* test03 */
{
/* Write must return written account of numbers */
- if (write(filedes, a, ARSIZE) != ARSIZE) err(1, WRITE, "bad");
+ if (write(filedes, a, ARSIZE) != ARSIZE) e(80);
/* Try giving 'write' wrong input */
/* Wrong filedes */
- if (write(-1, a, ARSIZE) != FAIL)
- err(2, WRITE, "filedes");
+ if (write(-1, a, ARSIZE) != FAIL) e(81);
else
- check(WRITE, EBADF);
+ if (errno != EBADF) e(82);
/* Wrong length (illegal) */
#ifndef PDPNOHANG
- if (write(filedes, a, -ARSIZE) != FAIL)
- err(2, WRITE, "length");
+ if (write(filedes, a, -ARSIZE) != FAIL) e(83);
else
- check(WRITE, EINVAL); /* EFAULT on vu45 */
+ if (errno != EINVAL) e(84);
#endif
} /* write_standards */
-/* "t2.c", created by Rene Montsma and Menno Wilcke */
/*****************************************************************************
* test READ *
int n, n1, fd[2];
char a[ARSIZE];
+ subtest = 4;
+
/* Test read after creat */
- if ((n = creat("file04", 0700)) != FF) /* no other open files may be
- * left */
- err(13, CREAT, "'file04'");
+ if ((n = creat("file04", 0700)) != FF) e(1);
else {
/* Closing and opening needed before writing */
try_close(n, "'file04'");
- if ((n = open("file04", RW)) < 0) err(5, OPEN, "'file04'");
+ if ((n = open("file04", RW)) < 0) e(2);
init_array(a);
- if (write(n, a, ARSIZE) != ARSIZE)
- err(1, WRITE, "bad");
+ if (write(n, a, ARSIZE) != ARSIZE) e(3);
else {
- if (lseek(n, 0L, SEEK_SET) != 0) err(5, LSEEK, "'file04'");
+ if (lseek(n, 0L, SEEK_SET) != 0) e(4);
read_standards(n, a);
read_more(n, a);
}
}
/* Test read after OPEN */
- if ((n = open("file04", R)) < 0)
- err(5, OPEN, "'file04'");
+ if ((n = open("file04", R)) < 0) e(5);
else {
read_standards(n, a);
read_more(n, a);
}
/* Test read after DUP */
- if ((n = open("file04", R)) < 0) err(5, OPEN, "'file04'");
- if ((n1 = dup(n)) < 0)
- err(5, DUP, "'file04'");
+ if ((n = open("file04", R)) < 0) e(6);
+ if ((n1 = dup(n)) < 0) e(7);
else {
read_standards(n1, a);
read_more(n1, a);
Remove(n, "file04");
/* Test read after pipe */
- if (pipe(fd) < 0)
- err(5, PIPE, NIL);
+ if (pipe(fd) < 0) e(8);
else {
if (write(fd[1], a, ARSIZE) != ARSIZE) {
- err(5, WRITE, "'fd[1]'");
+ e(9);
try_close(fd[1], "'fd[1]'");
} else {
try_close(fd[1], "'fd[1]'");
}
/* Last test: try to read a read-protected file */
- if ((n = open("drwx/-wx", W)) < 0)
- err(5, OPEN, "'drwx/-wx'");
+ if ((n = open("drwx/-wx", W)) < 0) e(10);
else {
- if (read(n, a, ARSIZE) != FAIL)
- err(11, READ, "read a non-read. file");
+ if (read(n, a, ARSIZE) != FAIL) e(11);
else
- check(READ, EBADF);
+ if (errno != EBADF) e(12);
try_close(n, "'/drwx/-wx'");
}
} /* test04 */
char b[ARSIZE];
clear_array(b);
- if (read(filedes, b, ARSIZE) != ARSIZE)
- err(1, READ, "bad");
- else if (comp_array(a, b, ARSIZE) != OK)
- err(7, "read/write", "values");
- else if (read(filedes, b, ARSIZE) != READ_EOF)
- err(11, READ, "read beyond endoffile");
+ if (read(filedes, b, ARSIZE) != ARSIZE) e(85);
+ else if (comp_array(a, b, ARSIZE) != OK) e(86);
+ else if (read(filedes, b, ARSIZE) != READ_EOF) e(87);
/* Try giving read wrong input: wrong filedes */
- if (read(FAIL, b, ARSIZE) != FAIL)
- err(2, READ, "filedes");
+ if (read(FAIL, b, ARSIZE) != FAIL) e(88);
else
- check(READ, EBADF);
+ if (errno != EBADF) e(89);
/* Wrong length */
- if (read(filedes, b, -ARSIZE) != FAIL)
- err(2, READ, "length");
+ if (read(filedes, b, -ARSIZE) != FAIL) e(90);
else
- check(READ, EINVAL);
+ if (errno != EINVAL) e(91);
} /* read_standards */
void read_more(filedes, a)
int i;
char b[ARSIZE];
- if (lseek(filedes, (long) (ARSIZE / 2), SEEK_SET) != ARSIZE / 2)
- err(5, LSEEK, "to location ARSIZE/2");
+ if (lseek(filedes, (long) (ARSIZE / 2), SEEK_SET) != ARSIZE / 2) e(92);
clear_array(b);
- if (read(filedes, b, ARSIZE) != ARSIZE / 2) err(1, READ, "bad");
+ if (read(filedes, b, ARSIZE) != ARSIZE / 2) e(93);
for (i = 0; i < ARSIZE / 2; i++)
- if (b[i] != a[(ARSIZE / 2) + i])
- err(7, READ, "from location ARSIZE/2");
+ if (b[i] != a[(ARSIZE / 2) + i]) e(94);
}
/*****************************************************************************
int n, n1, mode, fd[2];
char b[ARSIZE];
+ subtest = 5;
/* Test open after CREAT */
- if ((n = creat("file05", 0700)) != FF) /* no other open files left */
- err(13, CREAT, "'file05'");
+ if ((n = creat("file05", 0700)) != FF) e(1);
else {
- if ((n1 = open("file05", RW)) != FF + 1)
- err(13, OPEN, "'file05' after creation");
+ if ((n1 = open("file05", RW)) != FF + 1) e(2);
try_close(n1, "'file05' (open after creation)");
try_close(n, "'file05'");
- if ((n = open("file05", R)) != FF)
- err(13, OPEN, "after closing");
+ if ((n = open("file05", R)) != FF) e(3);
else
try_close(n, "'file05' (open after closing)");
/* Test all possible modes, try_open not only opens file (sometimes) *
* but closes files too (when opened) */
- if ((n = creat("file05", 0700)) < 0) /* no other files left */
- err(5, CREAT, "'file05' (2nd time)");
+ if ((n = creat("file05", 0700)) < 0) e(6);
else {
try_close(n, "file05");
for (mode = 0; mode <= 0700; mode += 0100) {
- if (chmod("file05", mode) != OK) err(5, CHMOD, "'file05'");
+ if (chmod("file05", mode) != OK) e(7);
if (mode <= 0100) {
try_open("file05", R, FAIL);
}
/* Test opening existing file */
- if ((n = open("drwx/rwx", R)) < 0)
- err(13, OPEN, "existing file");
+ if ((n = open("drwx/rwx", R)) < 0) e(8);
else { /* test close after DUP */
- if ((n1 = dup(n)) < 0)
- err(13, DUP, "'drwx/rwx'");
+ if ((n1 = dup(n)) < 0) e(9);
else {
try_close(n1, "duplicated fd 'drwx/rwx'");
- if (read(n1, b, ARSIZE) != FAIL)
- err(11, READ, "on closed dupped fd 'drwx/rwx'");
+ if (read(n1, b, ARSIZE) != FAIL) e(10);
else
- check(READ, EBADF);
+ if (errno != EBADF) e(11);
- if (read(n, b, ARSIZE) == FAIL) /* should read an eof */
- err(13, READ, "on fd '/drwx/rwx'");
+ if (read(n, b, ARSIZE) == FAIL) e(12);/* should read an eof */
}
try_close(n, "'drwx/rwx'");
}
/* Test close after PIPE */
- if (pipe(fd) < 0)
- err(13, PIPE, NIL);
+ if (pipe(fd) < 0) e(13);
else {
try_close(fd[1], "duplicated fd 'fd[1]'");
/* Fd[1] really should be closed now; check */
clear_array(b);
- if (read(fd[0], b, ARSIZE) != READ_EOF)
- err(11, READ, "read on empty pipe (and fd[1] was closed)");
+ if (read(fd[0], b, ARSIZE) != READ_EOF) e(14);
try_close(fd[0], "duplicated fd 'fd[0]'");
}
/* Try to open a non-existing file */
- if (open("non-file", R) != FAIL)
- err(11, OPEN, "open non-executable file");
+ if (open("non-file", R) != FAIL) e(15);
else
- check(OPEN, ENOENT);
+ if (errno != ENOENT) e(16);
/* Dir does not exist */
- if (open("dzzz/file05", R) != FAIL)
- err(11, OPEN, "open in an non-searchable dir");
+ if (open("dzzz/file05", R) != FAIL) e(17);
else
- check(OPEN, ENOENT);
+ if (errno != ENOENT) e(18);
/* Dir is not searchable */
- if ((n = open("drw-/rwx", R)) != FAIL)
- err(11, OPEN, "open in an non-searchabledir");
+ if ((n = open("drw-/rwx", R)) != FAIL) e(19);
else
- check(OPEN, EACCES);
+ if (errno != EACCES) e(20);
/* Unlink testfile */
try_unlink("file05");
/* File is not readable */
- if (open("drwx/-wx", R) != FAIL)
- err(11, OPEN, "open unreadable file for reading");
+ if (open("drwx/-wx", R) != FAIL) e(21);
else
- check(OPEN, EACCES);
+ if (errno != EACCES) e(22);
/* File is not writable */
- if (open("drwx/r-x", W) != FAIL)
- err(11, OPEN, "open unwritable file for writing");
+ if (open("drwx/r-x", W) != FAIL) e(23);
else
- check(OPEN, EACCES);
+ if (errno != EACCES) e(24);
/* Try opening more than MAXOPEN ('extra' (19-8-85)) files */
- if ((n = open_alot()) != MAXOPEN)
- err(13, OPEN, "MAXOPEN files");
+ if ((n = open_alot()) != MAXOPEN) e(25);
else
/* Maximum # of files opened now, another open should fail
* because * all filedescriptors have already been used. */
- if (open("drwx/rwx", RW) != FAIL)
- err(9, OPEN, "open");
+ if (open("drwx/rwx", RW) != FAIL) e(26);
else
- check(OPEN, EMFILE);
- if (close_alot(n) != n) err(5, CLOSE, "all opened files");
+ if (errno != EMFILE) e(27);
+ if (close_alot(n) != n) e(28);
/* Can close make mistakes ? */
- if (close(-1) != FAIL)
- err(2, CLOSE, "filedes");
+ if (close(-1) != FAIL) e(29);
else
- check(CLOSE, EBADF);
+ if (errno != EBADF) e(30);
} /* test05 */
void try_open(fname, mode, test)
{
int n;
- if ((n = open(fname, mode)) != test)
- err(11, OPEN, "break through filepermission with an incorrect mode");
+ if ((n = open(fname, mode)) != test) e(95);
if (n != FAIL) try_close(n, fname); /* cleanup */
} /* try_open */
char a[ARSIZE], b[ARSIZE];
int fd;
- if ((fd = open("drwx/rwx", RW)) != FF) /* there should be no */
- err(13, OPEN, "'drwx/rwx'"); /* other open files */
+ subtest = 6;
+
+ if ((fd = open("drwx/rwx", RW)) != FF) e(1);
else {
init_array(a);
- if (write(fd, a, 10) != 10)
- err(1, WRITE, "bad");
+ if (write(fd, a, 10) != 10) e(2);
else {
/* Lseek back to begin file */
- if (lseek(fd, 0L, SEEK_SET) != 0)
- err(5, LSEEK, "to begin file");
- else if (read(fd, b, 10) != 10)
- err(1, READ, "bad");
- else if (comp_array(a, b, 10) != OK)
- err(7, LSEEK, "values r/w after lseek to begin");
+ if (lseek(fd, 0L, SEEK_SET) != 0) e(3);
+ else if (read(fd, b, 10) != 10) e(4);
+ else if (comp_array(a, b, 10) != OK) e(5);
+
/* Lseek to endoffile */
- if (lseek(fd, 0L, SEEK_END) != 10)
- err(5, LSEEK, "to end of file");
- else if (read(fd, b, 1) != READ_EOF)
- err(7, LSEEK, "read at end of file");
+ if (lseek(fd, 0L, SEEK_END) != 10) e(6);
+ else if (read(fd, b, 1) != READ_EOF) e(7);
+
/* Lseek beyond file */
- if (lseek(fd, 10L, SEEK_CUR) != 20)
- err(5, LSEEK, "beyond end of file");
- else if (write(fd, a, 10) != 10)
- err(1, WRITE, "bad");
+ if (lseek(fd, 10L, SEEK_CUR) != 20) e(8);
+ else if (write(fd, a, 10) != 10) e(9);
else {
/* Lseek to begin second write */
- if (lseek(fd, 20L, SEEK_SET) != 20)
- err(5, LSEEK, "'/drwx/rwx'");
- if (read(fd, b, 10) != 10)
- err(1, READ, "bad");
- else if (comp_array(a, b, 10) != OK)
- err(7, LSEEK,
- "values read after lseek MAXOPEN");
+ if (lseek(fd, 20L, SEEK_SET) != 20) e(10);
+ if (read(fd, b, 10) != 10) e(11);
+ else if (comp_array(a, b, 10) != OK) e(12);
}
}
/* Lseek to position before begin of file */
- if (lseek(fd, -1L, 0) != FAIL)
- err(11, LSEEK, "lseek before beginning of file");
+ if (lseek(fd, -1L, 0) != FAIL) e(13);
try_close(fd, "'drwx/rwx'");
}
/* Lseek on invalid filediscriptor */
- if (lseek(-1, 0L, SEEK_SET) != FAIL)
- err(2, LSEEK, "filedes");
+ if (lseek(-1, 0L, SEEK_SET) != FAIL) e(14);
else
- check(LSEEK, EBADF);
+ if (errno != EBADF) e(15);
}
-/* "t3.c", created by Rene Montsma and Menno Wilcke */
-
/*****************************************************************************
* test ACCESS *
****************************************************************************/
void test07()
{
+ subtest = 7;
+
/* Check with proper parameters */
- if (access("drwx/rwx", RWX) != OK) err(5, ACCESS, "accessible file");
+ if (access("drwx/rwx", RWX) != OK) e(1);
- if (access("./././drwx/././rwx", 0) != OK)
- err(5, ACCESS, "'/./.(etc)/drwx///rwx'");
+ if (access("./././drwx/././rwx", 0) != OK) e(2);
/* Check 8 files with 8 different modes on 8 accesses */
- if (chdir("drwx") != OK) err(5, CHDIR, "'drwx'");
+ if (chdir("drwx") != OK) e(3);
access_standards();
- if (chdir("..") != OK) err(5, CHDIR, "'..'");
+ if (chdir("..") != OK) e(4);
/* Check several wrong combinations */
/* File does not exist */
- if (access("non-file", 0) != FAIL)
- err(11, ACCESS, "access non-existing file");
+ if (access("non-file", 0) != FAIL) e(5);
else
- check(ACCESS, ENOENT);
+ if (errno != ENOENT) e(6);
/* Non-searchable dir */
- if (access("drw-/rwx", 0) != FAIL)
- err(4, ACCESS, "'drw-'");
+ if (access("drw-/rwx", 0) != FAIL) e(7);
else
- check(ACCESS, EACCES);
+ if (errno != EACCES) e(8);
/* Searchable dir, but wrong file-mode */
- if (access("drwx/--x", RWX) != FAIL)
- err(11, ACCESS, "a non accessible file");
+ if (access("drwx/--x", RWX) != FAIL) e(9);
else
- check(ACCESS, EACCES);
+ if (errno != EACCES) e(10);
} /* test07 */
int mode, test;
char *fname;
{
- if (access(fname, mode) != test)
- err(100, ACCESS, "incorrect access on a file (try_access)");
+ if (access(fname, mode) != test) e(96);
} /* try_access */
-/* "support.c", created by Rene Montsma and Menno Wilcke */
/* Err, make_and_fill_dirs, init_array, clear_array, comp_array,
try_close, try_unlink, Remove, get_mode, check, open_alot,
ssize_t sz_read, sz_write;
size_t sz_read_exp, sz_read_sum, sz_write_sum;
+ subtest = 8;
+
/* try various combinations of buffer sizes */
for (i = 0; i <= TEST8_IOVCOUNT; i++)
for (j = 0; j < power(TEST8_BUFSZCOUNT, i); j++)
sz_read_sum : sz_write_sum;
/* test reading and writing */
- if ((fd = open("file08", O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0)
- err(13, OPEN, "'file08'");
+ if ((fd = open("file08", O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) e(1);
else {
sz_write = writev(fd, iovec_write, k);
- if (sz_write != sz_write_sum) err(5, WRITEV, "'file08'");
- if (lseek(fd, 0, SEEK_SET) != 0) err(5, LSEEK, "'file08'");
+ if (sz_write != sz_write_sum) e(2);
+ if (lseek(fd, 0, SEEK_SET) != 0) e(3);
sz_read = readv(fd, iovec_read, i);
- if (sz_read != sz_read_exp)
- err(5, READV, "'file08'");
- else
- {
+ if (sz_read != sz_read_exp) e(4);
+ else {
if (!iovec_is_equal(iovec_read, iovec_write, sz_read))
- err(8, READV, "'file08'");
+ e(5);
}
/* Remove testfile */
return result;
}
-/***********************************************************************
- * EXTENDED FIONS *
- **********************************************************************/
-/* First extended functions (i.e. not oldfashioned monixcalls.
- e(), nlcr(), octal.*/
-
-void e(string)
-char *string;
-{
- printf("Test program error: %s\n", string);
- errct++;
-}
-
-void nlcr()
-{
- fputs("\n",stdout);
-}
-
-void str(char *s)
-{
- fputs(s,stdout);
-}
-
-/*****************************************************************************
-* *
-* ERR(or) messages *
-* *
-*****************************************************************************/
-void err(number, scall, name)
- /* Give nice error messages */
-
-char *scall, *name;
-int number;
-
-{
- errct++;
- if (errct > MAXERR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- quit();
- }
- e("");
- str("\t");
- switch (number) {
- case 0:
- str(scall);
- str(": illegal initial value.");
- break;
- case 1:
- str(scall);
- str(": ");
- str(name);
- str(" value returned.");
- break;
- case 2:
- str(scall);
- str(": accepting illegal ");
- str(name);
- str(".");
- break;
- case 3:
- str(scall);
- str(": accepting non-existing file.");
- break;
- case 4:
- str(scall);
- str(": could search non-searchable dir (");
- str(name);
- str(").");
- break;
- case 5:
- str(scall);
- str(": cannot ");
- str(scall);
- str(" ");
- str(name);
- str(".");
- break;
- case 7:
- str(scall);
- str(": incorrect ");
- str(name);
- str(".");
- break;
- case 8:
- str(scall);
- str(": wrong values.");
- break;
- case 9:
- str(scall);
- str(": accepting too many ");
- str(name);
- str(" files.");
- break;
- case 10:
- str(scall);
- str(": even a superuser can't do anything!");
- break;
- case 11:
- str(scall);
- str(": could ");
- str(name);
- str(".");
- break;
- case 12:
- str(scall);
- str(": could write in non-writable dir (");
- str(name);
- str(").");
- break;
- case 13:
- str(scall);
- str(": wrong filedes returned (");
- str(name);
- str(").");
- break;
- case 100:
- str(scall); /* very common */
- str(": ");
- str(name);
- str(".");
- break;
- default: str("errornumber does not exist!\n");
- }
- nlcr();
-} /* err */
/*****************************************************************************
* *
{
int nr;
- if (chdir(dirname) != OK)
- err(5, CHDIR, "to dirname (put_f_in_dir)");
+ if (chdir(dirname) != OK) e(97);
else {
/* Creat the file */
- if ((nr = creat(fnames[mode], mode * 0100)) < 0)
- err(13, CREAT, fnames[mode]);
+ if ((nr = creat(fnames[mode], mode * 0100)) < 0) e(98);
else
try_close(nr, fnames[mode]);
- if (chdir("..") != OK)
- err(5, CHDIR, "to previous dir (put_f_in_dir)");
+ if (chdir("..") != OK) e(99);
}
} /* put_file_in_dir */
char *a, *b;
int range;
{
- if ((range < 0) || (range > ARSIZE)) {
- err(100, "comp_array", "illegal range");
+ assert(range >= 0 && range <= ARSIZE);
+
+ while (range-- && (*a++ == *b++));
+ if (*--a == *--b)
+ return(OK);
+ else
return(FAIL);
- } else {
- while (range-- && (*a++ == *b++));
- if (*--a == *--b)
- return(OK);
- else
- return(FAIL);
- }
} /* comp_array */
void try_close(filedes, name)
int filedes;
char *name;
{
- if (close(filedes) != OK) err(5, CLOSE, name);
+ if (close(filedes) != OK) e(100);
} /* try_close */
void try_unlink(fname)
char *fname;
{
- if (unlink(fname) != 0) err(5, UNLINK, fname);
+ if (unlink(fname) != 0) e(101);
} /* try_unlink */
void Remove(fdes, fname)
struct stat stbf1;
if (stat(name, &stbf1) != OK) {
- err(5, STAT, name);
+ e(102);
return(stbf1.st_mode); /* return a mode which will cause *
* error in the calling function *
* (file/dir bit) */
return(stbf1.st_mode & 07777); /* take last 4 bits */
} /* get_mode */
-/*****************************************************************************
-* *
-* CHECK *
-* *
-*****************************************************************************/
-
-void check(scall, number)
-int number;
-char *scall;
-{
- if (errno != number) {
- e(NIL);
- str("\t");
- str(scall);
- str(": bad errno-value: ");
- put(errno);
- str(" should have been: ");
- put(number);
- nlcr();
- }
-} /* check */
-
-void put(nr)
-int nr;
-{
- switch (nr) {
- case 0: str("unused"); break;
- case 1: str("EPERM"); break;
- case 2: str("ENOENT"); break;
- case 3: str("ESRCH"); break;
- case 4: str("EINTR"); break;
- case 5: str("EIO"); break;
- case 6: str("ENXIO"); break;
- case 7: str("E2BIG"); break;
- case 8: str("ENOEXEC"); break;
- case 9: str("EBADF"); break;
- case 10: str("ECHILD"); break;
- case 11: str("EAGAIN"); break;
- case 12: str("ENOMEM"); break;
- case 13: str("EACCES"); break;
- case 14: str("EFAULT"); break;
- case 15: str("ENOTBLK"); break;
- case 16: str("EBUSY"); break;
- case 17: str("EEXIST"); break;
- case 18: str("EXDEV"); break;
- case 19: str("ENODEV"); break;
- case 20: str("ENOTDIR"); break;
- case 21: str("EISDIR"); break;
- case 22: str("EINVAL"); break;
- case 23: str("ENFILE"); break;
- case 24: str("EMFILE"); break;
- case 25: str("ENOTTY"); break;
- case 26: str("ETXTBSY"); break;
- case 27: str("EFBIG"); break;
- case 28: str("ENOSPC"); break;
- case 29: str("ESPIPE"); break;
- case 30: str("EROFS"); break;
- case 31: str("EMLINK"); break;
- case 32: str("EPIPE"); break;
- case 33: str("EDOM"); break;
- case 34: str("ERANGE"); break;
- }
-}
/*****************************************************************************
* *
for (i = 0; i < MAXOPEN; i++)
if (open(file[i], R) == FAIL) break;
- if (i == 0) err(5, "open_alot", "at all");
+
+ if (i == 0)
+ e(103);
return(i);
} /* open_alot */
{
int i, count = 0;
- if (number > MAXOPEN)
- err(5, "close_alot", "accept this argument");
+ if (number > MAXOPEN) e(104);
else
for (i = FF; i < number + FF; i++)
if (close(i) != OK) count++;
for (i = 0; i < MAXOPEN; i++) try_unlink(file[i]);
/* Unlink the files in dir 'drwx' */
- if (chdir("drwx") != OK)
- err(5, CHDIR, "to 'drwx'");
+ if (chdir("drwx") != OK) e(105);
else {
for (i = 0; i < 8; i++) try_unlink(fnames[i]);
- if (chdir("..") != OK) err(5, CHDIR, "to '..'");
+ if (chdir("..") != OK) e(106);
}
/* Before unlinking files in some dirs, make them writable */
}
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define ITERATIONS 5
#define MAX_ERROR 4
-int is, array[4], parsigs, parcum, sigct, cumsig, errct, subtest;
-int iteration, kk = 0, errct = 0;
+int is, array[4], parsigs, parcum, sigct, cumsig, subtest;
+int iteration, kk = 0;
char buf[2048];
+#include "common.c"
+
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void test2a, (void));
_PROTOTYPE(void test2b, (void));
_PROTOTYPE(void test2f, (void));
_PROTOTYPE(void test2g, (void));
_PROTOTYPE(void sigpip, (int s));
-_PROTOTYPE(void quit, (void));
-_PROTOTYPE(void e, (int n));
int main(argc, argv)
int argc;
{
int i, m = 0xFFFF;
- sync();
-
- if (argc == 2) m = atoi(argv[1]);
-
- printf("Test 2 ");
- fflush(stdout); /* have to flush for child's benefit */
-
- system("rm -rf DIR_02; mkdir DIR_02");
- chdir("DIR_02");
+ start(2);
for (i = 0; i < ITERATIONS; i++) {
iteration = i;
cumsig++;
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(4);
- }
-}
-
-void e(n)
-int n;
-{
- int err_num = errno; /* save errno in case printf clobbers it */
-
- printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
- errno = err_num; /* restore errno, just in case */
- perror("");
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- exit(1);
- }
-}
#include <unistd.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
pid_t pid0, pid1, pid2, pid3;
-int s, i, fd, nextb, errct = 0;
+int s, i, fd, nextb;
char *tempfile = "test4.temp";
char buf[1024];
-extern int errno;
+
+#define MAX_ERROR 2
+
+#include "common.c"
_PROTOTYPE(int main, (void));
_PROTOTYPE(void subr, (void));
{
int k;
- printf("Test 4 ");
- fflush(stdout); /* have to flush for child's benefit */
-
- system("rm -rf DIR_04; mkdir DIR_04");
- chdir("DIR_04");
+ start(4);
creat(tempfile, 0777);
for (k = 0; k < 20; k++) {
exit(1);
}
-void quit()
-{
-
- chdir("..");
- system("rm -rf DIR*");
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#define ITERATIONS 3
#define MAX_ERROR 4
+#include "common.c"
+
/* we have to keep in mind the millisecond values are rounded up */
#define UPPERUSEC(us) ((us)+(1000000/system_hz))
#define EQUSEC(l,r) \
_PROTOTYPE(int do_check, (void));
_PROTOTYPE(void got_alarm, (int sig));
_PROTOTYPE(void busy_wait, (int secs));
-_PROTOTYPE(void e, (int n));
-_PROTOTYPE(void quit, (void));
+_PROTOTYPE(void my_e, (int n));
static char *executable;
static int signals;
static int timer;
-static int errct = 0, subtest;
static long system_hz;
static int sigs[] = { SIGALRM, SIGVTALRM, SIGPROF };
char **argv;
{
int i, m = 0xFFFF, n = 0xF;
+ char cp_cmd[NAME_MAX+10];
system_hz = sysconf(_SC_CLK_TCK);
exit(do_check());
}
- printf("Test 41 ");
- fflush(stdout);
-
executable = argv[0];
+ start(41);
+
+ snprintf(cp_cmd, sizeof(cp_cmd), "cp ../%s .", executable);
+ system(cp_cmd);
+
if (argc >= 2) m = atoi(argv[1]);
if (argc >= 3) n = atoi(argv[2]);
subtest = 0;
- errno = 0; if (!getitimer(-1, &it) || errno != EINVAL) e(1);
- errno = 0; if ( getitimer(timer, &it) ) e(2);
- errno = 0; if (!getitimer( 3, &it) || errno != EINVAL) e(3);
+ errno = 0; if (!getitimer(-1, &it) || errno != EINVAL) my_e(1);
+ errno = 0; if ( getitimer(timer, &it) ) my_e(2);
+ errno = 0; if (!getitimer( 3, &it) || errno != EINVAL) my_e(3);
}
/* test if we get back what we set */
subtest = 1;
/* no alarm should be set initially */
- if (getitimer(timer, &it)) e(1);
- if (!EQITIMER(it, 0, 0, 0, 0)) e(2);
+ if (getitimer(timer, &it)) my_e(1);
+ if (!EQITIMER(it, 0, 0, 0, 0)) my_e(2);
- if (setitimer(timer, &it, &oit)) e(3);
- if (setitimer(timer, &oit, NULL)) e(4);
- if (!EQITIMER(oit, 0, 0, 0, 0)) e(5);
+ if (setitimer(timer, &it, &oit)) my_e(3);
+ if (setitimer(timer, &oit, NULL)) my_e(4);
+ if (!EQITIMER(oit, 0, 0, 0, 0)) my_e(5);
FILLITIMER(it, 123, 0, 456, 0);
- if (setitimer(timer, &it, NULL)) e(6);
+ if (setitimer(timer, &it, NULL)) my_e(6);
FILLITIMER(it, 987, 0, 654, 0);
- if (setitimer(timer, &it, &oit)) e(7);
- if (!LEITIMER(oit, 123, 0, 456, 0)) e(8);
+ if (setitimer(timer, &it, &oit)) my_e(7);
+ if (!LEITIMER(oit, 123, 0, 456, 0)) my_e(8);
- if (getitimer(timer, &oit)) e(9);
- if (!LEITIMER(oit, 987, 0, 654, 0)) e(10);
+ if (getitimer(timer, &oit)) my_e(9);
+ if (!LEITIMER(oit, 987, 0, 654, 0)) my_e(10);
FILLITIMER(it, 0, 0, 0, 0);
- if (setitimer(timer, &it, &oit)) e(11);
- if (!LEITIMER(oit, 987, 0, 654, 0)) e(12);
+ if (setitimer(timer, &it, &oit)) my_e(11);
+ if (!LEITIMER(oit, 987, 0, 654, 0)) my_e(12);
- if (getitimer(timer, &oit)) e(13);
- if (!EQITIMER(oit, 0, 0, 0, 0)) e(14);
+ if (getitimer(timer, &oit)) my_e(13);
+ if (!EQITIMER(oit, 0, 0, 0, 0)) my_e(14);
}
/* test negative/large values */
subtest = 2;
FILLITIMER(it, 4, 0, 5, 0);
- if (setitimer(timer, &it, NULL)) e(1);
+ if (setitimer(timer, &it, NULL)) my_e(1);
FILLITIMER(it, 1000000000, 0, 0, 0);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(2);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(2);
FILLITIMER(it, 0, 1000000, 0, 0);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(3);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(3);
FILLITIMER(it, 0, 0, 0, 1000000);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(4);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(4);
FILLITIMER(it, -1, 0, 0, 0);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(5);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(5);
FILLITIMER(it, 0, -1, 0, 0);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(6);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(6);
FILLITIMER(it, 0, 0, -1, 0);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(7);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(7);
FILLITIMER(it, 0, 0, 0, -1);
- if (!setitimer(timer, &it, NULL) || errno != EINVAL) e(8);
+ if (!setitimer(timer, &it, NULL) || errno != EINVAL) my_e(8);
- if (getitimer(timer, &it)) e(9);
- if (!LEITIMER(it, 4, 0, 5, 0)) e(10);
+ if (getitimer(timer, &it)) my_e(9);
+ if (!LEITIMER(it, 4, 0, 5, 0)) my_e(10);
}
/* setitimer with a zero timer has to set the interval to zero as well */
it.it_interval.tv_sec = 1;
it.it_interval.tv_usec = 1;
- if (setitimer(timer, &it, NULL)) e(1);
- if (getitimer(timer, &it)) e(2);
- if (!EQITIMER(it, 0, 0, 0, 0)) e(3);
+ if (setitimer(timer, &it, NULL)) my_e(1);
+ if (getitimer(timer, &it)) my_e(2);
+ if (!EQITIMER(it, 0, 0, 0, 0)) my_e(3);
}
/* test actual timer functioning */
subtest = 4;
- if (signal(sigs[timer], got_alarm) == SIG_ERR) e(1);
+ if (signal(sigs[timer], got_alarm) == SIG_ERR) my_e(1);
FILLITIMER(it, 0, 1, 0, 1);
- if (setitimer(timer, &it, NULL)) e(2);
+ if (setitimer(timer, &it, NULL)) my_e(2);
signals = 0;
busy_wait(1);
FILLITIMER(it, 0, 0, 0, 0);
- if (setitimer(timer, &it, NULL)) e(3);
+ if (setitimer(timer, &it, NULL)) my_e(3);
/* we don't know how many signals we'll actually get in practice,
* so these checks more or less cover the extremes of the acceptable */
- if (signals < 2) e(4);
- if (signals > system_hz * 2) e(5);
+ if (signals < 2) my_e(4);
+ if (signals > system_hz * 2) my_e(5);
/* only for REAL timer can we check against the clock */
if (timer == ITIMER_REAL) {
FILLITIMER(it, 1, 0, 0, 0);
- if (setitimer(timer, &it, NULL)) e(6);
+ if (setitimer(timer, &it, NULL)) my_e(6);
signals = 0;
busy_wait(1);
FILLITIMER(it, 0, 0, 0, 0);
- if (setitimer(timer, &it, NULL)) e(7);
+ if (setitimer(timer, &it, NULL)) my_e(7);
- if (signals != 1) e(8);
+ if (signals != 1) my_e(8);
}
signals = 0;
busy_wait(1);
- if (signals != 0) e(9);
+ if (signals != 0) my_e(9);
}
/* test itimer/alarm interaction */
subtest = 5;
- if (signal(SIGALRM, got_alarm) == SIG_ERR) e(1);
+ if (signal(SIGALRM, got_alarm) == SIG_ERR) my_e(1);
FILLITIMER(it, 3, 0, 1, 0);
- if (setitimer(timer, &it, NULL)) e(2);
+ if (setitimer(timer, &it, NULL)) my_e(2);
- if (alarm(2) != 3) e(3);
+ if (alarm(2) != 3) my_e(3);
- if (getitimer(timer, &it)) e(4);
- if (!LEITIMER(it, 2, 0, 0, 0)) e(5);
+ if (getitimer(timer, &it)) my_e(4);
+ if (!LEITIMER(it, 2, 0, 0, 0)) my_e(5);
signals = 0;
busy_wait(5);
- if (signals != 1) e(6);
+ if (signals != 1) my_e(6);
- if (getitimer(timer, &it)) e(7);
- if (!EQITIMER(it, 0, 0, 0, 0)) e(8);
+ if (getitimer(timer, &it)) my_e(7);
+ if (!EQITIMER(it, 0, 0, 0, 0)) my_e(8);
}
/* test that the timer is reset on forking */
FILLITIMER(it, 12, 34, 56, 78);
- if (setitimer(timer, &it, NULL)) e(1);
+ if (setitimer(timer, &it, NULL)) my_e(1);
pid = fork();
- if (pid < 0) e(2);
+ if (pid < 0) my_e(2);
if (pid == 0) {
if (getitimer(timer, &it)) exit(5);
exit(0);
}
- if (wait(&status) != pid) e(3);
- if (!WIFEXITED(status)) e(4);
- if (WEXITSTATUS(status) != 0) e(WEXITSTATUS(status));
+ if (wait(&status) != pid) my_e(3);
+ if (!WIFEXITED(status)) my_e(4);
+ if (WEXITSTATUS(status) != 0) my_e(WEXITSTATUS(status));
FILLITIMER(it, 0, 0, 0, 0);
- if (setitimer(timer, &it, &oit)) e(7);
- if (!LEITIMER(oit, 12, 34, 56, 78)) e(8);
+ if (setitimer(timer, &it, &oit)) my_e(7);
+ if (!LEITIMER(oit, 12, 34, 56, 78)) my_e(8);
}
/* test if timer is carried over to exec()'ed process */
subtest = 7;
pid = fork();
- if (pid < 0) e(1);
+ if (pid < 0) my_e(1);
if (pid == 0) {
FILLITIMER(it, 3, 0, 1, 0);
exit(3);
}
- if (wait(&status) != pid) e(4);
+ if (wait(&status) != pid) my_e(4);
if (WIFSIGNALED(status)) {
/* process should have died from corresponding signal */
- if (WTERMSIG(status) != sigs[timer]) e(5);
+ if (WTERMSIG(status) != sigs[timer]) my_e(5);
}
else {
- if (WIFEXITED(status)) e(WEXITSTATUS(status));
- else e(6);
+ if (WIFEXITED(status)) my_e(WEXITSTATUS(status));
+ else my_e(6);
}
}
void got_alarm(sig)
int sig;
{
- if (sig != sigs[timer]) e(1001);
+ if (sig != sigs[timer]) my_e(1001);
signals++;
}
-void e(n)
+void my_e(n)
int n;
{
- printf("Timer %s, subtest %d, error %d, errno %d: %s\n",
- names[timer], subtest, n, errno, strerror(errno));
-
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- exit(1);
- }
-}
-
-void quit()
-{
-
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
+ printf("Timer %s, ", names[timer]);
+ e(n);
}
#define ITERATIONS 3
#define MAX_ERROR 4
+#include "common.c"
#define _WIFSTOPPED(s) (WIFSTOPPED(s) && !WIFSIGNALED(s) && !WIFEXITED(s))
#define _WIFSIGNALED(s) (!WIFSTOPPED(s) && WIFSIGNALED(s) && !WIFEXITED(s))
_PROTOTYPE(void test_defexec, (void));
_PROTOTYPE(void test_reattach_child, (void));
_PROTOTYPE(void test_reattach, (void));
-_PROTOTYPE(void e, (int n));
-_PROTOTYPE(void quit, (void));
+_PROTOTYPE(void my_e, (int n));
static char *executable;
-static int errct = 0, subtest;
static int child = 0, attach;
static pid_t ppid;
static int pfd[4];
char **argv;
{
int i, m = 0xFFFFFF, n = 0xF;
+ char cp_cmd[NAME_MAX + 10];
if (strcmp(argv[0], "DO CHECK") == 0) {
exit(42);
}
- printf("Test 42 ");
- fflush(stdout);
+ start(42);
executable = argv[0];
+ snprintf(cp_cmd, sizeof(cp_cmd), "cp ../%s .", executable);
+ system(cp_cmd);
+
if (argc >= 2) m = atoi(argv[1]);
if (argc >= 3) n = atoi(argv[2]);
void timed_test_timeout(int signum)
{
longjmp(timed_test_context, -1);
- e(700);
+ my_e(700);
quit();
exit(-1);
}
if (setjmp(timed_test_context) == 0)
{
/* the function gets 60 seconds to complete */
- if (signal(SIGALRM, timed_test_timeout) == SIG_ERR) { e(701); return; }
+ if (signal(SIGALRM, timed_test_timeout) == SIG_ERR) { my_e(701); return; }
alarm(60);
func();
alarm(0);
{
/* report timeout as error */
printf("timeout in %s\n", s);
- e(702);
+ my_e(702);
}
}
pid_t pid;
int r, status;
- if (pipe(pfd) != 0) e(200);
- if (pipe(&pfd[2]) != 0) e(201);
+ if (pipe(pfd) != 0) my_e(200);
+ if (pipe(&pfd[2]) != 0) my_e(201);
switch (attach) {
case 0: /* let child volunteer to be traced */
pid = fork();
- if (pid < 0) e(202);
+ if (pid < 0) my_e(202);
if (pid == 0) {
child = 1;
- if (ptrace(T_OK, 0, 0, 0) != 0) e(203);
+ if (ptrace(T_OK, 0, 0, 0) != 0) my_e(203);
WRITE(0);
c();
- e(204);
+ my_e(204);
}
- if (READ() != 0) e(205);
+ if (READ() != 0) my_e(205);
break;
case 1: /* attach to child process */
pid = fork();
- if (pid < 0) e(206);
+ if (pid < 0) my_e(206);
if (pid == 0) {
child = 1;
- if (READ() != 0) e(207);
+ if (READ() != 0) my_e(207);
c();
- e(208);
+ my_e(208);
}
- if (ptrace(T_ATTACH, pid, 0, 0) != 0) e(209);
+ if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(209);
- if (waitpid(pid, &status, 0) != pid) e(210);
- if (!_WIFSTOPPED(status)) e(211);
- if (WSTOPSIG(status) != SIGSTOP) e(212);
+ if (waitpid(pid, &status, 0) != pid) my_e(210);
+ if (!_WIFSTOPPED(status)) my_e(211);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(212);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(213);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(213);
WRITE(0);
case 2: /* attach to non-child process */
ppid = fork();
- if (ppid < 0) e(214);
+ if (ppid < 0) my_e(214);
if (ppid == 0) {
pid = fork();
if (pid == 0) {
child = 1;
- if (READ() != 0) e(216);
+ if (READ() != 0) my_e(216);
c();
- e(217);
+ my_e(217);
}
child = 1;
WRITE(pid);
- if (waitpid(pid, &status, 0) != pid) e(218);
- if (_WIFSTOPPED(status)) e(219);
- if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(218);
+ if (_WIFSTOPPED(status)) my_e(219);
+ if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) my_e(r);
exit(0);
}
pid = READ();
- if (ptrace(T_ATTACH, pid, 0, 0) != 0) e(220);
+ if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(220);
- if (waitpid(pid, &status, 0) != pid) e(221);
- if (!_WIFSTOPPED(status)) e(222);
- if (WSTOPSIG(status) != SIGSTOP) e(223);
+ if (waitpid(pid, &status, 0) != pid) my_e(221);
+ if (!_WIFSTOPPED(status)) my_e(222);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(223);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(224);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(224);
WRITE(0);
case 3: /* attach by forking from child */
ppid = fork();
- if (ppid < 0) e(225);
+ if (ppid < 0) my_e(225);
if (ppid == 0) {
child = 1;
- if (ptrace(T_OK, 0, 0, 0) != 0) e(226);
+ if (ptrace(T_OK, 0, 0, 0) != 0) my_e(226);
WRITE(0);
- if (READ() != 0) e(227);
+ if (READ() != 0) my_e(227);
pid = fork();
- if (pid < 0) e(228);
+ if (pid < 0) my_e(228);
if (pid == 0) {
c();
- e(229);
+ my_e(229);
}
WRITE(pid);
- if (waitpid(pid, &status, 0) != pid) e(230);
- if (_WIFSTOPPED(status)) e(231);
- if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(230);
+ if (_WIFSTOPPED(status)) my_e(231);
+ if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) my_e(r);
exit(0);
}
- if (READ() != 0) e(232);
+ if (READ() != 0) my_e(232);
- if (kill(ppid, SIGSTOP) != 0) e(233);
+ if (kill(ppid, SIGSTOP) != 0) my_e(233);
- if (waitpid(ppid, &status, 0) != ppid) e(234);
- if (!_WIFSTOPPED(status)) e(235);
- if (WSTOPSIG(status) != SIGSTOP) e(236);
+ if (waitpid(ppid, &status, 0) != ppid) my_e(234);
+ if (!_WIFSTOPPED(status)) my_e(235);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(236);
- if (ptrace(T_SETOPT, ppid, 0, TO_TRACEFORK) != 0) e(237);
+ if (ptrace(T_SETOPT, ppid, 0, TO_TRACEFORK) != 0) my_e(237);
- if (ptrace(T_RESUME, ppid, 0, 0) != 0) e(238);
+ if (ptrace(T_RESUME, ppid, 0, 0) != 0) my_e(238);
WRITE(0);
pid = READ();
- if (waitpid(pid, &status, 0) != pid) e(239);
- if (!_WIFSTOPPED(status)) e(240);
- if (WSTOPSIG(status) != SIGSTOP) e(241);
+ if (waitpid(pid, &status, 0) != pid) my_e(239);
+ if (!_WIFSTOPPED(status)) my_e(240);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(241);
- if (ptrace(T_SETOPT, pid, 0, 0) != 0) e(242);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(243);
+ if (ptrace(T_SETOPT, pid, 0, 0) != 0) my_e(242);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(243);
detach_running(ppid);
{
pid_t pid;
- if (pipe(pfd) != 0) e(300);
- if (pipe(&pfd[2]) != 0) e(301);
+ if (pipe(pfd) != 0) my_e(300);
+ if (pipe(&pfd[2]) != 0) my_e(301);
pid = fork();
- if (pid < 0) e(302);
+ if (pid < 0) my_e(302);
if (pid == 0) {
child = 1;
c();
- e(303);
+ my_e(303);
}
return pid;
void WRITE(value)
int value;
{
- if (write(pfd[child*2+1], &value, sizeof(value)) != sizeof(value)) e(400);
+ if (write(pfd[child*2+1], &value, sizeof(value)) != sizeof(value)) my_e(400);
}
int READ()
{
int value;
- if (read(pfd[2-child*2], &value, sizeof(value)) != sizeof(value)) e(401);
+ if (read(pfd[2-child*2], &value, sizeof(value)) != sizeof(value)) my_e(401);
return value;
}
int r, status;
if (attach == 2) {
- if (waitpid(ppid, &status, 0) != ppid) e(500);
- if (!_WIFEXITED(status)) e(501);
- if ((r = WEXITSTATUS(status)) != 0) e(r);
+ if (waitpid(ppid, &status, 0) != ppid) my_e(500);
+ if (!_WIFEXITED(status)) my_e(501);
+ if ((r = WEXITSTATUS(status)) != 0) my_e(r);
}
else {
/* Quick hack to clean up detached children */
*/
int status;
- if (kill(pid, SIGSTOP) != 0) e(600);
+ if (kill(pid, SIGSTOP) != 0) my_e(600);
- if (waitpid(pid, &status, 0) != pid) e(601);
+ if (waitpid(pid, &status, 0) != pid) my_e(601);
while (_WIFSTOPPED(status)) {
if (WSTOPSIG(status) == SIGSTOP) {
- if (ptrace(T_DETACH, pid, 0, 0) != 0) e(602);
+ if (ptrace(T_DETACH, pid, 0, 0) != 0) my_e(602);
return;
}
- if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) e(603);
+ if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(603);
- if (waitpid(pid, &status, 0) != pid) e(604);
+ if (waitpid(pid, &status, 0) != pid) my_e(604);
}
/* Apparently the process exited. */
- if (!_WIFEXITED(status) && !_WIFSIGNALED(status)) e(605);
+ if (!_WIFEXITED(status) && !_WIFSIGNALED(status)) my_e(605);
/* In our tests, that should not happen. */
- e(606);
+ my_e(606);
}
void dummy_handler(sig)
case SIGUSR1: bit = 1; break;
case SIGUSR2: bit = 2; break;
case SIGTERM: bit = 4; break;
- default: e(100);
+ default: my_e(100);
}
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, NULL);
- if (caught & bit) e(101);
+ if (caught & bit) my_e(101);
caught |= bit;
}
pid = traced_fork(test_wait_child);
- if (waitpid(pid, &status, 0) != pid) e(1);
- if (!_WIFEXITED(status)) e(2);
- if (WEXITSTATUS(status) != 42) e(3);
+ if (waitpid(pid, &status, 0) != pid) my_e(1);
+ if (!_WIFEXITED(status)) my_e(2);
+ if (WEXITSTATUS(status) != 42) my_e(3);
traced_wait();
}
void test_exec_child()
{
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
execl(executable, "DO CHECK", NULL);
- e(101);
+ my_e(101);
}
void test_exec()
WRITE(0);
/* An exec() should result in a trap signal. */
- if (waitpid(pid, &status, 0) != pid) e(1);
- if (!_WIFSTOPPED(status)) e(2);
- if (WSTOPSIG(status) != SIGTRAP) e(3);
+ if (waitpid(pid, &status, 0) != pid) my_e(1);
+ if (!_WIFSTOPPED(status)) my_e(2);
+ if (WSTOPSIG(status) != SIGTRAP) my_e(3);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(4);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(4);
- if (waitpid(pid, &status, 0) != pid) e(5);
- if (!_WIFEXITED(status)) e(6);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(5);
+ if (!_WIFEXITED(status)) my_e(6);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
WRITE(0);
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
/* It must not be possible for the child to stop the single-step signal. */
signal(SIGTRAP, SIG_IGN);
pid = traced_fork(test_step_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
/* While the child is running, neither waitpid() nor ptrace() should work. */
- if (waitpid(pid, &status, WNOHANG) != 0) e(2);
- if (ptrace(T_RESUME, pid, 0, 0) != -1) e(3);
- if (errno != EBUSY) e(4);
+ if (waitpid(pid, &status, WNOHANG) != 0) my_e(2);
+ if (ptrace(T_RESUME, pid, 0, 0) != -1) my_e(3);
+ if (errno != EBUSY) my_e(4);
- if (kill(pid, SIGUSR1) != 0) e(5);
+ if (kill(pid, SIGUSR1) != 0) my_e(5);
WRITE(0);
/* A kill() signal (other than SIGKILL) should be delivered to the tracer. */
- if (waitpid(pid, &status, 0) != pid) e(6);
- if (!_WIFSTOPPED(status)) e(7);
- if (WSTOPSIG(status) != SIGUSR1) e(8);
+ if (waitpid(pid, &status, 0) != pid) my_e(6);
+ if (!_WIFSTOPPED(status)) my_e(7);
+ if (WSTOPSIG(status) != SIGUSR1) my_e(8);
/* ptrace(T_STEP) should result in instruction-wise progress. */
for (count = 0; ; count++) {
- if (ptrace(T_STEP, pid, 0, 0) != 0) e(9);
+ if (ptrace(T_STEP, pid, 0, 0) != 0) my_e(9);
- if (waitpid(pid, &status, 0) != pid) e(10);
+ if (waitpid(pid, &status, 0) != pid) my_e(10);
if (_WIFEXITED(status)) break;
- if (!_WIFSTOPPED(status)) e(11);
- if (WSTOPSIG(status) != SIGTRAP) e(12);
+ if (!_WIFSTOPPED(status)) my_e(11);
+ if (WSTOPSIG(status) != SIGTRAP) my_e(12);
}
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
- if (count < 10) e(13); /* in practice: hundreds */
+ if (count < 10) my_e(13); /* in practice: hundreds */
traced_wait();
}
{
signal(SIGUSR1, exit_handler);
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
pause();
- e(101);
+ my_e(101);
}
void test_sig()
/* allow the child to enter the pause */
sleep(1);
- if (kill(pid, SIGUSR1) != 0) e(1);
- if (kill(pid, SIGUSR2) != 0) e(2);
+ if (kill(pid, SIGUSR1) != 0) my_e(1);
+ if (kill(pid, SIGUSR2) != 0) my_e(2);
/* All signals should arrive at the tracer, although in "random" order. */
- if (waitpid(pid, &status, 0) != pid) e(3);
- if (!_WIFSTOPPED(status)) e(4);
- if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) e(5);
+ if (waitpid(pid, &status, 0) != pid) my_e(3);
+ if (!_WIFSTOPPED(status)) my_e(4);
+ if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(5);
/* The tracer should see kills arriving while the tracee is stopped. */
- if (kill(pid, WSTOPSIG(status)) != 0) e(6);
+ if (kill(pid, WSTOPSIG(status)) != 0) my_e(6);
- if (waitpid(pid, &status, WNOHANG) != pid) e(7);
- if (!_WIFSTOPPED(status)) e(8);
- if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) e(9);
+ if (waitpid(pid, &status, WNOHANG) != pid) my_e(7);
+ if (!_WIFSTOPPED(status)) my_e(8);
+ if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(9);
sig = (WSTOPSIG(status) == SIGUSR1) ? SIGUSR2 : SIGUSR1;
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(10);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(10);
- if (waitpid(pid, &status, 0) != pid) e(11);
- if (!_WIFSTOPPED(status)) e(12);
- if (WSTOPSIG(status) != sig) e(13);
+ if (waitpid(pid, &status, 0) != pid) my_e(11);
+ if (!_WIFSTOPPED(status)) my_e(12);
+ if (WSTOPSIG(status) != sig) my_e(13);
- if (waitpid(pid, &status, WNOHANG) != 0) e(14);
+ if (waitpid(pid, &status, WNOHANG) != 0) my_e(14);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(15);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(15);
/* Ignored signals passed via ptrace() should be ignored. */
- if (kill(pid, SIGUSR1) != 0) e(16);
+ if (kill(pid, SIGUSR1) != 0) my_e(16);
- if (waitpid(pid, &status, 0) != pid) e(17);
- if (!_WIFSTOPPED(status)) e(18);
- if (WSTOPSIG(status) != SIGUSR1) e(19);
+ if (waitpid(pid, &status, 0) != pid) my_e(17);
+ if (!_WIFSTOPPED(status)) my_e(18);
+ if (WSTOPSIG(status) != SIGUSR1) my_e(19);
- if (ptrace(T_RESUME, pid, 0, SIGCHLD) != 0) e(20);
+ if (ptrace(T_RESUME, pid, 0, SIGCHLD) != 0) my_e(20);
/* if the pause has been aborted (shouldn't happen!), let the child exit */
sleep(1);
- if (waitpid(pid, &status, WNOHANG) != 0) e(21);
+ if (waitpid(pid, &status, WNOHANG) != 0) my_e(21);
/* Caught signals passed via ptrace() should invoke their signal handlers. */
- if (kill(pid, SIGUSR1) != 0) e(22);
+ if (kill(pid, SIGUSR1) != 0) my_e(22);
- if (waitpid(pid, &status, 0) != pid) e(23);
- if (!_WIFSTOPPED(status)) e(24);
- if (WSTOPSIG(status) != SIGUSR1) e(25);
+ if (waitpid(pid, &status, 0) != pid) my_e(23);
+ if (!_WIFSTOPPED(status)) my_e(24);
+ if (WSTOPSIG(status) != SIGUSR1) my_e(25);
- if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) e(26);
+ if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(26);
- if (waitpid(pid, &status, 0) != pid) e(27);
- if (!_WIFEXITED(status)) e(28);
- if ((r = WEXITSTATUS(status)) != 42) e(29);
+ if (waitpid(pid, &status, 0) != pid) my_e(27);
+ if (!_WIFEXITED(status)) my_e(28);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(29);
traced_wait();
}
pid = traced_fork(test_exit_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
sleep(1);
- if (kill(pid, SIGSTOP) != 0) e(2);
+ if (kill(pid, SIGSTOP) != 0) my_e(2);
- if (waitpid(pid, &status, 0) != pid) e(3);
- if (!_WIFSTOPPED(status)) e(4);
- if (WSTOPSIG(status) != SIGSTOP) e(5);
+ if (waitpid(pid, &status, 0) != pid) my_e(3);
+ if (!_WIFSTOPPED(status)) my_e(4);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(5);
/* There should be no more signals pending for the tracer now. */
- if (waitpid(pid, &status, WNOHANG) != 0) e(6);
+ if (waitpid(pid, &status, WNOHANG) != 0) my_e(6);
/* ptrace(T_EXIT) should terminate the process with the given exit value. */
- if (ptrace(T_EXIT, pid, 0, 42) != 0) e(7);
+ if (ptrace(T_EXIT, pid, 0, 42) != 0) my_e(7);
- if (waitpid(pid, &status, 0) != pid) e(8);
- if (!_WIFEXITED(status)) e(9);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(8);
+ if (!_WIFEXITED(status)) my_e(9);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
pause();
- e(100);
+ my_e(100);
}
void test_term()
pid = traced_fork(test_term_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
/* If the first of two signals terminates the traced child, the second signal
* may or may not be delivered to the tracer - this is merely a policy issue.
* However, nothing unexpected should happen.
*/
- if (kill(pid, SIGUSR1) != 0) e(2);
- if (kill(pid, SIGUSR2) != 0) e(3);
+ if (kill(pid, SIGUSR1) != 0) my_e(2);
+ if (kill(pid, SIGUSR2) != 0) my_e(3);
- if (waitpid(pid, &status, 0) != pid) e(4);
- if (!_WIFSTOPPED(status)) e(5);
+ if (waitpid(pid, &status, 0) != pid) my_e(4);
+ if (!_WIFSTOPPED(status)) my_e(5);
- if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) e(6);
+ if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(6);
- if (waitpid(pid, &status, 0) != pid) e(7);
+ if (waitpid(pid, &status, 0) != pid) my_e(7);
if (_WIFSTOPPED(status)) {
- if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) e(8);
+ if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(8);
- if (waitpid(pid, &status, 0) != pid) e(9);
+ if (waitpid(pid, &status, 0) != pid) my_e(9);
}
- if (!_WIFSIGNALED(status)) e(10);
- if (WTERMSIG(status) != SIGUSR1) e(11);
+ if (!_WIFSIGNALED(status)) my_e(10);
+ if (WTERMSIG(status) != SIGUSR1) my_e(11);
traced_wait();
}
pid = traced_fork(test_catch_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
- if (kill(pid, SIGUSR1) != 0) e(2);
- if (kill(pid, SIGUSR2) != 0) e(3);
+ if (kill(pid, SIGUSR1) != 0) my_e(2);
+ if (kill(pid, SIGUSR2) != 0) my_e(3);
- if (waitpid(pid, &status, 0) != pid) e(4);
- if (!_WIFSTOPPED(status)) e(5);
- if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) e(6);
+ if (waitpid(pid, &status, 0) != pid) my_e(4);
+ if (!_WIFSTOPPED(status)) my_e(5);
+ if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(6);
sig = (WSTOPSIG(status) == SIGUSR1) ? SIGUSR2 : SIGUSR1;
- if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) e(7);
+ if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(7);
- if (kill(pid, SIGTERM) != 0) e(8);
+ if (kill(pid, SIGTERM) != 0) my_e(8);
- if (waitpid(pid, &status, 0) != pid) e(9);
- if (!_WIFSTOPPED(status)) e(10);
- if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGTERM) e(11);
+ if (waitpid(pid, &status, 0) != pid) my_e(9);
+ if (!_WIFSTOPPED(status)) my_e(10);
+ if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGTERM) my_e(11);
if (WSTOPSIG(status) == sig) sig = SIGTERM;
- if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) e(12);
+ if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(12);
- if (kill(pid, SIGBUS) != 0) e(13);
+ if (kill(pid, SIGBUS) != 0) my_e(13);
- if (waitpid(pid, &status, 0) != pid) e(14);
- if (!_WIFSTOPPED(status)) e(15);
- if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGBUS) e(16);
+ if (waitpid(pid, &status, 0) != pid) my_e(14);
+ if (!_WIFSTOPPED(status)) my_e(15);
+ if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGBUS) my_e(16);
- if (ptrace(T_RESUME, pid, 0, sig) != 0) e(17);
+ if (ptrace(T_RESUME, pid, 0, sig) != 0) my_e(17);
if (WSTOPSIG(status) == sig) sig = SIGBUS;
- if (waitpid(pid, &status, 0) != pid) e(18);
- if (!_WIFSTOPPED(status)) e(19);
- if (WSTOPSIG(status) != sig) e(20);
+ if (waitpid(pid, &status, 0) != pid) my_e(18);
+ if (!_WIFSTOPPED(status)) my_e(19);
+ if (WSTOPSIG(status) != sig) my_e(20);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(21);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(21);
- if (waitpid(pid, &status, 0) != pid) e(22);
- if (!_WIFEXITED(status)) e(23);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(22);
+ if (!_WIFEXITED(status)) my_e(23);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
pause();
- e(100);
+ my_e(100);
}
void test_kill()
pid = traced_fork(test_kill_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
/* SIGKILL must be unstoppable in every way. */
- if (kill(pid, SIGKILL) != 0) e(2);
+ if (kill(pid, SIGKILL) != 0) my_e(2);
- if (waitpid(pid, &status, 0) != pid) e(3);
- if (!_WIFSIGNALED(status)) e(4);
- if (WTERMSIG(status) != SIGKILL) e(5);
+ if (waitpid(pid, &status, 0) != pid) my_e(3);
+ if (!_WIFSIGNALED(status)) my_e(4);
+ if (WTERMSIG(status) != SIGKILL) my_e(5);
/* After termination, the child must no longer be visible to the tracer. */
- if (waitpid(pid, &status, WNOHANG) != -1) e(6);
- if (errno != ECHILD) e(7);
+ if (waitpid(pid, &status, WNOHANG) != -1) my_e(6);
+ if (errno != ECHILD) my_e(7);
traced_wait();
}
void test_attach_child()
{
- if (ptrace(T_OK, 0, 0, 0) != -1) e(100);
- if (errno != EBUSY) e(101);
+ if (ptrace(T_OK, 0, 0, 0) != -1) my_e(100);
+ if (errno != EBUSY) my_e(101);
WRITE(0);
- if (READ() != 0) e(102);
+ if (READ() != 0) my_e(102);
exit(42);
}
subtest = 9;
/* Attaching to kernel processes is not allowed. */
- if (ptrace(T_ATTACH, -1, 0, 0) != -1) e(1);
- if (errno != ESRCH) e(2);
+ if (ptrace(T_ATTACH, -1, 0, 0) != -1) my_e(1);
+ if (errno != ESRCH) my_e(2);
/* Attaching to self is not allowed. */
- if (ptrace(T_ATTACH, getpid(), 0, 0) != -1) e(3);
- if (errno != EPERM) e(4);
+ if (ptrace(T_ATTACH, getpid(), 0, 0) != -1) my_e(3);
+ if (errno != EPERM) my_e(4);
/* Attaching to PM is not allowed. */
#if 0
/* FIXME: disabled until we can reliably determine PM's pid */
- if (ptrace(T_ATTACH, 0, 0, 0) != -1) e(5);
- if (errno != EPERM) e(6);
+ if (ptrace(T_ATTACH, 0, 0, 0) != -1) my_e(5);
+ if (errno != EPERM) my_e(6);
#endif
pid = traced_fork(test_attach_child);
/* Attaching more than once is not allowed. */
- if (ptrace(T_ATTACH, pid, 0, 0) != -1) e(7);
- if (errno != EBUSY) e(8);
+ if (ptrace(T_ATTACH, pid, 0, 0) != -1) my_e(7);
+ if (errno != EBUSY) my_e(8);
- if (READ() != 0) e(9);
+ if (READ() != 0) my_e(9);
/* Detaching a running child should not succeed. */
- if (ptrace(T_DETACH, pid, 0, 0) == 0) e(10);
- if (errno != EBUSY) e(11);
+ if (ptrace(T_DETACH, pid, 0, 0) == 0) my_e(10);
+ if (errno != EBUSY) my_e(11);
detach_running(pid);
WRITE(0);
- if (sigsuspend(&sset) != -1) e(102);
- if (errno != EINTR) e(103);
+ if (sigsuspend(&sset) != -1) my_e(102);
+ if (errno != EINTR) my_e(103);
- if (caught != 1) e(104);
+ if (caught != 1) my_e(104);
- if (READ() != 0) e(105);
+ if (READ() != 0) my_e(105);
while (caught != 7) sigsuspend(&oset);
pid = traced_pfork(test_detach_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
/* The tracer should not see signals sent to the process before attaching. */
- if (kill(pid, SIGUSR2) != 0) e(2);
+ if (kill(pid, SIGUSR2) != 0) my_e(2);
- if (ptrace(T_ATTACH, pid, 0, 0) != 0) e(3);
+ if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(3);
- if (waitpid(pid, &status, 0) != pid) e(4);
- if (!_WIFSTOPPED(status)) e(5);
- if (WSTOPSIG(status) != SIGSTOP) e(6);
+ if (waitpid(pid, &status, 0) != pid) my_e(4);
+ if (!_WIFSTOPPED(status)) my_e(5);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(6);
- if (ptrace(T_RESUME, pid, 0, 0) != 0) e(7);
+ if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(7);
- if (kill(pid, SIGUSR1) != 0) e(8);
+ if (kill(pid, SIGUSR1) != 0) my_e(8);
- if (waitpid(pid, &status, 0) != pid) e(9);
- if (!_WIFSTOPPED(status)) e(10);
- if (WSTOPSIG(status) != SIGUSR1) e(11);
+ if (waitpid(pid, &status, 0) != pid) my_e(9);
+ if (!_WIFSTOPPED(status)) my_e(10);
+ if (WSTOPSIG(status) != SIGUSR1) my_e(11);
/* Signals pending at the tracer should be passed on after detaching. */
- if (kill(pid, SIGTERM) != 0) e(12);
+ if (kill(pid, SIGTERM) != 0) my_e(12);
/* A signal may be passed with the detach request. */
- if (ptrace(T_DETACH, pid, 0, SIGUSR1) != 0) e(13);
+ if (ptrace(T_DETACH, pid, 0, SIGUSR1) != 0) my_e(13);
WRITE(0);
- if (waitpid(pid, &status, 0) != pid) e(14);
- if (!_WIFEXITED(status)) e(15);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(14);
+ if (!_WIFEXITED(status)) my_e(15);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
pid = fork();
- if (pid < 0) e(100);
+ if (pid < 0) my_e(100);
if (pid == 0) {
ptrace(T_OK, 0, 0, 0);
for (;;) pause();
}
- if (READ() != 0) e(101);
+ if (READ() != 0) my_e(101);
kill(getpid(), SIGKILL);
- e(102);
+ my_e(102);
}
void test_death()
cpid = READ();
- if (kill(cpid, 0) != 0) e(1);
+ if (kill(cpid, 0) != 0) my_e(1);
WRITE(0);
- if (waitpid(pid, &status, 0) != pid) e(2);
- if (!_WIFSIGNALED(status)) e(3);
- if (WTERMSIG(status) != SIGKILL) e(4);
+ if (waitpid(pid, &status, 0) != pid) my_e(2);
+ if (!_WIFSIGNALED(status)) my_e(3);
+ if (WTERMSIG(status) != SIGKILL) my_e(4);
/* The children of killed tracers should be terminated. */
while (kill(cpid, 0) == 0) sleep(1);
- if (errno != ESRCH) e(5);
+ if (errno != ESRCH) my_e(5);
traced_wait();
}
void test_zdeath_child()
{
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
exit(42);
}
tpid = fork();
- if (tpid < 0) e(1);
+ if (tpid < 0) my_e(1);
if (tpid == 0) {
if (ptrace(T_ATTACH, pid, 0, 0) != 0) exit(101);
sleep(1);
/* However, that should only happen once the tracer has actually died. */
- if (waitpid(pid, &status, WNOHANG) != 0) e(2);
+ if (waitpid(pid, &status, WNOHANG) != 0) my_e(2);
- if (waitpid(tpid, &status, 0) != tpid) e(3);
- if (!_WIFEXITED(status)) e(4);
- if ((r = WEXITSTATUS(status)) != 84) e(r);
+ if (waitpid(tpid, &status, 0) != tpid) my_e(3);
+ if (!_WIFEXITED(status)) my_e(4);
+ if ((r = WEXITSTATUS(status)) != 84) my_e(r);
- if (waitpid(pid, &status, 0) != pid) e(5);
- if (!_WIFEXITED(status)) e(6);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (waitpid(pid, &status, 0) != pid) my_e(5);
+ if (!_WIFEXITED(status)) my_e(6);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
WRITE(0);
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
/* Three calls (may fail) */
setuid(0);
close(123);
getpid();
- if (sigs != 2) e(101);
+ if (sigs != 2) my_e(101);
exit(42);
}
pid = traced_fork(test_syscall_child);
- if (READ() != 0) e(1);
+ if (READ() != 0) my_e(1);
- if (kill(pid, SIGSTOP) != 0) e(2);
+ if (kill(pid, SIGSTOP) != 0) my_e(2);
- if (waitpid(pid, &status, 0) != pid) e(3);
- if (!_WIFSTOPPED(status)) e(4);
- if (WSTOPSIG(status) != SIGSTOP) e(5);
+ if (waitpid(pid, &status, 0) != pid) my_e(3);
+ if (!_WIFSTOPPED(status)) my_e(4);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(5);
WRITE(0);
/* Upon resuming a first system call, no syscall leave event must be sent. */
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(6);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(6);
- if (waitpid(pid, &status, 0) != pid) e(7);
+ if (waitpid(pid, &status, 0) != pid) my_e(7);
for (i = 0; _WIFSTOPPED(status); i++) {
- if (WSTOPSIG(status) != SIGTRAP) e(8);
+ if (WSTOPSIG(status) != SIGTRAP) my_e(8);
/* Signals passed via T_SYSCALL should arrive, on enter and exit. */
if (i == 3) sig = SIGUSR1;
else if (i == 6) sig = SIGUSR2;
else sig = 0;
- if (ptrace(T_SYSCALL, pid, 0, sig) != 0) e(9);
+ if (ptrace(T_SYSCALL, pid, 0, sig) != 0) my_e(9);
- if (waitpid(pid, &status, 0) != pid) e(10);
+ if (waitpid(pid, &status, 0) != pid) my_e(10);
}
- if (!_WIFEXITED(status)) e(11);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (!_WIFEXITED(status)) my_e(11);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
/* The number of events seen is deterministic but libc-dependent. */
- if (i < 10 || i > 100) e(12);
+ if (i < 10 || i > 100) my_e(12);
/* The last system call event must be for entering exit(). */
- if (!(i % 2)) e(13);
+ if (!(i % 2)) my_e(13);
traced_wait();
}
WRITE(pid);
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
- if ((pid = fork()) < 0) e(101);
+ if ((pid = fork()) < 0) my_e(101);
exit(pid > 0 ? 42 : 84);
}
ppid = traced_fork(test_tracefork_child);
- if ((pgrp = READ()) <= 0) e(1);
+ if ((pgrp = READ()) <= 0) my_e(1);
- if (kill(ppid, SIGSTOP) != 0) e(2);
+ if (kill(ppid, SIGSTOP) != 0) my_e(2);
- if (waitpid(ppid, &status, 0) != ppid) e(3);
- if (!_WIFSTOPPED(status)) e(4);
- if (WSTOPSIG(status) != SIGSTOP) e(5);
+ if (waitpid(ppid, &status, 0) != ppid) my_e(3);
+ if (!_WIFSTOPPED(status)) my_e(4);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(5);
- if (ptrace(T_SETOPT, ppid, 0, TO_TRACEFORK) != 0) e(6);
+ if (ptrace(T_SETOPT, ppid, 0, TO_TRACEFORK) != 0) my_e(6);
WRITE(0);
- if (ptrace(T_SYSCALL, ppid, 0, 0) != 0) e(7);
+ if (ptrace(T_SYSCALL, ppid, 0, 0) != 0) my_e(7);
cpid = -1;
gotstop = -1;
for (ptraps = ctraps = 0; ppid || cpid; ) {
wpid = waitpid(-pgrp, &status, 0);
- if (wpid <= 0) e(8);
+ if (wpid <= 0) my_e(8);
if (cpid < 0 && wpid != ppid) {
cpid = wpid;
gotstop = 0;
}
- if (wpid != ppid && wpid != cpid) e(9);
+ if (wpid != ppid && wpid != cpid) my_e(9);
if (_WIFEXITED(status)) {
if (wpid == ppid) {
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
ppid = 0;
}
else {
- if ((r = WEXITSTATUS(status)) != 84) e(r);
+ if ((r = WEXITSTATUS(status)) != 84) my_e(r);
cpid = 0;
}
}
else {
- if (!_WIFSTOPPED(status)) e(10);
+ if (!_WIFSTOPPED(status)) my_e(10);
switch (WSTOPSIG(status)) {
case SIGCHLD:
case SIGHUP:
break;
case SIGSTOP:
- if (wpid != cpid) e(11);
- if (gotstop) e(12);
+ if (wpid != cpid) my_e(11);
+ if (gotstop) my_e(12);
gotstop = 1;
break;
case SIGTRAP:
else ctraps++;
break;
default:
- e(13);
+ my_e(13);
}
- if (ptrace(T_SYSCALL, wpid, 0, 0) != 0) e(14);
+ if (ptrace(T_SYSCALL, wpid, 0, 0) != 0) my_e(14);
}
}
* enter trap (typically for the fork()), the last one is the syscall enter
* trap for its exit().
*/
- if (ptraps < 3) e(15);
- if (!(ptraps % 2)) e(16);
+ if (ptraps < 3) my_e(15);
+ if (!(ptraps % 2)) my_e(16);
/* The child should get an even number of traps: the first one is a syscall
* leave trap from the fork(), the last one is the syscall enter trap for
* its exit().
*/
- if (ctraps < 2) e(17);
- if (ctraps % 2) e(18);
+ if (ctraps < 2) my_e(17);
+ if (ctraps % 2) my_e(18);
traced_wait();
}
pid = traced_fork(test_exec_child);
- if (kill(pid, SIGSTOP) != 0) e(1);
+ if (kill(pid, SIGSTOP) != 0) my_e(1);
- if (waitpid(pid, &status, 0) != pid) e(2);
- if (!_WIFSTOPPED(status)) e(3);
- if (WSTOPSIG(status) != SIGSTOP) e(4);
+ if (waitpid(pid, &status, 0) != pid) my_e(2);
+ if (!_WIFSTOPPED(status)) my_e(3);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(4);
- if (setflag && ptrace(T_SETOPT, pid, 0, opt) != 0) e(5);
+ if (setflag && ptrace(T_SETOPT, pid, 0, opt) != 0) my_e(5);
WRITE(0);
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(6);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(6);
*traps = 0;
*stop = -1;
for (;;) {
- if (waitpid(pid, &status, 0) != pid) e(7);
+ if (waitpid(pid, &status, 0) != pid) my_e(7);
if (_WIFEXITED(status)) break;
- if (!_WIFSTOPPED(status)) e(8);
+ if (!_WIFSTOPPED(status)) my_e(8);
switch (WSTOPSIG(status)) {
case SIGTRAP:
(*traps)++;
break;
case SIGSTOP:
- if (*stop >= 0) e(9);
+ if (*stop >= 0) my_e(9);
*stop = *traps;
break;
default:
- e(10);
+ my_e(10);
}
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(11);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(11);
}
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
* indistinguishable from a syscall trap, especially when considering failed
* exec() calls and immediately following signal handler invocations.
*/
- if (traps < 4) e(12);
- if (traps % 2) e(13);
- if (stop >= 0) e(14);
+ if (traps < 4) my_e(12);
+ if (traps % 2) my_e(13);
+ if (stop >= 0) my_e(14);
}
void test_altexec()
* for each system call, plus one for the final exit(). The stop must have
* taken place after a syscall enter event, i.e. must be odd as well.
*/
- if (traps < 3) e(12);
- if (!(traps % 2)) e(13);
- if (stop < 0) e(14);
- if (!(stop % 2)) e(15);
+ if (traps < 3) my_e(12);
+ if (!(traps % 2)) my_e(13);
+ if (stop < 0) my_e(14);
+ if (!(stop % 2)) my_e(15);
}
void test_noexec()
sigexec(1, TO_NOEXEC, &traps, &stop);
/* The exec causes no signal at all. As above, but without the SIGSTOPs. */
- if (traps < 3) e(12);
- if (!(traps % 2)) e(13);
- if (stop >= 0) e(14);
+ if (traps < 3) my_e(12);
+ if (!(traps % 2)) my_e(13);
+ if (stop >= 0) my_e(14);
}
void test_defexec()
/* See above. */
if (attach == 0) {
- if (traps < 4) e(12);
- if (traps % 2) e(13);
- if (stop >= 0) e(14);
+ if (traps < 4) my_e(12);
+ if (traps % 2) my_e(13);
+ if (stop >= 0) my_e(14);
}
else {
- if (traps < 3) e(15);
- if (!(traps % 2)) e(16);
- if (stop >= 0) e(17);
+ if (traps < 3) my_e(15);
+ if (!(traps % 2)) my_e(16);
+ if (stop >= 0) my_e(17);
}
}
{
struct timeval tv;
- if (READ() != 0) e(100);
+ if (READ() != 0) my_e(100);
tv.tv_sec = 2;
tv.tv_usec = 0;
- if (select(0, NULL, NULL, NULL, &tv) != 0) e(101);
+ if (select(0, NULL, NULL, NULL, &tv) != 0) my_e(101);
exit(42);
}
pid = traced_fork(test_reattach_child);
- if (kill(pid, SIGSTOP) != 0) e(1);
+ if (kill(pid, SIGSTOP) != 0) my_e(1);
- if (waitpid(pid, &status, 0) != pid) e(2);
- if (!_WIFSTOPPED(status)) e(3);
- if (WSTOPSIG(status) != SIGSTOP) e(4);
+ if (waitpid(pid, &status, 0) != pid) my_e(2);
+ if (!_WIFSTOPPED(status)) my_e(3);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(4);
WRITE(0);
* within a second, despite being traced. If this is not the case, the test
* may hang or fail, and the child may die from a SIGTRAP.
*/
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(5);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(5);
for (count = 0; (r = waitpid(pid, &status, 0)) == pid; count++) {
- if (!_WIFSTOPPED(status)) e(6);
- if (WSTOPSIG(status) != SIGTRAP) e(7);
+ if (!_WIFSTOPPED(status)) my_e(6);
+ if (WSTOPSIG(status) != SIGTRAP) my_e(7);
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(8);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(8);
}
- if (r != -1 || errno != EINTR) e(9);
+ if (r != -1 || errno != EINTR) my_e(9);
/* We always start with syscall enter event; the last event we should have
* seen before the alarm was entering the select() call.
*/
- if (!(count % 2)) e(10);
+ if (!(count % 2)) my_e(10);
/* Detach, and immediately attach again. */
detach_running(pid);
- if (ptrace(T_ATTACH, pid, 0, 0) != 0) e(11);
+ if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(11);
- if (waitpid(pid, &status, 0) != pid) e(12);
- if (!_WIFSTOPPED(status)) e(13);
- if (WSTOPSIG(status) != SIGSTOP) e(14);
+ if (waitpid(pid, &status, 0) != pid) my_e(12);
+ if (!_WIFSTOPPED(status)) my_e(13);
+ if (WSTOPSIG(status) != SIGSTOP) my_e(14);
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(15);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(15);
- if (waitpid(pid, &status, 0) != pid) e(16);
+ if (waitpid(pid, &status, 0) != pid) my_e(16);
for (count = 0; _WIFSTOPPED(status); count++) {
- if (WSTOPSIG(status) != SIGTRAP) e(17);
+ if (WSTOPSIG(status) != SIGTRAP) my_e(17);
- if (ptrace(T_SYSCALL, pid, 0, 0) != 0) e(18);
+ if (ptrace(T_SYSCALL, pid, 0, 0) != 0) my_e(18);
- if (waitpid(pid, &status, 0) != pid) e(19);
+ if (waitpid(pid, &status, 0) != pid) my_e(19);
}
- if (!_WIFEXITED(status)) e(20);
- if ((r = WEXITSTATUS(status)) != 42) e(r);
+ if (!_WIFEXITED(status)) my_e(20);
+ if ((r = WEXITSTATUS(status)) != 42) my_e(r);
/* We must not have seen the select()'s syscall leave event, and the last
* event will be the syscall enter for the exit().
*/
- if (!(count % 2)) e(21);
+ if (!(count % 2)) my_e(21);
traced_wait();
}
-void e(n)
+void my_e(n)
int n;
{
if (child) exit(n);
- printf("Subtest %d, attach type %d, error %d, errno %d: %s\n",
- subtest, attach, n, errno, strerror(errno));
-
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- exit(1);
- }
+ printf("Attach type %d, ", attach);
+ e(n);
}
-void quit()
-{
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
#include <sys/mman.h>
#include <sys/wait.h>
+#define MAX_ERROR 2
+#include "common.c"
+
+int subtest = 0;
+
int
main(int argc, char *argv[])
{
ssize_t l;
pid_t f;
- printf("Test 44 ");
- fflush(stdout);
+ start(44);
for(i = 0; i < CHUNKS; i++) {
v[i] = minix_mmap(vaddr, CHUNKSIZE, PROT_READ|PROT_WRITE, 0,
if(v[i] == MAP_FAILED) {
perror("minix_mmap");
fprintf(stderr, "minix_mmap failed\n");
- exit(1);
+ quit();
}
if(v[i] != vaddr) {
fprintf(stderr,
"minix_mmap said 0x%p but i wanted 0x%p\n",
v[i], vaddr);
- exit(1);
+ quit();
}
vaddr += CHUNKSIZE;
}
if((fd=open(DEV_ZERO, O_RDONLY)) < 0) {
perror("open");
fprintf(stderr, "open failed for %s\n", DEV_ZERO);
- exit(1);
+ quit();
}
#define TOTAL1 (CHUNKS1*CHUNKSIZE)
/* Make single read cross region boundary. */
if((l=read(fd, v[0], TOTAL1)) != TOTAL1) {
fprintf(stderr, "read %d but expected %d\n", l, TOTAL1);
- exit(1);
+ quit();
}
/* Force single copy to cross region boundary. */
t = v[CHUNKS1]+CHUNKSIZE-2;
if((l=read(fd, t, CHUNKSIZE)) != CHUNKSIZE) {
fprintf(stderr, "read %d but expected %d\n", l, CHUNKSIZE);
- exit(1);
+ quit();
}
}
/* Now start a child to test bogus memory access */
if((f = fork()) == -1) {
perror("fork");
- exit(1);
+ quit();
}
if(f > 0) {
/* Parent waits. */
if(waitpid(f, &st, 0) < 0) {
perror("waitpid");
- exit(1);
+ quit();
}
if(!WIFEXITED(st)) {
fprintf(stderr, "child not signaled\n");
- exit(1);
+ quit();
}
if(WEXITSTATUS(st) != 0) {
fprintf(stderr, "child exited with nonzero status\n");
- exit(1);
+ quit();
}
} else {
/* Child performs bogus read */
res = read(fd, buf, LARGESIZE);
if(res >= 0) {
fprintf(stderr, "res %d\n", res);
- exit(1);
+ quit();
}
if(errno != EFAULT) {
fprintf(stderr, "errno %d\n", errno);
- exit(1);
+ quit();
}
- exit(0);
+ return(0);
}
- printf("ok\n");
-
- exit(0);
+ quit();
+ return(-1);
}
#endif
#define MAX_ERROR 4
-static int errct;
+#include "common.c"
/* test strtol */
#define TYPE long
#endif /* defined(__LONG_LONG_SUPPORTED) */
-static void quit(void)
-{
- if (errct == 0)
- {
- printf("ok\n");
- exit(0);
- }
- else
- {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
-
int main(int argc, char **argv)
{
+ start(45);
#ifdef __LONG_LONG_SUPPORTED
- printf("Test 45 (GCC) ");
+ printf("(GCC) ");
#else
- printf("Test 45 (ACK) ");
+ printf("(ACK) ");
#endif
fflush(stdout);
#include <sys/sigcontext.h>
#define MAX_ERROR 4
-static int errct;
+#include "common.c"
/* maximum allowed FP difference for our tests */
#define EPSILON 0.00000000023283064365386962890625 /* 2^(-32) */
-static void quit(void)
-{
- if (errct == 0)
- {
- printf("ok\n");
- exit(0);
- }
- else
- {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
-
#define ERR(x, y) e(__LINE__, (x), (y))
-static void e(int n, double x, double y)
-{
- printf("Line %d, x=%.20g, y=%.20g\n", n, x, y);
- if (errct++ > MAX_ERROR)
- {
- printf("Too many errors; test aborted\n");
- exit(1);
- }
-}
-
static void signal_handler(int signum)
{
struct sigframe *sigframe;
printf("Signal %d at 0x%x\n", signum, sigframe->sf_scp->sc_regs.pc);
/* count as error */
- ERR(0, 0);
+ e(0);
fflush(stdout);
/* handle signa again next time */
static void test_fpclassify(double value, int class, int test_sign)
{
/* test fpclassify */
- if (fpclassify(value) != class) ERR(value, 0);
+ if (fpclassify(value) != class) e(101);
if (test_sign)
{
- if (fpclassify(-value) != class) ERR(-value, 0);
+ if (fpclassify(-value) != class) e(102);
/* test signbit */
- if (signbit(value)) ERR(value, 0);
- if (!signbit(-value)) ERR(-value, 0);
+ if (signbit(value)) e(103);
+ if (!signbit(-value)) e(104);
}
}
*/
assert(sizeof(negzero) == sizeof(double));
test_fpclassify(*(double *) negzero, FP_ZERO, 0);
- if (!signbit(*(double *) negzero)) ERR(0, 0);
+ if (!signbit(*(double *) negzero)) e(4);
/* test other small numbers for fpclassify and signbit */
d = 1;
/* update and check rounding mode */
mode_old = fegetround();
fesetround(mode);
- if (fegetround() != mode) ERR(0, 0);
+ if (fegetround() != mode) e(5);
/* perform rounding */
rounded = func(value);
/* check direction of rounding */
switch (exp)
{
- case ROUND_EQ: if (rounded != value) ERR(value, rounded); break;
- case ROUND_DN: if (rounded >= value) ERR(value, rounded); break;
- case ROUND_UP: if (rounded <= value) ERR(value, rounded); break;
+ case ROUND_EQ: if (rounded != value) e(6); break;
+ case ROUND_DN: if (rounded >= value) e(7); break;
+ case ROUND_UP: if (rounded <= value) e(8); break;
default: assert(0);
}
/* check whether the number is sufficiently close */
- if (fabs(value - rounded) >= 1) ERR(value, rounded);
+ if (fabs(value - rounded) >= 1) e(9);
/* check whether the number is integer */
- if (remainder(rounded, 1)) ERR(value, rounded);
+ if (remainder(rounded, 1)) e(10);
/* re-check and restore rounding mode */
- if (fegetround() != mode) ERR(0, 0);
+ if (fegetround() != mode) e(11);
fesetround(mode_old);
}
if (fabs(r1 - r2) > EPSILON && fabs(r1 + r2) > EPSILON)
{
printf("%.20g != %.20g\n", r1, r2);
- ERR(x, y);
+ e(13);
}
}
fenv_t fenv;
int i;
- printf("Test 47 ");
- fflush(stdout);
+ start(47);
/* no FPU errors, please */
- if (feholdexcept(&fenv) < 0) ERR(0, 0);
+ if (feholdexcept(&fenv) < 0) e(14);
/* some signals count as errors */
for (i = 0; i < _NSIG; i++)
#include <string.h>
#include <unistd.h>
-#define MAX_ERRORS 3
-
-static int errct;
-
-static void quit(void)
-{
- if (errct > 0)
- {
- printf("%d errors\n", errct);
- exit(1);
- }
- else
- {
- printf("ok\n");
- exit(0);
- }
-}
-
-static void err(void)
-{
- if (++errct >= MAX_ERRORS)
- {
- printf("aborted, too many errors\n");
- quit();
- }
-}
+#define MAX_ERROR 3
+#define err() e(__LINE__)
+#include "common.c"
static void printstr(const char *s)
{
{
int use_network;
- printf("Test 48 ");
- fflush(stdout);
+ start(48);
use_network = can_use_network();
if (!use_network)
#define TEST_64_BIT
#endif
-#define ERR err(__LINE__)
+#define ERR e(__LINE__)
#define MAX_ERROR 4
-static int errct;
-
-static void quit(void)
-{
- if (errct == 0)
- {
- printf("ok\n");
- exit(0);
- }
- else
- {
- printf("%d errors\n", errct);
- exit(1);
- }
-}
-
-static void err(int line)
-{
- printf("error at line %d\n", line);
- if (++errct >= MAX_ERROR)
- quit();
-}
+#include "common.c"
#define TEST_PRINTF(type, macro, value, result) \
{ \
char buffer[256]; \
snprintf(buffer, sizeof(buffer), "%" macro, (type) value); \
- if (strcmp(buffer, result) != 0) err(__LINE__); \
+ if (strcmp(buffer, result) != 0) ERR; \
}
int main(void)
{
+ start(49);
#ifdef __LONG_LONG_SUPPORTED
- printf("Test 49 (GCC) ");
+ printf("(GCC) ");
#else
- printf("Test 49 (ACK) ");
+ printf("(ACK) ");
#endif
fflush(stdout);
/* done */
quit();
- assert(0);
return -1;
}
_PROTOTYPE( void test_brk, (void) );
_PROTOTYPE( void verify_main_reenter, (void) );
-#define ERROR_MAX 5
+#define MAX_ERROR 5
#define SSIZE 32768
#define ROUNDS 10
#define SWAPS 10
-int errct = 0;
+#include "common.c"
+
+int subtest;
ucontext_t ctx[3];
int entered_func1, entered_func2, reentered_main, entered_overflow;
do_calcs();
if (fegetround() != FE_DOWNWARD) err(9, 4);
}
+ quit();
}
void do_parent(void)
void verify_main_reenter(void)
{
if (reentered_main == 0) err(4, 1);
- if (errct == 0) printf("ok\n");
}
int main(void)
{
+ start(51);
#ifdef __GNUC__
- printf("Test 51 (GCC) ");
+ printf("(GCC) ");
#else
- printf("Test 51 (ACK) ");
+ printf("(ACK) ");
#endif
fflush(stdout);
makecontext(&ctx[2], (void (*) (void)) do_child, 0);
if (swapcontext(&ctx[0], &ctx[2]) == -1) err(1, 16);
- return(0);
+ quit();
+ return(-1);
}
/* We can't use a global subtest variable reliably, because threads might
change the value when we reenter a thread (i.e., report wrong subtest
number). */
-void err(int subtest, int error_no)
+void err(int sub, int error_no)
{
- printf("Subtest %d, error %d\n", subtest, error_no);
-
- if (errct++ > ERROR_MAX) {
- printf("Too many errors, test aborted\n");
- exit(1);
- }
+ subtest = sub;
+ e(error_no);
}
#define SWAPS 40
#define MAX_ERROR 5
+#include "common.c"
+
int pipefdc[2];
int pipefdp[2];
-int subtest = 0, errct = 0;
+int subtest = 0;
int child_is_dead = 0;
void dead_child(int n);
void err(int n)
{
- printf("Subtest %d, error %d\n", subtest, n);
-
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- exit(1);
- }
-}
-
-void quit(void)
-{
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
+ e(n);
}
void do_calcs(void)
pid_t r;
subtest = 1;
+ start(52);
#ifdef __GNUC__
- printf("Test 52 (GCC) ");
+ printf("(GCC) ");
#else
- printf("Test 52 (ACK) ");
+ printf("(ACK) ");
#endif
fflush(stdout);
#define Fstat(a,b) if (fstat(a,b) != 0) printf("Can't fstat %d\n", a)
#define Time(t) if (time(t) == (time_t)-1) printf("Time error\n")
-int errct = 0;
-int subtest = 1;
-char MaxName[NAME_MAX + 1]; /* Name of maximum length */
-char MaxPath[PATH_MAX]; /* Same for path */
-char ToLongName[NAME_MAX + 2]; /* Name of maximum +1 length */
-char ToLongPath[PATH_MAX + 1]; /* Same for path, both too long */
+#include "common.c"
+
+int subtest;
_PROTOTYPE(void test8a, (void));
_PROTOTYPE(void test8b, (void));
-_PROTOTYPE(void e, (int number));
-_PROTOTYPE(void quit, (void));
int main(int argc, char *argv[])
{
int i, m = 0xFFFF;
- sync();
if (argc == 2) m = atoi(argv[1]);
- printf("Test 8 ");
- fflush(stdout);
-
+ start(8);
for (i = 0; i < ITERATIONS; i++) {
if (m & 0001) test8a();
if (m & 0002) test8b();
}
quit();
- return 1;
+ return(-1); /* Unreachable */
}
void test8a()
for (i = 3; i < OPEN_MAX; i++) (void) close(i);
}
-void e(n)
-int n;
-{
- int err_num = errno; /* Save in case printf clobbers it. */
-
- printf("Subtest %d, error %d errno=%d: ", subtest, n, errno);
- errno = err_num;
- perror("");
- if (errct++ > MAX_ERROR) {
- printf("Too many errors; test aborted\n");
- chdir("..");
- system("rm -rf DIR*");
- exit(1);
- }
- errno = 0;
-}
-
-void quit()
-{
- if (errct == 0) {
- printf("ok\n");
- exit(0);
- } else {
- printf("%d errors\n", errct);
- exit(1);
- }
-}