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 #include <ostream> |
| 6 |
5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
6 #include "sandbox/linux/seccomp-bpf/verifier.h" | 8 #include "sandbox/linux/seccomp-bpf/verifier.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 using namespace playground2; | 11 using namespace playground2; |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 const int kExpectedReturnValue = 42; | 15 const int kExpectedReturnValue = 42; |
14 | 16 |
15 TEST(SandboxBpf, CallSupports) { | 17 TEST(SandboxBpf, CallSupports) { |
16 // We check that we don't crash, but it's ok if the kernel doesn't | 18 // We check that we don't crash, but it's ok if the kernel doesn't |
17 // support it. | 19 // support it. |
18 Sandbox::supportsSeccompSandbox(-1); | 20 bool seccomp_bpf_supported = |
| 21 Sandbox::supportsSeccompSandbox(-1) == Sandbox::STATUS_AVAILABLE; |
| 22 // We want to log whether or not seccomp BPF is actually supported |
| 23 // since actual test coverage depends on it. |
| 24 RecordProperty("SeccompBPFSupported", |
| 25 seccomp_bpf_supported ? "true." : "false."); |
| 26 std::cout << "Seccomp BPF supported: " |
| 27 << (seccomp_bpf_supported ? "true." : "false.") |
| 28 << "\n"; |
19 } | 29 } |
20 | 30 |
21 TEST(SandboxBpf, CallSupportsTwice) { | 31 TEST(SandboxBpf, CallSupportsTwice) { |
22 Sandbox::supportsSeccompSandbox(-1); | 32 Sandbox::supportsSeccompSandbox(-1); |
23 Sandbox::supportsSeccompSandbox(-1); | 33 Sandbox::supportsSeccompSandbox(-1); |
24 } | 34 } |
25 | 35 |
26 __attribute__((noreturn)) void DoCrash() { | 36 __attribute__((noreturn)) void DoCrash() { |
27 // Cause a #PF. This only works if we assume that we have the default | 37 // Cause a #PF. This only works if we assume that we have the default |
28 // SIGSEGV handler. | 38 // SIGSEGV handler. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 261 } |
252 } | 262 } |
253 ExitGroup(kExpectedReturnValue); | 263 ExitGroup(kExpectedReturnValue); |
254 } | 264 } |
255 | 265 |
256 TEST(SandboxBpf, SyntheticPolicy) { | 266 TEST(SandboxBpf, SyntheticPolicy) { |
257 TryPolicyInProcess(SyntheticPolicy, SyntheticProcess); | 267 TryPolicyInProcess(SyntheticPolicy, SyntheticProcess); |
258 } | 268 } |
259 | 269 |
260 } // namespace | 270 } // namespace |
OLD | NEW |