aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-11-30 16:35:21 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-11-30 16:35:21 +0000
commit27d4977f1f4d0b4cbd67bd0cfc29d4d8cfff96f1 (patch)
tree813bc7820c98f3c15b1ca0462995825aa819265e /tests
parent9fd56265077b816b6639b45409d408c10f25f60c (diff)
parent7bfacaabf250d8aed5de82e8091b3251bd8dd53f (diff)
downloadandroid_bionic-27d4977f1f4d0b4cbd67bd0cfc29d4d8cfff96f1.tar.gz
android_bionic-27d4977f1f4d0b4cbd67bd0cfc29d4d8cfff96f1.tar.bz2
android_bionic-27d4977f1f4d0b4cbd67bd0cfc29d4d8cfff96f1.zip
Merge "Fix posix_spawn signal defaulting."
Diffstat (limited to 'tests')
-rw-r--r--tests/spawn_test.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/spawn_test.cpp b/tests/spawn_test.cpp
index 6a3920e39..d2e4ea1da 100644
--- a/tests/spawn_test.cpp
+++ b/tests/spawn_test.cpp
@@ -20,6 +20,7 @@
#include <fcntl.h>
#include <gtest/gtest.h>
+#include "ScopedSignalHandler.h"
#include "utils.h"
#include <android-base/file.h>
@@ -386,3 +387,41 @@ TEST(spawn, posix_spawn_POSIX_SPAWN_SETSIGDEF) {
ASSERT_EQ(0, posix_spawnattr_destroy(&sa));
}
+
+TEST(spawn, signal_stress) {
+ // Ensure that posix_spawn doesn't restore the caller's signal mask in the
+ // child without first defaulting any caught signals (http://b/68707996).
+ static pid_t parent = getpid();
+
+ pid_t pid = fork();
+ ASSERT_NE(-1, pid);
+
+ if (pid == 0) {
+ for (size_t i = 0; i < 1024; ++i) {
+ kill(0, SIGWINCH);
+ usleep(10);
+ }
+ return;
+ }
+
+ // We test both with and without attributes, because they used to be
+ // different codepaths. We also test with an empty `sigdefault` set.
+ posix_spawnattr_t attr1;
+ posix_spawnattr_init(&attr1);
+
+ sigset_t empty_mask = {};
+ posix_spawnattr_t attr2;
+ posix_spawnattr_init(&attr2);
+ posix_spawnattr_setflags(&attr2, POSIX_SPAWN_SETSIGDEF);
+ posix_spawnattr_setsigdefault(&attr2, &empty_mask);
+
+ posix_spawnattr_t* attrs[] = { nullptr, &attr1, &attr2 };
+
+ ScopedSignalHandler ssh(SIGWINCH, [](int) { ASSERT_EQ(getpid(), parent); });
+
+ ExecTestHelper eth;
+ eth.SetArgs({"true", nullptr});
+ for (size_t i = 0; i < 128; ++i) {
+ posix_spawn(nullptr, "true", nullptr, attrs[i % 3], eth.GetArgs(), nullptr);
+ }
+}