test_utils.h 927 B

123456789101112131415161718192021222324252627282930
  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. #ifndef SANDBOX_LINUX_TESTS_TEST_UTILS_H_
  5. #define SANDBOX_LINUX_TESTS_TEST_UTILS_H_
  6. #include <sys/types.h>
  7. namespace sandbox {
  8. // This class provide small helpers to help writing tests.
  9. class TestUtils {
  10. public:
  11. TestUtils() = delete;
  12. TestUtils(const TestUtils&) = delete;
  13. TestUtils& operator=(const TestUtils&) = delete;
  14. static bool CurrentProcessHasChildren();
  15. // |pid| is the return value of a fork()-like call. This
  16. // makes sure that if fork() succeeded the child exits
  17. // and the parent waits for it.
  18. static void HandlePostForkReturn(pid_t pid);
  19. static void* MapPagesOrDie(size_t num_pages);
  20. static void MprotectLastPageOrDie(char* addr, size_t num_pages);
  21. };
  22. } // namespace sandbox
  23. #endif // SANDBOX_LINUX_TESTS_TEST_UTILS_H_