From d6f3323b5af31e511031cf59e1179587a608d808 Mon Sep 17 00:00:00 2001 From: José Roberto de Souza Date: Mon, 14 Jan 2019 17:18:47 -0800 Subject: tests/fbcon_fbt: Enable cursor blinking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If cursor blinking is disabled no screen updates will happen and fbcon_fbt subtests will fail, so lets enable cursor blink while running this test and restore to the previous value when exiting it. v4: - renaming restore fd (Dhinakaran) - saving previous value as char (Dhinakaran) - skipping test if not able to open cursor blink file (Dhinakaran) Cc: Paulo Zanoni Cc: Dhinakaran Pandiyan Cc: Rodrigo Vivi Cc: Chris Wilson Reviewed-by: Maarten Lankhorst Signed-off-by: José Roberto de Souza --- lib/igt_sysfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/igt_sysfs.h | 1 + 2 files changed, 44 insertions(+) (limited to 'lib') diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index f806f4fc..c439944d 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -610,3 +610,46 @@ void kick_snd_hda_intel(void) out: close(fd); } + +static int fbcon_cursor_blink_fd = -1; +static char fbcon_cursor_blink_prev_value[2]; + +static void fbcon_cursor_blink_restore(int sig) +{ + write(fbcon_cursor_blink_fd, fbcon_cursor_blink_prev_value, + strlen(fbcon_cursor_blink_prev_value) + 1); + close(fbcon_cursor_blink_fd); +} + +/** + * fbcon_blink_enable: + * @enable: if true enables the fbcon cursor blinking otherwise disables it + * + * Enables or disables the cursor blinking in fbcon, it also restores the + * previous blinking state when exiting test. + * + */ +void fbcon_blink_enable(bool enable) +{ + const char *cur_blink_path = "/sys/class/graphics/fbcon/cursor_blink"; + int fd, r; + char buffer[2]; + + fd = open(cur_blink_path, O_RDWR); + igt_require(fd >= 0); + + /* Restore original value on exit */ + if (fbcon_cursor_blink_fd == -1) { + r = read(fd, fbcon_cursor_blink_prev_value, + sizeof(fbcon_cursor_blink_prev_value)); + if (r > 0) { + fbcon_cursor_blink_fd = dup(fd); + igt_assert(fbcon_cursor_blink_fd >= 0); + igt_install_exit_handler(fbcon_cursor_blink_restore); + } + } + + r = snprintf(buffer, sizeof(buffer), enable ? "1" : "0"); + write(fd, buffer, r + 1); + close(fd); +} diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h index c12e36d1..b646df30 100644 --- a/lib/igt_sysfs.h +++ b/lib/igt_sysfs.h @@ -57,5 +57,6 @@ bool igt_sysfs_set_boolean(int dir, const char *attr, bool value); void bind_fbcon(bool enable); void kick_snd_hda_intel(void); +void fbcon_blink_enable(bool enable); #endif /* __IGT_SYSFS_H__ */ -- cgit v1.2.3