diff mbox

[1/1] RFC: add ability to report gl api supported by tests

Message ID 1358902302-3015-1-git-send-email-tom.gall@linaro.org
State New
Headers show

Commit Message

Tom Gall Jan. 23, 2013, 12:51 a.m. UTC
This patch adds a new command line parameter -supports
to all tests that make use of
PIGLIT_GL_TEST_CONFIG_BEGIN/END. If passed when the
test is called, config->piglit_report_supported is set
to true and a JSON formated structure will be returned.
Within the structure is an encoded python dictionary with
  supports_gl_es_version : version
  supports_gl_core_version : version
  supports_gl_compat_version : version
The fields only exist in the structure if they are non-zero
in the test.

When -supports is passed only the JSON structure is returned
and the test is not run.

Within the piglit_gl_test_config structure a new fn pointer
named supported is added. If set and -supports is passed on the
command line, this function is called allowing tests that
read data files to report results based on the data file
passed on the command line.

Ex: With shader_runner it can via waffle utilize
GL or GL ES based on what is included in the
[required] section of that shader_test data file.

Signed-off-by: Tom Gall <tom.gall@linaro.org>
---
 tests/util/piglit-framework-gl.c |   54 +++++++++++++++++++++++++++++++++++---
 tests/util/piglit-framework-gl.h |   30 ++++++++++++++++++++-
 2 files changed, 80 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c
index 441e271..cf14594 100644
--- a/tests/util/piglit-framework-gl.c
+++ b/tests/util/piglit-framework-gl.c
@@ -60,7 +60,8 @@  delete_arg(char *argv[], int argc, int arg)
  * length is returned in @a argc.
  */
 static void
-process_args(int *argc, char *argv[])
+process_args(int *argc, char *argv[],
+             struct piglit_gl_test_config *config)
 {
 	int j;
 
@@ -104,19 +105,34 @@  process_args(int *argc, char *argv[])
 			}
 			*argc -= 2;
 			j -= 2;
+		} else if (!strcmp(argv[j], "-supports")) {
+			/* request to return json structure with API / version
+			 * support information.
+			 */
+			delete_arg(argv, *argc, j--);
+			*argc -= 1;
+			config->piglit_report_supported=true;
 		}
 	}
 }
 
 void
 piglit_gl_test_run(int argc, char *argv[],
-		   const struct piglit_gl_test_config *config)
+		   struct piglit_gl_test_config *config)
 {
-	process_args(&argc, argv);
+	process_args(&argc, argv, config);
 
 	piglit_width = config->window_width;
 	piglit_height = config->window_height;
 
+	if (config->piglit_report_supported) {
+		if (config->supported)
+			(config->supported)(argc,argv);
+		else
+			piglit_report_supported_apis(config);
+		exit(0);
+	}
+
 	gl_fw = piglit_gl_framework_factory(config);
 	if (gl_fw == NULL) {
 		printf("piglit: error: failed to create "
@@ -162,3 +178,35 @@  piglit_set_reshape_func(void (*func)(int w, int h))
 	if (!gl_fw->set_reshape_func)
 		gl_fw->set_reshape_func(gl_fw, func);
 }
+
+/* return JSON structure describing the capability of the test based
+ * on its supports_gl_core_version, supports_gl_compat_version and
+ * supports_gl_es_version as found in config.
+ */
+void
+piglit_report_supported_apis(const struct piglit_gl_test_config *config)
+{
+	bool print_comma = false;
+
+	printf("api: {");
+	if (config->supports_gl_es_version) {
+		printf("\"supports_gl_es_version\" : %d ",
+			config->supports_gl_es_version);
+		print_comma = true;
+	}
+	if (config->supports_gl_core_version) {
+		if (print_comma)
+			printf(",");
+		printf("\"supports_gl_core_version\" : %d ",
+			config->supports_gl_core_version);
+		print_comma = true;
+	}
+	if (config->supports_gl_compat_version) {
+		if (print_comma)
+			printf(",");
+		printf("\"supports_gl_compat_version\" : %d ",
+			config->supports_gl_compat_version);
+	}
+	printf("}\n" );
+	fflush(stdout);
+}
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 6ab791a..d3b6331 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -188,6 +188,33 @@  struct piglit_gl_test_config {
 	 */
 	enum piglit_result
 	(*display)(void);
+
+	/**
+	 * If -supports is passed when the test is called,
+	 * piglit_report_supported will be set to true and
+	 * a JSON formated structure will be returned. Within
+	 * structure is an encoded python dictionary with
+	 * supports_gl_es_version : version
+	 * supports_gl_core_version : version
+	 * supports_gl_compat_version : version
+	 *
+	 * With -supports only the JSON structure is returned
+	 * instead of the test being run.
+	 */
+	bool piglit_report_supported;
+
+	/**
+	 * If -suppports is passed when the test is called and
+	 * if the supported fn pointer is set, this function is
+	 * called allowing tests that read data files to
+	 * report results based on the data file passed on the
+	 * command line.
+	 * Ex: shader_runner could via waffle utilize a version
+	 * GL or GL ES based on what is included in the
+	 * [required] section of that shader_test data file.
+	 */
+	void
+	(*supported)(int argc, char *argv[]);
 };
 
 /**
@@ -201,7 +228,7 @@  piglit_gl_test_config_init(struct piglit_gl_test_config *config);
  */
 void
 piglit_gl_test_run(int argc, char *argv[],
-		   const struct piglit_gl_test_config *config);
+                   struct piglit_gl_test_config *config);
 
 #ifdef __cplusplus
 #  define PIGLIT_EXTERN_C_BEGIN extern "C" {
@@ -261,5 +288,6 @@  void piglit_present_results();
 void piglit_post_redisplay(void);
 void piglit_set_keyboard_func(void (*func)(unsigned char key, int x, int y));
 void piglit_set_reshape_func(void (*func)(int w, int h));
+void piglit_report_supported_apis(const struct piglit_gl_test_config *config);
 
 #endif /* PIGLIT_FRAMEWORK_H */