[igt-dev] [PATCH i-g-t 1/3] lib: Add functions to read parameters

José Roberto de Souza jose.souza at intel.com
Wed Sep 5 21:05:03 UTC 2018


This functions allow us to read i915 parameters, that is userful to
know the current state of the loaded driver.

Signed-off-by: José Roberto de Souza <jose.souza at intel.com>
---
 lib/igt_aux.c  | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_aux.h  |  2 ++
 lib/igt_core.h | 34 +++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 1250d5c5..5451f51c 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1228,6 +1228,40 @@ void igt_set_module_param(const char *name, const char *val)
 	igt_assert(close(fd) == 0);
 }
 
+/**
+ * igt_get_module_param:
+ * @name: i915.ko parameter name
+ * @val: i915.ko parameter value
+ * @val_len: the length of val buffer
+ * Returns: 0 in success
+ *
+ * This function gets the value of the given i915.ko parameter.
+ *
+ * Please consider using igt_get_module_param_int() for the integer and bool
+ * parameters.
+ */
+int igt_get_module_param(const char *name, char *val, size_t val_len)
+{
+	char file_path[PARAM_FILE_PATH_MAX_SZ];
+	size_t n;
+	int fd;
+
+	igt_assert_return_f(strlen(name) < PARAM_NAME_MAX_SZ, -1,
+			    "Need to increase PARAM_NAME_MAX_SZ\n");
+	snprintf(file_path, sizeof(file_path), "%s%s", MODULE_PARAM_DIR, name);
+
+	fd = open(file_path, O_RDONLY);
+	igt_assert_return(fd >= 0, -1);
+
+	n = read(fd, val, val_len);
+	igt_assert(close(fd) == 0);
+
+	igt_assert_return_f(n > 0 && n < PARAM_VALUE_MAX_SZ, -1,
+			    "Need to increase PARAM_VALUE_MAX_SZ\n");
+
+	return 0;
+}
+
 /**
  * igt_set_module_param_int:
  * @name: i915.ko parameter name
@@ -1248,6 +1282,30 @@ void igt_set_module_param_int(const char *name, int val)
 	igt_set_module_param(name, str);
 }
 
+/**
+ * igt_get_module_param_int:
+ * @name: i915.ko parameter name
+ * @val: i915.ko parameter value
+ * Returns: 0 in success
+ *
+ * This is a wrapper for igt_get_module_param() that takes an integer instead of
+ * a string. Please see igt_get_module_param().
+ */
+int igt_get_module_param_int(const char *name, int *val)
+{
+	char str[PARAM_VALUE_MAX_SZ];
+	long int ret;
+
+	ret = igt_get_module_param(name, str, sizeof(str));
+	if (ret)
+		return ret;
+
+	ret = strtol(str, NULL, 10);
+	*val = ret;
+
+	return 0;
+}
+
 /**
  * igt_terminate_process:
  * @sig: Signal to send
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index ef89faa9..fc948265 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -276,6 +276,8 @@ double igt_stop_siglatency(struct igt_mean *result);
 
 void igt_set_module_param(const char *name, const char *val);
 void igt_set_module_param_int(const char *name, int val);
+int igt_get_module_param(const char *name, char *val, size_t val_len);
+int igt_get_module_param_int(const char *name, int *val);
 
 int igt_terminate_process(int sig, const char *comm);
 void igt_lsof(const char *dpath);
diff --git a/lib/igt_core.h b/lib/igt_core.h
index b80e1702..59cbab21 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -337,6 +337,21 @@ static inline void igt_ignore_warn(bool value)
 		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , NULL); \
 	} while (0)
 
+/**
+ * igt_assert_return:
+ * @expr: condition to test
+ * @ret: returns value if condition is not met
+ *
+ * Fails (sub-)test if the condition is not met.
+ *
+ * Should be used everywhere where a test checks results.
+ */
+#define igt_assert_return(expr, ret) \
+	if (!(expr)) { \
+		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , NULL); \
+		return ret; \
+	}
+
 /**
  * igt_assert_f:
  * @expr: condition to test
@@ -354,6 +369,25 @@ static inline void igt_ignore_warn(bool value)
 		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , f); \
 	} while (0)
 
+/**
+ * igt_assert_return_f:
+ * @expr: condition to test
+ * @ret: returns value if condition is not met
+ * @...: format string and optional arguments
+ *
+ * Fails (sub-)test if the condition is not met.
+ *
+ * Should be used everywhere where a test checks results.
+ *
+ * In addition to the plain igt_assert() helper this allows to print additional
+ * information to help debugging test failures.
+ */
+#define igt_assert_return_f(expr, ret, f...) \
+	if (!(expr)) { \
+		__igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , f); \
+		return ret; \
+	}
+
 /**
  * igt_fail_on:
  * @expr: condition to test
-- 
2.18.0



More information about the igt-dev mailing list