| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h" | 10 #include "sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // The |policy| parameter should be a SyscallEvaluator function pointer | 69 // The |policy| parameter should be a SyscallEvaluator function pointer |
| 70 // (which is now a deprecated way of expressing policies). | 70 // (which is now a deprecated way of expressing policies). |
| 71 // BPF_TEST() takes a C++ data type as an optional fourth parameter. If | 71 // BPF_TEST() takes a C++ data type as an optional fourth parameter. If |
| 72 // present, this sets up a variable that can be accessed as "BPF_AUX". This | 72 // present, this sets up a variable that can be accessed as "BPF_AUX". This |
| 73 // variable will be passed as an argument to the "policy" function. Policies | 73 // variable will be passed as an argument to the "policy" function. Policies |
| 74 // would typically use it as an argument to SandboxBPF::Trap(), if they want to | 74 // would typically use it as an argument to SandboxBPF::Trap(), if they want to |
| 75 // communicate data between the BPF_TEST() and a Trap() function. The life-time | 75 // communicate data between the BPF_TEST() and a Trap() function. The life-time |
| 76 // of this object is the same as the life-time of the process running under the | 76 // of this object is the same as the life-time of the process running under the |
| 77 // seccomp-bpf policy. | 77 // seccomp-bpf policy. |
| 78 // The type specified in |aux| and the last parameter of the policy function | 78 // The type specified in |aux| and the last parameter of the policy function |
| 79 // must be compatible. If |aux| is not specified, the policy function must | 79 // must be compatible. |aux| must not be void. |
| 80 // take a void* as its last parameter (that is, must have the EvaluateSyscall | 80 #define BPF_TEST(test_case_name, test_name, policy, aux) \ |
| 81 // type). | |
| 82 #define BPF_TEST(test_case_name, test_name, policy, aux...) \ | |
| 83 BPF_DEATH_TEST(test_case_name, test_name, DEATH_SUCCESS(), policy, aux) | 81 BPF_DEATH_TEST(test_case_name, test_name, DEATH_SUCCESS(), policy, aux) |
| 84 | 82 |
| 85 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the | 83 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the |
| 86 // test will fail with a particular known error condition. Use the DEATH_XXX() | 84 // test will fail with a particular known error condition. Use the DEATH_XXX() |
| 87 // macros from unit_tests.h to specify the expected error condition. | 85 // macros from unit_tests.h to specify the expected error condition. |
| 88 #define BPF_DEATH_TEST(test_case_name, test_name, death, policy, aux...) \ | 86 #define BPF_DEATH_TEST(test_case_name, test_name, death, policy, aux) \ |
| 89 void BPF_TEST_##test_name( \ | 87 void BPF_TEST_##test_name( \ |
| 90 sandbox::BPFTesterCompatibilityDelegate<aux>::AuxType* BPF_AUX); \ | 88 sandbox::BPFTesterCompatibilityDelegate<aux>::AuxType* BPF_AUX); \ |
| 91 TEST(test_case_name, DISABLE_ON_TSAN(test_name)) { \ | 89 TEST(test_case_name, DISABLE_ON_TSAN(test_name)) { \ |
| 92 sandbox::SandboxBPFTestRunner bpf_test_runner( \ | 90 sandbox::SandboxBPFTestRunner bpf_test_runner( \ |
| 93 new sandbox::BPFTesterCompatibilityDelegate<aux>(BPF_TEST_##test_name, \ | 91 new sandbox::BPFTesterCompatibilityDelegate<aux>(BPF_TEST_##test_name, \ |
| 94 policy)); \ | 92 policy)); \ |
| 95 sandbox::UnitTests::RunTestInProcess(&bpf_test_runner, death); \ | 93 sandbox::UnitTests::RunTestInProcess(&bpf_test_runner, death); \ |
| 96 } \ | 94 } \ |
| 97 void BPF_TEST_##test_name( \ | 95 void BPF_TEST_##test_name( \ |
| 98 sandbox::BPFTesterCompatibilityDelegate<aux>::AuxType* BPF_AUX) | 96 sandbox::BPFTesterCompatibilityDelegate<aux>::AuxType* BPF_AUX) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 } | 115 } |
| 118 | 116 |
| 119 private: | 117 private: |
| 120 void (*test_function_)(void); | 118 void (*test_function_)(void); |
| 121 DISALLOW_COPY_AND_ASSIGN(BPFTesterSimpleDelegate); | 119 DISALLOW_COPY_AND_ASSIGN(BPFTesterSimpleDelegate); |
| 122 }; | 120 }; |
| 123 | 121 |
| 124 } // namespace sandbox | 122 } // namespace sandbox |
| 125 | 123 |
| 126 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 124 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| OLD | NEW |