All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 1/5] lib/igt_aux: Add igt_get_module_param_int.
Date: Mon, 12 Mar 2018 18:30:09 +0100	[thread overview]
Message-ID: <20180312173013.50903-2-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20180312173013.50903-1-maarten.lankhorst@linux.intel.com>

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@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

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2018-03-12 17:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12 17:30 [igt-dev] [PATCH i-g-t 0/5] tests/kms_frontbuffer_tracking: Rework to prevent modesets! Maarten Lankhorst
2018-03-12 17:30 ` Maarten Lankhorst [this message]
2018-03-14 14:00   ` [igt-dev] [PATCH i-g-t 1/5] lib/igt_aux: Add igt_get_module_param_int Chris Wilson
2018-03-12 17:30 ` [igt-dev] [PATCH i-g-t 2/5] tests/kms_frontbuffer_tracking: Rework toggling drrs/fbc/psr Maarten Lankhorst
2018-03-12 17:30 ` [igt-dev] [PATCH i-g-t 3/5] tests/kms_frontbuffer_tracking: Fix basic subtest Maarten Lankhorst
2018-03-12 17:30 ` [igt-dev] [PATCH i-g-t 4/5] tests/kms_frontbuffer_tracking: Add support for toggling edp psr through debugfs Maarten Lankhorst
2018-03-12 17:30 ` [igt-dev] [PATCH i-g-t 5/5] tests/kms_frontbuffer_tracking: Remove redundant modesets during subtest start, v2 Maarten Lankhorst
2018-03-12 23:51 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_frontbuffer_tracking: Rework to prevent modesets! Patchwork
2018-03-13  5:02 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180312173013.50903-2-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.