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

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

Issue 1292753009: sandbox/linux: move ErrorCode into bpf_dsl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bpf_dsl-deps
Patch Set: Rebase and cleanup test code 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/bpf_dsl_impl.h ('k') | sandbox/linux/bpf_dsl/errorcode.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc
diff --git a/sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc b/sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc
index ab1a2c85ab5ac88b6b35b3ee18796c27b5427ec4..5da1e5724e5650db9087eef6e0556c9e607a07bb 100644
--- a/sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc
+++ b/sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc
@@ -23,9 +23,8 @@
#include "sandbox/linux/bpf_dsl/policy.h"
#include "sandbox/linux/bpf_dsl/policy_compiler.h"
#include "sandbox/linux/bpf_dsl/seccomp_macros.h"
-#include "sandbox/linux/bpf_dsl/trap_registry.h"
+#include "sandbox/linux/bpf_dsl/test_trap_registry.h"
#include "sandbox/linux/bpf_dsl/verifier.h"
-#include "sandbox/linux/seccomp-bpf/errorcode.h"
#include "sandbox/linux/system_headers/linux_filter.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -58,57 +57,6 @@ struct arch_seccomp_data FakeSyscall(int nr,
return data;
}
-class FakeTrapRegistry : public TrapRegistry {
- public:
- FakeTrapRegistry() : map_() {}
- virtual ~FakeTrapRegistry() {}
-
- uint16_t Add(TrapFnc fnc, const void* aux, bool safe) override {
- EXPECT_TRUE(safe);
-
- const uint16_t next_id = map_.size() + 1;
- return map_.insert(std::make_pair(Key(fnc, aux), next_id)).first->second;
- }
-
- bool EnableUnsafeTraps() override {
- ADD_FAILURE() << "Unimplemented";
- return false;
- }
-
- private:
- using Key = std::pair<TrapFnc, const void*>;
-
- std::map<Key, uint16_t> map_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeTrapRegistry);
-};
-
-intptr_t FakeTrapFuncOne(const arch_seccomp_data& data, void* aux) { return 1; }
-intptr_t FakeTrapFuncTwo(const arch_seccomp_data& data, void* aux) { return 2; }
-
-// Test that FakeTrapRegistry correctly assigns trap IDs to trap handlers.
-TEST(FakeTrapRegistry, TrapIDs) {
- struct {
- TrapRegistry::TrapFnc fnc;
- const void* aux;
- } funcs[] = {
- {FakeTrapFuncOne, nullptr},
- {FakeTrapFuncTwo, nullptr},
- {FakeTrapFuncOne, funcs},
- {FakeTrapFuncTwo, funcs},
- };
-
- FakeTrapRegistry 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));
- }
- }
-}
-
class PolicyEmulator {
public:
explicit PolicyEmulator(const Policy* policy) : program_(), traps_() {
@@ -140,7 +88,7 @@ class PolicyEmulator {
private:
CodeGen::Program program_;
- FakeTrapRegistry traps_;
+ TestTrapRegistry traps_;
DISALLOW_COPY_AND_ASSIGN(PolicyEmulator);
};
« no previous file with comments | « sandbox/linux/bpf_dsl/bpf_dsl_impl.h ('k') | sandbox/linux/bpf_dsl/errorcode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698