Add undefined/no-undefined mode options to GTester

https://bugzilla.gnome.org/show_bug.cgi?id=666116
This commit is contained in:
Simon McVittie 2011-12-14 17:31:23 +00:00 committed by Matthias Clasen
parent fa4792c35e
commit 993de34a77
4 changed files with 76 additions and 2 deletions

View File

@ -70,7 +70,38 @@ list paths of available test cases
<varlistentry> <varlistentry>
<term><option>-m=<replaceable>MODE</replaceable></option></term> <term><option>-m=<replaceable>MODE</replaceable></option></term>
<listitem><para> <listitem><para>
run test cases in <replaceable>MODE</replaceable>, which can be perf, slow, thorough or quick. The default mode is quick. run test cases in <replaceable>MODE</replaceable>, which can be one of:
<variablelist>
<term><option>perf</option></term>
<listitem><para>
run performance tests
</para></listitem>
<term><option>slow</option>, <option>thorough</option></term>
<listitem><para>
run slow tests, or repeat non-deterministic tests more often
</para></listitem>
<term><option>quick</option></term>
<listitem><para>
do not run slow or performance tests, or do extra repeats
of non-deterministic tests (default)
</para></listitem>
<term><option>undefined</option></term>
<listitem><para>
run test cases that deliberately provoke checks or assertion
failures, if implemented (default)
</para></listitem>
<term><option>no-undefined</option></term>
<listitem><para>
do not run test cases that deliberately provoke checks or
assertion failures
</para></listitem>
</variablelist>
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>

View File

@ -50,6 +50,7 @@ static gboolean subtest_verbose = FALSE;
static gboolean subtest_mode_fatal = TRUE; static gboolean subtest_mode_fatal = TRUE;
static gboolean subtest_mode_perf = FALSE; static gboolean subtest_mode_perf = FALSE;
static gboolean subtest_mode_quick = TRUE; static gboolean subtest_mode_quick = TRUE;
static gboolean subtest_mode_undefined = TRUE;
static const gchar *subtest_seedstr = NULL; static const gchar *subtest_seedstr = NULL;
static gchar *subtest_last_seed = NULL; static gchar *subtest_last_seed = NULL;
static GSList *subtest_paths = NULL; static GSList *subtest_paths = NULL;
@ -307,6 +308,8 @@ launch_test_binary (const char *binary,
argc++; argc++;
if (subtest_mode_perf) if (subtest_mode_perf)
argc++; argc++;
if (!subtest_mode_undefined)
argc++;
if (gtester_list_tests) if (gtester_list_tests)
argc++; argc++;
if (subtest_seedstr) if (subtest_seedstr)
@ -337,6 +340,8 @@ launch_test_binary (const char *binary,
argv[i++] = "-m=slow"; argv[i++] = "-m=slow";
if (subtest_mode_perf) if (subtest_mode_perf)
argv[i++] = "-m=perf"; argv[i++] = "-m=perf";
if (!subtest_mode_undefined)
argv[i++] = "-m=no-undefined";
if (gtester_list_tests) if (gtester_list_tests)
argv[i++] = "-l"; argv[i++] = "-l";
if (subtest_seedstr) if (subtest_seedstr)
@ -479,6 +484,7 @@ usage (gboolean just_version)
g_print (" -l list paths of available test cases\n"); g_print (" -l list paths of available test cases\n");
g_print (" -m=perf, -m=slow, -m=quick -m=thorough\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 (" 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 (" -p=TESTPATH only start test cases matching TESTPATH\n");
g_print (" -s=TESTPATH skip 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"); 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_quick = TRUE;
subtest_mode_perf = FALSE; 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 else
g_error ("unknown test mode: -m %s", mode); g_error ("unknown test mode: -m %s", mode);
argv[i] = NULL; argv[i] = NULL;

View File

@ -140,6 +140,17 @@
* Returns: %TRUE if in performance mode * Returns: %TRUE if in performance mode
*/ */
/**
* 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: * g_test_verbose:
* *
@ -496,6 +507,7 @@ static GTestConfig mutable_test_config_vars = {
FALSE, /* test_perf */ FALSE, /* test_perf */
FALSE, /* test_verbose */ FALSE, /* test_verbose */
FALSE, /* test_quiet */ FALSE, /* test_quiet */
TRUE, /* test_undefined */
}; };
const GTestConfig * const g_test_config_vars = &mutable_test_config_vars; 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_quick = TRUE;
mutable_test_config_vars.test_perf = FALSE; 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 else
g_error ("unknown test mode: -m %s", mode); g_error ("unknown test mode: -m %s", mode);
argv[i] = NULL; argv[i] = NULL;
@ -770,6 +786,7 @@ parse_args (gint *argc_p,
" -p TESTPATH execute all tests matching TESTPATH\n" " -p TESTPATH execute all tests matching TESTPATH\n"
" -s TESTPATH skip all tests matching TESTPATH\n" " -s TESTPATH skip all tests matching TESTPATH\n"
" -m {perf|slow|thorough|quick} Execute tests according modes\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" " --debug-log debug test logging output\n"
" -k, --keep-going gtester-specific argument\n" " -k, --keep-going gtester-specific argument\n"
" --GTestLogFD=N gtester-specific argument\n" " --GTestLogFD=N gtester-specific argument\n"
@ -830,7 +847,7 @@ parse_args (gint *argc_p,
* </para></listitem> * </para></listitem>
* </varlistentry> * </varlistentry>
* <varlistentry> * <varlistentry>
* <term><option>-m {perf|slow|thorough|quick}</option></term> * <term><option>-m {perf|slow|thorough|quick|undefined|no-undefined}</option></term>
* <listitem><para> * <listitem><para>
* execute tests according to these test modes: * execute tests according to these test modes:
* <variablelist> * <variablelist>
@ -853,6 +870,20 @@ parse_args (gint *argc_p,
* quick tests, should run really quickly and give good coverage. * quick tests, should run really quickly and give good coverage.
* </para></listitem> * </para></listitem>
* </varlistentry> * </varlistentry>
* <varlistentry>
* <term>undefined</term>
* <listitem><para>
* tests for undefined behaviour, may provoke programming errors
* under g_test_trap_fork() to check that appropriate assertions
* or warnings are given
* </para></listitem>
* </varlistentry>
* <varlistentry>
* <term>no-undefined</term>
* <listitem><para>
* avoid tests for undefined behaviour
* </para></listitem>
* </varlistentry>
* </variablelist> * </variablelist>
* </para></listitem> * </para></listitem>
* </varlistentry> * </varlistentry>

View File

@ -98,6 +98,7 @@ void g_test_init (int *argc,
#define g_test_perf() (g_test_config_vars->test_perf) #define g_test_perf() (g_test_config_vars->test_perf)
#define g_test_verbose() (g_test_config_vars->test_verbose) #define g_test_verbose() (g_test_config_vars->test_verbose)
#define g_test_quiet() (g_test_config_vars->test_quiet) #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: /) */ /* run all tests under toplevel suite (path: /) */
int g_test_run (void); int g_test_run (void);
/* hook up a test functions under test path */ /* hook up a test functions under test path */
@ -234,6 +235,7 @@ typedef struct {
gboolean test_perf; /* run performance tests */ gboolean test_perf; /* run performance tests */
gboolean test_verbose; /* extra info */ gboolean test_verbose; /* extra info */
gboolean test_quiet; /* reduce output */ gboolean test_quiet; /* reduce output */
gboolean test_undefined; /* run tests that are meant to assert */
} GTestConfig; } GTestConfig;
GLIB_VAR const GTestConfig * const g_test_config_vars; GLIB_VAR const GTestConfig * const g_test_config_vars;