[Piglit] [PATCH 06/13] util: Move subtest utils to API-independent files
Chad Versace
chad.versace at linux.intel.com
Wed Mar 26 10:40:22 PDT 2014
Pre-patch, piglit-framework-gl.{c,h} defined the function and structs
for working with subtests. This patch moves them to piglit-util.{c,h},
so that they become available for non-GL tests.
This is simply a copy-paste patch. The patch does not modify the
relocated code.
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
tests/util/piglit-framework-gl.c | 121 --------------------------------------
tests/util/piglit-framework-gl.h | 34 -----------
tests/util/piglit-util.c | 122 +++++++++++++++++++++++++++++++++++++++
tests/util/piglit-util.h | 42 ++++++++++++++
4 files changed, 164 insertions(+), 155 deletions(-)
diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c
index 76d751c..a97babc 100644
--- a/tests/util/piglit-framework-gl.c
+++ b/tests/util/piglit-framework-gl.c
@@ -59,68 +59,6 @@ delete_arg(char *argv[], int argc, int arg)
}
}
-static void
-piglit_parse_subtest_args(int *argc, char *argv[],
- const struct piglit_subtest *subtests,
- const char ***out_selected_subtests,
- size_t *out_num_selected_subtests)
-{
- int j;
- const char **selected_subtests = NULL;
- size_t num_selected_subtests = 0;
-
- for (j = 1; j < *argc; j++) {
- if (streq(argv[j], "-subtest")) {
- int i;
-
- ++j;
- if (j >= *argc) {
- fprintf(stderr,
- "-subtest requires an argument\n");
- piglit_report_result(PIGLIT_FAIL);
- }
-
- if (!piglit_find_subtest(subtests, argv[j])) {
- fprintf(stderr, "Test defines no subtest with "
- "name '%s'\n", argv[j]);
- piglit_report_result(PIGLIT_FAIL);
- }
-
- selected_subtests =
- realloc(selected_subtests,
- (num_selected_subtests + 1)
- * sizeof(char*));
- selected_subtests[num_selected_subtests] = argv[j];
- ++num_selected_subtests;
-
- /* Remove 2 arguments from the command line. */
- for (i = j + 1; i < *argc; i++) {
- argv[i - 2] = argv[i];
- }
- *argc -= 2;
- j -= 2;
- } else if (streq(argv[j], "-list-subtests")) {
- int i;
-
- if (subtests == NULL) {
- fprintf(stderr, "Test defines no subtests!\n");
- exit(EXIT_FAILURE);
- }
-
- for (i = 0; !PIGLIT_SUBTEST_END(&subtests[i]); ++i) {
- printf("%s: %s\n",
- subtests[i].option,
- subtests[i].name);
- }
-
- exit(EXIT_SUCCESS);
- }
- }
-
- *out_selected_subtests = selected_subtests;
- *out_num_selected_subtests = num_selected_subtests;
-}
-
/**
* Recognized arguments are removed from @a argv. The updated array
* length is returned in @a argc.
@@ -274,65 +212,6 @@ piglit_destroy_dma_buf(struct piglit_dma_buf *buf)
gl_fw->destroy_dma_buf(buf);
}
-const struct piglit_subtest *
-piglit_find_subtest(const struct piglit_subtest *subtests, const char *name)
-{
- unsigned i;
-
- for (i = 0; !PIGLIT_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_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_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, "%s",
- subtest->name);
-
- piglit_merge_result(&result, subtest_result);
- }
- } else {
- unsigned i;
-
- for (i = 0; !PIGLIT_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, "%s",
- all_subtests[i].name);
-
- piglit_merge_result(&result, subtest_result);
- }
- }
-
- return result;
-}
-
size_t
piglit_get_selected_tests(const char ***selected_subtests)
{
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 127f4be..9824372 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -43,31 +43,6 @@ enum piglit_gl_visual {
};
/**
- * An idividual subtest that makes up part of a test group.
- */
-struct piglit_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_subtest structures
- *
- * The array of subtests is terminated by structure with a \c NULL \c
- * name pointer.
- */
-#define PIGLIT_SUBTEST_END(s) ((s)->name == NULL)
-
-/**
* @brief Configuration for running an OpenGL test.
*
* To run a test, pass this to piglit_gl_test_run().
@@ -358,13 +333,4 @@ piglit_create_dma_buf(unsigned w, unsigned h, unsigned cpp,
void
piglit_destroy_dma_buf(struct piglit_dma_buf *buf);
-const struct piglit_subtest *
-piglit_find_subtest(const struct piglit_subtest *subtests, const char *name);
-
-enum piglit_result
-piglit_run_selected_subtests(const struct piglit_subtest *all_subtests,
- const char **selected_subtests,
- size_t num_selected_subtests,
- enum piglit_result previous_result);
-
#endif /* PIGLIT_FRAMEWORK_H */
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index d5a51ed..1d0f393 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -541,3 +541,125 @@ piglit_strip_arg(int *argc, char *argv[], const char *arg)
return false;
}
+
+void
+piglit_parse_subtest_args(int *argc, char *argv[],
+ const struct piglit_subtest *subtests,
+ const char ***out_selected_subtests,
+ size_t *out_num_selected_subtests)
+{
+ int j;
+ const char **selected_subtests = NULL;
+ size_t num_selected_subtests = 0;
+
+ for (j = 1; j < *argc; j++) {
+ if (streq(argv[j], "-subtest")) {
+ int i;
+
+ ++j;
+ if (j >= *argc) {
+ fprintf(stderr,
+ "-subtest requires an argument\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ if (!piglit_find_subtest(subtests, argv[j])) {
+ fprintf(stderr, "Test defines no subtest with "
+ "name '%s'\n", argv[j]);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ selected_subtests =
+ realloc(selected_subtests,
+ (num_selected_subtests + 1)
+ * sizeof(char*));
+ selected_subtests[num_selected_subtests] = argv[j];
+ ++num_selected_subtests;
+
+ /* Remove 2 arguments from the command line. */
+ for (i = j + 1; i < *argc; i++) {
+ argv[i - 2] = argv[i];
+ }
+ *argc -= 2;
+ j -= 2;
+ } else if (streq(argv[j], "-list-subtests")) {
+ int i;
+
+ if (subtests == NULL) {
+ fprintf(stderr, "Test defines no subtests!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; !PIGLIT_SUBTEST_END(&subtests[i]); ++i) {
+ printf("%s: %s\n",
+ subtests[i].option,
+ subtests[i].name);
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ *out_selected_subtests = selected_subtests;
+ *out_num_selected_subtests = num_selected_subtests;
+}
+
+
+const struct piglit_subtest *
+piglit_find_subtest(const struct piglit_subtest *subtests, const char *name)
+{
+ unsigned i;
+
+ for (i = 0; !PIGLIT_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_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_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, "%s",
+ subtest->name);
+
+ piglit_merge_result(&result, subtest_result);
+ }
+ } else {
+ unsigned i;
+
+ for (i = 0; !PIGLIT_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, "%s",
+ all_subtests[i].name);
+
+ piglit_merge_result(&result, subtest_result);
+ }
+ }
+
+ return result;
+}
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 84d4726..a90f59f 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -117,6 +117,40 @@ enum piglit_result {
PIGLIT_WARN
};
+/**
+ * An idividual subtest that makes up part of a test group.
+ */
+struct piglit_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_subtest structures
+ *
+ * The array of subtests is terminated by structure with a \c NULL \c
+ * name pointer.
+ */
+#define PIGLIT_SUBTEST_END(s) ((s)->name == NULL)
+
+const struct piglit_subtest*
+piglit_find_subtest(const struct piglit_subtest *subtests, const char *name);
+
+enum piglit_result
+piglit_run_selected_subtests(const struct piglit_subtest *all_subtests,
+ const char **selected_subtests,
+ size_t num_selected_subtests,
+ enum piglit_result previous_result);
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
@@ -210,6 +244,14 @@ piglit_split_string_to_array(const char *string, const char *separators);
bool
piglit_strip_arg(int *argc, char *argv[], const char *arg);
+void
+piglit_parse_subtest_args(int *argc, char *argv[],
+ const struct piglit_subtest *subtests,
+ const char ***out_selected_subtests,
+ size_t *out_num_selected_subtests);
+
+
+
#ifdef __cplusplus
} /* end extern "C" */
#endif
--
1.8.5.3
More information about the Piglit
mailing list