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 <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 | 11 |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "build/build_config_functions.h" | |
14 #include "sandbox/linux/tests/unit_tests.h" | 13 #include "sandbox/linux/tests/unit_tests.h" |
15 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
16 | 15 |
17 namespace sandbox { | 16 namespace sandbox { |
18 | 17 |
19 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the | 18 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the |
20 // test will fail with a particular known error condition. Use the DEATH_XXX() | 19 // test will fail with a particular known error condition. Use the DEATH_XXX() |
21 // macros from unit_tests.h to specify the expected error condition. | 20 // macros from unit_tests.h to specify the expected error condition. |
22 // A BPF_DEATH_TEST is always disabled under ThreadSanitizer, see | 21 // A BPF_DEATH_TEST is always disabled under ThreadSanitizer, see |
23 // crbug.com/243968. | 22 // crbug.com/243968. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 sandbox.set_proc_fd(proc_fd); | 85 sandbox.set_proc_fd(proc_fd); |
87 sandbox.SetSandboxPolicyDeprecated(arg->policy(), &arg->aux_); | 86 sandbox.SetSandboxPolicyDeprecated(arg->policy(), &arg->aux_); |
88 sandbox.Sandbox::StartSandbox(); | 87 sandbox.Sandbox::StartSandbox(); |
89 | 88 |
90 arg->test()(arg->aux_); | 89 arg->test()(arg->aux_); |
91 } else { | 90 } else { |
92 printf("This BPF test is not fully running in this configuration!\n"); | 91 printf("This BPF test is not fully running in this configuration!\n"); |
93 // Android, ARM and Valgrind are the three only configurations where we | 92 // Android, ARM and Valgrind are the three only configurations where we |
94 // accept not having kernel BPF support. | 93 // accept not having kernel BPF support. |
95 // TODO(jln): remote ARM from this list when possible (crbug.com/243478). | 94 // TODO(jln): remote ARM from this list when possible (crbug.com/243478). |
96 if (!build::IsAndroid() && !IsRunningOnValgrind() && | 95 if (!IsAndroid() && !IsRunningOnValgrind() && !IsArchitectureArm()) { |
97 !build::IsArchitectureARM()) { | |
98 const bool seccomp_bpf_is_supported = false; | 96 const bool seccomp_bpf_is_supported = false; |
99 BPF_ASSERT(seccomp_bpf_is_supported); | 97 BPF_ASSERT(seccomp_bpf_is_supported); |
100 } | 98 } |
101 // Call the compiler and verify the policy. That's the least we can do, | 99 // Call the compiler and verify the policy. That's the least we can do, |
102 // if we don't have kernel support. | 100 // if we don't have kernel support. |
103 playground2::Sandbox sandbox; | 101 playground2::Sandbox sandbox; |
104 sandbox.SetSandboxPolicyDeprecated(arg->policy(), &arg->aux_); | 102 sandbox.SetSandboxPolicyDeprecated(arg->policy(), &arg->aux_); |
105 playground2::Sandbox::Program* program = | 103 playground2::Sandbox::Program* program = |
106 sandbox.AssembleFilter(true /* force_verification */); | 104 sandbox.AssembleFilter(true /* force_verification */); |
107 delete program; | 105 delete program; |
108 sandbox::UnitTests::IgnoreThisTest(); | 106 sandbox::UnitTests::IgnoreThisTest(); |
109 } | 107 } |
110 } | 108 } |
111 | 109 |
112 private: | 110 private: |
113 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); | 111 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); |
114 }; | 112 }; |
115 | 113 |
116 } // namespace | 114 } // namespace |
117 | 115 |
118 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 116 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
OLD | NEW |