1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/linux/bpf_dsl/test_trap_registry.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 intptr_t TestTrapFuncOne(const arch_seccomp_data
& data
, void* aux
) {
19 intptr_t TestTrapFuncTwo(const arch_seccomp_data
& data
, void* aux
) {
23 // Test that TestTrapRegistry correctly assigns trap IDs to trap handlers.
24 TEST(TestTrapRegistry
, TrapIDs
) {
26 TrapRegistry::TrapFnc fnc
;
29 {TestTrapFuncOne
, nullptr},
30 {TestTrapFuncTwo
, nullptr},
31 {TestTrapFuncOne
, funcs
},
32 {TestTrapFuncTwo
, funcs
},
35 TestTrapRegistry traps
;
37 // Add traps twice to test that IDs are reused correctly.
38 for (int i
= 0; i
< 2; ++i
) {
39 for (size_t j
= 0; j
< arraysize(funcs
); ++j
) {
40 // Trap IDs start at 1.
41 EXPECT_EQ(j
+ 1, traps
.Add(funcs
[j
].fnc
, funcs
[j
].aux
, true));
47 } // namespace bpf_dsl
48 } // namespace sandbox