diff options
Diffstat (limited to 'ninja/src/subprocess_test.cc')
-rw-r--r-- | ninja/src/subprocess_test.cc | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/ninja/src/subprocess_test.cc b/ninja/src/subprocess_test.cc index 07cc52f6ba3..ee161908f79 100644 --- a/ninja/src/subprocess_test.cc +++ b/ninja/src/subprocess_test.cc @@ -16,8 +16,6 @@ #include "test.h" -#include <string> - #ifndef _WIN32 // SetWithLots need setrlimit. #include <stdio.h> @@ -122,22 +120,35 @@ TEST_F(SubprocessTest, InterruptParentWithSigTerm) { ASSERT_FALSE("We should have been interrupted"); } -// A shell command to check if the current process is connected to a terminal. -// This is different from having stdin/stdout/stderr be a terminal. (For -// instance consider the command "yes < /dev/null > /dev/null 2>&1". -// As "ps" will confirm, "yes" could still be connected to a terminal, despite -// not having any of the standard file descriptors be a terminal. -static const char kIsConnectedToTerminal[] = "tty < /dev/tty > /dev/null"; +TEST_F(SubprocessTest, InterruptChildWithSigHup) { + Subprocess* subproc = subprocs_.Add("kill -HUP $$"); + ASSERT_NE((Subprocess *) 0, subproc); + + while (!subproc->Done()) { + subprocs_.DoWork(); + } + + EXPECT_EQ(ExitInterrupted, subproc->Finish()); +} + +TEST_F(SubprocessTest, InterruptParentWithSigHup) { + Subprocess* subproc = subprocs_.Add("kill -HUP $PPID ; sleep 1"); + ASSERT_NE((Subprocess *) 0, subproc); + + while (!subproc->Done()) { + bool interrupted = subprocs_.DoWork(); + if (interrupted) + return; + } + + ASSERT_FALSE("We should have been interrupted"); +} TEST_F(SubprocessTest, Console) { // Skip test if we don't have the console ourselves. if (isatty(0) && isatty(1) && isatty(2)) { - // Test that stdin, stdout and stderr are a terminal. - // Also check that the current process is connected to a terminal. Subprocess* subproc = - subprocs_.Add(std::string("test -t 0 -a -t 1 -a -t 2 && ") + - std::string(kIsConnectedToTerminal), - /*use_console=*/true); + subprocs_.Add("test -t 0 -a -t 1 -a -t 2", /*use_console=*/true); ASSERT_NE((Subprocess*)0, subproc); while (!subproc->Done()) { @@ -148,18 +159,6 @@ TEST_F(SubprocessTest, Console) { } } -TEST_F(SubprocessTest, NoConsole) { - Subprocess* subproc = - subprocs_.Add(kIsConnectedToTerminal, /*use_console=*/false); - ASSERT_NE((Subprocess*)0, subproc); - - while (!subproc->Done()) { - subprocs_.DoWork(); - } - - EXPECT_NE(ExitSuccess, subproc->Finish()); -} - #endif TEST_F(SubprocessTest, SetWithSingle) { @@ -227,7 +226,8 @@ TEST_F(SubprocessTest, SetWithLots) { rlimit rlim; ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlim)); if (rlim.rlim_cur < kNumProcs) { - printf("Raise [ulimit -n] well above %u (currently %lu) to make this test go\n", kNumProcs, rlim.rlim_cur); + printf("Raise [ulimit -n] above %u (currently %lu) to make this test go\n", + kNumProcs, rlim.rlim_cur); return; } |