[Piglit] [PATCH v3 2/5] util: Add common framework for command-line invoked subtests
Paul Berry
stereotype441 at gmail.com
Mon Oct 21 11:29:17 PDT 2013
On 15 October 2013 17:32, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> 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.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Chad Versace <chad.versace at linux.intel.com>
> ---
> tests/util/piglit-framework-gl.c | 94
> ++++++++++++++++++++++++++++++++++++++--
> tests/util/piglit-framework-gl.h | 32 ++++++++++++++
> 2 files changed, 123 insertions(+), 3 deletions(-)
>
> diff --git a/tests/util/piglit-framework-gl.c
> b/tests/util/piglit-framework-gl.c
> index dd2e6a5..635b52c 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; subtests[i].subtest_func != NULL; 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();
> + piglit_report_subtest_result(subtest_result,
> + subtest->name);
> +
> + piglit_merge_result(&result, subtest_result);
> + }
> + } else {
> + unsigned i;
> +
> + for (i = 0; all_subtests[i].subtest_func != NULL; i++) {
> + const enum piglit_result subtest_result =
> + all_subtests[i].subtest_func();
> + 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 fcc1594..0aca75c 100644
> --- a/tests/util/piglit-framework-gl.h
> +++ b/tests/util/piglit-framework-gl.h
> @@ -43,6 +43,20 @@ 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);
>
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.
> +};
> +
> +/**
> * @brief Configuration for running an OpenGL test.
> *
> * To run a test, pass this to piglit_gl_test_run().
> @@ -168,6 +182,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 +310,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 */
> --
> 1.8.1.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20131021/c108a9fb/attachment.html>
More information about the Piglit
mailing list