From: Richard W.M. Jones Date: Thu, 14 May 2009 13:43:53 +0000 (+0100) Subject: Enable run-time conditional test prerequisites. X-Git-Tag: 1.0.26~8 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=7ca3bda1660b58b82f4a11bc5637bf610a43aba6 Enable run-time conditional test prerequisites. --- diff --git a/Makefile.am b/Makefile.am index fcf5f61..50c9e7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,7 +103,9 @@ tests_CFLAGS = \ tests_LDADD = $(top_builddir)/src/libguestfs.la TESTS = tests -TESTS_ENVIRONMENT = $(VG) +TESTS_ENVIRONMENT = \ + SKIP_TEST_COMMAND=$(shell ldd test-command | grep -sq 'not a dynamic executable' || echo 1) \ + $(VG) $(TESTS): $(INITRAMFS) $(VMLINUZ) diff --git a/src/generator.ml b/src/generator.ml index 009b980..82bfb88 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -207,6 +207,12 @@ and test_prereq = * unimplemented feature. *) | Disabled + (* 'string' is some C code (a function body) that should return + * true or false. The test will run if the code returns true. + *) + | If of string + (* As for 'If' but the test runs _unless_ the code returns true. *) + | Unless of string (* Some initial scenarios for testing. *) and test_init = @@ -235,6 +241,11 @@ and test_init = and seq = cmd list and cmd = string list +(* Canned test prerequisites. *) +let env_is_true env = + sprintf "const char *str = getenv (\"%s\"); + return str && strcmp (str, \"1\") == 0;" env + (* Note about long descriptions: When referring to another * action, use the format C (ie. the full name of * the C function). This will be replaced as appropriate in other @@ -1180,51 +1191,51 @@ particular that the filename is not prepended to the output (the C<-b> option)."); ("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning], - [InitBasicFS, Always, TestOutput ( + [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 1"]], "Result1"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 2"]], "Result2\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 3"]], "\nResult3"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 4"]], "\nResult4\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 5"]], "\nResult5\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 6"]], "\n\nResult6\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 7"]], ""); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 8"]], "\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 9"]], "\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 11"]], "Result11-1\nResult11-2"); - InitBasicFS, Always, TestLastFail ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestLastFail ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command"]])], @@ -1259,47 +1270,47 @@ all filesystems that are needed are mounted at the right locations."); ("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning], - [InitBasicFS, Always, TestOutputList ( + [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 1"]], ["Result1"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 2"]], ["Result2"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 3"]], ["";"Result3"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 4"]], ["";"Result4"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 5"]], ["";"Result5";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 7"]], []); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 8"]], [""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 9"]], ["";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])], @@ -3666,12 +3677,32 @@ int main (int argc, char *argv[]) and generate_one_test name i (init, prereq, test) = let test_name = sprintf "test_%s_%d" name i in + (match prereq with + | Disabled | Always -> () + | If code | Unless code -> + pr "static int %s_prereq (void)\n" test_name; + pr "{\n"; + pr " %s\n" code; + pr "}\n"; + pr "\n"; + ); + pr "static int %s (void)\n" test_name; pr "{\n"; (match prereq with | Disabled -> - pr " printf (\"%%s skipped (test disabled in generator)\\n\", \"%s\");\n" test_name + pr " printf (\"%%s skipped (reason: test disabled in generator)\\n\", \"%s\");\n" test_name + | If _ -> + pr " if (%s_prereq ()) {\n" test_name; + generate_one_test_body name i test_name init test; + pr " } else\n"; + pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name + | Unless _ -> + pr " if (! %s_prereq ()) {\n" test_name; + generate_one_test_body name i test_name init test; + pr " } else\n"; + pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name | Always -> generate_one_test_body name i test_name init test ); diff --git a/tests.c b/tests.c index 000dbac..b1382c0 100644 --- a/tests.c +++ b/tests.c @@ -298,7 +298,7 @@ static int test_strings_e_0 (void) static int test_strings_e_1 (void) { - printf ("%s skipped (test disabled in generator)\n", "test_strings_e_1"); + printf ("%s skipped (reason: test disabled in generator)\n", "test_strings_e_1"); return 0; } @@ -4981,8 +4981,15 @@ static int test_stat_0 (void) return 0; } +static int test_command_lines_0_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_0 (void) { + if (! test_command_lines_0_prereq ()) { /* InitBasicFS for command_lines (0): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5093,11 +5100,20 @@ static int test_command_lines_0 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_0"); return 0; } +static int test_command_lines_1_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_1 (void) { + if (! test_command_lines_1_prereq ()) { /* InitBasicFS for command_lines (1): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5208,11 +5224,20 @@ static int test_command_lines_1 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_1"); return 0; } +static int test_command_lines_2_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_2 (void) { + if (! test_command_lines_2_prereq ()) { /* InitBasicFS for command_lines (2): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5335,11 +5360,20 @@ static int test_command_lines_2 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_2"); return 0; } +static int test_command_lines_3_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_3 (void) { + if (! test_command_lines_3_prereq ()) { /* InitBasicFS for command_lines (3): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5462,11 +5496,20 @@ static int test_command_lines_3 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_3"); return 0; } +static int test_command_lines_4_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_4 (void) { + if (! test_command_lines_4_prereq ()) { /* InitBasicFS for command_lines (4): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5601,11 +5644,20 @@ static int test_command_lines_4 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_4"); return 0; } +static int test_command_lines_5_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_5 (void) { + if (! test_command_lines_5_prereq ()) { /* InitBasicFS for command_lines (5): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5752,11 +5804,20 @@ static int test_command_lines_5 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_5"); return 0; } +static int test_command_lines_6_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_6 (void) { + if (! test_command_lines_6_prereq ()) { /* InitBasicFS for command_lines (6): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5855,11 +5916,20 @@ static int test_command_lines_6 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_6"); return 0; } +static int test_command_lines_7_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_7 (void) { + if (! test_command_lines_7_prereq ()) { /* InitBasicFS for command_lines (7): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -5970,11 +6040,20 @@ static int test_command_lines_7 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_7"); return 0; } +static int test_command_lines_8_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_8 (void) { + if (! test_command_lines_8_prereq ()) { /* InitBasicFS for command_lines (8): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6097,11 +6176,20 @@ static int test_command_lines_8 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_8"); return 0; } +static int test_command_lines_9_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_9 (void) { + if (! test_command_lines_9_prereq ()) { /* InitBasicFS for command_lines (9): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6224,11 +6312,20 @@ static int test_command_lines_9 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_9"); return 0; } +static int test_command_lines_10_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_lines_10 (void) { + if (! test_command_lines_10_prereq ()) { /* InitBasicFS for command_lines (10): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6351,11 +6448,20 @@ static int test_command_lines_10 (void) free (r[i]); free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_lines_10"); return 0; } +static int test_command_0_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_0 (void) { + if (! test_command_0_prereq ()) { /* InitBasicFS for command (0): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6451,11 +6557,20 @@ static int test_command_0 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_0"); return 0; } +static int test_command_1_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_1 (void) { + if (! test_command_1_prereq ()) { /* InitBasicFS for command (1): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6551,11 +6666,20 @@ static int test_command_1 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_1"); return 0; } +static int test_command_2_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_2 (void) { + if (! test_command_2_prereq ()) { /* InitBasicFS for command (2): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6651,11 +6775,20 @@ static int test_command_2 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_2"); return 0; } +static int test_command_3_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_3 (void) { + if (! test_command_3_prereq ()) { /* InitBasicFS for command (3): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6751,11 +6884,20 @@ static int test_command_3 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_3"); return 0; } +static int test_command_4_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_4 (void) { + if (! test_command_4_prereq ()) { /* InitBasicFS for command (4): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6851,11 +6993,20 @@ static int test_command_4 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_4"); return 0; } +static int test_command_5_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_5 (void) { + if (! test_command_5_prereq ()) { /* InitBasicFS for command (5): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -6951,11 +7102,20 @@ static int test_command_5 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_5"); return 0; } +static int test_command_6_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_6 (void) { + if (! test_command_6_prereq ()) { /* InitBasicFS for command (6): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7051,11 +7211,20 @@ static int test_command_6 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_6"); return 0; } +static int test_command_7_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_7 (void) { + if (! test_command_7_prereq ()) { /* InitBasicFS for command (7): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7151,11 +7320,20 @@ static int test_command_7 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_7"); return 0; } +static int test_command_8_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_8 (void) { + if (! test_command_8_prereq ()) { /* InitBasicFS for command (8): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7251,11 +7429,20 @@ static int test_command_8 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_8"); return 0; } +static int test_command_9_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_9 (void) { + if (! test_command_9_prereq ()) { /* InitBasicFS for command (9): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7351,11 +7538,20 @@ static int test_command_9 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_9"); return 0; } +static int test_command_10_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_10 (void) { + if (! test_command_10_prereq ()) { /* InitBasicFS for command (10): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7451,11 +7647,20 @@ static int test_command_10 (void) } free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_10"); return 0; } +static int test_command_11_prereq (void) +{ + const char *str = getenv ("SKIP_TEST_COMMAND"); + return str && strcmp (str, "1") == 0; +} + static int test_command_11 (void) { + if (! test_command_11_prereq ()) { /* InitBasicFS for command (11): create ext2 on /dev/sda1 */ { char device[] = "/dev/sda"; @@ -7544,6 +7749,8 @@ static int test_command_11 (void) return -1; free (r); } + } else + printf ("%s skippedd (reason: test prerequisite)\n", "test_command_11"); return 0; }