about summary refs log tree commit diff
path: root/support
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-11-28 19:59:45 +0100
committerFlorian Weimer <fweimer@redhat.com>2018-11-28 20:57:18 +0100
commit96cd0558bcd69481ccc42e1b392f0c0b36fce2b0 (patch)
tree9318349a9edfb5c5e6314c9bb560ff909511bbfc /support
parent530504e3a825a63ad4976f24cd50aa9b15d3b91e (diff)
downloadglibc-96cd0558bcd69481ccc42e1b392f0c0b36fce2b0.tar.gz
glibc-96cd0558bcd69481ccc42e1b392f0c0b36fce2b0.tar.xz
glibc-96cd0558bcd69481ccc42e1b392f0c0b36fce2b0.zip
support: Add signal support to support_capture_subprocess_check
Signal zero does not terminate a process, so it is safe to use negative
values for signal numbers.

Adjust libio/tst-vtables-common.c to use this new functionality,
instead of determining the termination status for a signal indirectly.
Diffstat (limited to 'support')
-rw-r--r--support/capture_subprocess.h15
-rw-r--r--support/support_capture_subprocess_check.c41
-rw-r--r--support/tst-support_capture_subprocess.c14
3 files changed, 59 insertions, 11 deletions
diff --git a/support/capture_subprocess.h b/support/capture_subprocess.h
index b0886ba1d1..4734b877ad 100644
--- a/support/capture_subprocess.h
+++ b/support/capture_subprocess.h
@@ -49,13 +49,16 @@ enum support_capture_allow
   sc_allow_stderr = 0x04,
 };
 
-/* Check that the subprocess exited with STATUS and that only the
-   allowed outputs happened.  ALLOWED is a combination of
-   support_capture_allow flags.  Report errors under the CONTEXT
-   message.  */
+/* Check that the subprocess exited and that only the allowed outputs
+   happened.  If STATUS_OR_SIGNAL is nonnegative, it is the expected
+   (decoded) exit status of the process, as returned by WEXITSTATUS.
+   If STATUS_OR_SIGNAL is negative, -STATUS_OR_SIGNAL is the expected
+   termination signal, as returned by WTERMSIG.  ALLOWED is a
+   combination of support_capture_allow flags.  Report errors under
+   the CONTEXT message.  */
 void support_capture_subprocess_check (struct support_capture_subprocess *,
-                                       const char *context, int status,
-                                       int allowed)
+                                       const char *context,
+                                       int status_or_signal, int allowed)
   __attribute__ ((nonnull (1, 2)));
 
 #endif /* SUPPORT_CAPTURE_SUBPROCESS_H */
diff --git a/support/support_capture_subprocess_check.c b/support/support_capture_subprocess_check.c
index ff5ee89fb0..8b4c352c96 100644
--- a/support/support_capture_subprocess_check.c
+++ b/support/support_capture_subprocess_check.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <support/capture_subprocess.h>
 #include <support/check.h>
+#include <sys/wait.h>
 
 static void
 print_context (const char *context, bool *failed)
@@ -31,9 +32,22 @@ print_context (const char *context, bool *failed)
   printf ("error: subprocess failed: %s\n", context);
 }
 
+static void
+print_actual_status (struct support_capture_subprocess *proc)
+{
+  if (WIFEXITED (proc->status))
+    printf ("error:   actual exit status: %d [0x%x]\n",
+            WEXITSTATUS (proc->status), proc->status);
+  else if (WIFSIGNALED (proc->status))
+    printf ("error:   actual termination signal: %d [0x%x]\n",
+            WTERMSIG (proc->status), proc->status);
+  else
+    printf ("error:   actual undecoded exit status: [0x%x]\n", proc->status);
+}
+
 void
 support_capture_subprocess_check (struct support_capture_subprocess *proc,
-                                  const char *context, int status,
+                                  const char *context, int status_or_signal,
                                   int allowed)
 {
   TEST_VERIFY ((allowed & sc_allow_none)
@@ -44,11 +58,28 @@ support_capture_subprocess_check (struct support_capture_subprocess *proc,
                      || (allowed & sc_allow_stderr))));
 
   bool failed = false;
-  if (proc->status != status)
+  if (status_or_signal >= 0)
     {
-      print_context (context, &failed);
-      printf ("error:   expected exit status: %d\n", status);
-      printf ("error:   actual exit status:   %d\n", proc->status);
+      /* Expect regular termination.  */
+      if (!(WIFEXITED (proc->status)
+            && WEXITSTATUS (proc->status) == status_or_signal))
+        {
+          print_context (context, &failed);
+          printf ("error:   expected exit status: %d\n", status_or_signal);
+          print_actual_status (proc);
+        }
+    }
+  else
+    {
+      /* status_or_signal < 0.  Expect termination by signal.  */
+      if (!(WIFSIGNALED (proc->status)
+            && WTERMSIG (proc->status) == -status_or_signal))
+        {
+          print_context (context, &failed);
+          printf ("error:   expected termination signal: %d\n",
+                  -status_or_signal);
+          print_actual_status (proc);
+        }
     }
   if (!(allowed & sc_allow_stdout) && proc->out.length != 0)
     {
diff --git a/support/tst-support_capture_subprocess.c b/support/tst-support_capture_subprocess.c
index a685256091..5339e85b07 100644
--- a/support/tst-support_capture_subprocess.c
+++ b/support/tst-support_capture_subprocess.c
@@ -168,15 +168,29 @@ do_test (void)
                 = support_capture_subprocess (callback, &test);
               check_stream ("stdout", &result.out, test.out);
               check_stream ("stderr", &result.err, test.err);
+
+              /* Allowed output for support_capture_subprocess_check.  */
+              int check_allow = 0;
+              if (lengths[length_idx_stdout] > 0)
+                check_allow |= sc_allow_stdout;
+              if (lengths[length_idx_stderr] > 0)
+                check_allow |= sc_allow_stderr;
+              if (check_allow == 0)
+                check_allow = sc_allow_none;
+
               if (test.signal != 0)
                 {
                   TEST_VERIFY (WIFSIGNALED (result.status));
                   TEST_VERIFY (WTERMSIG (result.status) == test.signal);
+                  support_capture_subprocess_check (&result, "signal",
+                                                    -SIGTERM, check_allow);
                 }
               else
                 {
                   TEST_VERIFY (WIFEXITED (result.status));
                   TEST_VERIFY (WEXITSTATUS (result.status) == test.status);
+                  support_capture_subprocess_check (&result, "exit",
+                                                    test.status, check_allow);
                 }
               support_capture_subprocess_free (&result);
               free (test.out);