]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
add ptmx support to test-container
authorDJ Delorie <dj@redhat.com>
Fri, 14 Mar 2025 20:08:12 +0000 (16:08 -0400)
committerDJ Delorie <dj@redhat.com>
Tue, 1 Apr 2025 19:20:40 +0000 (15:20 -0400)
support/Makefile
support/test-container.c
support/tst-support-openpty-c.c [new file with mode: 0644]
support/tst-support-openpty.c [new file with mode: 0644]

index dfe8e547f650c84ff175cd94704922a20729b01f..d41278eeab34ae357a1afc76714baad16d70ee76 100644 (file)
@@ -330,6 +330,7 @@ tests = \
   README-testing \
   tst-support-namespace \
   tst-support-open-dev-null-range \
+  tst-support-openpty \
   tst-support-process_state \
   tst-support_blob_repeat \
   tst-support_capture_subprocess \
@@ -351,6 +352,10 @@ tests = \
   tst-xsigstack \
   # tests
 
+tests-container = \
+  tst-support-openpty-c \
+  # tests-container
+
 ifeq ($(run-built-tests),yes)
 tests-special = \
   $(objpfx)tst-support_record_failure-2.out
index 79d3189e2fbb312345842e9b5904be8ad0f6459d..a641250079948109049446b95a984f9c4d43e3c7 100644 (file)
@@ -1151,6 +1151,9 @@ main (int argc, char **argv)
   devmount (new_root_path, "null");
   devmount (new_root_path, "zero");
   devmount (new_root_path, "urandom");
+#ifdef __linux__
+  devmount (new_root_path, "ptmx");
+#endif
 
   /* We're done with the "old" root, switch to the new one.  */
   if (chroot (new_root_path) < 0)
@@ -1217,6 +1220,14 @@ main (int argc, char **argv)
 
   maybe_xmkdir ("/tmp", 0755);
 
+#ifdef __linux__
+  maybe_xmkdir ("/dev/pts", 0777);
+  if (mount ("/dev/pts", "/dev/pts", "devpts", 0, "newinstance,ptmxmode=0666,mode=0666") < 0)
+    FAIL_EXIT1 ("can't mount /dev/pts: %m\n");
+  if (mount ("/dev/pts/ptmx", "/dev/ptmx", "", MS_BIND | MS_REC, NULL) < 0)
+    FAIL_EXIT1 ("can't mount /dev/ptmx\n");
+#endif
+
   if (require_pidns)
     {
       /* Now that we're pid 1 (effectively "root") we can mount /proc  */
diff --git a/support/tst-support-openpty-c.c b/support/tst-support-openpty-c.c
new file mode 100644 (file)
index 0000000..0a6a428
--- /dev/null
@@ -0,0 +1,2 @@
+/* Same test, but in a test-container.  */
+#include "tst-support-openpty.c"
diff --git a/support/tst-support-openpty.c b/support/tst-support-openpty.c
new file mode 100644 (file)
index 0000000..1222d70
--- /dev/null
@@ -0,0 +1,49 @@
+/* Basic test for support_openpty support in test-container.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <support/tty.h>
+#include <support/check.h>
+#include <support/support.h>
+
+/* Note: the purpose of this test isn't to test if ptys function
+   correctly, but only to verify that test-container's support for
+   them is correct.  The many checks in support_openpty.c are
+   sufficient for this.  */
+
+int
+do_test (void)
+{
+  int outer, inner;
+  char *name;
+  struct termios term;
+  struct winsize win;
+
+  cfmakeraw (&term);
+  win.ws_row = 24;
+  win.ws_col = 80;
+
+  support_openpty (&outer, &inner, &name, &term, &win);
+
+  return 0;
+}
+
+#include <support/test-driver.c>