diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-11-27 20:03:25 +0100 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-11-28 11:57:58 +0100 |
commit | 9fc7e1386aade4cf0cd0e27354f47cde48253fb6 (patch) | |
tree | 0957278f9ec27cd4da5ea58ef77b050dc844f629 | |
parent | 021909e10d1bf9192c6245802b0df4866681b3f0 (diff) |
lib/drmtest: subtest infrastructure
To make these helpers as least invasive as possible simply initialize
the options with a getopt parser and let the control flow be steered
with a simple helper which gets the subtest name as an argument.
The only tricky part for using it is that the subtest check helper
doubles up as the conduit to enumerate tests (and in that mode
prevents any test from being run). It is therefore important that
nothing gets printed to stdout outside of these checks.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r-- | lib/drmtest.c | 60 | ||||
-rw-r--r-- | lib/drmtest.h | 3 |
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c index a18b3a0f..e55f63ad 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -36,6 +36,7 @@ #include <signal.h> #include <pciaccess.h> #include <math.h> +#include <getopt.h> #include "drmtest.h" #include "i915_drm.h" @@ -513,6 +514,65 @@ void drmtest_stop_signal_helper(void) signal_helper = -1; } +/* subtests helpers */ +static bool list_subtests = false; +static char *run_single_subtest = NULL; + +void drmtest_subtest_init(int argc, char **argv) +{ + int c, option_index = 0; + static struct option long_options[] = { + {"list-subtests", 0, 0, 'l'}, + {"run-subtest", 1, 0, 'r'}, + {NULL, 0, 0, 0,} + }; + + /* supress getopt errors about unknown options */ + opterr = 0; + while((c = getopt_long(argc, argv, "", + long_options, &option_index)) != -1) { + switch(c) { + case 'l': + list_subtests = true; + goto out; + case 'r': + run_single_subtest = strdup(optarg); + goto out; + } + } + +out: + /* reset opt parsing */ + optind = 1; +} + +/* + * Note: Testcases which use these helpers MUST NOT output anything to stdout + * outside of places protected by drmtest_run_subtest checks - the piglit + * runner adds every line to the subtest list. + */ +bool drmtest_run_subtest(const char *subtest_name) +{ + if (list_subtests) { + printf("%s\n", subtest_name); + return false; + } + + if (!run_single_subtest) { + return true; + } else { + if (strcmp(subtest_name, run_single_subtest) == 0) + return true; + + return false; + } +} + +bool drmtest_only_list_subtests(void) +{ + return list_subtests; +} + /* other helpers */ void drmtest_exchange_int(void *array, unsigned i, unsigned j) { diff --git a/lib/drmtest.h b/lib/drmtest.h index fcb10bb9..796fa837 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -84,6 +84,9 @@ void drmtest_permute_array(void *array, unsigned size, unsigned i, unsigned j)); void drmtest_progress(const char *header, uint64_t i, uint64_t total); +void drmtest_subtest_init(int argc, char **argv); +bool drmtest_run_subtest(const char *subtest_name); +bool drmtest_only_list_subtests(void); /* helpers based upon the libdrm buffer manager */ void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr); |