From: Ben Gras Date: Tue, 16 Apr 2013 16:04:46 +0000 (+0000) Subject: tests cleanup X-Git-Tag: v3.3.0~1025 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=5977114c42e557bdbd946851ea6605701d9f4a4c;p=minix.git tests cleanup . make common.o link with the tests instead of being #included as common.c . fix warnings about missing prototypes by declaring functions static . reduces some duplicated code Change-Id: Ic2a765d7f5886add5863190efec3fdd2d2ea2137 --- diff --git a/test/Makefile b/test/Makefile index 4ded59455..ceea1188e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -70,6 +70,10 @@ LDSTATIC= -dynamic PROGS+= test63 mod .endif +.for o in $(PROGS) +OBJS.${o} += common.o +.endfor + # LSC Make sure there is not leftover after a failed testrun clean: .PHONY .MAKE $(MAKE) -C select clean diff --git a/test/common.c b/test/common.c index 40b2fccc6..3ccb6700b 100644 --- a/test/common.c +++ b/test/common.c @@ -1,6 +1,6 @@ /* Utility routines for Minix tests. * This is designed to be #includ'ed near the top of test programs. It is - * self-contained except for MAX_ERRORS. + * self-contained except for max_error. */ #include @@ -10,18 +10,17 @@ #include #include -int common_test_nr = -1, errct = 0, subtest; +#include "common.h" -#define e(errn) e_f(__FILE__, __LINE__, (errn)) +int common_test_nr = -1, errct = 0, subtest; -void cleanup(void); -int does_fs_truncate(void); -void e_f(char *file, int lineno, int n); -int name_max(char *path); -void quit(void); -void rm_rf_dir(int test_nr); -void rm_rf_ppdir(int test_nr); -void start(int test_nr); +/* provide a default max_error symbol as Max_error with a value + * of 5. The test program can override it wit its own max_error + * symbol if it wants that this code will then use instead. + */ +__weak_alias(max_error,Max_error); +int Max_error = 5; +extern int max_error; void start(test_nr) int test_nr; @@ -107,7 +106,7 @@ void e_f(char *file, int line, int n) if (errct == 0) printf("\n"); /* finish header */ printf("%s:%d: Subtest %d, error %d, errno %d: %s\n", file, line, subtest, n, errno, strerror(errno)); - if (++errct > MAX_ERROR) { + if (++errct > max_error) { printf("Too many errors; test aborted\n"); cleanup(); exit(1); diff --git a/test/common.h b/test/common.h new file mode 100644 index 000000000..d98bf30be --- /dev/null +++ b/test/common.h @@ -0,0 +1,24 @@ + +#include +#include +#include +#include +#include +#include +#include + +#define e(errn) e_f(__FILE__, __LINE__, (errn)) +#define em(errn,msg) do { fprintf(stderr, "%s\n", msg); e(errn); } while(0) + +void printprogress(char *msg, int i, int max); +void cleanup(void); +int does_fs_truncate(void); +void e_f(char *file, int lineno, int n); +int name_max(char *path); +void quit(void); +void rm_rf_dir(int test_nr); +void rm_rf_ppdir(int test_nr); +void start(int test_nr); + +extern int common_test_nr, errct, subtest; + diff --git a/test/magic.h b/test/magic.h index 4fdd0c40a..a8436f5db 100644 --- a/test/magic.h +++ b/test/magic.h @@ -7,3 +7,4 @@ #define MAGIC6 0x17D1FF long hellodriver(void); +long modfunction(long, long *, long); diff --git a/test/t40a.c b/test/t40a.c index 8dcbc7bef..ea31ad152 100644 --- a/test/t40a.c +++ b/test/t40a.c @@ -22,16 +22,7 @@ #define MAX_ERROR 5 -int errct = 0, subtest = -1; - -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} +#include "common.h" int main(int argc, char **argv) { fd_set fds; @@ -50,7 +41,7 @@ int main(int argc, char **argv) { FD_ZERO(&fds); for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(1, "fd set should be completely empty"); + em(1, "fd set should be completely empty"); break; } } @@ -59,7 +50,7 @@ int main(int argc, char **argv) { for(i = 0; i < OPEN_MAX; i++) FD_SET(i, &fds); for(i = 0; i < OPEN_MAX; i++) { if(!FD_ISSET(i, &fds)) { - e(2, "fd set should be completely filled"); + em(2, "fd set should be completely filled"); break; } } @@ -68,7 +59,7 @@ int main(int argc, char **argv) { FD_ZERO(&fds); for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(3, "fd set should be completely empty"); + em(3, "fd set should be completely empty"); break; } } @@ -77,7 +68,7 @@ int main(int argc, char **argv) { for(i = 0; i < OPEN_MAX; i += 2) FD_SET(i, &fds); for(i = 0; i < OPEN_MAX - 1; i+= 2 ) { if(!(FD_ISSET(i, &fds) && !FD_ISSET(i+1, &fds))) { - e(4, "bit pattern does not match"); + em(4, "bit pattern does not match"); break; } } @@ -86,7 +77,7 @@ int main(int argc, char **argv) { FD_ZERO(&fds); for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(5,"fd set should be completely empty"); + em(5,"fd set should be completely empty"); break; } } @@ -95,7 +86,7 @@ int main(int argc, char **argv) { for(i = 0; i < OPEN_MAX - 1; i += 2) FD_SET(i+1, &fds); for(i = 0; i < OPEN_MAX - 1; i+= 2 ) { if(!(FD_ISSET(i+1, &fds) && !FD_ISSET(i, &fds))) { - e(6, "bit pattern does not match"); + em(6, "bit pattern does not match"); break; } } @@ -104,7 +95,7 @@ int main(int argc, char **argv) { FD_ZERO(&fds); for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(7, "fd set should be completely empty"); + em(7, "fd set should be completely empty"); break; } } @@ -114,7 +105,7 @@ int main(int argc, char **argv) { for(i = 0; i < OPEN_MAX; i++) FD_CLR(i, &fds); /* Clear all bits */ for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(8, "all bits in fd set should be cleared"); + em(8, "all bits in fd set should be cleared"); break; } } @@ -123,7 +114,7 @@ int main(int argc, char **argv) { FD_ZERO(&fds); for(i = 0; i < OPEN_MAX; i++) { if(FD_ISSET(i, &fds)) { - e(9, "fd set should be completely empty"); + em(9, "fd set should be completely empty"); break; } } @@ -132,7 +123,7 @@ int main(int argc, char **argv) { for(i = 0; i < OPEN_MAX; i += 2) FD_CLR(i, &fds); /* Clear all bits */ for(i = 0; i < OPEN_MAX; i += 2) { if(FD_ISSET(i, &fds)) { - e(10, "all even bits in fd set should be cleared"); + em(10, "all even bits in fd set should be cleared"); break; } } diff --git a/test/t40b.c b/test/t40b.c index 967e13522..533954977 100644 --- a/test/t40b.c +++ b/test/t40b.c @@ -23,24 +23,16 @@ #include #include +#include "common.h" + #define FILE1 "selecttestb-1" #define FILES 2 #define TIME 3 #define MAX_ERROR 10 -int errct = 0, subtest = -1; char errorbuf[1000]; -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} - int main(int argc, char **argv) { int fd1, fd2, retval; fd_set fds_read, fds_write, fds_error; @@ -64,7 +56,7 @@ int main(int argc, char **argv) { if((fd1 = open(FILE1, O_WRONLY|O_CREAT, 0644)) == -1) { snprintf(errorbuf, sizeof(errorbuf), "failed to open file %s for writing", FILE1); - e(1, errorbuf); + em(1, errorbuf); perror(NULL); exit(1); } @@ -73,7 +65,7 @@ int main(int argc, char **argv) { if((fd2 = open(FILE1, O_RDONLY)) == -1) { snprintf(errorbuf, sizeof(errorbuf), "failed to open file %s for reading", FILE1); - e(2, errorbuf); + em(2, errorbuf); perror(NULL); exit(1); } @@ -94,20 +86,20 @@ int main(int argc, char **argv) { /* Correct amount of ready file descriptors? 1 read + 1 write + 2 errors */ if(retval != 4) { - e(3, "four fds should be set"); + em(3, "four fds should be set"); } /* Test resulting bit masks */ - if(!FD_ISSET(fd1, &fds_write)) e(4, "write should be set"); - if(!FD_ISSET(fd2, &fds_read)) e(5, "read should be set"); - if(!FD_ISSET(fd1, &fds_error)) e(6, "error should be set"); - if(!FD_ISSET(fd2, &fds_error)) e(7, "error should be set"); + if(!FD_ISSET(fd1, &fds_write)) em(4, "write should be set"); + if(!FD_ISSET(fd2, &fds_read)) em(5, "read should be set"); + if(!FD_ISSET(fd1, &fds_error)) em(6, "error should be set"); + if(!FD_ISSET(fd2, &fds_error)) em(7, "error should be set"); /* Was it instantaneous? */ if(end-start != TIME - TIME) { snprintf(errorbuf,sizeof(errorbuf),"time spent blocking is not %d, but %ld", TIME - TIME, (long int) (end-start)); - e(8, errorbuf); + em(8, errorbuf); } /* Wait for read to become ready on O_WRONLY. This should fail immediately. */ @@ -120,10 +112,10 @@ int main(int argc, char **argv) { retval = select(fd2+1, &fds_read, NULL, &fds_error, &tv); /* Correct amount of ready file descriptors? 1 read + 2 error */ - if(retval != 3) e(9, "incorrect amount of ready file descriptors"); - if(!FD_ISSET(fd1, &fds_read)) e(10, "read should be set"); - if(!FD_ISSET(fd1, &fds_error)) e(11, "error should be set"); - if(!FD_ISSET(fd2, &fds_error)) e(12, "error should be set"); + if(retval != 3) em(9, "incorrect amount of ready file descriptors"); + if(!FD_ISSET(fd1, &fds_read)) em(10, "read should be set"); + if(!FD_ISSET(fd1, &fds_error)) em(11, "error should be set"); + if(!FD_ISSET(fd2, &fds_error)) em(12, "error should be set"); /* Try again as above, bit this time with O_RDONLY in the write set */ FD_ZERO(&fds_error); @@ -135,10 +127,10 @@ int main(int argc, char **argv) { retval = select(fd2+1, NULL, &fds_write, &fds_error, &tv); /* Correct amount of ready file descriptors? 1 write + 2 errors */ - if(retval != 3) e(13, "incorrect amount of ready file descriptors"); - if(!FD_ISSET(fd2, &fds_write)) e(14, "write should be set"); - if(!FD_ISSET(fd1, &fds_error)) e(15, "error should be set"); - if(!FD_ISSET(fd2, &fds_error)) e(16, "error should be set"); + if(retval != 3) em(13, "incorrect amount of ready file descriptors"); + if(!FD_ISSET(fd2, &fds_write)) em(14, "write should be set"); + if(!FD_ISSET(fd1, &fds_error)) em(15, "error should be set"); + if(!FD_ISSET(fd2, &fds_error)) em(16, "error should be set"); close(fd1); close(fd2); diff --git a/test/t40c.c b/test/t40c.c index c816b2647..6a71c4d9d 100644 --- a/test/t40c.c +++ b/test/t40c.c @@ -21,23 +21,14 @@ #include #include +#include "common.h" + #define TERMINALW "/dev/ttypf" #define TERMINALR "/dev/ptypf" #define SENDSTRING "minixrocks" #define MAX_ERROR 5 -int errct = 0, subtest = -1; - -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} - -void open_terminal(int *child_fd, int *parent_fd) { +static void open_terminal(int *child_fd, int *parent_fd) { int fd1, fd2, i; char opentermw[5+OPEN_MAX+1]; char opentermr[5+OPEN_MAX+1]; @@ -68,7 +59,7 @@ void open_terminal(int *child_fd, int *parent_fd) { exit(EXIT_FAILURE); } -int do_child(int terminal) { +static int do_child(int terminal) { struct timeval tv; /* Going to sleep for two seconds to allow the parent proc to get ready */ @@ -86,7 +77,7 @@ int do_child(int terminal) { exit(0); } -int do_parent(int child, int terminal) { +static int do_parent(int child, int terminal) { fd_set fds_read, fds_write, fds_error; int retval; @@ -103,21 +94,21 @@ int do_parent(int child, int terminal) { * sub-test as reading from fd is blocking at this point. */ retval = select(terminal+1, &fds_read, &fds_write, &fds_error, NULL); - if(retval != 1) e(1, "incorrect amount of ready file descriptors"); + if(retval != 1) em(1, "incorrect amount of ready file descriptors"); - if(FD_ISSET(terminal, &fds_read)) e(2, "read should NOT be set"); - if(!FD_ISSET(terminal, &fds_write)) e(3, "write should be set"); - if(FD_ISSET(terminal, &fds_error)) e(4, "error should NOT be set"); + if(FD_ISSET(terminal, &fds_read)) em(2, "read should NOT be set"); + if(!FD_ISSET(terminal, &fds_write)) em(3, "write should be set"); + if(FD_ISSET(terminal, &fds_error)) em(4, "error should NOT be set"); /* Block until ready; until child wrote stuff */ FD_ZERO(&fds_read); FD_ZERO(&fds_write); FD_ZERO(&fds_error); FD_SET(terminal, &fds_read); retval = select(terminal+1, &fds_read, NULL, &fds_error, NULL); - if(retval != 1) e(5, "incorrect amount of ready file descriptors"); - if(!FD_ISSET(terminal, &fds_read)) e(6, "read should be set"); - if(FD_ISSET(terminal, &fds_error)) e(7, "error should not be set"); + if(retval != 1) em(5, "incorrect amount of ready file descriptors"); + if(!FD_ISSET(terminal, &fds_read)) em(6, "read should be set"); + if(FD_ISSET(terminal, &fds_error)) em(7, "error should not be set"); FD_ZERO(&fds_read); FD_ZERO(&fds_error); @@ -125,7 +116,7 @@ int do_parent(int child, int terminal) { retval = select(terminal+1, NULL, &fds_write, NULL, NULL); /* As it is impossible to write to a read only fd, this select should return * immediately with fd set in fds_write. */ - if(retval != 1) e(8, "incorrect amount or ready file descriptors"); + if(retval != 1) em(8, "incorrect amount or ready file descriptors"); close(terminal); waitpid(child, &retval, 0); diff --git a/test/t40d.c b/test/t40d.c index 4834ab17c..e4070affb 100644 --- a/test/t40d.c +++ b/test/t40d.c @@ -44,22 +44,14 @@ #define DO_TIMEOUT 7 #define MAX_ERROR 5 -int errct = 0, subtest = -1; +#include "common.h" + char errbuf[1000]; int fd_ap[2]; /* Anonymous pipe; read from fd_ap[0], write to fd_ap[1] */ int fd_np1; /* Named pipe */ int fd_np2; /* Named pipe */ -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} - -void do_child(void) { +static void do_child(void) { struct timeval tv; /* Open named pipe for writing. This will block until a reader arrives. */ @@ -125,7 +117,8 @@ void do_child(void) { exit(0); } -int count_fds(int nfds, fd_set *fds) { +#if 0 +static int count_fds(int nfds, fd_set *fds) { /* Return number of bits set in fds */ int i, result = 0; assert(fds != NULL && nfds > 0); @@ -134,8 +127,9 @@ int count_fds(int nfds, fd_set *fds) { } return result; } +#endif -int empty_fds(int nfds, fd_set *fds) { +static int empty_fds(int nfds, fd_set *fds) { /* Returns nonzero if the first bits up to nfds in fds are not set */ int i; assert(fds != NULL && nfds > 0); @@ -143,7 +137,7 @@ int empty_fds(int nfds, fd_set *fds) { return 1; } -int compare_fds(int nfds, fd_set *lh, fd_set *rh) { +static int compare_fds(int nfds, fd_set *lh, fd_set *rh) { /* Returns nonzero if lh equals rh up to nfds bits */ int i; assert(lh != NULL && rh != NULL && nfds > 0); @@ -156,7 +150,8 @@ int compare_fds(int nfds, fd_set *lh, fd_set *rh) { return 1; } -void dump_fds(int nfds, fd_set *fds) { +#if 0 +static void dump_fds(int nfds, fd_set *fds) { /* Print a graphical representation of bits in fds */ int i; if(fds != NULL && nfds > 0) { @@ -164,8 +159,9 @@ void dump_fds(int nfds, fd_set *fds) { printf("\n"); } } +#endif -void do_parent(int child) { +static void do_parent(int child) { fd_set fds_read, fds_write, fds_error; fd_set fds_compare_read, fds_compare_write; struct timeval tv; @@ -205,16 +201,16 @@ void do_parent(int child) { if(retval <= 0) { snprintf(errbuf, sizeof(errbuf), "one fd should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(1, errbuf); + em(1, errbuf); } - if(!empty_fds(fd_np1+1,&fds_read)) e(2, "no read bits should be set"); + if(!empty_fds(fd_np1+1,&fds_read)) em(2, "no read bits should be set"); /* Make sure the write bit is set (and just 1 bit) */ FD_ZERO(&fds_compare_write); FD_SET(fd_np1, &fds_compare_write); if(!compare_fds(fd_np1+1, &fds_compare_write, &fds_write)) - e(3, "write should be set"); + em(3, "write should be set"); /* Clear sets and set up new bit masks */ FD_ZERO(&fds_read); FD_ZERO(&fds_write); @@ -231,14 +227,14 @@ void do_parent(int child) { if(retval != 1) { snprintf(errbuf, sizeof(errbuf), "one fd should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(4, errbuf); + em(4, errbuf); } - if(!FD_ISSET(fd_np1, &fds_read)) e(5, "read should be set"); + if(!FD_ISSET(fd_np1, &fds_read)) em(5, "read should be set"); /* Note that we left the write set empty. This should be equivalent to * setting this parameter to NULL. */ - if(!empty_fds(fd_np1+1, &fds_write)) e(6, "write should NOT be set"); + if(!empty_fds(fd_np1+1, &fds_write)) em(6, "write should NOT be set"); /* In case something went wrong above, we might end up with a child process * blocking on a write call we close the file descriptor now. Synchronize on @@ -284,21 +280,21 @@ void do_parent(int child) { if(retval <= 0) { snprintf(errbuf, sizeof(errbuf), "two fds should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(7, errbuf); + em(7, errbuf); } /* Make sure read bit is set (and just 1 bit) */ FD_ZERO(&fds_compare_read); FD_SET(fd_np2, &fds_compare_read); if(!compare_fds(fd_np2+1, &fds_compare_read, &fds_read)) - e(8, "read should be set"); + em(8, "read should be set"); /* Write bit should be set (and just 1 bit) */ FD_ZERO(&fds_compare_write); FD_SET(fd_np2, &fds_compare_write); if(!compare_fds(fd_np2+1, &fds_compare_write, &fds_write)) - e(9, "write should be set"); + em(9, "write should be set"); if(!empty_fds(fd_np2+1, &fds_error)) - e(10, "Error should NOT be set"); + em(10, "Error should NOT be set"); FD_ZERO(&fds_read); FD_ZERO(&fds_write); FD_SET(fd_np2, &fds_write); @@ -310,10 +306,10 @@ void do_parent(int child) { if(retval != 1) { snprintf(errbuf, sizeof(errbuf), "one fd should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(11, errbuf); + em(11, errbuf); } - if(!empty_fds(fd_np2+1, &fds_read)) e(12, "read should NOT be set"); + if(!empty_fds(fd_np2+1, &fds_read)) em(12, "read should NOT be set"); /* Anonymous pipe */ @@ -328,13 +324,13 @@ void do_parent(int child) { if(retval != 1) { snprintf(errbuf, sizeof(errbuf), "one fd should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(13, errbuf); + em(13, errbuf); } /* Make sure write bit is set (and just 1 bit) */ FD_ZERO(&fds_compare_write); FD_SET(fd_ap[1], &fds_compare_write); if(!compare_fds(fd_ap[1]+1, &fds_compare_write, &fds_write)) - e(14, "write should be set"); + em(14, "write should be set"); /* Intentionally test reading from pipe and letting it time out. */ FD_SET(fd_ap[0], &fds_read); @@ -345,14 +341,14 @@ void do_parent(int child) { end = time(NULL); /* Did we time out? */ - if(retval != 0) e(15, "we should have timed out"); + if(retval != 0) em(15, "we should have timed out"); /* Did it take us approximately 1 second? */ if((int) (end - start) != 1) { snprintf(errbuf, sizeof(errbuf), "time out is not 1 second (instead, it is %ld)", (long int) (end - start)); - e(16, errbuf); + em(16, errbuf); } /* Do another read, but this time we expect incoming data from child. */ @@ -363,12 +359,12 @@ void do_parent(int child) { retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); /* Correct amount of ready file descriptors? Just 1 read. */ - if(retval != 1) e(17, "one fd should be set"); + if(retval != 1) em(17, "one fd should be set"); /* Is the read bit set? And just 1 bit. */ FD_ZERO(&fds_compare_read); FD_SET(fd_ap[0], &fds_compare_read); if(!compare_fds(fd_ap[0]+1, &fds_compare_read, &fds_read)) - e(18, "read should be set."); + em(18, "read should be set."); /* By convention fd_ap[0] is meant to be used for reading from the pipe and * fd_ap[1] is meant for writing, where fd_ap is a an anonymous pipe. diff --git a/test/t40e.c b/test/t40e.c index 9759d67e1..52a3483c0 100644 --- a/test/t40e.c +++ b/test/t40e.c @@ -62,6 +62,8 @@ #include #include +#include "common.h" + #define DO_HANDLEDATA 1 #define DO_PAUSE 3 #define DO_TIMEOUT 7 @@ -69,22 +71,13 @@ #define NUMCHILDREN 5 #define MAX_ERROR 10 -int errct = 0, subtest = -1; char errbuf[1000]; -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} - /* All *_fds routines are helping routines. They intentionally use FD_* macros in order to prevent making assumptions on how the macros are implemented.*/ -int count_fds(int nfds, fd_set *fds) { +#if 0 +static int count_fds(int nfds, fd_set *fds) { /* Return number of bits set in fds */ int i, result = 0; assert(fds != NULL && nfds > 0); @@ -93,8 +86,9 @@ int count_fds(int nfds, fd_set *fds) { } return result; } +#endif -int empty_fds(int nfds, fd_set *fds) { +static int empty_fds(int nfds, fd_set *fds) { /* Returns nonzero if the first bits up to nfds in fds are not set */ int i; assert(fds != NULL && nfds > 0); @@ -102,7 +96,7 @@ int empty_fds(int nfds, fd_set *fds) { return 1; } -int compare_fds(int nfds, fd_set *lh, fd_set *rh) { +static int compare_fds(int nfds, fd_set *lh, fd_set *rh) { /* Returns nonzero if lh equals rh up to nfds bits */ int i; assert(lh != NULL && rh != NULL && nfds > 0); @@ -115,7 +109,8 @@ int compare_fds(int nfds, fd_set *lh, fd_set *rh) { return 1; } -void dump_fds(int nfds, fd_set *fds) { +#if 0 +static void dump_fds(int nfds, fd_set *fds) { /* Print a graphical representation of bits in fds */ int i; if(fds != NULL && nfds > 0) { @@ -123,8 +118,9 @@ void dump_fds(int nfds, fd_set *fds) { printf("\n"); } } +#endif -void do_child(int childno) { +static void do_child(int childno) { int fd_sock, port; int retval; @@ -203,11 +199,11 @@ void do_child(int childno) { retval = select(fd_sock+1, NULL, &fds_write, NULL, &tv); - if(retval <= 0) e(6, "expected one fd to be ready"); + if(retval <= 0) em(6, "expected one fd to be ready"); FD_ZERO(&fds_compare_write); FD_SET(fd_sock, &fds_compare_write); if(!compare_fds(fd_sock+1, &fds_compare_write, &fds_compare_write)) - e(7, "write should be set"); + em(7, "write should be set"); } if(close(fd_sock) < 0) { @@ -218,7 +214,7 @@ void do_child(int childno) { exit(errct); } -void do_parent(void) { +static void do_parent(void) { #if !defined(__minix) int yes = 1; #endif @@ -317,7 +313,7 @@ void do_parent(void) { if(retval <= 0) { snprintf(errbuf, sizeof(errbuf), "two fds should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(1, errbuf); + em(1, errbuf); } FD_ZERO(&fds_compare_read); FD_ZERO(&fds_compare_write); @@ -327,10 +323,10 @@ void do_parent(void) { is not specified and the other side might have data ready for us to read */ if(!compare_fds(sockets[childresults]+1, &fds_compare_write, &fds_write)) - e(2, "write should be set"); + em(2, "write should be set"); if(!empty_fds(sockets[childresults]+1, &fds_error)) - e(3, "no error should be set"); + em(3, "no error should be set"); } @@ -356,13 +352,13 @@ void do_parent(void) { if(retval <= 0) { snprintf(errbuf, sizeof(errbuf), "one fd should be set%s", (retval == 0 ? " (TIMEOUT)" : "")); - e(4, errbuf); + em(4, errbuf); } /* Check read bit is set */ FD_ZERO(&fds_compare_read); FD_SET(fd_sock, &fds_compare_read); if(!compare_fds(fd_sock+1, &fds_compare_read, &fds_read)) - e(5, "read should be set"); + em(5, "read should be set"); /* Accept incoming connection to unblock child 5 */ diff --git a/test/t40f.c b/test/t40f.c index 239af96b5..6521468b4 100644 --- a/test/t40f.c +++ b/test/t40f.c @@ -19,6 +19,8 @@ #include #include +#include "common.h" + #define DO_HANDLEDATA 1 #define DO_PAUSE 3 #define DO_TIMEOUT 7 @@ -27,23 +29,14 @@ #define DELTA(x,y) (x.tv_sec - y.tv_sec) * CLOCKS_PER_SEC \ + (x.tv_usec - y.tv_usec) * CLOCKS_PER_SEC / 1000000 -int errct = 0, subtest = -1, got_signal = 0; +int got_signal = 0; int fd_ap[2]; -void catch_signal(int sig_no) { +static void catch_signal(int sig_no) { got_signal = 1; } -void e(int n, char *s) { - printf("Subtest %d, error %d, %s\n", subtest, n, s); - - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - exit(errct); - } -} - -float compute_diff(struct timeval start, struct timeval end, float compare) { +static float compute_diff(struct timeval start, struct timeval end, float compare) { /* Compute time difference. It is assumed that the value of start <= end. */ clock_t delta; int seconds, hundreths; @@ -60,7 +53,7 @@ float compute_diff(struct timeval start, struct timeval end, float compare) { return diff; } -void do_child(void) { +static void do_child(void) { struct timeval tv; /* Let the parent do initial read and write tests from and to the pipe. */ @@ -75,7 +68,7 @@ void do_child(void) { exit(0); } -void do_parent(int child) { +static void do_parent(int child) { fd_set fds_read; struct timeval tv, start_time, end_time; int retval; @@ -96,13 +89,13 @@ void do_parent(int child) { (void) gettimeofday(&end_time, NULL); /* Record ending time */ /* Did we time out? */ - if(retval != 0) e(1, "Should have timed out"); + if(retval != 0) em(1, "Should have timed out"); /* Approximately right? The standard does not specify how precise the timeout should be. Instead, the granularity is implementation-defined. In this test we assume that the difference should be no more than half a second.*/ if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) - e(2, "Time difference too large"); + em(2, "Time difference too large"); /* Let's wait for another DO_PAUSE seconds, expressed as microseconds */ FD_ZERO(&fds_read); @@ -114,9 +107,9 @@ void do_parent(int child) { retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ - if(retval != 0) e(3, "Should have timed out"); + if(retval != 0) em(3, "Should have timed out"); if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) - e(4, "Time difference too large"); + em(4, "Time difference too large"); /* Let's wait for another DO_PAUSE seconds, expressed in seconds and micro seconds. */ @@ -129,9 +122,9 @@ void do_parent(int child) { retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ - if(retval != 0) e(5, "Should have timed out"); + if(retval != 0) em(5, "Should have timed out"); if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) - e(6, "Time difference too large"); + em(6, "Time difference too large"); /* Finally, we test if our timeout is interrupted by a signal */ FD_ZERO(&fds_read); @@ -143,11 +136,11 @@ void do_parent(int child) { retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ - if(retval != -1) e(7, "Should have been interrupted"); + if(retval != -1) em(7, "Should have been interrupted"); if(compute_diff(start_time, end_time, DO_TIMEOUT) < DO_DELTA) - e(8, "Failed to get interrupted by a signal"); + em(8, "Failed to get interrupted by a signal"); - if(!got_signal) e(9, "Failed to get interrupted by a signal"); + if(!got_signal) em(9, "Failed to get interrupted by a signal"); waitpid(child, &retval, 0); exit(errct); diff --git a/test/test1.c b/test/test1.c index b5ee190e6..7cf2dbb60 100644 --- a/test/test1.c +++ b/test/test1.c @@ -9,13 +9,13 @@ #include #define SIGNUM 10 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 volatile int glov, gct; -int errct; int subtest; -#include "common.c" int main(int argc, char *argv []); void test1a(void); diff --git a/test/test10.c b/test/test10.c index 040b0f33a..400f2e6d2 100644 --- a/test/test10.c +++ b/test/test10.c @@ -15,8 +15,9 @@ char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g", long prog[PROGBUF_LONGS]; int psize; -#define MAX_ERROR 2 -#include "common.c" +int max_error = 2; +#include "common.h" + int main(void); void spawn(int n); diff --git a/test/test11.c b/test/test11.c index 755ecf20b..a36e37e55 100644 --- a/test/test11.c +++ b/test/test11.c @@ -11,13 +11,14 @@ #include #define ITERATIONS 10 -#define MAX_ERROR 1 +int max_error = 1; +#include "common.h" + int errct, subtest; char *envp[3] = {"spring", "summer", 0}; char *passwd_file = "/etc/passwd"; -#include "common.c" int main(int argc, char *argv[]); void test11a(void); diff --git a/test/test12.c b/test/test12.c index 16fc86867..ff90822d6 100644 --- a/test/test12.c +++ b/test/test12.c @@ -10,9 +10,10 @@ #include #define NUM_TIMES 1000 -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + -#include "common.c" int main(void); diff --git a/test/test13.c b/test/test13.c index 9ab4dd165..772751ffc 100644 --- a/test/test13.c +++ b/test/test13.c @@ -17,8 +17,9 @@ char buffer[BLOCK_SIZE]; -#define MAX_ERROR 2 -#include "common.c" +int max_error = 2; +#include "common.h" + int main(void); void quit(void); diff --git a/test/test14.c b/test/test14.c index 479fdb250..fc85cd5cd 100644 --- a/test/test14.c +++ b/test/test14.c @@ -8,12 +8,13 @@ #include #define TRIALS 100 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + char name[20] = {"TMP14."}; int subtest = 1; -#include "common.c" int main(void); void quit(void); diff --git a/test/test15.c b/test/test15.c index 449f8eb89..dc631511b 100644 --- a/test/test15.c +++ b/test/test15.c @@ -17,14 +17,14 @@ #define STREQ(a, b) (strcmp((a), (b)) == 0) char *it = ""; /* Routine name for message routines. */ -int errct; /* count errors */ int waserror = 0; /* For exit status. */ char uctest[] = "\004\203"; /* For testing signedness of chars. */ int charsigned; /* Result. */ -#define MAX_ERROR 2 -#include "common.c" +int max_error = 2; +#include "common.h" + void check(int thing, int number); void equal(char *a, char *b, int number); diff --git a/test/test16.c b/test/test16.c index 37bd75892..71babccae 100644 --- a/test/test16.c +++ b/test/test16.c @@ -9,12 +9,13 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + int subtest, passes; int V1filesystem = 0; -#include "common.c" int main(int argc, char *argv []); void test16init(void); diff --git a/test/test17.c b/test/test17.c index 236e988d8..94c920fdb 100644 --- a/test/test17.c +++ b/test/test17.c @@ -17,7 +17,9 @@ #define NOCRASH 1 /* test11(), 2nd pipe */ #define PDPNOHANG 1 /* test03(), write_standards() */ -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + #define USER_ID 12 #define GROUP_ID 1 @@ -61,7 +63,6 @@ #define DUP "dup" #define UTIME "utime" -int errct; /* "decl.c", created by Rene Montsma and Menno Wilcke */ @@ -76,7 +77,6 @@ char *mode_fnames[MODES] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rw /* "test.c", created by Rene Montsma and Menno Wilcke */ -#include "common.c" int main(int argc, char *argv []); void test(int mask); diff --git a/test/test18.c b/test/test18.c index b4d94cb26..6adb71407 100644 --- a/test/test18.c +++ b/test/test18.c @@ -64,8 +64,9 @@ #define DUP "dup" #define UTIME "utime" -int errct; -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + /* "decl.c", created by Rene Montsma and Menno Wilcke */ @@ -78,7 +79,6 @@ char *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}, /* "test.c", created by Rene Montsma and Menno Wilcke */ -#include "common.c" int main(int argc, char **argv); void test(void); diff --git a/test/test19.c b/test/test19.c index 015c63c84..07bf16313 100644 --- a/test/test19.c +++ b/test/test19.c @@ -8,7 +8,9 @@ #include #include -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + #define NB 30L #define NBOUNDS 6 @@ -20,7 +22,6 @@ char b[4] = {0, 1, 2, 3}, c[4] = {10, 20, 30, 40}, d[4] = {6, 7, 8, 9}; long bounds[NBOUNDS] = {7, 9, 50, 519, 520, 40000L}; char buff[30000]; -#include "common.c" int main(int argc, char *argv[]); void test19a(void); diff --git a/test/test2.c b/test/test2.c index 0e20d01ed..11bb3a735 100644 --- a/test/test2.c +++ b/test/test2.c @@ -11,13 +11,14 @@ #include #define ITERATIONS 5 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + int is, array[4], parsigs, parcum, sigct, cumsig, subtest; int iteration, kk = 0; char buf[2048]; -#include "common.c" int main(int argc, char *argv []); void test2a(void); @@ -63,13 +64,13 @@ void test2a() subtest = 1; if (pipe(fd) < 0) { printf("pipe error. errno= %d\n", errno); - errct++; + e(10); quit(); } i = fork(); if (i < 0) { printf("fork failed\n"); - errct++; + e(11); quit(); } if (i != 0) { @@ -79,7 +80,7 @@ void test2a() for (q = 0; q < 8; q++) { if (write(fd[1], buf, 2048) < 0) { printf("write pipe err. errno=%d\n", errno); - errct++; + e(12); quit(); } } @@ -87,7 +88,7 @@ void test2a() wait(&q); if (q != 256 * 58) { printf("wrong exit code %d\n", q); - errct++; + e(13); quit(); } } else { @@ -97,7 +98,7 @@ void test2a() n = read(fd[0], buf, 512); if (n != 512) { printf("read yielded %d bytes, not 512\n", n); - errct++; + e(14); quit(); } for (j = 0; j < n; j++) diff --git a/test/test20.c b/test/test20.c index dcb5b968d..88203b78e 100644 --- a/test/test20.c +++ b/test/test20.c @@ -20,14 +20,15 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -#include "common.c" int superuser; diff --git a/test/test21.c b/test/test21.c index 80d5b866c..8e5741fee 100644 --- a/test/test21.c +++ b/test/test21.c @@ -16,9 +16,10 @@ #include #define ITERATIONS 1 -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + -#include "common.c" int main(int argc, char *argv []); void test21a(void); diff --git a/test/test22.c b/test/test22.c index bdefc73a4..93fc5f9a6 100644 --- a/test/test22.c +++ b/test/test22.c @@ -9,14 +9,14 @@ #include #include -#define MAX_ERROR 4 /* Stop after ``MAX_ERROR'' errors. */ +#include "common.h" + #define ITERATIONS 2 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -#include "common.c" void test22a(void); int mode(char *filename); diff --git a/test/test23.c b/test/test23.c index 6f78b96f5..d4033cf30 100644 --- a/test/test23.c +++ b/test/test23.c @@ -10,10 +10,11 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 3 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test24.c b/test/test24.c index 2f741c121..f20c3b983 100644 --- a/test/test24.c +++ b/test/test24.c @@ -20,10 +20,11 @@ void test24c(void); void makelongnames(void); #define OVERFLOW_DIR_NR (OPEN_MAX + 1) -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 5 -#include "common.c" #define DIRENT0 ((struct dirent *) NULL) #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) diff --git a/test/test25.c b/test/test25.c index 01a81dcb9..04863d811 100644 --- a/test/test25.c +++ b/test/test25.c @@ -16,10 +16,11 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 2 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test26.c b/test/test26.c index 5bb9c4196..8d14fb2a0 100644 --- a/test/test26.c +++ b/test/test26.c @@ -12,7 +12,9 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) @@ -20,7 +22,6 @@ #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) #define Mkfifo(f) if (mkfifo(f,0777)!=0) printf("Can't make fifo %s\n", f) -#include "common.c" void test26a(void); void test26b(void); diff --git a/test/test27.c b/test/test27.c index 412576de8..fb5345734 100644 --- a/test/test27.c +++ b/test/test27.c @@ -13,13 +13,14 @@ #include #define MODE_MASK (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID) -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 2 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) -#include "common.c" int superuser; char *MaxName; /* Name of maximum length */ diff --git a/test/test28.c b/test/test28.c index cea5ba3b6..ce8b3557f 100644 --- a/test/test28.c +++ b/test/test28.c @@ -20,10 +20,11 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 2 -#include "common.c" #define DIRENT0 ((struct dirent *) NULL) diff --git a/test/test29.c b/test/test29.c index ccbd4d1af..966f31a27 100644 --- a/test/test29.c +++ b/test/test29.c @@ -24,7 +24,9 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) @@ -34,7 +36,6 @@ #define IS_CLOEXEC(fd) ((fcntl(fd, F_GETFD) & FD_CLOEXEC) == FD_CLOEXEC) #define SET_CLOEXEC(fd) fcntl(fd, F_SETFD, FD_CLOEXEC) -#include "common.c" int superuser; diff --git a/test/test3.c b/test/test3.c index 5490b3b9e..1d66ada5e 100644 --- a/test/test3.c +++ b/test/test3.c @@ -12,13 +12,14 @@ #include #define ITERATIONS 10 -#define MAX_ERROR 0 +int max_error = 0; +#include "common.h" + #define SIZE 64 int subtest; char el_weirdo[] = "\n\t\\\e@@!!##\e\e\n\n"; -#include "common.c" int main(int argc, char *argv []); void test3a(void); diff --git a/test/test30.c b/test/test30.c index 4f0302dab..3e032614f 100644 --- a/test/test30.c +++ b/test/test30.c @@ -19,10 +19,11 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test31.c b/test/test31.c index 70ee0d8ec..f65fbcd23 100644 --- a/test/test31.c +++ b/test/test31.c @@ -12,10 +12,11 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test32.c b/test/test32.c index 4a7957139..5fe0c07dc 100644 --- a/test/test32.c +++ b/test/test32.c @@ -12,7 +12,9 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 2 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) @@ -20,7 +22,6 @@ #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) #define Creat(f) if (close(creat(f,0777))!=0) printf("Can't creat %s\n",f) -#include "common.c" int superuser; char *MaxName; /* Name of maximum length */ diff --git a/test/test33.c b/test/test33.c index 22b7fc379..3135b862a 100644 --- a/test/test33.c +++ b/test/test33.c @@ -12,10 +12,11 @@ #include #include -#define MAX_ERROR 1 +int max_error = 1; +#include "common.h" + #define ITERATIONS 2 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test34.c b/test/test34.c index d1278f869..8223d67da 100644 --- a/test/test34.c +++ b/test/test34.c @@ -19,11 +19,12 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 4 #define N 100 -#include "common.c" #define ALL_RWXB (S_IRWXU | S_IRWXG | S_IRWXO) #define ALL_SETB (S_ISUID | S_ISGID) diff --git a/test/test35.c b/test/test35.c index d0898efb0..d997855a0 100644 --- a/test/test35.c +++ b/test/test35.c @@ -14,11 +14,12 @@ #include #include -#define MAX_ERROR 1 +int max_error = 1; +#include "common.h" + #define ITERATIONS 10 #define N 100 -#include "common.c" #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) diff --git a/test/test36.c b/test/test36.c index 1e668da24..948992ee4 100644 --- a/test/test36.c +++ b/test/test36.c @@ -12,14 +12,15 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 10 #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -#include "common.c" int superuser; diff --git a/test/test37.c b/test/test37.c index 751d67c91..17635b785 100644 --- a/test/test37.c +++ b/test/test37.c @@ -12,9 +12,10 @@ #define ITERATIONS 2 #define SIGS 14 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + -#include "common.c" int iteration, cumsig, sig1, sig2; diff --git a/test/test38.c b/test/test38.c index ff1b558ce..3b87b107b 100644 --- a/test/test38.c +++ b/test/test38.c @@ -18,7 +18,9 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 3 #define BUF_SIZE 1024 @@ -26,7 +28,6 @@ #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -#include "common.c" int superuser; int signumber = 0; diff --git a/test/test39.c b/test/test39.c index f8b3f4fed..05b143e94 100644 --- a/test/test39.c +++ b/test/test39.c @@ -2,8 +2,9 @@ #include #include #include -#define MAX_ERROR 1 -#include "common.c" +int max_error = 1; +#include "common.h" + void test39a(void); diff --git a/test/test4.c b/test/test4.c index 877ac4948..3cf6c9fa5 100644 --- a/test/test4.c +++ b/test/test4.c @@ -15,9 +15,10 @@ int s, i, fd, nextb; char *tempfile = "test4.temp"; char buf[1024]; -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + -#include "common.c" int main(void); void subr(void); diff --git a/test/test40.c b/test/test40.c index 74593e1a2..686f02268 100644 --- a/test/test40.c +++ b/test/test40.c @@ -11,8 +11,9 @@ #include #include -#define MAX_ERROR 5 -#include "common.c" +int max_error = 5; +#include "common.h" + int main(int argc, char **argv) { char *tests[] = {"t40a", "t40b", "t40c", "t40d", "t40e", "t40f"}; diff --git a/test/test41.c b/test/test41.c index 526362dd6..0cec41c9c 100644 --- a/test/test41.c +++ b/test/test41.c @@ -15,9 +15,10 @@ #include #define ITERATIONS 3 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + -#include "common.c" /* we have to keep in mind the millisecond values are rounded up */ #define UPPERUSEC(us) ((us)+(1000000/system_hz)) diff --git a/test/test42.c b/test/test42.c index 12b726cbf..3ce0aa534 100644 --- a/test/test42.c +++ b/test/test42.c @@ -11,8 +11,9 @@ #include #define ITERATIONS 3 -#define MAX_ERROR 4 -#include "common.c" +int max_error = 4; +#include "common.h" + #define _WIFSTOPPED(s) (WIFSTOPPED(s) && !WIFSIGNALED(s) && !WIFEXITED(s)) #define _WIFSIGNALED(s) (!WIFSTOPPED(s) && WIFSIGNALED(s) && !WIFEXITED(s)) diff --git a/test/test43.c b/test/test43.c index e06838af9..9ca300101 100644 --- a/test/test43.c +++ b/test/test43.c @@ -10,12 +10,13 @@ #include #include -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + int subtest; static const char *executable; -#include "common.c" #define ERR (e(__LINE__)) diff --git a/test/test44.c b/test/test44.c index 1f6dfa210..8efa9ea03 100644 --- a/test/test44.c +++ b/test/test44.c @@ -7,8 +7,9 @@ #include #include -#define MAX_ERROR 2 -#include "common.c" +int max_error = 2; +#include "common.h" + int subtest = 0; diff --git a/test/test45.c b/test/test45.c index 66e04c550..c12513c75 100644 --- a/test/test45.c +++ b/test/test45.c @@ -8,8 +8,9 @@ #pragma clang diagnostic ignored "-Wtautological-compare" #endif -#define MAX_ERROR 4 -#include "common.c" +int max_error = 4; +#include "common.h" + /* test strtol */ #define TYPE long diff --git a/test/test45.h b/test/test45.h index 3e21fb354..62ddcffb7 100644 --- a/test/test45.h +++ b/test/test45.h @@ -32,11 +32,7 @@ static void GLUE(e, TYPE_FUNC)(int n, const char *s, TYPE result, int base) /* watch out: don't overwrite the static buffer in make_string */ printf("Subtest %s, error %d, errno=%d, s=\"%s\", base=%d, ", TOSTRING(TYPE_FUNC), n, errno, s, base); printf("result=%s\n", GLUE(make_string, TYPE_FUNC)(result, base)); - if (errct++ > MAX_ERROR) - { - printf("Too many errors; test aborted\n"); - exit(1); - } + e(7); } static void GLUE(test_string, TYPE_FUNC)(const char *s, TYPE value, int base) diff --git a/test/test46.c b/test/test46.c index 3698262f2..93b80512d 100644 --- a/test/test46.c +++ b/test/test46.c @@ -28,7 +28,9 @@ void group_test_4(void); void group_test_5(void); int dotest(void (*testfunc)(void)); -#define MAX_ERROR 5 +int max_error = 5; +#include "common.h" + #define IMAGINARY_GID 100 #define IMAGINARY_GID_STR "100" #define IMAGINARY_UID 101 @@ -37,7 +39,6 @@ int dotest(void (*testfunc)(void)); setgid((IMAGINARY_GID) + 1 ); \ setuid(IMAGINARY_UID); \ } while(0) -#include "common.c" int subtest = -1, errorct = 0; diff --git a/test/test47.c b/test/test47.c index 5126cd8a8..98aaacfef 100644 --- a/test/test47.c +++ b/test/test47.c @@ -6,8 +6,9 @@ #include #include -#define MAX_ERROR 4 -#include "common.c" +int max_error = 4; +#include "common.h" + /* maximum allowed FP difference for our tests */ #define EPSILON 0.00000000023283064365386962890625 /* 2^(-32) */ diff --git a/test/test48.c b/test/test48.c index a1af20b78..814d6d71a 100644 --- a/test/test48.c +++ b/test/test48.c @@ -6,9 +6,10 @@ #include #include -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + #define err() e(__LINE__) -#include "common.c" static void printstr(const char *s) { @@ -253,7 +254,7 @@ static void memsetl(void *s, unsigned long c, size_t n) p[i] = c >> (8 * (i % sizeof(c))); } -void test_getnameinfo( +static void test_getnameinfo( unsigned long ipaddr, unsigned short port, const char *exp_node, diff --git a/test/test49.c b/test/test49.c index 1fcbeefe2..a5c69dfc8 100644 --- a/test/test49.c +++ b/test/test49.c @@ -10,8 +10,9 @@ #define ERR e(__LINE__) -#define MAX_ERROR 4 -#include "common.c" +int max_error = 4; +#include "common.h" + #define TEST_PRINTF(type, macro, value, result) \ { \ diff --git a/test/test5.c b/test/test5.c index 2960d8f27..ac72eb455 100644 --- a/test/test5.c +++ b/test/test5.c @@ -11,13 +11,14 @@ #include #define ITERATIONS 2 -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + int subtest; int zero[1024]; int sigmap[5] = {9, 10, 11}; -#include "common.c" int main(int argc, char *argv[]); void test5a(void); diff --git a/test/test50.c b/test/test50.c index 6c2d6a69d..601891a3a 100644 --- a/test/test50.c +++ b/test/test50.c @@ -6,13 +6,14 @@ #include #define ITERATIONS 1 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define TESTFILE "testfile" #define TESTSIZE 4096 #define THRESHOLD 1048576 -#include "common.c" int main(int argc, char *argv[]); void prepare(void); diff --git a/test/test51.c b/test/test51.c index ab1990252..4cac6fc5e 100644 --- a/test/test51.c +++ b/test/test51.c @@ -29,12 +29,13 @@ void just_exit(void); void test_brk(void); void verify_main_reenter(void); -#define MAX_ERROR 5 +int max_error = 5; +#include "common.h" + #define SSIZE 32768 #define ROUNDS 10 #define SWAPS 10 -#include "common.c" int subtest; ucontext_t ctx[3]; @@ -130,7 +131,7 @@ void do_parent(void) /* Returning to main thread through uc_link */ } -void fail(void) +static void fail(void) { /* Shouldn't get here */ err(5, 1); diff --git a/test/test52.c b/test/test52.c index 1ac0e2f6a..59f6d6f76 100644 --- a/test/test52.c +++ b/test/test52.c @@ -8,9 +8,10 @@ #define ROUNDS 20 #define SWAPS 40 -#define MAX_ERROR 5 +int max_error = 5; +#include "common.h" + -#include "common.c" int pipefdc[2]; int pipefdp[2]; diff --git a/test/test53.c b/test/test53.c index 67794aed0..6f946a688 100644 --- a/test/test53.c +++ b/test/test53.c @@ -8,10 +8,11 @@ #include #define ERR err(__LINE__) -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define TIMED 0 -#include "common.c" static volatile int expect_SIGFPE; static u64_t i, j, k; @@ -27,10 +28,7 @@ static void err(int line) ex64hi(k), ex64lo(k)); /* quit after too many errors */ - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - quit(); - } + e(7); } #define LENGTHOF(arr) (sizeof(arr) / sizeof(arr[0])) diff --git a/test/test54.c b/test/test54.c index 4bbeafb47..5caa99472 100644 --- a/test/test54.c +++ b/test/test54.c @@ -6,12 +6,13 @@ #include #include -#define MAX_ERROR 3 -#include "common.c" +int max_error = 3; +#include "common.h" + int subtest = -1; -void do_test(void) +static void do_test(void) { int fd; char *wbuf, *rbuf; diff --git a/test/test55.c b/test/test55.c index d309d390d..700ee1a14 100644 --- a/test/test55.c +++ b/test/test55.c @@ -8,11 +8,12 @@ #define TRIALS 10 #define SIZE 65536 -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + int subtest; char *filename = "statvfs_test_XXXXXX"; -#include "common.c" void create_file(void) { diff --git a/test/test56.c b/test/test56.c index ce5b78f47..bbf17e056 100644 --- a/test/test56.c +++ b/test/test56.c @@ -57,10 +57,11 @@ /* Maximum number of errors that we'll allow to occur before this test * program gives us and quits. */ -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + /* Use the common testing code instead of reinventing the wheel. */ -#include "common.c" /* path of the unix domain socket */ #define TEST_SUN_PATH "test.sock" @@ -131,12 +132,7 @@ void test_fail_fl(char *msg, char *file, int line) free(timestamp); timestamp = NULL; } - errct++; - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - quit(); - exit(1); - } + e(7); } #define test_fail(msg) test_fail_fl(msg, __FILE__, __LINE__) diff --git a/test/test57.c b/test/test57.c index 6efcad257..0720e111b 100644 --- a/test/test57.c +++ b/test/test57.c @@ -28,7 +28,7 @@ void check_context_loop(void); unsigned long newstate[REGS], origstate[REGS]; -void handler(int signal) +static void handler(int signal) { int st; sigset_t set, oset; diff --git a/test/test58.c b/test/test58.c index 6ce9a8af5..c327639eb 100644 --- a/test/test58.c +++ b/test/test58.c @@ -22,11 +22,12 @@ #include int subtest = -1; -#define MAX_ERROR 999 /* Effectively no limit. This is necessary as this +int max_error = 999; /* Effectively no limit. This is necessary as this * test tries to undo errors and should therefore not * preemptively exit, as that would leave the FS * in a corrupted state. */ -#include "common.c" + +#include "common.h" #define TEST_PATH "a/b/c" #define INTEGR_MSG "You might want to check fs integrity\n" diff --git a/test/test59.c b/test/test59.c index 100634c01..b67d86236 100644 --- a/test/test59.c +++ b/test/test59.c @@ -14,10 +14,10 @@ #define event_t mthread_event_t #define rwlock_t mthread_rwlock_t -#define MAX_ERROR 5 -#include "common.c" +int max_error = 5; +#include "common.h" + -int errct; static int count, condition_met; static int th_a, th_b, th_c, th_d, th_e, th_f, th_g, th_h; static int mutex_a_step, mutex_b_step, mutex_c_step; diff --git a/test/test6.c b/test/test6.c index 1e0d7a423..2976d4897 100644 --- a/test/test6.c +++ b/test/test6.c @@ -10,12 +10,13 @@ #include #include -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + int subtest = 1; int zilch[5000]; -#include "common.c" int main(int argc, char *argv []); void test6a(void); diff --git a/test/test60.c b/test/test60.c index 3375a6065..e3b1ae630 100644 --- a/test/test60.c +++ b/test/test60.c @@ -3,8 +3,9 @@ #include #include -#define MAX_ERROR 5 -#include "common.c" +int max_error = 5; +#include "common.h" + int subtest = -1; @@ -97,7 +98,7 @@ void test_setuid(void) } -void test_setugid(void) +static void test_setugid(void) { /* Execve a new process that has setuid and setgid bits set */ subtest = 5; @@ -233,7 +234,7 @@ void test_self(void) } } -void switch_to_su(void) +static void switch_to_su(void) { subtest = 0; if (setuid(0) != 0) e(1); diff --git a/test/test61.c b/test/test61.c index 42c3746e4..958dfedd9 100644 --- a/test/test61.c +++ b/test/test61.c @@ -5,8 +5,9 @@ #include #include -#define MAX_ERROR 5 -#include "common.c" +int max_error = 5; +#include "common.h" + void dangling_slink(int sub_test, char const slink_to[PATH_MAX]); diff --git a/test/test62.c b/test/test62.c index eb625aea3..348d0353d 100644 --- a/test/test62.c +++ b/test/test62.c @@ -6,8 +6,9 @@ #include #include -#define MAX_ERROR 1 -#include "common.c" +int max_error = 1; +#include "common.h" + double state = 2.0; static int count; diff --git a/test/test63.c b/test/test63.c index c838426e8..8d9581cfe 100644 --- a/test/test63.c +++ b/test/test63.c @@ -16,10 +16,11 @@ #include #include -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + #include "magic.h" -#include "common.c" int main (int argc, char *argv[]) { diff --git a/test/test64.c b/test/test64.c index 52f741c1d..e1608b85e 100644 --- a/test/test64.c +++ b/test/test64.c @@ -10,10 +10,11 @@ #include #include -#define MAX_ERROR 2 +int max_error = 2; +#include "common.h" + #include "magic.h" -#include "common.c" int main (int argc, char *argv[]) { diff --git a/test/test65.c b/test/test65.c index 27347e93c..7266e6628 100644 --- a/test/test65.c +++ b/test/test65.c @@ -6,8 +6,9 @@ #include #include -#define MAX_ERROR 0 -#include "common.c" +int max_error = 0; +#include "common.h" + #define TESTMNT "testmnt" #define TESTFILE "test.txt" diff --git a/test/test66.c b/test/test66.c index 920b137a0..b5e26b9ac 100644 --- a/test/test66.c +++ b/test/test66.c @@ -12,9 +12,10 @@ #include #include -#define MAX_ERROR 10 +int max_error = 10; +#include "common.h" + -#include "common.c" #define RESULTSNAME desired #define SUBRESULTS 131 diff --git a/test/test67.c b/test/test67.c index 7f79b397b..64fdd92c4 100644 --- a/test/test67.c +++ b/test/test67.c @@ -10,10 +10,11 @@ #include #include -#define MAX_ERROR 5 +int max_error = 5; +#include "common.h" + #define CLOEXEC_PORT 3490 #define FORK_PORT 3491 -#include "common.c" static int fd = 0; diff --git a/test/test68.c b/test/test68.c index cdc5e6f61..dd51d6b13 100644 --- a/test/test68.c +++ b/test/test68.c @@ -7,8 +7,9 @@ #include #include -#define MAX_ERROR 5 -#include "common.c" +int max_error = 5; +#include "common.h" + void copy_subtests(void); void test_pipe_cloexec(void); diff --git a/test/test69.c b/test/test69.c index 7c1a6e631..403d82508 100644 --- a/test/test69.c +++ b/test/test69.c @@ -13,14 +13,15 @@ #include #define TRIALS 100 -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #ifndef DEBUG #define DEBUG 0 #endif int subtest = 1; -#include "common.c" int main(void); void quit(void); diff --git a/test/test7.c b/test/test7.c index 978394995..c8b78f117 100644 --- a/test/test7.c +++ b/test/test7.c @@ -18,7 +18,9 @@ #include #define ITERATIONS 4 -#define MAX_ERROR 3 +int max_error = 3; +#include "common.h" + #define ITEMS 32 #define READ 10 #define WRITE 20 @@ -28,7 +30,6 @@ char buf[ITEMS] = {0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9}; -#include "common.c" int subtes, xfd; int whence = SEEK_SET, func_code = F_SETLK; diff --git a/test/test8.c b/test/test8.c index cfc20a531..693b9d144 100644 --- a/test/test8.c +++ b/test/test8.c @@ -12,13 +12,14 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + #define ITERATIONS 60 #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") -#include "common.c" int subtest; diff --git a/test/test9.c b/test/test9.c index 67b6042b0..65689c140 100644 --- a/test/test9.c +++ b/test/test9.c @@ -4,9 +4,10 @@ #include #include -#define MAX_ERROR 4 +int max_error = 4; +#include "common.h" + -#include "common.c" char *tmpa;