[igt-dev] [PATCH i-g-t 1/5] lib/igt_aux: Add igt_get_module_param_int.
Maarten Lankhorst
maarten.lankhorst at linux.intel.com
Mon Mar 12 17:30:09 UTC 2018
This is useful for retrieving the current module parameter value,
without having to write helper code for each callsite.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
lib/igt_aux.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_aux.h | 3 +++
2 files changed, 64 insertions(+)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index aabf6e50f0b3..bd8b7c62d4d7 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1286,6 +1286,67 @@ void igt_set_module_param_int(const char *name, int val)
igt_set_module_param(name, str);
}
+/**
+ * igt_set_module_param:
+ * @name: i915.ko parameter name
+ *
+ * This function returns the current value for the given i915.ko parameter.
+ * This value must be freed with free().
+ *
+ * Please consider using igt_get_module_param_int() for the integer and bool
+ * parameters.
+ */
+char *igt_get_module_param(const char *name)
+{
+ char file_path[PARAM_FILE_PATH_MAX_SZ];
+ char str[PARAM_VALUE_MAX_SZ], *dup;
+ int fd;
+ ssize_t ret;
+
+ igt_assert_f(strlen(name) < PARAM_NAME_MAX_SZ,
+ "Need to increase PARAM_NAME_MAX_SZ\n");
+ strcpy(file_path, MODULE_PARAM_DIR);
+ strcpy(file_path + strlen(MODULE_PARAM_DIR), name);
+
+ fd = open(file_path, O_RDWR);
+ ret = read(fd, str, sizeof(str));
+ igt_assert(ret > 0);
+ igt_assert_f(ret < PARAM_VALUE_MAX_SZ,
+ "Need to increase PARAM_VALUE_MAX_SZ\n");
+ str[ret] = 0;
+
+ igt_assert(close(fd) == 0);
+
+ dup = strdup(str);
+ igt_assert(dup);
+ return dup;
+}
+
+/**
+ * igt_get_module_param_int:
+ * @name: i915.ko parameter name
+ *
+ * This is a wrapper for igt_get_module_param() that returns an integer
+ * instead of a string. Please see igt_get_module_param().
+ */
+int igt_get_module_param_int(const char *name)
+{
+ char *val = igt_get_module_param(name);
+
+ int ret;
+
+ if (*val == 'Y')
+ ret = 1;
+ else if (*val == 'N')
+ ret = 0;
+ else
+ ret = strtoll(val, NULL, 10);
+
+ free(val);
+
+ return ret;
+}
+
/**
* igt_terminate_process:
* @sig: Signal to send
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 43dd15fe3b32..8b7ef14944f3 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -284,6 +284,9 @@ 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);
+char *igt_get_module_param(const char *name);
+int igt_get_module_param_int(const char *name);
+
int igt_terminate_process(int sig, const char *comm);
void igt_lsof(const char *dpath);
--
2.16.2
More information about the igt-dev
mailing list