Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: sandbox/linux/seccomp-bpf/errorcode_unittest.cc

Issue 278583005: Linux Sandbox: Add support for SECCOMP_RET_TRACE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix LOG(FATAL) behavior on Android. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf/errorcode.cc ('k') | sandbox/linux/seccomp-bpf/linux_seccomp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <errno.h> 5 #include <errno.h>
6 6
7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
8 #include "sandbox/linux/tests/unit_tests.h" 8 #include "sandbox/linux/tests/unit_tests.h"
9 9
10 namespace sandbox { 10 namespace sandbox {
11 11
12 namespace { 12 namespace {
13 13
14 SANDBOX_TEST(ErrorCode, ErrnoConstructor) { 14 SANDBOX_TEST(ErrorCode, ErrnoConstructor) {
15 ErrorCode e0; 15 ErrorCode e0;
16 SANDBOX_ASSERT(e0.err() == SECCOMP_RET_INVALID); 16 SANDBOX_ASSERT(e0.err() == SECCOMP_RET_INVALID);
17 17
18 ErrorCode e1(ErrorCode::ERR_ALLOWED); 18 ErrorCode e1(ErrorCode::ERR_ALLOWED);
19 SANDBOX_ASSERT(e1.err() == SECCOMP_RET_ALLOW); 19 SANDBOX_ASSERT(e1.err() == SECCOMP_RET_ALLOW);
20 20
21 ErrorCode e2(EPERM); 21 ErrorCode e2(EPERM);
22 SANDBOX_ASSERT(e2.err() == SECCOMP_RET_ERRNO + EPERM); 22 SANDBOX_ASSERT(e2.err() == SECCOMP_RET_ERRNO + EPERM);
23 23
24 SandboxBPF sandbox; 24 SandboxBPF sandbox;
25 ErrorCode e3 = sandbox.Trap(NULL, NULL); 25 ErrorCode e3 = sandbox.Trap(NULL, NULL);
26 SANDBOX_ASSERT((e3.err() & SECCOMP_RET_ACTION) == SECCOMP_RET_TRAP); 26 SANDBOX_ASSERT((e3.err() & SECCOMP_RET_ACTION) == SECCOMP_RET_TRAP);
27
28 uint16_t data = 0xdead;
29 ErrorCode e4(ErrorCode::ERR_TRACE + data);
30 SANDBOX_ASSERT(e4.err() == SECCOMP_RET_TRACE + data);
31 }
32
33 SANDBOX_DEATH_TEST(ErrorCode,
34 InvalidSeccompRetTrace,
35 DEATH_MESSAGE("Invalid use of ErrorCode object")) {
36 // Should die if the trace data does not fit in 16 bits.
37 ErrorCode e(ErrorCode::ERR_TRACE + (1 << 16));
27 } 38 }
28 39
29 SANDBOX_TEST(ErrorCode, Trap) { 40 SANDBOX_TEST(ErrorCode, Trap) {
30 SandboxBPF sandbox; 41 SandboxBPF sandbox;
31 ErrorCode e0 = sandbox.Trap(NULL, "a"); 42 ErrorCode e0 = sandbox.Trap(NULL, "a");
32 ErrorCode e1 = sandbox.Trap(NULL, "b"); 43 ErrorCode e1 = sandbox.Trap(NULL, "b");
33 SANDBOX_ASSERT((e0.err() & SECCOMP_RET_DATA) + 1 == 44 SANDBOX_ASSERT((e0.err() & SECCOMP_RET_DATA) + 1 ==
34 (e1.err() & SECCOMP_RET_DATA)); 45 (e1.err() & SECCOMP_RET_DATA));
35 46
36 ErrorCode e2 = sandbox.Trap(NULL, "a"); 47 ErrorCode e2 = sandbox.Trap(NULL, "a");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 SANDBOX_ASSERT(e1.LessThan(e4)); 87 SANDBOX_ASSERT(e1.LessThan(e4));
77 SANDBOX_ASSERT(e3.LessThan(e4)); 88 SANDBOX_ASSERT(e3.LessThan(e4));
78 SANDBOX_ASSERT(e4.LessThan(e5)); 89 SANDBOX_ASSERT(e4.LessThan(e5));
79 SANDBOX_ASSERT(!e4.LessThan(e6)); 90 SANDBOX_ASSERT(!e4.LessThan(e6));
80 SANDBOX_ASSERT(!e6.LessThan(e4)); 91 SANDBOX_ASSERT(!e6.LessThan(e4));
81 } 92 }
82 93
83 } // namespace 94 } // namespace
84 95
85 } // namespace sandbox 96 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/errorcode.cc ('k') | sandbox/linux/seccomp-bpf/linux_seccomp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698