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

Side by Side Diff: sandbox/linux/bpf_dsl/syscall_set_unittest.cc

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/bpf_dsl/syscall_set.cc ('k') | sandbox/linux/sandbox_linux.gypi » ('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 "sandbox/linux/seccomp-bpf/syscall_iterator.h" 5 #include "sandbox/linux/bpf_dsl/syscall_set.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" 9 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h"
10 #include "sandbox/linux/tests/unit_tests.h" 10 #include "sandbox/linux/tests/unit_tests.h"
11 11
12 namespace sandbox { 12 namespace sandbox {
13 13
14 namespace { 14 namespace {
15 15
16 const SyscallSet kSyscallSets[] = { 16 const SyscallSet kSyscallSets[] = {
17 SyscallSet::All(), 17 SyscallSet::All(),
18 SyscallSet::InvalidOnly(), 18 SyscallSet::InvalidOnly(),
19 }; 19 };
20 20
21 SANDBOX_TEST(SyscallIterator, Monotonous) { 21 SANDBOX_TEST(SyscallSet, Monotonous) {
22 for (const SyscallSet& set : kSyscallSets) { 22 for (const SyscallSet& set : kSyscallSets) {
23 uint32_t prev = 0; 23 uint32_t prev = 0;
24 bool have_prev = false; 24 bool have_prev = false;
25 for (uint32_t sysnum : set) { 25 for (uint32_t sysnum : set) {
26 if (have_prev) { 26 if (have_prev) {
27 SANDBOX_ASSERT(sysnum > prev); 27 SANDBOX_ASSERT(sysnum > prev);
28 } else if (set == SyscallSet::All()) { 28 } else if (set == SyscallSet::All()) {
29 // The iterator should start at 0. 29 // The iterator should start at 0.
30 SANDBOX_ASSERT(sysnum == 0); 30 SANDBOX_ASSERT(sysnum == 0);
31 } 31 }
(...skipping 15 matching lines...) Expand all
47 uint32_t prev = min - 1; 47 uint32_t prev = min - 1;
48 for (uint32_t sysnum : SyscallSet::All()) { 48 for (uint32_t sysnum : SyscallSet::All()) {
49 if (sysnum >= min && sysnum <= max) { 49 if (sysnum >= min && sysnum <= max) {
50 SANDBOX_ASSERT(prev == sysnum - 1); 50 SANDBOX_ASSERT(prev == sysnum - 1);
51 prev = sysnum; 51 prev = sysnum;
52 } 52 }
53 } 53 }
54 SANDBOX_ASSERT(prev == max); 54 SANDBOX_ASSERT(prev == max);
55 } 55 }
56 56
57 SANDBOX_TEST(SyscallIterator, ValidSyscallRanges) { 57 SANDBOX_TEST(SyscallSet, ValidSyscallRanges) {
58 AssertRange(MIN_SYSCALL, MAX_PUBLIC_SYSCALL); 58 AssertRange(MIN_SYSCALL, MAX_PUBLIC_SYSCALL);
59 #if defined(__arm__) 59 #if defined(__arm__)
60 AssertRange(MIN_PRIVATE_SYSCALL, MAX_PRIVATE_SYSCALL); 60 AssertRange(MIN_PRIVATE_SYSCALL, MAX_PRIVATE_SYSCALL);
61 AssertRange(MIN_GHOST_SYSCALL, MAX_SYSCALL); 61 AssertRange(MIN_GHOST_SYSCALL, MAX_SYSCALL);
62 #endif 62 #endif
63 } 63 }
64 64
65 SANDBOX_TEST(SyscallIterator, InvalidSyscalls) { 65 SANDBOX_TEST(SyscallSet, InvalidSyscalls) {
66 static const uint32_t kExpected[] = { 66 static const uint32_t kExpected[] = {
67 #if defined(__mips__) 67 #if defined(__mips__)
68 0, 68 0,
69 MIN_SYSCALL - 1, 69 MIN_SYSCALL - 1,
70 #endif 70 #endif
71 MAX_PUBLIC_SYSCALL + 1, 71 MAX_PUBLIC_SYSCALL + 1,
72 #if defined(__arm__) 72 #if defined(__arm__)
73 MIN_PRIVATE_SYSCALL - 1, 73 MIN_PRIVATE_SYSCALL - 1,
74 MAX_PRIVATE_SYSCALL + 1, 74 MAX_PRIVATE_SYSCALL + 1,
75 MIN_GHOST_SYSCALL - 1, 75 MIN_GHOST_SYSCALL - 1,
(...skipping 10 matching lines...) Expand all
86 if (!SyscallSet::IsValid(sysnum)) { 86 if (!SyscallSet::IsValid(sysnum)) {
87 SANDBOX_ASSERT(i < arraysize(kExpected)); 87 SANDBOX_ASSERT(i < arraysize(kExpected));
88 SANDBOX_ASSERT(kExpected[i] == sysnum); 88 SANDBOX_ASSERT(kExpected[i] == sysnum);
89 ++i; 89 ++i;
90 } 90 }
91 } 91 }
92 SANDBOX_ASSERT(i == arraysize(kExpected)); 92 SANDBOX_ASSERT(i == arraysize(kExpected));
93 } 93 }
94 } 94 }
95 95
96 SANDBOX_TEST(SyscallIterator, ValidOnlyIsOnlyValid) { 96 SANDBOX_TEST(SyscallSet, ValidOnlyIsOnlyValid) {
97 for (uint32_t sysnum : SyscallSet::ValidOnly()) { 97 for (uint32_t sysnum : SyscallSet::ValidOnly()) {
98 SANDBOX_ASSERT(SyscallSet::IsValid(sysnum)); 98 SANDBOX_ASSERT(SyscallSet::IsValid(sysnum));
99 } 99 }
100 } 100 }
101 101
102 SANDBOX_TEST(SyscallIterator, InvalidOnlyIsOnlyInvalid) { 102 SANDBOX_TEST(SyscallSet, InvalidOnlyIsOnlyInvalid) {
103 for (uint32_t sysnum : SyscallSet::InvalidOnly()) { 103 for (uint32_t sysnum : SyscallSet::InvalidOnly()) {
104 SANDBOX_ASSERT(!SyscallSet::IsValid(sysnum)); 104 SANDBOX_ASSERT(!SyscallSet::IsValid(sysnum));
105 } 105 }
106 } 106 }
107 107
108 SANDBOX_TEST(SyscallIterator, AllIsValidOnlyPlusInvalidOnly) { 108 SANDBOX_TEST(SyscallSet, AllIsValidOnlyPlusInvalidOnly) {
109 std::vector<uint32_t> merged; 109 std::vector<uint32_t> merged;
110 const SyscallSet valid_only = SyscallSet::ValidOnly(); 110 const SyscallSet valid_only = SyscallSet::ValidOnly();
111 const SyscallSet invalid_only = SyscallSet::InvalidOnly(); 111 const SyscallSet invalid_only = SyscallSet::InvalidOnly();
112 std::merge(valid_only.begin(), 112 std::merge(valid_only.begin(),
113 valid_only.end(), 113 valid_only.end(),
114 invalid_only.begin(), 114 invalid_only.begin(),
115 invalid_only.end(), 115 invalid_only.end(),
116 std::back_inserter(merged)); 116 std::back_inserter(merged));
117 117
118 const SyscallSet all = SyscallSet::All(); 118 const SyscallSet all = SyscallSet::All();
119 SANDBOX_ASSERT(merged == std::vector<uint32_t>(all.begin(), all.end())); 119 SANDBOX_ASSERT(merged == std::vector<uint32_t>(all.begin(), all.end()));
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 } // namespace sandbox 124 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/bpf_dsl/syscall_set.cc ('k') | sandbox/linux/sandbox_linux.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698