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 "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
7 #include "sandbox/linux/tests/unit_tests.h" | 7 #include "sandbox/linux/tests/unit_tests.h" |
8 | 8 |
9 using namespace playground2; | 9 using namespace playground2; |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 SANDBOX_TEST(SyscallIterator, Monotonous) { | 13 SANDBOX_TEST(SyscallIterator, Monotonous) { |
14 for (int i = 0; i < 2; ++i) { | 14 for (int i = 0; i < 2; ++i) { |
15 bool invalid_only = !i; // Testing both |invalid_only| cases. | 15 bool invalid_only = !i; // Testing both |invalid_only| cases. |
16 SyscallIterator iter(invalid_only); | 16 SyscallIterator iter(invalid_only); |
17 uint32_t next = iter.Next(); | 17 uint32_t next = iter.Next(); |
18 | 18 |
19 if (!invalid_only) { | 19 if (!invalid_only) { |
20 // The iterator should start at 0. | 20 // The iterator should start at 0. |
21 SANDBOX_ASSERT(next == 0); | 21 SANDBOX_ASSERT(next == 0); |
22 } | 22 } |
23 for (uint32_t last = next; !iter.Done(); last = next) { | 23 for (uint32_t last = next; !iter.Done(); last = next) { |
24 next = iter.Next(); | 24 next = iter.Next(); |
25 SANDBOX_ASSERT(last < next); | 25 SANDBOX_ASSERT(last < next); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | 72 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); |
73 for (uint32_t last = next; next < MAX_SYSCALL + 1; last = next) { | 73 for (uint32_t last = next; next < MAX_SYSCALL + 1; last = next) { |
74 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | 74 SANDBOX_ASSERT((next = iter.Next()) == last + 1); |
75 } | 75 } |
76 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | 76 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); |
77 } | 77 } |
78 #endif | 78 #endif |
79 | 79 |
80 SANDBOX_TEST(SyscallIterator, Invalid) { | 80 SANDBOX_TEST(SyscallIterator, Invalid) { |
81 for (int i = 0; i < 2; ++i) { | 81 for (int i = 0; i < 2; ++i) { |
82 bool invalid_only = !i; // Testing both |invalid_only| cases. | 82 bool invalid_only = !i; // Testing both |invalid_only| cases. |
83 SyscallIterator iter(invalid_only); | 83 SyscallIterator iter(invalid_only); |
84 uint32_t next = iter.Next(); | 84 uint32_t next = iter.Next(); |
85 | 85 |
86 while (next < MAX_SYSCALL + 1) { | 86 while (next < MAX_SYSCALL + 1) { |
87 next = iter.Next(); | 87 next = iter.Next(); |
88 } | 88 } |
89 | 89 |
90 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | 90 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); |
91 while (next < 0x7FFFFFFFu) { | 91 while (next < 0x7FFFFFFFu) { |
92 next = iter.Next(); | 92 next = iter.Next(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // The iterator should skip until the last invalid syscall in this range. | 125 // The iterator should skip until the last invalid syscall in this range. |
126 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | 126 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); |
127 while (next <= MAX_SYSCALL) { | 127 while (next <= MAX_SYSCALL) { |
128 next = iter.Next(); | 128 next = iter.Next(); |
129 } | 129 } |
130 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | 130 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); |
131 #endif | 131 #endif |
132 } | 132 } |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | |
OLD | NEW |