From 3186a83d890b05be6a140999bab38c604ffcd66f Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 20 Aug 2014 08:44:45 +0800 Subject: [PATCH] Tools/NetTest - Annotate runner log file with test name --- Tools/NetTest_Runner/include/stack.h | 2 +- Tools/NetTest_Runner/main.c | 22 +++++++++++++--------- Tools/NetTest_Runner/stack.c | 6 +++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tools/NetTest_Runner/include/stack.h b/Tools/NetTest_Runner/include/stack.h index 7ac2083b..0110f04b 100644 --- a/Tools/NetTest_Runner/include/stack.h +++ b/Tools/NetTest_Runner/include/stack.h @@ -12,7 +12,7 @@ extern void Stack_AddInterface(const char *Name, int AddrType, const void *Addr, extern void Stack_AddRoute(int Type, const void *Network, int MaskBits, const void *NextHop); extern void Stack_AddArg(const char *Fmt, ...); -extern int Stack_Start(const char *Subcommand); +extern int Stack_Start(const char *TestName, const char *Subcommand); extern void Stack_Kill(void); extern int Stack_SendCommand(const char *CommandString, ...); diff --git a/Tools/NetTest_Runner/main.c b/Tools/NetTest_Runner/main.c index 05b455f8..5c175d71 100644 --- a/Tools/NetTest_Runner/main.c +++ b/Tools/NetTest_Runner/main.c @@ -23,12 +23,16 @@ int main(int argc, char *argv[]) return 1; typedef bool t_test(void); - t_test *tests[] = { - Test_ARP_Basic, - Test_TCP_Basic, - //Test_TCP_WindowSizes, - Test_TCP_Reset, - NULL + struct { + t_test *fcn; + const char *name; + } tests[] = { + #define _(fcn) {fcn, #fcn} + _(Test_ARP_Basic), + _(Test_TCP_Basic), + //_(Test_TCP_WindowSizes), + _(Test_TCP_Reset), + {NULL,NULL} }; // Truncate the two output files @@ -40,18 +44,18 @@ int main(int argc, char *argv[]) int n_pass = 0; int n_fail = 0; - for(int i = 0; tests[i]; i ++ ) + for(int i = 0; tests[i].fcn; i ++ ) { Stack_AddDevice("/tmp/acess2net", (char[]){TEST_MAC}); Stack_AddInterface("eth0", 4, (const char[]){TEST_IP}, 24); Stack_AddRoute(4, "\0\0\0\0", 0, (const char[]){HOST_IP}); - if( Stack_Start("cmdline") ) + if( Stack_Start(tests[i].name, "cmdline") ) goto teardown; if( Net_Receive(0, 1, &argc, 1000) == 0 ) goto teardown; - bool result = tests[i](); + bool result = tests[i].fcn(); printf("%s: %s\n", gsTestName, (result ? "PASS" : "FAIL")); if(result) diff --git a/Tools/NetTest_Runner/stack.c b/Tools/NetTest_Runner/stack.c index 1a224e85..e828c563 100644 --- a/Tools/NetTest_Runner/stack.c +++ b/Tools/NetTest_Runner/stack.c @@ -92,7 +92,7 @@ void sigchld_handler(int signum) fprintf(stderr, "FAILURE: Child exited (%i)\n", status); } -int Stack_Start(const char *Subcommand) +int Stack_Start(const char *RunName, const char *Subcommand) { Stack_AddArg(Subcommand); @@ -107,8 +107,8 @@ int Stack_Start(const char *Subcommand) fcntl(giStack_InFD, F_SETFD, FD_CLOEXEC); FILE *fp; - fp = fopen("stdout.txt", "a"); fprintf(fp, "--- Startup\n"); fclose(fp); - fp = fopen("stderr.txt", "a"); fprintf(fp, "--- Startup\n"); fclose(fp); + fp = fopen("stdout.txt", "a"); fprintf(fp, "--- TEST: %s\n", RunName); fclose(fp); + fp = fopen("stderr.txt", "a"); fprintf(fp, "--- TEST: %s\n", RunName); fclose(fp); posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); -- 2.20.1