From: Simon McVittie Date: Wed, 14 Dec 2011 17:31:23 +0000 (+0000) Subject: Add undefined/no-undefined mode options to GTester X-Git-Tag: 2.31.8~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=993de34a77bdbfc37e210a85382e5f34f604efe9;p=platform%2Fupstream%2Fglib.git Add undefined/no-undefined mode options to GTester https://bugzilla.gnome.org/show_bug.cgi?id=666116 --- diff --git a/docs/reference/glib/gtester.xml b/docs/reference/glib/gtester.xml index dcaae7d..75a1cea 100644 --- a/docs/reference/glib/gtester.xml +++ b/docs/reference/glib/gtester.xml @@ -70,7 +70,38 @@ list paths of available test cases -run test cases in MODE, which can be perf, slow, thorough or quick. The default mode is quick. + run test cases in MODE, which can be one of: + + + + + run performance tests + + + , + + run slow tests, or repeat non-deterministic tests more often + + + + + do not run slow or performance tests, or do extra repeats + of non-deterministic tests (default) + + + + + run test cases that deliberately provoke checks or assertion + failures, if implemented (default) + + + + + do not run test cases that deliberately provoke checks or + assertion failures + + + diff --git a/glib/gtester.c b/glib/gtester.c index df9d665..e9d695f 100644 --- a/glib/gtester.c +++ b/glib/gtester.c @@ -50,6 +50,7 @@ static gboolean subtest_verbose = FALSE; static gboolean subtest_mode_fatal = TRUE; static gboolean subtest_mode_perf = FALSE; static gboolean subtest_mode_quick = TRUE; +static gboolean subtest_mode_undefined = TRUE; static const gchar *subtest_seedstr = NULL; static gchar *subtest_last_seed = NULL; static GSList *subtest_paths = NULL; @@ -307,6 +308,8 @@ launch_test_binary (const char *binary, argc++; if (subtest_mode_perf) argc++; + if (!subtest_mode_undefined) + argc++; if (gtester_list_tests) argc++; if (subtest_seedstr) @@ -337,6 +340,8 @@ launch_test_binary (const char *binary, argv[i++] = "-m=slow"; if (subtest_mode_perf) argv[i++] = "-m=perf"; + if (!subtest_mode_undefined) + argv[i++] = "-m=no-undefined"; if (gtester_list_tests) argv[i++] = "-l"; if (subtest_seedstr) @@ -479,6 +484,7 @@ usage (gboolean just_version) g_print (" -l list paths of available test cases\n"); g_print (" -m=perf, -m=slow, -m=quick -m=thorough\n"); g_print (" run test cases in mode perf, slow/thorough or quick (default)\n"); + g_print (" -m=no-undefined don't run test cases that provoke assertions\n"); g_print (" -p=TESTPATH only start test cases matching TESTPATH\n"); g_print (" -s=TESTPATH skip test cases matching TESTPATH\n"); g_print (" --seed=SEEDSTRING start all tests with random number seed SEEDSTRING\n"); @@ -596,6 +602,10 @@ parse_args (gint *argc_p, subtest_mode_quick = TRUE; subtest_mode_perf = FALSE; } + else if (strcmp (mode, "undefined") == 0) + subtest_mode_undefined = TRUE; + else if (strcmp (mode, "no-undefined") == 0) + subtest_mode_undefined = FALSE; else g_error ("unknown test mode: -m %s", mode); argv[i] = NULL; diff --git a/glib/gtestutils.c b/glib/gtestutils.c index b7f3223..3406d43 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -141,6 +141,17 @@ */ /** + * g_test_undefined: + * + * Returns %TRUE if tests may provoke assertions and other formally-undefined + * behaviour under g_test_trap_fork(), to verify that appropriate warnings + * are given. It can be useful to turn this off if running tests under + * valgrind. + * + * Returns: %TRUE if tests may provoke programming errors + */ + +/** * g_test_verbose: * * Returns %TRUE if tests are run in verbose mode. @@ -496,6 +507,7 @@ static GTestConfig mutable_test_config_vars = { FALSE, /* test_perf */ FALSE, /* test_verbose */ FALSE, /* test_quiet */ + TRUE, /* test_undefined */ }; const GTestConfig * const g_test_config_vars = &mutable_test_config_vars; @@ -722,6 +734,10 @@ parse_args (gint *argc_p, mutable_test_config_vars.test_quick = TRUE; mutable_test_config_vars.test_perf = FALSE; } + else if (strcmp (mode, "undefined") == 0) + mutable_test_config_vars.test_undefined = TRUE; + else if (strcmp (mode, "no-undefined") == 0) + mutable_test_config_vars.test_undefined = FALSE; else g_error ("unknown test mode: -m %s", mode); argv[i] = NULL; @@ -770,6 +786,7 @@ parse_args (gint *argc_p, " -p TESTPATH execute all tests matching TESTPATH\n" " -s TESTPATH skip all tests matching TESTPATH\n" " -m {perf|slow|thorough|quick} Execute tests according modes\n" + " -m {undefined|no-undefined} Execute tests according modes\n" " --debug-log debug test logging output\n" " -k, --keep-going gtester-specific argument\n" " --GTestLogFD=N gtester-specific argument\n" @@ -830,7 +847,7 @@ parse_args (gint *argc_p, * * * - * + * * * execute tests according to these test modes: * @@ -853,6 +870,20 @@ parse_args (gint *argc_p, * quick tests, should run really quickly and give good coverage. * * + * + * undefined + * + * tests for undefined behaviour, may provoke programming errors + * under g_test_trap_fork() to check that appropriate assertions + * or warnings are given + * + * + * + * no-undefined + * + * avoid tests for undefined behaviour + * + * * * * diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 0184c7c..3cd173c 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -98,6 +98,7 @@ void g_test_init (int *argc, #define g_test_perf() (g_test_config_vars->test_perf) #define g_test_verbose() (g_test_config_vars->test_verbose) #define g_test_quiet() (g_test_config_vars->test_quiet) +#define g_test_undefined() (g_test_config_vars->test_undefined) /* run all tests under toplevel suite (path: /) */ int g_test_run (void); /* hook up a test functions under test path */ @@ -234,6 +235,7 @@ typedef struct { gboolean test_perf; /* run performance tests */ gboolean test_verbose; /* extra info */ gboolean test_quiet; /* reduce output */ + gboolean test_undefined; /* run tests that are meant to assert */ } GTestConfig; GLIB_VAR const GTestConfig * const g_test_config_vars;