1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <signal.h> 6 #include <stdlib.h> 7 #include <sys/types.h> 8 #include <sys/wait.h> 9 #include <unistd.h> 10 11 #include "base/logging.h" 12 #include "base/posix/eintr_wrapper.h" 13 #include "sandbox/linux/tests/unit_tests.h" 14 15 namespace sandbox { 16 17 namespace { 18 19 // Let's not use any of the "magic" values used internally in unit_tests.cc, 20 // such as kExpectedValue. 21 const int kExpectedExitCode = 100; 22 23 SANDBOX_DEATH_TEST(UnitTests, 24 DeathExitCode, 25 DEATH_EXIT_CODE(kExpectedExitCode)) { 26 _exit(kExpectedExitCode); 27 } 28 29 const int kExpectedSignalNumber = SIGKILL; 30 31 SANDBOX_DEATH_TEST(UnitTests, 32 DeathBySignal, 33 DEATH_BY_SIGNAL(kExpectedSignalNumber)) { 34 raise(kExpectedSignalNumber); 35 } 36 37 SANDBOX_DEATH_TEST(UnitTests, 38 DeathWithMessage, 39 DEATH_MESSAGE("Hello")) { 40 LOG(ERROR) << "Hello"; 41 _exit(1); 42 } 43 44 SANDBOX_DEATH_TEST(UnitTests, 45 SEGVDeathWithMessage, 46 DEATH_SEGV_MESSAGE("Hello")) { 47 LOG(ERROR) << "Hello"; 48 while (1) { 49 volatile char* addr = reinterpret_cast<volatile char*>(NULL); 50 *addr = '\0'; 51 } 52 53 _exit(2); 54 } 55 56 SANDBOX_TEST_ALLOW_NOISE(UnitTests, NoisyTest) { 57 LOG(ERROR) << "The cow says moo!"; 58 } 59 60 } // namespace 61 62 } // namespace sandbox 63