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 TEST(test_case_name, test_name) { \ |
| 22 sandbox::BpfTests::TestArgs arg(BPF_TEST_##test_name, policy); \ |
| 23 sandbox::BpfTests::RunTestInProcess(sandbox::BpfTests::TestWrapper, &arg);\ |
| 24 } \ |
| 25 void BPF_TEST_##test_name() |
| 26 |
| 27 // Assertions are handled exactly the same as with a normal SANDBOX_TEST() |
| 28 #define BPF_ASSERT SANDBOX_ASSERT |
| 29 |
| 30 |
| 31 class BpfTests : public UnitTests { |
| 32 public: |
| 33 class TestArgs { |
| 34 public: |
| 35 TestArgs(void (*test)(), playground2::Sandbox::EvaluateSyscall policy) |
| 36 : test_(test), |
| 37 policy_(policy) { |
| 38 } |
| 39 |
| 40 void (*test() const)() { return test_; } |
| 41 playground2::Sandbox::EvaluateSyscall policy() const { return policy_; } |
| 42 |
| 43 private: |
| 44 void (*test_)(); |
| 45 playground2::Sandbox::EvaluateSyscall policy_; |
| 46 }; |
| 47 |
| 48 static void TestWrapper(void *void_arg); |
| 49 |
| 50 private: |
| 51 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); |
| 52 }; |
| 53 |
| 54 } // namespace |
| 55 |
| 56 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
OLD | NEW |