OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 7 |
| 8 #include "sandbox/linux/tests/unit_tests.h" |
| 9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 10 |
| 11 |
| 12 namespace sandbox { |
| 13 |
| 14 // BPF_TEST() is a special version of SANDBOX_TEST(). It turns into a no-op, |
| 15 // if the host does not have kernel support for running BPF filters. |
| 16 // Also, it takes advantage of the Die class to avoid calling LOG(FATAL), from |
| 17 // inside our tests, as we don't need or even want all the error handling that |
| 18 // LOG(FATAL) would do. |
| 19 #define BPF_TEST(test_case_name, test_name, policy) \ |
| 20 void BPF_TEST_##test_name(); \ |
| 21 void BPF_TEST_##test_name##_wrapper() { \ |
| 22 Die::EnableSimpleExit(); \ |
| 23 if (reinterpret_cast<void *>(policy) != NULL) { \ |
| 24 Sandbox::setSandboxPolicy(policy, NULL); \ |
| 25 } \ |
| 26 BPF_TEST_##test_name(); \ |
| 27 } \ |
| 28 TEST(test_case_name, test_name) { \ |
| 29 if (playground2::Sandbox::supportsSeccompSandbox(-1) == \ |
| 30 Sandbox::STATUS_AVAILABLE) { \ |
| 31 sandbox::BpfTests::RunTestInProcess(BPF_TEST_##test_name##_wrapper); \ |
| 32 } else { \ |
| 33 /* TODO(markus): Call the compiler and verify the policy. That's the */ \ |
| 34 /* least we can do, if we don't have kernel support. */ \ |
| 35 } \ |
| 36 } \ |
| 37 void BPF_TEST_##test_name() |
| 38 |
| 39 // Assertions are handled exactly the same as with a normal SANDBOX_TEST() |
| 40 #define BPF_ASSERT SANDBOX_ASSERT |
| 41 |
| 42 |
| 43 class BpfTests : public UnitTests { |
| 44 private: |
| 45 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
| 50 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
OLD | NEW |