From: Thomas Veerman Date: Thu, 2 Sep 2010 09:33:37 +0000 (+0000) Subject: Clean up the created temp file after running the test. X-Git-Tag: v3.1.8~24 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=e7252adc1e674b61e5099a5b87103bfa9605794d;p=minix.git Clean up the created temp file after running the test. --- diff --git a/test/test54.c b/test/test54.c index f3fc904c1..ed9950d21 100644 --- a/test/test54.c +++ b/test/test54.c @@ -6,7 +6,12 @@ #include #include -int main(void) +#define MAX_ERROR 3 +#include "common.c" + +int subtest = -1; + +void do_test(void) { int fd; char *wbuf, *rbuf; @@ -17,48 +22,34 @@ int main(void) char *filename; int i; - printf("Test 54 "); - fflush(stdout); - - if((filename = mktemp("/tmp/pwrite_test_XXXXXXX")) == NULL) { - err(1, "Failed to create tempfile"); - } + subtest = 1; - if((fd = open(filename, O_CREAT|O_RDWR)) < 0) { - err(1, "Failed to open %s", filename); - } + if((filename = mktemp("pwrite_test_XXXXXXX")) == NULL) e(1); + if((fd = open(filename, O_CREAT|O_RDWR)) < 0) e(2); size = 1 + rand() % 4096; off = rand(); - if((wbuf = malloc(sizeof(char)*size)) == NULL) { - errx(1, "Malloc failed.\n"); - } + if((wbuf = malloc(sizeof(char)*size)) == NULL) e(3); for(i = 0; i < size; i++) { wbuf[i] = 1 + rand()%127; } - if((nwritten = pwrite(fd, wbuf, size, off)) < 0) { - err(1, "pwrite failed"); - } - - if((rbuf = malloc(sizeof(char)*nwritten)) == NULL) { - errx(1, "Malloc failed.\n"); - } - - if((nread = pread(fd, rbuf, nwritten, off)) < 0) { - err(1, "pread failed"); - } - - if(strncmp(rbuf, wbuf, nread) != 0) { - err(1, "Test failed.\n"); - } - - printf("ok\n"); + if((nwritten = pwrite(fd, wbuf, size, off)) < 0) e(4); + if((rbuf = malloc(sizeof(char)*nwritten)) == NULL) e(5); + if((nread = pread(fd, rbuf, nwritten, off)) < 0) e(6); + if(strncmp(rbuf, wbuf, nread) != 0) e(7); close(fd); free(wbuf); + unlink(filename); +} + - return 0; +int main(void) +{ + start(54); + do_test(); + quit(); }