summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Vivi <rodrigo.vivi@intel.com>2014-12-09 20:44:11 -0500
committerRodrigo Vivi <rodrigo.vivi@intel.com>2015-04-16 11:08:37 -0700
commitae9c685133c5a1f30418d6fda1ce898c11c7053c (patch)
tree7636ce50037a22d9abbf3e9360f66ca72d0ab414
parente1ac04462d94a9f51335b9f3849ce0bb29b534e4 (diff)
lib/igt_aux: Introduce igt_interactive_debug_manual_check.
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. v3: Make [Y/n] check inside aux function as suggested by Daniel. Also renaming and adding first use case along with the axu function. v4: Simplify function name and make it assert pressed key is different from n/N as suggested by Daniel. Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
-rw-r--r--lib/igt_aux.c50
-rw-r--r--lib/igt_aux.h1
-rw-r--r--tests/kms_psr_sink_crc.c8
3 files changed, 53 insertions, 6 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 131ff4b6..788ac3fb 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -448,6 +448,56 @@ void igt_debug_wait_for_keypress(const char *var)
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
}
+/**
+ * igt_debug_manual_check:
+ * @var: var lookup to to enable this wait
+ * @expected: message to be printed as expected behaviour before wait for keys Y/n
+ *
+ * Waits for a key press when run interactively and when the corresponding debug
+ * var is set in the --interactive-debug=<var> variable. Multiple vars
+ * can be specified as a comma-separated list or alternatively "all" if a wait
+ * should happen for all cases.
+ *
+ * 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.
+ *
+ * When not connected to a terminal interactive_debug is ignored
+ * and execution immediately continues. For this reason by default this function
+ * returns true. It returns false only when N/n is pressed indicating the
+ * user ins't seeing what was expected.
+ *
+ * Force test fail when N/n is pressed.
+ */
+void igt_debug_manual_check(const char *var, const char *expected)
+{
+ struct termios oldt, newt;
+ char key;
+
+ if (!isatty(STDIN_FILENO))
+ return;
+
+ if (!igt_interactive_debug)
+ return;
+
+ if (!strstr(igt_interactive_debug, var) &&
+ !strstr(igt_interactive_debug, "all"))
+ return;
+
+ igt_info("Is %s [Y/n]", expected);
+
+ tcgetattr ( STDIN_FILENO, &oldt );
+ newt = oldt;
+ newt.c_lflag &= ~ICANON;
+ tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
+ key = getchar();
+ tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
+
+ igt_info("\n");
+
+ igt_assert(key != 'n' && key != 'N');
+}
+
#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 0c361f26..7a5078b0 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -63,6 +63,7 @@ void igt_system_hibernate_autoresume(void);
void igt_drop_root(void);
void igt_debug_wait_for_keypress(const char *var);
+void igt_debug_manual_check(const char *var, const char *expected);
enum igt_runtime_pm_status {
IGT_RUNTIME_PM_STATUS_ACTIVE,
diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
index 7f0b989a..7558b6d8 100644
--- a/tests/kms_psr_sink_crc.c
+++ b/tests/kms_psr_sink_crc.c
@@ -266,7 +266,7 @@ static void get_sink_crc(data_t *data, char *crc) {
igt_require(file);
ret = fscanf(file, "%s\n", crc);
- igt_require_f(ret > 0, "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=manual\n");
+ igt_require_f(ret > 0, "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=no-crc\n");
fclose(file);
@@ -316,11 +316,7 @@ static bool is_green(char *crc)
static void assert_or_manual(bool condition, const char *expected)
{
- if (igt_interactive_debug)
- igt_info("Is %s?\n", expected);
- else
- igt_debug("%s\n", expected);
- igt_debug_wait_for_keypress("manual");
+ igt_debug_manual_check("no-crc", expected);
igt_assert(igt_interactive_debug || condition);
}