[Intel-gfx] [PATCH i-g-t 08/15] lib/igt_aux: Introduce igt_debug_warn_and_wait_for_key.
Rodrigo Vivi
rodrigo.vivi at intel.com
Mon Jan 12 10:22:00 PST 2015
This is an extention of igt_debug_wait_for_keypress that also can have
customized message and return key pressed.
v2: This is actualy a v2. V1 was an extension of original
igt_debug_wait_for_keypress but it was nacked.
Signed-off-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
---
lib/igt_aux.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_aux.h | 1 +
2 files changed, 47 insertions(+)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 54e5c58..8f25845 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -488,6 +488,52 @@ void igt_debug_wait_for_keypress(const char *var)
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
}
+/**
+ * igt_debug_wait_for_key:
+ * @var: var lookup to to enable this wait
+ * @msg: message to be printed before wait for key
+ *
+ * Waits for a key press when run interactively and when the corresponding debug
+ * var is set in the --interactive-debug=<var> variable. Multiple keys
+ * can be specified as a comma-separated list or alternatively "all" if a wait
+ * should happen for all cases.
+ *
+ * When not connected to a terminal interactive_debug is ignored
+ * and execution immediately continues.
+ *
+ * This is useful for display tests where under certain situation manual
+ * inspection of the display is useful. Or when running a testcase in the
+ * background.
+ *
+ * Returns: key pressed block
+ */
+char igt_debug_warn_and_wait_for_key(const char *var, const char *msg)
+{
+ struct termios oldt, newt;
+ char key = 0;
+
+ if (!isatty(STDIN_FILENO))
+ return key;
+
+ if (!igt_interactive_debug)
+ return key;
+
+ if (!strstr(igt_interactive_debug, var) &&
+ !strstr(igt_interactive_debug, "all"))
+ return key;
+
+ igt_info("%s", msg);
+
+ tcgetattr ( STDIN_FILENO, &oldt );
+ newt = oldt;
+ newt.c_lflag &= ~ICANON;
+ tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
+ key = getchar();
+ tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
+
+ return key;
+}
+
#define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power"
/* We just leak this on exit ... */
int pm_status_fd = -1;
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 798a5b4..87b3e35 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -65,6 +65,7 @@ void igt_system_suspend_autoresume(void);
void igt_drop_root(void);
void igt_debug_wait_for_keypress(const char *var);
+char igt_debug_warn_and_wait_for_key(const char *var, const char *msg);
enum igt_runtime_pm_status {
IGT_RUNTIME_PM_STATUS_ACTIVE,
--
2.1.0
More information about the Intel-gfx
mailing list