From: "José Roberto de Souza" <jose.souza@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 1/3] lib: Add functions to read parameters
Date: Wed, 5 Sep 2018 14:05:03 -0700 [thread overview]
Message-ID: <20180905210505.28867-1-jose.souza@intel.com> (raw)
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@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2018-09-05 21:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-05 21:05 José Roberto de Souza [this message]
2018-09-05 21:05 ` [igt-dev] [PATCH i-g-t 2/3] lib/psr: Read enable_psr instead of relly in a value assumption José Roberto de Souza
2018-09-05 21:05 ` [igt-dev] [PATCH i-g-t 3/3] lib: Use newly added igt_get_module_param() in igt_save_module_param() José Roberto de Souza
2018-09-05 21:36 ` [igt-dev] [PATCH i-g-t 1/3] lib: Add functions to read parameters Chris Wilson
2018-09-05 22:42 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] " Patchwork
2018-09-06 7:29 ` [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=20180905210505.28867-1-jose.souza@intel.com \
--to=jose.souza@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox