From 9fc7e1386aade4cf0cd0e27354f47cde48253fb6 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 27 Nov 2012 20:03:25 +0100 Subject: [PATCH] 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 --- lib/drmtest.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/drmtest.h | 3 +++ 2 files changed, 63 insertions(+) diff --git a/lib/drmtest.c b/lib/drmtest.c index a18b3a0..e55f63a 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -36,6 +36,7 @@ #include #include #include +#include #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 fcb10bb..796fa83 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); -- 2.7.4