unit_tests_unittest.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <signal.h>
  5. #include <stdlib.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8. #include <unistd.h>
  9. #include "base/logging.h"
  10. #include "base/posix/eintr_wrapper.h"
  11. #include "sandbox/linux/tests/unit_tests.h"
  12. namespace sandbox {
  13. namespace {
  14. // Let's not use any of the "magic" values used internally in unit_tests.cc,
  15. // such as kExpectedValue.
  16. const int kExpectedExitCode = 100;
  17. SANDBOX_DEATH_TEST(UnitTests,
  18. DeathExitCode,
  19. DEATH_EXIT_CODE(kExpectedExitCode)) {
  20. _exit(kExpectedExitCode);
  21. }
  22. const int kExpectedSignalNumber = SIGKILL;
  23. SANDBOX_DEATH_TEST(UnitTests,
  24. DeathBySignal,
  25. DEATH_BY_SIGNAL(kExpectedSignalNumber)) {
  26. raise(kExpectedSignalNumber);
  27. }
  28. SANDBOX_DEATH_TEST(UnitTests,
  29. DeathWithMessage,
  30. DEATH_MESSAGE("Hello")) {
  31. LOG(ERROR) << "Hello";
  32. _exit(1);
  33. }
  34. SANDBOX_DEATH_TEST(UnitTests,
  35. SEGVDeathWithMessage,
  36. DEATH_SEGV_MESSAGE("Hello")) {
  37. LOG(ERROR) << "Hello";
  38. while (true) {
  39. volatile char* addr = reinterpret_cast<volatile char*>(NULL);
  40. *addr = '\0';
  41. }
  42. }
  43. SANDBOX_TEST_ALLOW_NOISE(UnitTests, NoisyTest) {
  44. LOG(ERROR) << "The cow says moo!";
  45. }
  46. } // namespace
  47. } // namespace sandbox