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

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: Fixed upload. 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..f41aaa305f890effad674c820a959d4d46a24029
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc
@@ -0,0 +1,128 @@
+// 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) {
jln (very slow on Chromium) 2012/10/12 20:26:52 Please add a comment: "Testing the following under
Jorge Lucangeli Obes 2012/10/13 01:39:30 Done.
+ SyscallIterator iter(!i);
+ uint32_t next = iter.Next();
+ if (i || MIN_SYSCALL != 0) {
jln (very slow on Chromium) 2012/10/12 20:26:52 Add a comment: we want to poke at 0, when we're ex
Jorge Lucangeli Obes 2012/10/13 01:39:30 This is poking when invalid_only == false (invalid
+ SANDBOX_ASSERT(next == 0);
+ }
+ for (uint32_t last = next; !iter.Done(); last = next) {
+ next = iter.Next();
+ SANDBOX_ASSERT(last < next);
+ }
+ SANDBOX_ASSERT(next == 0xFFFFFFFFu);
jln (very slow on Chromium) 2012/10/12 20:26:52 This is testing for undocumented behavior: that 0x
Jorge Lucangeli Obes 2012/10/13 01:39:30 Done.
+ }
+}
+
+SANDBOX_TEST(SyscallIterator, SyscallRange) {
+ SyscallIterator iter(false);
jln (very slow on Chromium) 2012/10/12 20:26:52 Please add comments, what is this trying to do ?
Jorge Lucangeli Obes 2012/10/13 01:39:30 Done.
+ 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