summaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorJordan Justen <jordan.l.justen@intel.com>2017-10-29 16:21:52 -0700
committerJordan Justen <jordan.l.justen@intel.com>2018-06-11 00:43:27 -0700
commitd6669f87f79712cfacd333e849ac2efe2a25889b (patch)
tree8c28f6f82b75526da12e200b334bef90e99d2925 /tests/util
parent273c634b668afeeab3007f20c84839b7cd12b1e4 (diff)
util: Add piglit_env_var_as_boolean
This is copied from Mesa's env_var_as_boolean. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/piglit-util.c27
-rw-r--r--tests/util/piglit-util.h9
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index ed7d21c95..3a8f9bcfb 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -867,3 +867,30 @@ piglit_free_aligned(void *p)
free(p);
#endif
}
+
+
+/**
+ * \brief Reads an environment variable and interprets its value as a boolean.
+ *
+ * Recognizes 0/false/no and 1/true/yes. Other values result in the
+ * \a default_value.
+ */
+bool
+piglit_env_var_as_boolean(const char *var_name, bool default_value)
+{
+ const char *str = getenv(var_name);
+ if (str == NULL)
+ return default_value;
+
+ if (strcmp(str, "1") == 0 ||
+ strcasecmp(str, "true") == 0 ||
+ strcasecmp(str, "yes") == 0) {
+ return true;
+ } else if (strcmp(str, "0") == 0 ||
+ strcasecmp(str, "false") == 0 ||
+ strcasecmp(str, "no") == 0) {
+ return false;
+ } else {
+ return default_value;
+ }
+}
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 0a5eab810..53cffedbb 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -393,6 +393,15 @@ size_t
piglit_join_paths(char buf[], size_t buf_size, int n, ...);
/**
+ * \brief Reads an environment variable and interprets its value as a boolean.
+ *
+ * Recognizes 0/false/no and 1/true/yes. Other values result in the
+ * \a default_value.
+ */
+bool
+piglit_env_var_as_boolean(const char *var_name, bool default_value);
+
+/**
* \brief Whether piglit_time_get* return monotonically increasing time.
*
* Can be used to determine how accurate/reliable the time returned by the