test: add restore_tty helper and use it
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 16 Oct 2024 00:55:55 +0000 (10:55 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 16 Oct 2024 08:03:03 +0000 (18:03 +1000)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1062>

test/litest.c

index 169c03c51b629017c7365f5231b75cda54d29ffb..0b2d8ee83bdd6d4a2780694449bee88c70039654 100644 (file)
@@ -4993,6 +4993,23 @@ disable_tty(void)
        return tty_mode;
 }
 
+static void
+restore_tty(int tty_mode)
+{
+       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
+       }
+}
+
 int
 main(int argc, char **argv)
 {
@@ -5043,18 +5060,7 @@ main(int argc, char **argv)
 
        litest_free_test_list(&all_tests);
 
-       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
-       }
+       restore_tty(tty_mode);
 
        return min(failed_tests, 255);
 }