[Piglit] [PATCH 3/9] util: Add piglit_source_dir()

Chad Versace chad.versace at linux.intel.com
Mon Jul 9 10:43:31 PDT 2012


This function reads the environment variable PIGLIT_SOURCE_DIR, and
reports failure if the function is undefined. The intention is that tests
should use to construct the path to any needed data files.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/util/piglit-util.c | 13 +++++++++++++
 tests/util/piglit-util.h |  9 +++++++++
 2 files changed, 22 insertions(+)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index f6c2ba0..f01ff5e 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -334,3 +334,16 @@ char *piglit_load_text_file(const char *file_name, unsigned *size)
 	return text;
 #endif
 }
+
+const char*
+piglit_source_dir(void)
+{
+
+    const char *s = getenv("PIGLIT_SOURCE_DIR");
+
+    if (s == NULL) {
+        printf("error: env var PIGLIT_SOURCE_DIR is undefined\n");
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    return s;
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 661078f..b5e6d3a 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -126,6 +126,15 @@ extern void piglit_set_rlimit(unsigned long lim);
 
 char *piglit_load_text_file(const char *file_name, unsigned *size);
 
+/**
+ * \brief Read environment variable PIGLIT_SOURCE_DIR.
+ *
+ * If environment is not defined, then report failure. The intention is
+ * that tests should use this to construct the path to any needed data files.
+ */
+const char*
+piglit_source_dir(void);
+
 #ifdef __cplusplus
 } /* end extern "C" */
 #endif
-- 
1.7.11.1



More information about the Piglit mailing list