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

Unified Diff: sandbox/linux/bpf_dsl/test_trap_registry_unittest.cc

Issue 1310773006: Update sandbox/linux from upstream (Closed) Base URL: ssh://ssh.github.com/domokit/mojo.git@master
Patch Set: Update to 3909ebfa69566f7374a6900e63cd4d3c73a35378 Created 5 years, 4 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
« no previous file with comments | « sandbox/linux/bpf_dsl/test_trap_registry.cc ('k') | sandbox/linux/bpf_dsl/verifier.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/bpf_dsl/test_trap_registry_unittest.cc
diff --git a/sandbox/linux/bpf_dsl/test_trap_registry_unittest.cc b/sandbox/linux/bpf_dsl/test_trap_registry_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1c08c93baedf9f36af4df194e339e43c6a461959
--- /dev/null
+++ b/sandbox/linux/bpf_dsl/test_trap_registry_unittest.cc
@@ -0,0 +1,48 @@
+// Copyright 2015 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/bpf_dsl/test_trap_registry.h"
+
+#include <stddef.h>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sandbox {
+namespace bpf_dsl {
+namespace {
+
+intptr_t TestTrapFuncOne(const arch_seccomp_data& data, void* aux) {
+ return 1;
+}
+
+intptr_t TestTrapFuncTwo(const arch_seccomp_data& data, void* aux) {
+ return 2;
+}
+
+// Test that TestTrapRegistry correctly assigns trap IDs to trap handlers.
+TEST(TestTrapRegistry, TrapIDs) {
+ struct {
+ TrapRegistry::TrapFnc fnc;
+ const void* aux;
+ } funcs[] = {
+ {TestTrapFuncOne, nullptr},
+ {TestTrapFuncTwo, nullptr},
+ {TestTrapFuncOne, funcs},
+ {TestTrapFuncTwo, funcs},
+ };
+
+ TestTrapRegistry traps;
+
+ // Add traps twice to test that IDs are reused correctly.
+ for (int i = 0; i < 2; ++i) {
+ for (size_t j = 0; j < arraysize(funcs); ++j) {
+ // Trap IDs start at 1.
+ EXPECT_EQ(j + 1, traps.Add(funcs[j].fnc, funcs[j].aux, true));
+ }
+ }
+}
+
+} // namespace
+} // namespace bpf_dsl
+} // namespace sandbox
« no previous file with comments | « sandbox/linux/bpf_dsl/test_trap_registry.cc ('k') | sandbox/linux/bpf_dsl/verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698