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 |