[v3,2/2] linux: Add wait4 test case

Message ID 20200410185513.1284043-2-alistair.francis@wdc.com
State New, archived
Headers
Series [v4,1/2] linux: wait4: Fix incorrect return value comparison |

Commit Message

Alistair Francis April 10, 2020, 6:55 p.m. UTC
  Add a simple test that checks if the wait4 syscall works without an
rusage argument. This test would have caught the bugs introduced in
commit 600f00b "linux: Use long time_t for wait4/getrusage".
---
 sysdeps/unix/sysv/linux/Makefile    |  2 +-
 sysdeps/unix/sysv/linux/tst-wait4.c | 51 +++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/tst-wait4.c
  

Patch

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 60dc5cf9e5..d5fdb4369a 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -98,7 +98,7 @@  tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
 	 tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
 	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
 	 tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \
-	 tst-tgkill
+	 tst-tgkill tst-wait4
 tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc
 
 CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables
diff --git a/sysdeps/unix/sysv/linux/tst-wait4.c b/sysdeps/unix/sysv/linux/tst-wait4.c
new file mode 100644
index 0000000000..44287797a7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-wait4.c
@@ -0,0 +1,51 @@ 
+/* Smoke test for the wait4 system call.
+   Copyright (C) 2019-2020 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 <support/check.h>
+#include <support/namespace.h>
+#include <sys/wait.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+/* Check that wait4 works with no rusage arg.  */
+static void
+test_wait4_no_usage (void)
+{
+  pid_t child = fork ();
+
+  if (child == 0)
+    {
+      pause ();
+      exit (0);
+    }
+
+  wait4 (child, &(int){0}, WNOHANG, NULL);
+  kill (child, SIGKILL);
+}
+
+static int
+do_test (void)
+{
+  test_wait4_no_usage();
+
+  return 0;
+}
+
+#include <support/test-driver.c>