diff --git a/tests/alloca.c b/tests/alloca.c index 3d774c5fccae729e8d7ba258ac25c483382e77d0..0e4a2d49028276587b45ce44ccb2107536ca4434 100644 --- a/tests/alloca.c +++ b/tests/alloca.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char *str = (char *) alloca(17); diff --git a/tests/args.c b/tests/args.c index c868d78d2ea587058bae3a3b83fbdadd41b846f7..6dc49d13259989b4b82daf728243d2f04a4cf8b2 100644 --- a/tests/args.c +++ b/tests/args.c @@ -1,6 +1,8 @@ #include <string.h> #include <unistd.h> +#include "test_helpers.h" + int main(int argc, char *argv[]) { for(int i = 0; i < argc; i++) { write(STDOUT_FILENO, argv[i], strlen(argv[i])); diff --git a/tests/arpainet.c b/tests/arpainet.c index cae9921b5490f8025dd8bb4a4af178615138ac0f..4b9f4a4067b6c5168f841bc4a4c185bfa4ca1bfa 100644 --- a/tests/arpainet.c +++ b/tests/arpainet.c @@ -3,6 +3,8 @@ #include <string.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { uint32_t hl = 0xBADFACED; uint32_t nl = htonl(hl); @@ -20,5 +22,4 @@ int main(void) { struct in_addr* addr = malloc(sizeof addr); inet_aton(addr_str, addr); assert(strcmp(inet_ntoa(*addr), addr_str) == 0); - } diff --git a/tests/assert.c b/tests/assert.c index 0ab46cafa2d41ecf512ec216c35e5f040b30e881..6049a38e173db3fd8f0d61030c06e76e667b855d 100644 --- a/tests/assert.c +++ b/tests/assert.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { assert(1 == 1); assert(1 + 1 == 2); diff --git a/tests/constructor.c b/tests/constructor.c index 38fc58cbaf9fd037751e3cf122939e07636272c4..ddde65029fed9606baa463d2506ad9ac1ecde639 100644 --- a/tests/constructor.c +++ b/tests/constructor.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include "test_helpers.h" __attribute__((constructor)) void constructor_no_priority(void) { diff --git a/tests/ctype.c b/tests/ctype.c index 1dd70680f246f7339232185f8e98f41e3741ebeb..de7ebb59d1e7e6c4ded407a2fba193498be2a94e 100644 --- a/tests/ctype.c +++ b/tests/ctype.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + struct test_case { int c; int isalnum; diff --git a/tests/destructor.c b/tests/destructor.c index 40840ccde6ea8eb69bdf9b728a75018c3d9efa05..234cf2ed42550b216525951706a10d0e8eb5b73a 100644 --- a/tests/destructor.c +++ b/tests/destructor.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include "test_helpers.h" __attribute__((destructor)) void destructor_no_priority(void) { diff --git a/tests/dirent/main.c b/tests/dirent/main.c index e9f943526da46bb90c3e3da81741247f33d2337e..0a8e265d38d30dde9fe3120015253cdb8c745f97 100644 --- a/tests/dirent/main.c +++ b/tests/dirent/main.c @@ -3,6 +3,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { printf("%lu\n", sizeof(struct dirent)); diff --git a/tests/dirent/scandir.c b/tests/dirent/scandir.c index a3102e5e101adbad0e0d07749d1f9a9f48e942e8..a4d5954250093259283bbf1ddcc8a18fcc729969 100644 --- a/tests/dirent/scandir.c +++ b/tests/dirent/scandir.c @@ -3,17 +3,18 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int filter(const struct dirent* dirent) { return strstr(dirent->d_name, "3") == NULL; } int main(void) { struct dirent** array; + int len = scandir("example_dir/", &array, filter, alphasort); - if (len < 0) { - perror("scandir"); - exit(EXIT_FAILURE); - } + ERROR_IF(scandir, len, == -1); + UNEXP_IF(scandir, len, < 0); for(int i = 0; i < len; i += 1) { puts(array[i]->d_name); diff --git a/tests/error.c b/tests/error.c index 09756286f8a30fc84b2524a103c225f9e3adba12..0ae8de70db80be565539cc3ab0963fc688558667 100644 --- a/tests/error.c +++ b/tests/error.c @@ -3,6 +3,8 @@ #include <string.h> #include <errno.h> +#include "test_helpers.h" + int main(void) { chdir("nonexistent"); printf("errno: %d = %s\n", errno, strerror(errno)); diff --git a/tests/fcntl/create.c b/tests/fcntl/create.c index a5b6ffe30c41f45a635ebbe3ccf1f829657c586e..1d7dce6e8028c2bfec79d3d68efdba7e5a8483af 100644 --- a/tests/fcntl/create.c +++ b/tests/fcntl/create.c @@ -2,14 +2,13 @@ #include <stdlib.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { int fd = creat("create.out", 0755); - if (fd >= 0) { - write(fd, "Hello World!\n", 13); - close(fd); - exit(EXIT_SUCCESS); - } else { - write(STDERR_FILENO, "creat failed\n", 13); - exit(EXIT_FAILURE); - } + ERROR_IF(creat, fd, == -1); + UNEXP_IF(creat, fd, < 0); + + write(fd, "Hello World!\n", 13); + close(fd); } diff --git a/tests/fcntl/fcntl.c b/tests/fcntl/fcntl.c index 3ec16a84d145c3952983b4bf236dbf5a1c58c1e1..689502f2b50426c55338d1a3903d2894ae8eb152 100644 --- a/tests/fcntl/fcntl.c +++ b/tests/fcntl/fcntl.c @@ -2,12 +2,25 @@ #include <stdio.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { - //Lose our fd and pull it again - creat("fcntl.out", 0777); + // Lose our fd and pull it again + { + int fd = creat("fcntl.out", 0777); + ERROR_IF(creat, fd, == -1); + UNEXP_IF(creat, fd, < 0); + } + int newfd = open("fcntl.out", 0); + ERROR_IF(open, newfd, == -1); + UNEXP_IF(open, newfd, < 0); + int newfd2 = fcntl(newfd, F_DUPFD, 0); + // TODO: The standard doesn't define errors for F_DUPFD + printf("fd %d duped into fd %d\n", newfd, newfd2); + close(newfd); close(newfd2); } diff --git a/tests/fnmatch.c b/tests/fnmatch.c index 9fa673f539f1ec14fa0bb692fadd6509c082599f..a126cbd15277671c5765c63ef4f9fc2d55fa7cdc 100644 --- a/tests/fnmatch.c +++ b/tests/fnmatch.c @@ -1,6 +1,8 @@ #include <fnmatch.h> #include <stdio.h> +#include "test_helpers.h" + void test(char* pattern, char* input, int flags) { if (!fnmatch(pattern, input, flags)) { printf("\"%s\" matches \"%s\"\n", pattern, input); diff --git a/tests/libgen.c b/tests/libgen.c index 91b18a4f3cbc5a6f1fdc428bb67dd3873a34e20e..460e710fcb064ef7a5cd1d65edd0eef6d458b61d 100644 --- a/tests/libgen.c +++ b/tests/libgen.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + typedef struct { char * in; char * expected_out; diff --git a/tests/locale.c b/tests/locale.c index dde3364da4728c1aff54691a694f9f718e8befce..bb80cf7d0f4c505ae54096d84e2d0ec5955ca6a9 100644 --- a/tests/locale.c +++ b/tests/locale.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <string.h> +#include "test_helpers.h" + int main(void) { // TODO: Implement locale properly and test it here char* val = setlocale(LC_ALL, NULL); diff --git a/tests/math.c b/tests/math.c index 9f485b1b0e3fd66108853c0d9e15b25d73c1c955..8ff0a729117e5191b88ba22126965213d9b11990 100644 --- a/tests/math.c +++ b/tests/math.c @@ -1,6 +1,8 @@ #include <math.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { double pi = 3.14; float c = cos(pi); diff --git a/tests/netdb/getaddrinfo.c b/tests/netdb/getaddrinfo.c index b57c1bb2c5c7110d709cfb0e55430b77931fd85a..daecf8390d8eb69c463fc3b9bc9bcba2f45a679d 100644 --- a/tests/netdb/getaddrinfo.c +++ b/tests/netdb/getaddrinfo.c @@ -8,6 +8,8 @@ #include <sys/socket.h> #include <arpa/inet.h> +#include "test_helpers.h" + int main(void) { struct addrinfo hints, *res; int errcode; diff --git a/tests/netdb/netdb.c b/tests/netdb/netdb.c index d81f08d632a0c76b0d6c10fc2039946f34c74992..a7808df22fe7fb64021efcc9510ea01411e97033 100644 --- a/tests/netdb/netdb.c +++ b/tests/netdb/netdb.c @@ -35,6 +35,8 @@ #include <unistd.h> #include <errno.h> +#include "test_helpers.h" + int error_count; static void output_servent (const char *call, struct servent *sptr) diff --git a/tests/pwd.c b/tests/pwd.c index 59acfdef66eff492e5d85af26dc6693304c849f3..6e51c6c13003ecacd31cee313f286c28ca37e9ca 100644 --- a/tests/pwd.c +++ b/tests/pwd.c @@ -3,6 +3,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + void print(struct passwd *pwd) { printf("pw_name: %s\n", pwd->pw_name); printf("pw_password: %s\n", pwd->pw_passwd); diff --git a/tests/regex.c b/tests/regex.c index d59989e758643cc8c43225b8c192f0549418557e..894781e4478bec68d8a727ae3290723915c7c81d 100644 --- a/tests/regex.c +++ b/tests/regex.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { regex_t regex; char error_buf[256]; diff --git a/tests/resource/getrusage.c b/tests/resource/getrusage.c index e2384c8d5c9bbe1a055dd95b18e1f5265023cc37..4a5c51e39e71229aaab71fa67e28af162afc53e4 100644 --- a/tests/resource/getrusage.c +++ b/tests/resource/getrusage.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <sys/resource.h> +#include "test_helpers.h" + void ptimeval(struct timeval* val) { printf("{ tv_sec: %ld, tv_usec: %ld }\n", val->tv_sec, val->tv_usec); } @@ -10,10 +12,9 @@ void ptimeval(struct timeval* val) { int main(void) { struct rusage r_usage; - if (getrusage(RUSAGE_SELF, &r_usage) == -1) { - perror("getrusage"); - exit(EXIT_FAILURE); - } + int status = getrusage(RUSAGE_SELF, &r_usage); + ERROR_IF(getrusage, status, == -1); + UNEXP_IF(getrusage, status, != 0); printf("ru_utime:"); ptimeval(&r_usage.ru_utime); diff --git a/tests/select.c b/tests/select.c index 596a589a832615b34101840c5fbb13b31301d686..a367b4ce16ba4530964e5b9834161e31e88e3c71 100644 --- a/tests/select.c +++ b/tests/select.c @@ -3,6 +3,8 @@ #include <sys/select.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { int fd = open("select.c", 0, 0); diff --git a/tests/setjmp.c b/tests/setjmp.c index fe117e4dec9d75c14821399b46132569e6d1bfe3..3abc56f80496c7d0e14a816b3f32258fb784f3b6 100644 --- a/tests/setjmp.c +++ b/tests/setjmp.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <setjmp.h> +#include "test_helpers.h" + int main(void) { jmp_buf buf; if (setjmp(buf)) { diff --git a/tests/signal.c b/tests/signal.c index 3c1ceab8d8ba2889dac19dd8eef80bba998f7ef9..57d1323e2c92e0b01bbf36541c449378d547950f 100644 --- a/tests/signal.c +++ b/tests/signal.c @@ -4,6 +4,8 @@ #include <unistd.h> #include <errno.h> +#include "test_helpers.h" + void handler(int sig) { puts("Signal handler called!"); } diff --git a/tests/stdio/all.c b/tests/stdio/all.c index d1e393e3074628320e9b5103f306e5c793f8c5ed..2ccc35eb4131da5433722825a4515ca8dc408e43 100644 --- a/tests/stdio/all.c +++ b/tests/stdio/all.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { FILE *f = fopen("stdio/stdio.in", "r"); printf("%c\n", fgetc(f)); diff --git a/tests/stdio/buffer.c b/tests/stdio/buffer.c index 50b236f14829ca9df62b969a5a336a9d06b55433..69efe8ebac27cb25d61e38a8b9bee5183e106a43 100644 --- a/tests/stdio/buffer.c +++ b/tests/stdio/buffer.c @@ -1,5 +1,7 @@ #include <stdio.h> +#include "test_helpers.h" + int main(void) { // Tests what used to be a bug with buffering fwrite("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1, 999, stdout); diff --git a/tests/stdio/fgets.c b/tests/stdio/fgets.c index 28254debefd8e45e1a52132d510e731306689a73..6e2b715bf4eb44aa7755496bffebd59f0264103d 100644 --- a/tests/stdio/fgets.c +++ b/tests/stdio/fgets.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { //FILE *f = fopen("/etc/ssl/certs/ca-certificates.crt", "r"); FILE *f = fopen("stdio/stdio.in", "r"); diff --git a/tests/stdio/fputs.c b/tests/stdio/fputs.c index 52aef7da681681329bec90fd909543cbaba54fc4..7d76d12ab1c9c3e9215581f06efb673e1bebbf53 100644 --- a/tests/stdio/fputs.c +++ b/tests/stdio/fputs.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <errno.h> +#include "test_helpers.h" + int main(void) { FILE *f = fopen("stdio/fputs.out", "w"); char *in = "Hello World!"; diff --git a/tests/stdio/fread.c b/tests/stdio/fread.c index e69b6f1700df5cb05f220d57b6540368db48e0a6..ea14368ebfb34fec36d91cff64082d4cf0ca4a3e 100644 --- a/tests/stdio/fread.c +++ b/tests/stdio/fread.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { FILE *fp = fopen("stdio/fread.in", "rb"); diff --git a/tests/stdio/freopen.c b/tests/stdio/freopen.c index e7ec2c271d3d19a745c02aec2c9eceb78a740806..f6b4dbed91413d22cfd10d883a160ac84b480fb5 100644 --- a/tests/stdio/freopen.c +++ b/tests/stdio/freopen.c @@ -1,5 +1,7 @@ #include <stdio.h> +#include "test_helpers.h" + int main(void) { freopen("stdio/stdio.in", "r", stdin); char in[6]; diff --git a/tests/stdio/fseek.c b/tests/stdio/fseek.c index ddbcfb67785c44b03c110f1d258936019117ed32..c07cf79b58f1c94ca7848814556b219cd659a722 100644 --- a/tests/stdio/fseek.c +++ b/tests/stdio/fseek.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { FILE *f = fopen("stdio/stdio.in", "r"); if (fseek(f, 14, SEEK_CUR) < 0) { diff --git a/tests/stdio/fwrite.c b/tests/stdio/fwrite.c index c858cca17450ace8d1b321e44db8a6725fc0f688..24c7040fb79789e69bf4305f5168f2a97d05fe10 100644 --- a/tests/stdio/fwrite.c +++ b/tests/stdio/fwrite.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <errno.h> +#include "test_helpers.h" + int main(void) { FILE *f = fopen("stdio/fwrite.out", "w"); const char ptr[] = "Hello World!"; diff --git a/tests/stdio/getc_unget.c b/tests/stdio/getc_unget.c index fded82577f3abb687410d31073d6772b3c83c68a..77351c40f14c274dc542a356b8d77396e8cb04e7 100644 --- a/tests/stdio/getc_unget.c +++ b/tests/stdio/getc_unget.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { ungetc('h', stdin); char c; diff --git a/tests/stdio/mutex.c b/tests/stdio/mutex.c index 229e3f56ec7dbc620ce129ad8f79b794b05468e5..aae45caa12bb315d707be6c14a673e838a43a12b 100644 --- a/tests/stdio/mutex.c +++ b/tests/stdio/mutex.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { FILE* f = fopen("stdio/stdio.in", "r"); diff --git a/tests/stdio/popen.c b/tests/stdio/popen.c index b534fb9f5e8b7b85aa7f492795f5b052cc50aee1..967ad78ace7bdf8cfa26d7a16377f668978840f5 100644 --- a/tests/stdio/popen.c +++ b/tests/stdio/popen.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { FILE *fp; int status; diff --git a/tests/stdio/printf.c b/tests/stdio/printf.c index ea7b8dde0233060ee0f975fef646cb1675f48e21..f36cc970c7e60e00f0d60ee8ed7e9d4e408e52a0 100644 --- a/tests/stdio/printf.c +++ b/tests/stdio/printf.c @@ -1,5 +1,7 @@ #include <stdio.h> +#include "test_helpers.h" + int main(void) { int sofar = 0; int len = printf( diff --git a/tests/stdio/rename.c b/tests/stdio/rename.c index 31cf8f252db6d56c70999326895706650aa0f0c7..5c0dc89de643ff2a0c49141625e558a264969bfe 100644 --- a/tests/stdio/rename.c +++ b/tests/stdio/rename.c @@ -4,6 +4,8 @@ #include <string.h> #include <unistd.h> +#include "test_helpers.h" + static char oldpath[] = "old-name.out"; static char newpath[] = "new-name.out"; static char str[] = "Hello, World!"; diff --git a/tests/stdio/scanf.c b/tests/stdio/scanf.c index a19daaf3bb35f9c12b60bb16fe5f4ae31fc7ebe8..8978928cea14b93e0faa2b3c87c396d73b977b80 100644 --- a/tests/stdio/scanf.c +++ b/tests/stdio/scanf.c @@ -1,6 +1,8 @@ #include <stdarg.h> #include <stdio.h> +#include "test_helpers.h" + struct params { short sa; int ia; diff --git a/tests/stdio/setvbuf.c b/tests/stdio/setvbuf.c index 2b0356bf15dee4c0bdf014e002458ad83992cbea..2e79590abafab178c7f35e203ee5054e03ba7919 100644 --- a/tests/stdio/setvbuf.c +++ b/tests/stdio/setvbuf.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { setvbuf(stdout, 0, _IONBF, 0); FILE *f = fopen("stdio/stdio.in", "r"); diff --git a/tests/stdio/sprintf.c b/tests/stdio/sprintf.c index 2de35e450848fdfa4dc6379018765654534f2dd6..0c29fe291b05edb11b6c1bd1566efd3ef1336394 100644 --- a/tests/stdio/sprintf.c +++ b/tests/stdio/sprintf.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char buffer[72]; diff --git a/tests/stdlib/a64l.c b/tests/stdlib/a64l.c index ddf7d885263783df7a11965ee31965bfa2956123..24937f52061f9bc6a79b0d6de04090b4c05fa252 100644 --- a/tests/stdlib/a64l.c +++ b/tests/stdlib/a64l.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char * s = "azAZ9."; // test boundaries long l = a64l(s); diff --git a/tests/stdlib/alloc.c b/tests/stdlib/alloc.c index b21dfadb187c0f2231774dd339e45b35efca099c..29bc41ebe71be6e2178e27b25d0b9770a0c1f49d 100644 --- a/tests/stdlib/alloc.c +++ b/tests/stdlib/alloc.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { char * ptr = (char *)malloc(256); printf("malloc %p\n", ptr); diff --git a/tests/stdlib/atof.c b/tests/stdlib/atof.c index 19f6e25c7753a070c56c26a8b5159bc86a9934cd..ec945ef6972d4d537db0b8153b37a47e5ca2e310 100644 --- a/tests/stdlib/atof.c +++ b/tests/stdlib/atof.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { double d = atof("-3.14"); printf("%f\n", d); diff --git a/tests/stdlib/atoi.c b/tests/stdlib/atoi.c index 3e06f29c890fdd5d0eb7ffac3912556b853e6c29..26497f27f4a84f98989da485f4ba41626ed17508 100644 --- a/tests/stdlib/atoi.c +++ b/tests/stdlib/atoi.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%d\n", atoi(" -42")); printf("%d\n", atoi(" +555")); diff --git a/tests/stdlib/bsearch.c b/tests/stdlib/bsearch.c index 678e8a7e83f8526fd53b9d37e9780883d6add59b..fe55cfce70c66a495103f29bf17ceb4f00da5438 100644 --- a/tests/stdlib/bsearch.c +++ b/tests/stdlib/bsearch.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int int_cmp(const void* a, const void* b) { return *(const int*) a - *(const int*) b; } diff --git a/tests/stdlib/div.c b/tests/stdlib/div.c index 394e8423789cd842223f8382276ba1ddc2e8a6a9..5a768b8ed80645d396cbe47dd5cf5d65ec3b09dc 100644 --- a/tests/stdlib/div.c +++ b/tests/stdlib/div.c @@ -1,20 +1,23 @@ #include <stdlib.h> - volatile float f; - volatile long double ld; - volatile unsigned long long ll; - lldiv_t mydivt; + +#include "test_helpers.h" + +volatile float f; +volatile long double ld; +volatile unsigned long long ll; +lldiv_t mydivt; int main(void) { - char* tmp; - f = strtof("gnu", &tmp); - ld = strtold("gnu", &tmp); - ll = strtoll("gnu", &tmp, 10); - ll = strtoull("gnu", &tmp, 10); - ll = llabs(10); - mydivt = lldiv(10,1); - ll = mydivt.quot; - ll = mydivt.rem; - ll = atoll("10"); - _Exit(0); + char* tmp; + f = strtof("gnu", &tmp); + ld = strtold("gnu", &tmp); + ll = strtoll("gnu", &tmp, 10); + ll = strtoull("gnu", &tmp, 10); + ll = llabs(10); + mydivt = lldiv(10,1); + ll = mydivt.quot; + ll = mydivt.rem; + ll = atoll("10"); + _Exit(0); } diff --git a/tests/stdlib/env.c b/tests/stdlib/env.c index 5bdda7f3d5db35b4aaf3a0b240be15ce63ce575a..b5524067b12e15f4da733027ddb7b4a98a506040 100644 --- a/tests/stdlib/env.c +++ b/tests/stdlib/env.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { //puts(getenv("SHELL")); //puts(getenv("CC")); diff --git a/tests/stdlib/mkostemps.c b/tests/stdlib/mkostemps.c index aa544e9aa7d1818d59f70ead054ee0d5a360bc91..370ffd009a4955fbee30ccf504cd5672a340df46 100644 --- a/tests/stdlib/mkostemps.c +++ b/tests/stdlib/mkostemps.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char* file_name = (char*) calloc(18, sizeof(char)); strcpy(file_name, "tempXXXXXX.suffix"); diff --git a/tests/stdlib/mktemp.c b/tests/stdlib/mktemp.c index 0a23e6ed25522f86edfc6a87082b14aa79154deb..7d43078e4b0edccf97db60a7095912d5bf4d43b9 100644 --- a/tests/stdlib/mktemp.c +++ b/tests/stdlib/mktemp.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char* string = (char*) calloc(20, sizeof(char)); strcpy(string, "tempXXXXXX"); diff --git a/tests/stdlib/rand.c b/tests/stdlib/rand.c index f3883c3fdbdc9246cc422257c78a2831d340b330..a665e2a4661274de9861839b1e31fd96a8158708 100644 --- a/tests/stdlib/rand.c +++ b/tests/stdlib/rand.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%d\n", rand()); srand(259); diff --git a/tests/stdlib/realpath.c b/tests/stdlib/realpath.c index c5df66f9dd9794642a12e1e80948144d57ab87b8..a1583f864df1d78853763994794c8a570ad860e2 100644 --- a/tests/stdlib/realpath.c +++ b/tests/stdlib/realpath.c @@ -4,6 +4,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char* path = realpath("stdlib/realpath.c", NULL); if (!path) { diff --git a/tests/stdlib/strtod.c b/tests/stdlib/strtod.c index ae88af4db2648110d2d3585454752511cfdcd817..d6826f67617e8bc34d7997a1bc9134f2fd32268f 100644 --- a/tests/stdlib/strtod.c +++ b/tests/stdlib/strtod.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char* endptr = 0; double d; diff --git a/tests/stdlib/strtol.c b/tests/stdlib/strtol.c index 2977d64747fcdc6f9936f4eaab798ff7391c32e7..17c4155de62a87dba67891bddc63e0311ad2c0f8 100644 --- a/tests/stdlib/strtol.c +++ b/tests/stdlib/strtol.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%ld\n", strtol(" -42", NULL, 0)); printf("%ld\n", strtol(" +555", NULL, 0)); diff --git a/tests/stdlib/strtoul.c b/tests/stdlib/strtoul.c index afb903cb386287a4f3b5761f70682eb0e4bc4df7..365f268c919cec540c0bf2b16c04a8eb22fcd1c8 100644 --- a/tests/stdlib/strtoul.c +++ b/tests/stdlib/strtoul.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%ld\n", strtoul(" -42", NULL, 0)); printf("%ld\n", strtoul(" +555", NULL, 0)); diff --git a/tests/stdlib/system.c b/tests/stdlib/system.c index 5e9d662cd64a4ac34f736e67b5060264415a5b32..8b7d02201aca1b94dc249866d4a5149ed917c113 100644 --- a/tests/stdlib/system.c +++ b/tests/stdlib/system.c @@ -1,5 +1,8 @@ #include <stdlib.h> +#include "test_helpers.h" + int main(void) { - system("echo test of system"); + int status = system("echo test of system"); + ERROR_IF(system, status, == -1); } diff --git a/tests/string/mem.c b/tests/string/mem.c index 305d643904a62f7eb70b3790b9b19e12972faa1b..5b1b497b403ebc53d3ea9e7188004d288bbf2f65 100644 --- a/tests/string/mem.c +++ b/tests/string/mem.c @@ -2,6 +2,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { puts("# mem #"); char arr[100]; diff --git a/tests/string/strcat.c b/tests/string/strcat.c index 0653b7f480140ccfc1be13539c185c4ead42017d..cbfe52218be26b8632ba8559112c0e2cc47330dc 100644 --- a/tests/string/strcat.c +++ b/tests/string/strcat.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char dest1[12] = "hello"; printf("%s\n", strcat(dest1, " world")); // should be hello world diff --git a/tests/string/strchr.c b/tests/string/strchr.c index fb2e07e056fa060c849a7e26387f1271ebe7b6a3..ebe973a51a8633666407a89299ed1e850b5ffdc7 100644 --- a/tests/string/strchr.c +++ b/tests/string/strchr.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%s\n", strchr("hello", 'e')); // should be ello printf("%s\n", strchr("world", 'l')); // should be ld diff --git a/tests/string/strcpy.c b/tests/string/strcpy.c index 69159d738e275b70686160084fa759ad272401f4..d78d26e51b9c96f4568891c6da6c0ef69ba94cdb 100644 --- a/tests/string/strcpy.c +++ b/tests/string/strcpy.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <string.h> +#include "test_helpers.h" + int main(void) { char dst[20]; diff --git a/tests/string/strcspn.c b/tests/string/strcspn.c index 7370558c912acae854736f54b6648d1ddee267d0..969d6ec66362c49ac92a7405b0c498d7094228db 100644 --- a/tests/string/strcspn.c +++ b/tests/string/strcspn.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char *world = "world"; printf("%ld\n", strcspn("hello", world)); // should be 2 diff --git a/tests/string/strncmp.c b/tests/string/strncmp.c index fd4033c8e650369f7dc443f6f1d18600e1f2bd90..d42b3e39a514a3bebb04768e8bf1bb1df73d4a03 100644 --- a/tests/string/strncmp.c +++ b/tests/string/strncmp.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%d\n", strncmp("a", "aa", 2)); printf("%d\n", strncmp("a", "aä", 2)); diff --git a/tests/string/strpbrk.c b/tests/string/strpbrk.c index bb5ca56ee0d9f0adac1f99635d521f883291fda8..88e62f74637bd93f2c8083bd0b0c19f17c714df2 100644 --- a/tests/string/strpbrk.c +++ b/tests/string/strpbrk.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char* source = "The quick drawn fix jumps over the lazy bug"; diff --git a/tests/string/strrchr.c b/tests/string/strrchr.c index a8ae06c024212f519dba040a4c3abb25f0155001..379d023d6afc19031b5d23332a12babcd50756c9 100644 --- a/tests/string/strrchr.c +++ b/tests/string/strrchr.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { char s0[] = "hello, world"; char* ptr = strrchr(s0, 'l'); diff --git a/tests/string/strspn.c b/tests/string/strspn.c index c198a20bf0b4bc43d862df8419663e4634aeb5fc..2f5ae33e9d611d7da3d0c403b3939ea4dd65d2ff 100644 --- a/tests/string/strspn.c +++ b/tests/string/strspn.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char *hello = "hello"; char *world = "world"; diff --git a/tests/string/strstr.c b/tests/string/strstr.c index d36b4d915a5d888b7ea44aac25bdbc642a039dd0..aa097864caa1da705d0ebaf27b613fbabf41229f 100644 --- a/tests/string/strstr.c +++ b/tests/string/strstr.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { printf("%s\n", strstr("In relibc we trust", "rust")); printf("%s\n", strstr("In relibc we trust", "libc")); diff --git a/tests/string/strtok.c b/tests/string/strtok.c index d2e066acb368cdfdef89ec28301f36d3e36a86b8..4781968e826a8e3ce74331a97ea95635e0117093 100644 --- a/tests/string/strtok.c +++ b/tests/string/strtok.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, " "is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux.\n"; diff --git a/tests/string/strtok_r.c b/tests/string/strtok_r.c index 8873635c69dc6c4fef027280c0953097e0c4a8dd..1c188c76b10c49f299c62f8fea27754f2445f358 100644 --- a/tests/string/strtok_r.c +++ b/tests/string/strtok_r.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, " "is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux.\n"; diff --git a/tests/strings.c b/tests/strings.c index 11cdb48feb9fa35e82f1133dda8a57f38deeefc9..6d3c4742cbb20c38dc3640cfe907dcf23477f23b 100644 --- a/tests/strings.c +++ b/tests/strings.c @@ -3,6 +3,8 @@ #include <stdio.h> #include <strings.h> +#include "test_helpers.h" + int main(void) { assert(!bcmp("hello", "hehe", 2)); assert(bcmp("hello", "haha", 2)); diff --git a/tests/sys_utsname/uname.c b/tests/sys_utsname/uname.c index 8e094df416cba07aa2d6dd83d65024004db2e4ed..836fef71fd8c0dcfb4d683af9501250f0f64cd24 100644 --- a/tests/sys_utsname/uname.c +++ b/tests/sys_utsname/uname.c @@ -1,19 +1,19 @@ #include <stdio.h> #include <sys/utsname.h> +#include "test_helpers.h" + int main(void) { struct utsname system_info; int result = uname(&system_info); + ERROR_IF(uname, result, == -1); + UNEXP_IF(uname, result, < 0); - if (result < 0) { - perror("uname"); - } else { - printf("sysname: '%s'\n", system_info.sysname); - printf("nodename: '%s'\n", system_info.nodename); - printf("release: '%s'\n", system_info.release); - printf("version: '%s'\n", system_info.version); - printf("machine: '%s'\n", system_info.machine); - //printf("domainname: '%s'\n", system_info.domainname); - } + printf("sysname: '%s'\n", system_info.sysname); + printf("nodename: '%s'\n", system_info.nodename); + printf("release: '%s'\n", system_info.release); + printf("version: '%s'\n", system_info.version); + printf("machine: '%s'\n", system_info.machine); + //printf("domainname: '%s'\n", system_info.domainname); } diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 2905ab0818494fabe9298351118fc4fb1f610eda..6db31e2d7a2b9f99282b9db1d14d766eec7dd1a1 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -1,27 +1,40 @@ #ifndef _TEST_HELPERS #define _TEST_HELPERS +#include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> +#include <unistd.h> // Throws an error on a well-defined error value. +// Don't pass functions as status or condition, it might evaluate them multiple times. #define ERROR_IF(func, status, condition) { \ if (status condition) { \ - fprintf(stderr, "%s:%d: ‘%s‘ returned an error in function ‘%s’: %s (%d)\n", \ - __FILE__, __LINE__, #func, __func__, strerror(errno), errno); \ - exit(EXIT_FAILURE); \ + fprintf(stderr, "%s:%s:%d: '%s' returned an error: %s (%d)\n", \ + __FILE__, __func__, __LINE__, #func, strerror(errno), errno); \ + _exit(EXIT_FAILURE); \ }\ } // Throws an error on an return value not defined by the standards. // Used for sanity checking the return values. +// Don't pass functions as status or condition it might evaluate them multiple times. #define UNEXP_IF(func, status, condition) { \ if (status condition) { \ - fprintf(stderr, "%s:%d: ‘%s‘ returned a value not defined by the standards in function ‘%s’: %d\n", \ - __FILE__, __LINE__, #func, __func__, status); \ - exit(EXIT_FAILURE); \ + fprintf(stderr, "%s:%s:%d: '%s' returned a non-standard value: %d\n", \ + __FILE__, __func__, __LINE__, #func, status); \ + _exit(EXIT_FAILURE); \ }\ } +// A convenience macro to show where the test fail. +#define exit(code) { \ + if (code != EXIT_SUCCESS) { \ + fprintf(stderr, "%s:%s:%d: Test failed with exit(%s)\n", \ + __FILE__, __func__, __LINE__, #code); \ + } \ + _exit(code); \ +} + #endif /* _TEST_HELPERS */ diff --git a/tests/time/asctime.c b/tests/time/asctime.c index 9f7e2b5494854e5a2de30d983bb6a46817c94ac7..480de464a7863ec44dd1ff06c2cccd1c7daf5539 100644 --- a/tests/time/asctime.c +++ b/tests/time/asctime.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { time_t a = 0; struct tm *time_info = gmtime(&a); diff --git a/tests/time/gettimeofday.c b/tests/time/gettimeofday.c index a17e2aedf553ca5a10b8037254cead3b254580db..e43b38dc862c2e265fac61dbd8a4246837384ddc 100644 --- a/tests/time/gettimeofday.c +++ b/tests/time/gettimeofday.c @@ -1,8 +1,14 @@ #include <sys/time.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { struct timeval tv; - gettimeofday(&tv, NULL); + + // gettimeofday always returns 0, no errors are defined + int gtod = gettimeofday(&tv, NULL); + UNEXP_IF(gettimeofday, gtod, != 0); + printf("%ld: %ld\n", tv.tv_sec, tv.tv_usec); } diff --git a/tests/time/gmtime.c b/tests/time/gmtime.c index a0af0ab6beca24544999248dc209a971e189ad11..a77d19fb9a172040c82ae15d2d14b3505ca691b7 100644 --- a/tests/time/gmtime.c +++ b/tests/time/gmtime.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <string.h> +#include "test_helpers.h" + int main(void) { time_t a = 0; struct tm expected = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_year = 70, diff --git a/tests/time/localtime.c b/tests/time/localtime.c index 5f96b3ea2302720ef2c085b1295add987ad12341..df8d2d550f7b4f659f036484679b964e61425583 100644 --- a/tests/time/localtime.c +++ b/tests/time/localtime.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <time.h> +#include "test_helpers.h" + int main(void) { int day = 60 * 60 * 24; time_t inputs[] = { -(day * 33), -day, -1, -500, 0, 1, 1531454950 }; diff --git a/tests/time/macros.c b/tests/time/macros.c index 737dab831f0b39dd2e7ccfb76da4a2d6e36ad7d0..60e2f96e7c434581bdb33d4708208253e56b639e 100644 --- a/tests/time/macros.c +++ b/tests/time/macros.c @@ -1,6 +1,8 @@ #include <assert.h> #include <sys/time.h> +#include "test_helpers.h" + int main(void) { struct timeval x = { .tv_usec = 15 }; struct timeval y = { 0 }; diff --git a/tests/time/mktime.c b/tests/time/mktime.c index f3010de6e77718f302c9a921d04e6e7166147b2e..79e5e3cf6787be32b6bfc0f07e8e101462540cf1 100644 --- a/tests/time/mktime.c +++ b/tests/time/mktime.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <time.h> +#include "test_helpers.h" + int check(time_t input) { struct tm* t = localtime(&input); diff --git a/tests/time/strftime.c b/tests/time/strftime.c index 99da578bfd92f5643a001372734a73f7f2ee8db0..c9299e0b21b30ca9f50bc025d6eb63eab5eafeee 100644 --- a/tests/time/strftime.c +++ b/tests/time/strftime.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <time.h> +#include "test_helpers.h" + void print(time_t timestamp, char* fmt) { char* out = malloc(50); size_t n = strftime(out, 50, fmt, localtime(×tamp)); diff --git a/tests/time/time.c b/tests/time/time.c index 8ee969ed2fdd1daa1fce942bd5b217dbcdde7fae..84b818ddb681b777b01453e0dff89e40c98e489e 100644 --- a/tests/time/time.c +++ b/tests/time/time.c @@ -2,24 +2,17 @@ #include <stdio.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { struct timespec tm = {0, 0}; int cgt = clock_gettime(CLOCK_REALTIME, &tm); - if (cgt == -1) { - perror("clock_gettime"); - exit(EXIT_FAILURE); - } + ERROR_IF(clock_gettime, cgt, == -1); time_t t = time(NULL); - if (t == (time_t)-1) { - perror("time"); - exit(EXIT_FAILURE); - } + ERROR_IF(time, t, == (time_t)-1); clock_t c = clock(); - if (c == (clock_t)-1) { - perror("clock"); - exit(EXIT_FAILURE); - } + ERROR_IF(clock, c, == (clock_t)-1); } diff --git a/tests/time/times.c b/tests/time/times.c index 91829b4cadb1f1c9612366b652b75dc85ad560b2..018f9423e7d86c08b3363ab6db1b4fe6af0658e3 100644 --- a/tests/time/times.c +++ b/tests/time/times.c @@ -2,9 +2,13 @@ #include <sys/times.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { struct tms tms; - printf("return: %ld\n", times(&tms)); + + int status = times(&tms); + ERROR_IF(times, status, == (time_t)-1); printf("tm_utime: %ld\n", tms.tms_utime); printf("tm_stime: %ld\n", tms.tms_stime); diff --git a/tests/unistd/access.c b/tests/unistd/access.c index f7a5ecf6ae83f1a09c9c3846c23b6d9671bf027b..87ee7c9fbccb84d177e1774d8581c709c0c1fe0f 100644 --- a/tests/unistd/access.c +++ b/tests/unistd/access.c @@ -2,6 +2,8 @@ #include <unistd.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { if (access("example_dir/1-never-gonna-give-you-up", R_OK | W_OK)) { perror("access"); diff --git a/tests/unistd/dup.c b/tests/unistd/dup.c index 0c7ff8ecb9061a8d17cd29aecb241dc0e5b0fbaa..ca879d6ed63e16328a256a4d28671ec23fbdfebd 100644 --- a/tests/unistd/dup.c +++ b/tests/unistd/dup.c @@ -2,15 +2,42 @@ #include <fcntl.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { - creat("dup.out", 0777); + int fd0 = creat("dup.out", 0777); + ERROR_IF(creat, fd0, == -1); + UNEXP_IF(creat, fd0, < 0); + int fd1 = open("dup.out", 0); + ERROR_IF(open, fd1, == -1); + UNEXP_IF(open, fd1, < 0); + int fd2 = dup(fd1); + ERROR_IF(dup, fd2, == -1); + UNEXP_IF(dup, fd2, < 0); + printf("fd %d duped into fd %d\n", fd1, fd2); - close(fd1); - close(fd2); + + int c1 = close(fd1); + ERROR_IF(close, c1, == -1); + UNEXP_IF(close, c1, != 0); + + int c2 = close(fd2); + ERROR_IF(close, c2, == -1); + UNEXP_IF(close, c2, != 0); + int fd3 = open("dup.out", 0x0002, 0x1000); - dup2(fd3, 1); + ERROR_IF(open, fd3, == -1); + UNEXP_IF(open, fd3, < 0); + + int fd4 = dup2(fd3, 1); + ERROR_IF(dup2, fd4, == -1); + UNEXP_IF(dup2, fd4, < 0); + printf("hello fd %d", fd3); - close(fd3); + + int c3 = close(fd3); + ERROR_IF(close, c3, == -1); + UNEXP_IF(close, c3, != 0); } diff --git a/tests/unistd/getcwd.c b/tests/unistd/getcwd.c index 22074dd7092f6e69f47c2c2c294c36d33b63d694..1df201e4f93b41489a703809518a8e169b3e587a 100644 --- a/tests/unistd/getcwd.c +++ b/tests/unistd/getcwd.c @@ -4,6 +4,8 @@ #include <string.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { char first[PATH_MAX] = { 0 }; getcwd(first, PATH_MAX); diff --git a/tests/unistd/getid.c b/tests/unistd/getid.c index d2a2bf579c96111c4b0b79d46c08d33997fe69c7..fdd8eb285db51744f77659f922168de1ddfa65eb 100644 --- a/tests/unistd/getid.c +++ b/tests/unistd/getid.c @@ -1,6 +1,8 @@ #include <unistd.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { gid_t egid = getegid(); uid_t euid = geteuid(); diff --git a/tests/unistd/getopt.c b/tests/unistd/getopt.c index b1eb262556ab9ab09f1377ce99fda9e9d5ee6246..d6f33fe0789a41f25d1b87b7883c344630296d95 100644 --- a/tests/unistd/getopt.c +++ b/tests/unistd/getopt.c @@ -1,6 +1,8 @@ #include <unistd.h> #include <stdio.h> +#include "test_helpers.h" + #define RUN(...) \ { \ optind = 1; \ diff --git a/tests/unistd/getopt_long.c b/tests/unistd/getopt_long.c index 3c947a7d54f769c73bab2bd9166ecbb8aee97743..9afca067ed7951529099300f760278230ce69ce8 100644 --- a/tests/unistd/getopt_long.c +++ b/tests/unistd/getopt_long.c @@ -1,6 +1,8 @@ #include <getopt.h> #include <stdio.h> +#include "test_helpers.h" + #define RUN(...) { \ optind = 1; \ optarg = NULL; \ diff --git a/tests/unistd/isatty.c b/tests/unistd/isatty.c index 25248c5fff3486495d2c44e34339eb91e3daaf80..5f7edfe886ed95901e0da2192251040459e06f3b 100644 --- a/tests/unistd/isatty.c +++ b/tests/unistd/isatty.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { int status = isatty(STDOUT_FILENO); diff --git a/tests/unistd/link.c b/tests/unistd/link.c index 19cf0810e72892868d8f59b92d01be1fc00b3797..a1a949fd483c7f011946ac6a27f35ed1601165b0 100644 --- a/tests/unistd/link.c +++ b/tests/unistd/link.c @@ -4,6 +4,8 @@ #include <sys/stat.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { printf("%ld\n", sizeof(struct stat)); diff --git a/tests/unistd/pathconf.c b/tests/unistd/pathconf.c index 5aeaee8b6739561c40ee03a35e2ffdbb07ad1012..fd2e6dcd1ae441f1cc3cd1abeacbf06a5207280b 100644 --- a/tests/unistd/pathconf.c +++ b/tests/unistd/pathconf.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <unistd.h> +#include "test_helpers.h" + #define PC(N) { \ errno = 0; \ printf("%s (%d): %ld (%d)\n", #N, _PC_ ## N, fpathconf(0, _PC_ ## N), errno); \ diff --git a/tests/unistd/pipe.c b/tests/unistd/pipe.c index ba1b1c9906d071ac54aa0516747f2cafe02cf0c4..88403c40adc5f922911d3ddf5b586bc41eefee55 100644 --- a/tests/unistd/pipe.c +++ b/tests/unistd/pipe.c @@ -4,6 +4,8 @@ #include <string.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { int pid, pip[2]; char instring[20]; diff --git a/tests/unistd/setid.c b/tests/unistd/setid.c index 5a35bbb54f10bf0fbf571d76727285d27f3c0eb3..c5184bddd2ade1cd2e010eba8044afa6be507c04 100644 --- a/tests/unistd/setid.c +++ b/tests/unistd/setid.c @@ -5,20 +5,24 @@ #include <sys/types.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { - if( setpgid( getpid(), 0 ) == -1 ) { - perror( "setpgid" ); - } - printf( "%d belongs to process group %d\n", - getpid(), getpgrp() ); + int pg_status = setpgid(getpid(), 0); + ERROR_IF(setpgid, pg_status, == -1); + UNEXP_IF(setpgid, pg_status, != 0); + + printf("%d belongs to process group %d\n", getpid(), getpgrp()); + + int reg_status = setregid(-1, -1); + ERROR_IF(setregid, reg_status, == -1); + UNEXP_IF(setregid, reg_status, != 0); - if( setregid(-1, -1) == -1 ) { - perror( "setregid" ); - } printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid()); - if( setreuid(-1, -1) == -1 ) { - perror( "setreuid" ); - } + int reu_status = setreuid(-1, -1); + ERROR_IF(setreuid, reu_status, == -1); + UNEXP_IF(setreuid, reu_status, != 0); + printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid()); } diff --git a/tests/unistd/sleep.c b/tests/unistd/sleep.c index 7aa46108c96f42ceae0799b104232ebe7f99b608..5f4005eb1215ce0088b5efbacdc593f6eddf944c 100644 --- a/tests/unistd/sleep.c +++ b/tests/unistd/sleep.c @@ -2,6 +2,8 @@ #include <unistd.h> #include <stdio.h> +#include "test_helpers.h" + int main(void) { sleep(2); perror("sleep"); diff --git a/tests/unistd/stat.c b/tests/unistd/stat.c index 00997ca43b7613bec8956652de6873702cac1faa..be856646bd1f09b925911ac338d66fb628f666b1 100644 --- a/tests/unistd/stat.c +++ b/tests/unistd/stat.c @@ -4,15 +4,16 @@ #include <sys/stat.h> #include <unistd.h> +#include "test_helpers.h" + int main(void) { - printf("%ld\n", sizeof(struct stat)); + printf("sizeof(struct stat): %ld\n", sizeof(struct stat)); struct stat buf; - if (stat("unistd/stat.c", &buf)) { - perror("stat"); - exit(EXIT_FAILURE); - } + int stat_status = stat("unistd/stat.c", &buf); + ERROR_IF(stat, stat_status, == -1); + UNEXP_IF(stat, stat_status, != 0); printf("st_size: %lu\n", buf.st_size); printf("st_blksize: %lu\n", buf.st_blksize); diff --git a/tests/unistd/sysconf.c b/tests/unistd/sysconf.c index be64b647c6cfefce5d6ce1b4993cb6f2ee8f1180..7d9031366e52c54e31735e08f3b64906f8a226e1 100644 --- a/tests/unistd/sysconf.c +++ b/tests/unistd/sysconf.c @@ -2,6 +2,8 @@ #include <stdio.h> #include <unistd.h> +#include "test_helpers.h" + #define SC(N) { \ errno = 0; \ printf("%s (%d): %ld (%d)\n", #N, _SC_ ## N, sysconf(_SC_ ## N), errno); \ diff --git a/tests/unistd/write.c b/tests/unistd/write.c index 47cc4e0213834108763f653d2d744ae8dab7ca2b..5dde94c727f0e3b11854a66a0dc3a7dea26b2c2d 100644 --- a/tests/unistd/write.c +++ b/tests/unistd/write.c @@ -1,5 +1,7 @@ #include <unistd.h> +#include "test_helpers.h" + int main(void) { write(STDOUT_FILENO, "Hello World!\n", 13); } diff --git a/tests/waitpid.c b/tests/waitpid.c index 6cf019d07246a5be125e9f1b479143c9ef200ca8..e0b77829f4bb185b769832a6191338357a18ee99 100644 --- a/tests/waitpid.c +++ b/tests/waitpid.c @@ -2,6 +2,8 @@ #include <unistd.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { pid_t pid = fork(); if (pid == 0) { diff --git a/tests/wchar/mbrtowc.c b/tests/wchar/mbrtowc.c index f05f70313a36575c3755a2161fea7c2b6170b881..0a1824429ae68352ed712e7e57222a3763a70f4c 100644 --- a/tests/wchar/mbrtowc.c +++ b/tests/wchar/mbrtowc.c @@ -2,6 +2,8 @@ #include <string.h> #include <wchar.h> +#include "test_helpers.h" + int main(void) { mbstate_t state; memset(&state, 0, sizeof state); diff --git a/tests/wchar/mbsrtowcs.c b/tests/wchar/mbsrtowcs.c index 15dff0b7e80297cb74a0cf868de4cbe284fa701c..6db79da51ac3b61e5362dd7846b29dffd8f87069 100644 --- a/tests/wchar/mbsrtowcs.c +++ b/tests/wchar/mbsrtowcs.c @@ -2,6 +2,8 @@ #include <string.h> #include <wchar.h> +#include "test_helpers.h" + void print_as_wide(const char* mbstr) { mbstate_t state; diff --git a/tests/wchar/putwchar.c b/tests/wchar/putwchar.c index 2f39a8ea10e6c2008783ecdc023de89b747b596e..7b11264f7dd31799cebd2a8767d04b45e1fe98ac 100644 --- a/tests/wchar/putwchar.c +++ b/tests/wchar/putwchar.c @@ -3,6 +3,8 @@ #include <wchar.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { wchar_t *wcs = L"zß水ðŸŒ"; diff --git a/tests/wchar/wcrtomb.c b/tests/wchar/wcrtomb.c index 233496ed3771bc5f8be970c6cd3b012fb504e191..9978da5ab4eea7b580d3488c7d08c5f71b4681ff 100644 --- a/tests/wchar/wcrtomb.c +++ b/tests/wchar/wcrtomb.c @@ -3,6 +3,8 @@ #include <wchar.h> #include <stdlib.h> +#include "test_helpers.h" + int main(void) { mbstate_t state; memset(&state, 0, sizeof state);