|
|
d8307d |
commit 96cd0558bcd69481ccc42e1b392f0c0b36fce2b0
|
|
|
d8307d |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
d8307d |
Date: Wed Nov 28 19:59:45 2018 +0100
|
|
|
d8307d |
|
|
|
d8307d |
support: Add signal support to support_capture_subprocess_check
|
|
|
d8307d |
|
|
|
d8307d |
Signal zero does not terminate a process, so it is safe to use negative
|
|
|
d8307d |
values for signal numbers.
|
|
|
d8307d |
|
|
|
d8307d |
Adjust libio/tst-vtables-common.c to use this new functionality,
|
|
|
d8307d |
instead of determining the termination status for a signal indirectly.
|
|
|
d8307d |
|
|
|
d8307d |
diff --git a/libio/tst-vtables-common.c b/libio/tst-vtables-common.c
|
|
|
d8307d |
index 5e3101206919fa1b..85e246cd1131f8e8 100644
|
|
|
d8307d |
--- a/libio/tst-vtables-common.c
|
|
|
d8307d |
+++ b/libio/tst-vtables-common.c
|
|
|
d8307d |
@@ -380,21 +380,6 @@ without_compatibility_fflush (void *closure)
|
|
|
d8307d |
_exit (1);
|
|
|
d8307d |
}
|
|
|
d8307d |
|
|
|
d8307d |
-/* Exit status after abnormal termination. */
|
|
|
d8307d |
-static int termination_status;
|
|
|
d8307d |
-
|
|
|
d8307d |
-static void
|
|
|
d8307d |
-init_termination_status (void)
|
|
|
d8307d |
-{
|
|
|
d8307d |
- pid_t pid = xfork ();
|
|
|
d8307d |
- if (pid == 0)
|
|
|
d8307d |
- abort ();
|
|
|
d8307d |
- xwaitpid (pid, &termination_status, 0);
|
|
|
d8307d |
-
|
|
|
d8307d |
- TEST_VERIFY (WIFSIGNALED (termination_status));
|
|
|
d8307d |
- TEST_COMPARE (WTERMSIG (termination_status), SIGABRT);
|
|
|
d8307d |
-}
|
|
|
d8307d |
-
|
|
|
d8307d |
static void
|
|
|
d8307d |
check_for_termination (const char *name, void (*callback) (void *))
|
|
|
d8307d |
{
|
|
|
d8307d |
@@ -404,7 +389,7 @@ check_for_termination (const char *name, void (*callback) (void *))
|
|
|
d8307d |
shared->calls = 0;
|
|
|
d8307d |
struct support_capture_subprocess proc
|
|
|
d8307d |
= support_capture_subprocess (callback, NULL);
|
|
|
d8307d |
- support_capture_subprocess_check (&proc, name, termination_status,
|
|
|
d8307d |
+ support_capture_subprocess_check (&proc, name, -SIGABRT,
|
|
|
d8307d |
sc_allow_stderr);
|
|
|
d8307d |
const char *message
|
|
|
d8307d |
= "Fatal error: glibc detected an invalid stdio handle\n";
|
|
|
d8307d |
@@ -491,7 +476,6 @@ run_tests (bool initially_disabled)
|
|
|
d8307d |
|
|
|
d8307d |
shared = support_shared_allocate (sizeof (*shared));
|
|
|
d8307d |
shared->initially_disabled = initially_disabled;
|
|
|
d8307d |
- init_termination_status ();
|
|
|
d8307d |
|
|
|
d8307d |
if (initially_disabled)
|
|
|
d8307d |
{
|
|
|
d8307d |
diff --git a/support/capture_subprocess.h b/support/capture_subprocess.h
|
|
|
d8307d |
index d5eac84d09ae325f..2d2384e73df0d2d0 100644
|
|
|
d8307d |
--- a/support/capture_subprocess.h
|
|
|
d8307d |
+++ b/support/capture_subprocess.h
|
|
|
d8307d |
@@ -55,13 +55,16 @@ enum support_capture_allow
|
|
|
d8307d |
sc_allow_stderr = 0x04,
|
|
|
d8307d |
};
|
|
|
d8307d |
|
|
|
d8307d |
-/* Check that the subprocess exited with STATUS and that only the
|
|
|
d8307d |
- allowed outputs happened. ALLOWED is a combination of
|
|
|
d8307d |
- support_capture_allow flags. Report errors under the CONTEXT
|
|
|
d8307d |
- message. */
|
|
|
d8307d |
+/* Check that the subprocess exited and that only the allowed outputs
|
|
|
d8307d |
+ happened. If STATUS_OR_SIGNAL is nonnegative, it is the expected
|
|
|
d8307d |
+ (decoded) exit status of the process, as returned by WEXITSTATUS.
|
|
|
d8307d |
+ If STATUS_OR_SIGNAL is negative, -STATUS_OR_SIGNAL is the expected
|
|
|
d8307d |
+ termination signal, as returned by WTERMSIG. ALLOWED is a
|
|
|
d8307d |
+ combination of support_capture_allow flags. Report errors under
|
|
|
d8307d |
+ the CONTEXT message. */
|
|
|
d8307d |
void support_capture_subprocess_check (struct support_capture_subprocess *,
|
|
|
d8307d |
- const char *context, int status,
|
|
|
d8307d |
- int allowed)
|
|
|
d8307d |
+ const char *context,
|
|
|
d8307d |
+ int status_or_signal, int allowed)
|
|
|
d8307d |
__attribute__ ((nonnull (1, 2)));
|
|
|
d8307d |
|
|
|
d8307d |
#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */
|
|
|
d8307d |
diff --git a/support/support_capture_subprocess_check.c b/support/support_capture_subprocess_check.c
|
|
|
d8307d |
index ff5ee89fb02599ae..8b4c352c96227b78 100644
|
|
|
d8307d |
--- a/support/support_capture_subprocess_check.c
|
|
|
d8307d |
+++ b/support/support_capture_subprocess_check.c
|
|
|
d8307d |
@@ -20,6 +20,7 @@
|
|
|
d8307d |
#include <stdio.h>
|
|
|
d8307d |
#include <support/capture_subprocess.h>
|
|
|
d8307d |
#include <support/check.h>
|
|
|
d8307d |
+#include <sys/wait.h>
|
|
|
d8307d |
|
|
|
d8307d |
static void
|
|
|
d8307d |
print_context (const char *context, bool *failed)
|
|
|
d8307d |
@@ -31,9 +32,22 @@ print_context (const char *context, bool *failed)
|
|
|
d8307d |
printf ("error: subprocess failed: %s\n", context);
|
|
|
d8307d |
}
|
|
|
d8307d |
|
|
|
d8307d |
+static void
|
|
|
d8307d |
+print_actual_status (struct support_capture_subprocess *proc)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ if (WIFEXITED (proc->status))
|
|
|
d8307d |
+ printf ("error: actual exit status: %d [0x%x]\n",
|
|
|
d8307d |
+ WEXITSTATUS (proc->status), proc->status);
|
|
|
d8307d |
+ else if (WIFSIGNALED (proc->status))
|
|
|
d8307d |
+ printf ("error: actual termination signal: %d [0x%x]\n",
|
|
|
d8307d |
+ WTERMSIG (proc->status), proc->status);
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ printf ("error: actual undecoded exit status: [0x%x]\n", proc->status);
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
void
|
|
|
d8307d |
support_capture_subprocess_check (struct support_capture_subprocess *proc,
|
|
|
d8307d |
- const char *context, int status,
|
|
|
d8307d |
+ const char *context, int status_or_signal,
|
|
|
d8307d |
int allowed)
|
|
|
d8307d |
{
|
|
|
d8307d |
TEST_VERIFY ((allowed & sc_allow_none)
|
|
|
d8307d |
@@ -44,11 +58,28 @@ support_capture_subprocess_check (struct support_capture_subprocess *proc,
|
|
|
d8307d |
|| (allowed & sc_allow_stderr))));
|
|
|
d8307d |
|
|
|
d8307d |
bool failed = false;
|
|
|
d8307d |
- if (proc->status != status)
|
|
|
d8307d |
+ if (status_or_signal >= 0)
|
|
|
d8307d |
{
|
|
|
d8307d |
- print_context (context, &failed);
|
|
|
d8307d |
- printf ("error: expected exit status: %d\n", status);
|
|
|
d8307d |
- printf ("error: actual exit status: %d\n", proc->status);
|
|
|
d8307d |
+ /* Expect regular termination. */
|
|
|
d8307d |
+ if (!(WIFEXITED (proc->status)
|
|
|
d8307d |
+ && WEXITSTATUS (proc->status) == status_or_signal))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ print_context (context, &failed);
|
|
|
d8307d |
+ printf ("error: expected exit status: %d\n", status_or_signal);
|
|
|
d8307d |
+ print_actual_status (proc);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ }
|
|
|
d8307d |
+ else
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ /* status_or_signal < 0. Expect termination by signal. */
|
|
|
d8307d |
+ if (!(WIFSIGNALED (proc->status)
|
|
|
d8307d |
+ && WTERMSIG (proc->status) == -status_or_signal))
|
|
|
d8307d |
+ {
|
|
|
d8307d |
+ print_context (context, &failed);
|
|
|
d8307d |
+ printf ("error: expected termination signal: %d\n",
|
|
|
d8307d |
+ -status_or_signal);
|
|
|
d8307d |
+ print_actual_status (proc);
|
|
|
d8307d |
+ }
|
|
|
d8307d |
}
|
|
|
d8307d |
if (!(allowed & sc_allow_stdout) && proc->out.length != 0)
|
|
|
d8307d |
{
|
|
|
d8307d |
diff --git a/support/tst-support_capture_subprocess.c b/support/tst-support_capture_subprocess.c
|
|
|
d8307d |
index 63b6699622f97fcc..99570879eedd65b1 100644
|
|
|
d8307d |
--- a/support/tst-support_capture_subprocess.c
|
|
|
d8307d |
+++ b/support/tst-support_capture_subprocess.c
|
|
|
d8307d |
@@ -285,15 +285,29 @@ do_multiple_tests (enum test_type type)
|
|
|
d8307d |
|
|
|
d8307d |
check_stream ("stdout", &result.out, test.out);
|
|
|
d8307d |
check_stream ("stderr", &result.err, test.err);
|
|
|
d8307d |
+
|
|
|
d8307d |
+ /* Allowed output for support_capture_subprocess_check. */
|
|
|
d8307d |
+ int check_allow = 0;
|
|
|
d8307d |
+ if (lengths[length_idx_stdout] > 0)
|
|
|
d8307d |
+ check_allow |= sc_allow_stdout;
|
|
|
d8307d |
+ if (lengths[length_idx_stderr] > 0)
|
|
|
d8307d |
+ check_allow |= sc_allow_stderr;
|
|
|
d8307d |
+ if (check_allow == 0)
|
|
|
d8307d |
+ check_allow = sc_allow_none;
|
|
|
d8307d |
+
|
|
|
d8307d |
if (test.signal != 0)
|
|
|
d8307d |
{
|
|
|
d8307d |
TEST_VERIFY (WIFSIGNALED (result.status));
|
|
|
d8307d |
TEST_VERIFY (WTERMSIG (result.status) == test.signal);
|
|
|
d8307d |
+ support_capture_subprocess_check (&result, "signal",
|
|
|
d8307d |
+ -SIGTERM, check_allow);
|
|
|
d8307d |
}
|
|
|
d8307d |
else
|
|
|
d8307d |
{
|
|
|
d8307d |
TEST_VERIFY (WIFEXITED (result.status));
|
|
|
d8307d |
TEST_VERIFY (WEXITSTATUS (result.status) == test.status);
|
|
|
d8307d |
+ support_capture_subprocess_check (&result, "exit",
|
|
|
d8307d |
+ test.status, check_allow);
|
|
|
d8307d |
}
|
|
|
d8307d |
support_capture_subprocess_free (&result);
|
|
|
d8307d |
free (test.out);
|