From: Nathaniel Wesley Filardo Date: Sat, 24 Oct 2015 02:37:28 +0000 (-0400) Subject: TAPish test macros X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=HEAD;p=xv6-public TAPish test macros While here, convert usertests to use a minimal amount of the TAPish stuff for ease of instrumentation. --- diff --git a/318_test-tapish.h b/318_test-tapish.h new file mode 100644 index 0000000..2519e24 --- /dev/null +++ b/318_test-tapish.h @@ -0,0 +1,32 @@ +/* + * Macros for test emission. Compatible with the Test Anything Protocol if + * TEST_PREFIX is defined to be the empty string. + */ + +/* Isn't this gross */ +#define TEST_ID_(x) x +#define TEST_CONCAT_(a,b) a b + +#ifndef TEST_NAME +#error Define TEST_NAME before including test-tapish +#endif +#ifndef TEST_PREFIX_PREFIX +#define TEST_PREFIX_PREFIX "TAPME: " +#endif +/* Prefix for test harness aid, since QEMU and other tools output, too */ +#define TEST_PREFIX TEST_CONCAT_(TEST_CONCAT_(TEST_PREFIX_PREFIX, TEST_NAME), " ") + +/* Primitives */ +#define TEST_STRT(n) do { printf(2, TEST_PREFIX "1..%d\n" , n ); } while(0); +#define TEST_FINI(msg, ...) do { printf(2, TEST_PREFIX "ok - " msg "\n", ##__VA_ARGS__); } while(0); +#define TEST_FAIL(msg, ...) do { printf(2, TEST_PREFIX "not ok - " msg "\n", ##__VA_ARGS__); } while(0); +#define TEST_EXIT(msg, ...) do { printf(2, TEST_PREFIX "Bail out! " msg "\n", ##__VA_ARGS__); exit(); } while(0); +#define TEST_DIAG(msg, ...) do { printf(2, TEST_PREFIX "# " msg "\n", ##__VA_ARGS__); } while(0); + +/* Conditionals */ +#define TEST_FAIL_IF(cond, msg, ...) if(cond) { TEST_FAIL(msg, ##__VA_ARGS__); } +#define TEST_EXIT_IF(cond, msg, ...) if(cond) { TEST_EXIT(msg, ##__VA_ARGS__); } +#define TEST_DIAG_IF(cond, msg, ...) if(cond) { TEST_DIAG(msg, ##__VA_ARGS__); } + +#define TEST_FAIL_IF_THEN(cond, then, msg, ...) if(cond) { TEST_FAIL(msg, ##__VA_ARGS__); then; } +#define TEST_DIAG_IF_THEN(cond, then, msg, ...) if(cond) { TEST_DIAG(msg, ##__VA_ARGS__); then; } diff --git a/usertests.c b/usertests.c index 22a7bfb..83d1106 100644 --- a/usertests.c +++ b/usertests.c @@ -8,9 +8,12 @@ #include "traps.h" #include "memlayout.h" +#define TEST_NAME "usertests" +#include "318_test-tapish.h" + char buf[8192]; char name[3]; -char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 }; +char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", "\n" TEST_PREFIX "ok -", 0 }; int stdout = 1; // does chdir() call iput(p->cwd) in a transaction? @@ -1707,11 +1710,9 @@ int main(int argc, char *argv[]) { printf(1, "usertests starting\n"); + TEST_STRT(1); - if(open("usertests.ran", 0) >= 0){ - printf(1, "already ran user tests -- rebuild fs.img\n"); - exit(); - } + TEST_EXIT_IF(open("usertests.ran", 0) >= 0, "already ran user tests -- rebuild fs.img"); close(open("usertests.ran", O_CREATE)); createdelete(); @@ -1719,6 +1720,7 @@ main(int argc, char *argv[]) concreate(); fourfiles(); sharedfd(); + TEST_DIAG("group 1"); bigargtest(); bigwrite(); @@ -1726,20 +1728,24 @@ main(int argc, char *argv[]) bsstest(); sbrktest(); validatetest(); + TEST_DIAG("group 2"); opentest(); writetest(); writetest1(); createtest(); + TEST_DIAG("group 3"); openiputtest(); exitiputtest(); iputtest(); + TEST_DIAG("group 4"); mem(); pipe1(); preempt(); exitwait(); + TEST_DIAG("group 5"); rmdot(); fourteen(); @@ -1752,6 +1758,7 @@ main(int argc, char *argv[]) forktest(); bigdir(); // slow exectest(); + TEST_DIAG("group 6"); exit(); }