summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2013-10-04 15:41:17 -0700
committerIan Romanick <ian.d.romanick@intel.com>2013-10-30 10:51:39 -0700
commit44f919a5ab4ac08e55771bf921e5c9ac4ab2f88c (patch)
treec7a9d3f8a03fb02db41fcae940449a3f08e7fdbf
parent0565f39a436a354c1248aeaf2d10e57864e07c1c (diff)
util: Add common framework for command-line invoked subtests
There are two parts to this. First, command line options of the form "-subtest foo" have their argument (the "foo" part) stored in a list in the piglit_gl_test_config. Tests can use this functionality without having to use any of the other parts. This allows every piglit test to have the same syntax for specifying which subtests to run. Second, tests can create a list of piglit_gl_subtest structures. Each structure describes a single subtest: the name (as it will apear in the log), the command-line name (as supplied to -subtest), and the function that implements the test. Helper function use this table and the list of tests specified by -subtest options to run a group of tests. A later patch shows an example of using this functionality. v2: Use piglit_merge_result instead of piglit_update_result_from_subtest_result. Suggested by Eric, seconded by Chad. v3: Rename piglit_gl_subtest::subtest to piglit_gl_subtest::subtest_func. Fix some Doxygen comments. Both suggested by Chad. v4: Add a 'void *data' field to piglit_gl_subtest that is passed to piglit_gl_subtest::subtest_func. Add a macro to detect the end of a list of subtests. Both suggested by Paul and seconded by Chad. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r--tests/util/piglit-framework-gl.c94
-rw-r--r--tests/util/piglit-framework-gl.h43
2 files changed, 134 insertions, 3 deletions
diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c
index dd2e6a5db..cad4c24ec 100644
--- a/tests/util/piglit-framework-gl.c
+++ b/tests/util/piglit-framework-gl.c
@@ -40,7 +40,8 @@ int piglit_width;
int piglit_height;
static void
-process_args(int *argc, char *argv[], unsigned *force_samples);
+process_args(int *argc, char *argv[], unsigned *force_samples,
+ struct piglit_gl_test_config *config);
void
piglit_gl_test_config_init(struct piglit_gl_test_config *config)
@@ -63,7 +64,8 @@ delete_arg(char *argv[], int argc, int arg)
* length is returned in @a argc.
*/
static void
-process_args(int *argc, char *argv[], unsigned *force_samples)
+process_args(int *argc, char *argv[], unsigned *force_samples,
+ struct piglit_gl_test_config *config)
{
int j;
@@ -111,6 +113,33 @@ process_args(int *argc, char *argv[], unsigned *force_samples)
*force_samples = atoi(argv[j]+9);
delete_arg(argv, *argc, j--);
*argc -= 1;
+ } else if (!strcmp(argv[j], "-subtest")) {
+ int i;
+
+ j++;
+ if (j >= *argc) {
+ fprintf(stderr,
+ "-subtest requires an argument\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ config->selected_subtests =
+ realloc(config->selected_subtests,
+ sizeof(char *)
+ * (config->num_selected_subtests + 1));
+ config->selected_subtests[config->num_selected_subtests] =
+ argv[j];
+
+ config->num_selected_subtests++;
+
+ /* Remove 2 arguments (hence the 'i - 2') from the
+ * command line.
+ */
+ for (i = j + 1; i < *argc; i++) {
+ argv[i - 2] = argv[i];
+ }
+ *argc -= 2;
+ j -= 2;
}
}
}
@@ -121,7 +150,7 @@ piglit_gl_process_args(int *argc, char *argv[],
{
unsigned force_samples = 0;
- process_args(argc, argv, &force_samples);
+ process_args(argc, argv, &force_samples, config);
if (force_samples > 1)
config->window_samples = force_samples;
@@ -223,3 +252,62 @@ piglit_destroy_dma_buf(struct piglit_dma_buf *buf)
if (gl_fw->destroy_dma_buf)
gl_fw->destroy_dma_buf(buf);
}
+
+const struct piglit_gl_subtest *
+piglit_find_subtest(const struct piglit_gl_subtest *subtests, const char *name)
+{
+ unsigned i;
+
+ for (i = 0; !PIGLIT_GL_SUBTEST_END(&subtests[i]); i++) {
+ if (strcmp(subtests[i].option, name) == 0)
+ return &subtests[i];
+ }
+
+ return NULL;
+}
+
+enum piglit_result
+piglit_run_selected_subtests(const struct piglit_gl_subtest *all_subtests,
+ const char **selected_subtests,
+ size_t num_selected_subtests,
+ enum piglit_result previous_result)
+{
+ enum piglit_result result = previous_result;
+
+ if (num_selected_subtests) {
+ unsigned i;
+
+ for (i = 0; i < num_selected_subtests; i++) {
+ enum piglit_result subtest_result;
+ const char *const name = selected_subtests[i];
+ const struct piglit_gl_subtest *subtest =
+ piglit_find_subtest(all_subtests, name);
+
+ if (subtest == NULL) {
+ fprintf(stderr,
+ "Unknown subtest \"%s\".\n",
+ name);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ subtest_result = subtest->subtest_func(subtest->data);
+ piglit_report_subtest_result(subtest_result,
+ subtest->name);
+
+ piglit_merge_result(&result, subtest_result);
+ }
+ } else {
+ unsigned i;
+
+ for (i = 0; !PIGLIT_GL_SUBTEST_END(&all_subtests[i]); i++) {
+ const enum piglit_result subtest_result =
+ all_subtests[i].subtest_func(all_subtests[i].data);
+ piglit_report_subtest_result(subtest_result,
+ all_subtests[i].name);
+
+ piglit_merge_result(&result, subtest_result);
+ }
+ }
+
+ return result;
+}
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index fcc1594e8..6276d7e54 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -43,6 +43,31 @@ enum piglit_gl_visual {
};
/**
+ * An idividual subtest that makes up part of a test group.
+ */
+struct piglit_gl_subtest {
+ /** Name of the subtest as it will appear in the log. */
+ const char *name;
+
+ /** Command line name used to select this test. */
+ const char *option;
+
+ /** Function that implements the test. */
+ enum piglit_result (*subtest_func)(void *data);
+
+ /** Passed as the data parameter to subtest_func.*/
+ void *data;
+};
+
+/**
+ * Detect the end of an array of piglit_gl_subtest structures
+ *
+ * The array of subtests is terminated by structure with a \c NULL \c
+ * name pointer.
+ */
+#define PIGLIT_GL_SUBTEST_END(s) ((s)->name == NULL)
+
+/**
* @brief Configuration for running an OpenGL test.
*
* To run a test, pass this to piglit_gl_test_run().
@@ -168,6 +193,15 @@ struct piglit_gl_test_config {
*/
enum piglit_result
(*display)(void);
+
+ /**
+ * Names of subtests supplied on the command line.
+ *
+ * The paramaters passed to each -subtest command line option is
+ * stored here in the order of appearance on the command line.
+ */
+ const char **selected_subtests;
+ size_t num_selected_subtests;
};
/**
@@ -287,4 +321,13 @@ piglit_create_dma_buf(unsigned w, unsigned h, unsigned cpp,
void
piglit_destroy_dma_buf(struct piglit_dma_buf *buf);
+const struct piglit_gl_subtest *
+piglit_find_subtest(const struct piglit_gl_subtest *subtests, const char *name);
+
+enum piglit_result
+piglit_run_selected_subtests(const struct piglit_gl_subtest *all_subtests,
+ const char **selected_subtests,
+ size_t num_selected_subtests,
+ enum piglit_result previous_result);
+
#endif /* PIGLIT_FRAMEWORK_H */