| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 11 #include "sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h" | 13 #include "sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h" |
| 12 #include "sandbox/linux/tests/unit_tests.h" | 14 #include "sandbox/linux/tests/unit_tests.h" |
| 13 | 15 |
| 14 namespace sandbox { | 16 namespace sandbox { |
| 15 | 17 |
| 16 // BPF_TEST_C() is a special version of SANDBOX_TEST(). It runs a test function | 18 // BPF_TEST_C() is a special version of SANDBOX_TEST(). It runs a test function |
| 17 // in a sub-process, under a seccomp-bpf policy specified in | 19 // in a sub-process, under a seccomp-bpf policy specified in |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // class name as a template parameter to implement the BPFTesterDelegate | 99 // class name as a template parameter to implement the BPFTesterDelegate |
| 98 // interface which can be used to build BPF unittests with | 100 // interface which can be used to build BPF unittests with |
| 99 // the SandboxBPFTestRunner class. | 101 // the SandboxBPFTestRunner class. |
| 100 template <class PolicyClass> | 102 template <class PolicyClass> |
| 101 class BPFTesterSimpleDelegate : public BPFTesterDelegate { | 103 class BPFTesterSimpleDelegate : public BPFTesterDelegate { |
| 102 public: | 104 public: |
| 103 explicit BPFTesterSimpleDelegate(void (*test_function)(void)) | 105 explicit BPFTesterSimpleDelegate(void (*test_function)(void)) |
| 104 : test_function_(test_function) {} | 106 : test_function_(test_function) {} |
| 105 ~BPFTesterSimpleDelegate() override {} | 107 ~BPFTesterSimpleDelegate() override {} |
| 106 | 108 |
| 107 scoped_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { | 109 std::unique_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { |
| 108 return scoped_ptr<bpf_dsl::Policy>(new PolicyClass()); | 110 return std::unique_ptr<bpf_dsl::Policy>(new PolicyClass()); |
| 109 } | 111 } |
| 110 void RunTestFunction() override { | 112 void RunTestFunction() override { |
| 111 DCHECK(test_function_); | 113 DCHECK(test_function_); |
| 112 test_function_(); | 114 test_function_(); |
| 113 } | 115 } |
| 114 | 116 |
| 115 private: | 117 private: |
| 116 void (*test_function_)(void); | 118 void (*test_function_)(void); |
| 117 DISALLOW_COPY_AND_ASSIGN(BPFTesterSimpleDelegate); | 119 DISALLOW_COPY_AND_ASSIGN(BPFTesterSimpleDelegate); |
| 118 }; | 120 }; |
| 119 | 121 |
| 120 } // namespace sandbox | 122 } // namespace sandbox |
| 121 | 123 |
| 122 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 124 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| OLD | NEW |