From 63a2180b4015507c1fcc99cc8dba5ef06686cfc8 Mon Sep 17 00:00:00 2001 From: Greg V Date: Tue, 10 Jul 2018 13:47:54 +0300 Subject: [PATCH] test: support disabling tty on FreeBSD Instead of K_OFF, use K_RAW plus termios raw mode. (Same approach as in the Weston patches) --- test/litest.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/litest.c b/test/litest.c index ac836e03..7c9cf00b 100644 --- a/test/litest.c +++ b/test/litest.c @@ -51,6 +51,9 @@ #if HAVE_LIBSYSTEMD #include #endif +#ifdef __FreeBSD__ +#include +#endif #include "litest.h" #include "litest-int.h" @@ -3974,8 +3977,21 @@ disable_tty(void) !in_debugger && getenv("CK_FORK") == NULL && isatty(STDIN_FILENO) && - ioctl(STDIN_FILENO, KDGKBMODE, &tty_mode) == 0) + ioctl(STDIN_FILENO, KDGKBMODE, &tty_mode) == 0) { +#ifdef __linux__ ioctl(STDIN_FILENO, KDSKBMODE, K_OFF); +#elif __FreeBSD__ + ioctl(STDIN_FILENO, KDSKBMODE, K_RAW); + + /* Put the tty into raw mode */ + struct termios tios; + if (tcgetattr(STDIN_FILENO, &tios)) + fprintf(stderr, "Failed to get terminal attribute: %d - %s\n", errno, strerror(errno)); + cfmakeraw(&tios); + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios)) + fprintf(stderr, "Failed to set terminal attribute: %d - %s\n", errno, strerror(errno)); +#endif + } #endif /* DISABLE_DEVICE_TESTS */ return tty_mode; @@ -4023,8 +4039,18 @@ main(int argc, char **argv) failed_tests = litest_run(argc, argv); - if (tty_mode != -1) + if (tty_mode != -1) { ioctl(STDIN_FILENO, KDSKBMODE, tty_mode); +#ifdef __FreeBSD__ + /* Put the tty into "sane" mode */ + struct termios tios; + if (tcgetattr(STDIN_FILENO, &tios)) + fprintf(stderr, "Failed to get terminal attribute: %d - %s\n", errno, strerror(errno)); + cfmakesane(&tios); + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios)) + fprintf(stderr, "Failed to set terminal attribute: %d - %s\n", errno, strerror(errno)); +#endif + } return failed_tests; }