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

Unified Diff: sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc

Issue 11096012: Add a platform-specific syscall number iterator. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rename #define's and extract ARM private syscall logic. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc
diff --git a/sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc b/sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42f84de39e85332e3e57447b4da3a7cf00df0ee7
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
+#include "sandbox/linux/seccomp-bpf/syscall_iterator.h"
+#include "sandbox/linux/tests/unit_tests.h"
+
+using namespace playground2;
+
+namespace {
+
+SANDBOX_TEST(SyscallIterator, Monotonous) {
+ for (int i = 0; i < 2; ++i) {
+ SyscallIterator iter(!i);
+ uint32_t next = iter.Next();
+ if (i || MIN_SYSCALL != 0) {
+ SANDBOX_ASSERT(next == 0);
+ }
+ for (uint32_t last = next; !iter.Done(); last = next) {
+ next = iter.Next();
+ SANDBOX_ASSERT(last < next);
+ }
+ SANDBOX_ASSERT(next == 0xFFFFFFFFu);
+ }
+}
+
+SANDBOX_TEST(SyscallIterator, SyscallRange) {
+ SyscallIterator iter(false);
+ uint32_t next = iter.Next();
+ while (next < std::max(MIN_SYSCALL, 1u)-1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == std::max(MIN_SYSCALL, 1u)-1);
+ for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL+1; last = next) {
+ SANDBOX_ASSERT((next = iter.Next()) == last+1);
+ }
+ SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL+1);
+}
+
+#if defined(__i386__) || defined(__x86_64__)
+SANDBOX_TEST(SyscallIterator, X32) {
+ SyscallIterator iter(false);
+ uint32_t next = iter.Next();
+ while (next < std::max(MIN_SYSCALL^0x40000000u, 1u)-1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == std::max(MIN_SYSCALL^0x40000000u, 1u)-1);
+ for (uint32_t last = next; next < (MAX_SYSCALL^0x40000000u)+1; last = next) {
+ SANDBOX_ASSERT((next = iter.Next()) == last+1);
+ }
+ SANDBOX_ASSERT(next == (MAX_SYSCALL^0x40000000u)+1);
+}
+#endif
+
+#if defined(__arm__)
+SANDBOX_TEST(SyscallIterator, ARMPrivate) {
+ SyscallIterator iter(false);
+ uint32_t next = iter.Next();
+ while (next < MIN_PRIVATE_SYSCALL-1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL-1);
+ for (uint32_t last = next; next < MAX_PRIVATE_SYSCALL+1; last = next) {
+ SANDBOX_ASSERT((next = iter.Next()) == last+1);
+ }
+ SANDBOX_ASSERT(next == MAX_PRIVATE_SYSCALL+1);
+}
+
+SANDBOX_TEST(SyscallIterator, ARMHidden) {
+ SyscallIterator iter(false);
+ uint32_t next = iter.Next();
+ while (next < MIN_GHOST_SYSCALL-1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL-1);
+ for (uint32_t last = next; next < MAX_SYSCALL+1; last = next) {
+ SANDBOX_ASSERT((next = iter.Next()) == last+1);
+ }
+ SANDBOX_ASSERT(next == MAX_SYSCALL+1);
+}
+#endif
+
+SANDBOX_TEST(SyscallIterator, Invalid) {
+ for (int i = 0; i < 2; ++i) {
+ SyscallIterator iter(!i);
+ uint32_t next = iter.Next();
+ if (i || MIN_SYSCALL != 0) {
+ SANDBOX_ASSERT(next == 0);
+ }
+ if (MIN_SYSCALL > 1) {
+ while (next < MIN_SYSCALL-1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == MIN_SYSCALL-1);
+ }
+ while (next < MAX_SYSCALL+1) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == MAX_SYSCALL+1);
+ while (next < 0x7FFFFFFFu) {
+ next = iter.Next();
+ }
+ SANDBOX_ASSERT(next == 0x7FFFFFFFu);
+ next = iter.Next();
+ SANDBOX_ASSERT(next == 0x80000000u);
+ SANDBOX_ASSERT(!iter.Done());
+ next = iter.Next();
+ SANDBOX_ASSERT( iter.Done());
+ SANDBOX_ASSERT(next == 0xFFFFFFFFu);
+ }
+}
+
+SANDBOX_TEST(SyscallIterator, InvalidOnly) {
+ for (SyscallIterator iter(true); !iter.Done(); ) {
+ uint32_t next = iter.Next();
+ SANDBOX_ASSERT(next < MIN_SYSCALL || next > MAX_PUBLIC_SYSCALL);
+#if defined(__arm__)
+ SANDBOX_ASSERT(next < MIN_PRIVATE_SYSCALL || next > MAX_PRIVATE_SYSCALL);
+ SANDBOX_ASSERT(next < MIN_GHOST_SYSCALL || next > MAX_SYSCALL);
+#endif
+ }
+
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698