<div dir="ltr">On 15 October 2013 17:32, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
There are two parts to this.<br>
<br>
First, command line options of the form "-subtest foo" have their<br>
argument (the "foo" part) stored in a list in the<br>
piglit_gl_test_config. Tests can use this functionality without having<br>
to use any of the other parts. This allows every piglit test to have<br>
the same syntax for specifying which subtests to run.<br>
<br>
Second, tests can create a list of piglit_gl_subtest structures. Each<br>
structure describes a single subtest: the name (as it will apear in the<br>
log), the command-line name (as supplied to -subtest), and the function<br>
that implements the test. Helper function use this table and the list<br>
of tests specified by -subtest options to run a group of tests.<br>
<br>
</div>A later patch shows an example of using this functionality.<br>
<br>
v2: Use piglit_merge_result instead of<br>
piglit_update_result_from_subtest_result. Suggested by Eric, seconded<br>
by Chad.<br>
<br>
v3: Rename piglit_gl_subtest::subtest to<br>
piglit_gl_subtest::subtest_func. Fix some Doxygen comments. Both<br>
suggested by Chad.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
Cc: Chad Versace <<a href="mailto:chad.versace@linux.intel.com">chad.versace@linux.intel.com</a>><br>
---<br>
tests/util/piglit-framework-gl.c | 94 ++++++++++++++++++++++++++++++++++++++--<br>
tests/util/piglit-framework-gl.h | 32 ++++++++++++++<br>
2 files changed, 123 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c<br>
index dd2e6a5..635b52c 100644<br>
<div class="im">--- a/tests/util/piglit-framework-gl.c<br>
+++ b/tests/util/piglit-framework-gl.c<br>
@@ -40,7 +40,8 @@ int piglit_width;<br>
int piglit_height;<br>
<br>
static void<br>
-process_args(int *argc, char *argv[], unsigned *force_samples);<br>
+process_args(int *argc, char *argv[], unsigned *force_samples,<br>
+ struct piglit_gl_test_config *config);<br>
<br>
void<br>
</div> piglit_gl_test_config_init(struct piglit_gl_test_config *config)<br>
@@ -63,7 +64,8 @@ delete_arg(char *argv[], int argc, int arg)<br>
<div class="im"> * length is returned in @a argc.<br>
*/<br>
static void<br>
-process_args(int *argc, char *argv[], unsigned *force_samples)<br>
+process_args(int *argc, char *argv[], unsigned *force_samples,<br>
+ struct piglit_gl_test_config *config)<br>
{<br>
int j;<br>
<br>
</div>@@ -111,6 +113,33 @@ process_args(int *argc, char *argv[], unsigned *force_samples)<br>
<div><div class="h5"> *force_samples = atoi(argv[j]+9);<br>
delete_arg(argv, *argc, j--);<br>
*argc -= 1;<br>
+ } else if (!strcmp(argv[j], "-subtest")) {<br>
+ int i;<br>
+<br>
+ j++;<br>
+ if (j >= *argc) {<br>
+ fprintf(stderr,<br>
+ "-subtest requires an argument\n");<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ config->selected_subtests =<br>
+ realloc(config->selected_subtests,<br>
+ sizeof(char *)<br>
+ * (config->num_selected_subtests + 1));<br>
+ config->selected_subtests[config->num_selected_subtests] =<br>
+ argv[j];<br>
+<br>
+ config->num_selected_subtests++;<br>
+<br>
+ /* Remove 2 arguments (hence the 'i - 2') from the<br>
+ * command line.<br>
+ */<br>
+ for (i = j + 1; i < *argc; i++) {<br>
+ argv[i - 2] = argv[i];<br>
+ }<br>
+ *argc -= 2;<br>
+ j -= 2;<br>
}<br>
}<br>
}<br>
</div></div>@@ -121,7 +150,7 @@ piglit_gl_process_args(int *argc, char *argv[],<br>
{<br>
unsigned force_samples = 0;<br>
<div class="im"><br>
- process_args(argc, argv, &force_samples);<br>
+ process_args(argc, argv, &force_samples, config);<br>
<br>
if (force_samples > 1)<br>
config->window_samples = force_samples;<br>
</div>@@ -223,3 +252,62 @@ piglit_destroy_dma_buf(struct piglit_dma_buf *buf)<br>
<div class="im"> if (gl_fw->destroy_dma_buf)<br>
gl_fw->destroy_dma_buf(buf);<br>
}<br>
+<br>
+const struct piglit_gl_subtest *<br>
+piglit_find_subtest(const struct piglit_gl_subtest *subtests, const char *name)<br>
+{<br>
+ unsigned i;<br>
+<br>
</div>+ for (i = 0; subtests[i].subtest_func != NULL; i++) {<br>
<div><div class="h5">+ if (strcmp(subtests[i].option, name) == 0)<br>
+ return &subtests[i];<br>
+ }<br>
+<br>
+ return NULL;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_run_selected_subtests(const struct piglit_gl_subtest *all_subtests,<br>
+ const char **selected_subtests,<br>
+ size_t num_selected_subtests,<br>
+ enum piglit_result previous_result)<br>
+{<br>
+ enum piglit_result result = previous_result;<br>
+<br>
+ if (num_selected_subtests) {<br>
+ unsigned i;<br>
+<br>
+ for (i = 0; i < num_selected_subtests; i++) {<br>
+ enum piglit_result subtest_result;<br>
+ const char *const name = selected_subtests[i];<br>
+ const struct piglit_gl_subtest *subtest =<br>
+ piglit_find_subtest(all_subtests, name);<br>
+<br>
+ if (subtest == NULL) {<br>
+ fprintf(stderr,<br>
+ "Unknown subtest \"%s\".\n",<br>
+ name);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
</div></div>+ subtest_result = subtest->subtest_func();<br>
<div class="im">+ piglit_report_subtest_result(subtest_result,<br>
+ subtest->name);<br>
+<br>
</div>+ piglit_merge_result(&result, subtest_result);<br>
<div class="im">+ }<br>
+ } else {<br>
+ unsigned i;<br>
+<br>
</div>+ for (i = 0; all_subtests[i].subtest_func != NULL; i++) {<br>
<div class="im">+ const enum piglit_result subtest_result =<br>
</div>+ all_subtests[i].subtest_func();<br>
<div class="im">+ piglit_report_subtest_result(subtest_result,<br>
+ all_subtests[i].name);<br>
+<br>
</div>+ piglit_merge_result(&result, subtest_result);<br>
<div class="im">+ }<br>
+ }<br>
+<br>
+ return result;<br>
+}<br>
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h<br>
</div>index fcc1594..0aca75c 100644<br>
<div class="im">--- a/tests/util/piglit-framework-gl.h<br>
+++ b/tests/util/piglit-framework-gl.h<br>
@@ -43,6 +43,20 @@ enum piglit_gl_visual {<br>
};<br>
<br>
/**<br>
+ * An idividual subtest that makes up part of a test group.<br>
+ */<br>
+struct piglit_gl_subtest {<br>
+ /** Name of the subtest as it will appear in the log. */<br>
+ const char *name;<br>
+<br>
+ /** Command line name used to select this test. */<br>
+ const char *option;<br>
+<br>
+ /** Function that implements the test. */<br>
</div>+ enum piglit_result (*subtest_func)(void);<br></blockquote><div><br></div><div>Would you have any objection to adding a void * to this structure, which would then get passed to subtest_func? That would give the test implementor extra flexibility if they want to share a single subtest_func between multiple similar subtests. It would also allow for the possibility that the set of available subtests is determined at run time rather than compile time.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+};<br>
<div class="im">+<br>
+/**<br>
* @brief Configuration for running an OpenGL test.<br>
*<br>
* To run a test, pass this to piglit_gl_test_run().<br>
@@ -168,6 +182,15 @@ struct piglit_gl_test_config {<br>
*/<br>
enum piglit_result<br>
(*display)(void);<br>
+<br>
+ /**<br>
+ * Names of subtests supplied on the command line.<br>
+ *<br>
+ * The paramaters passed to each -subtest command line option is<br>
+ * stored here in the order of appearance on the command line.<br>
+ */<br>
+ const char **selected_subtests;<br>
+ size_t num_selected_subtests;<br>
};<br>
<br>
/**<br>
</div>@@ -287,4 +310,13 @@ piglit_create_dma_buf(unsigned w, unsigned h, unsigned cpp,<br>
<div class="im HOEnZb"> void<br>
piglit_destroy_dma_buf(struct piglit_dma_buf *buf);<br>
<br>
+const struct piglit_gl_subtest *<br>
+piglit_find_subtest(const struct piglit_gl_subtest *subtests, const char *name);<br>
+<br>
+enum piglit_result<br>
+piglit_run_selected_subtests(const struct piglit_gl_subtest *all_subtests,<br>
+ const char **selected_subtests,<br>
+ size_t num_selected_subtests,<br>
+ enum piglit_result previous_result);<br>
+<br>
#endif /* PIGLIT_FRAMEWORK_H */<br>
</div><span class="HOEnZb"><font color="#888888">--<br>
1.8.1.4<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</div></div></blockquote></div><br></div></div>