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

Unified Diff: sandbox/linux/seccomp-bpf/bpf_tests.h

Issue 10878033: Simplified unit testing of sandboxing code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing parameter that suppresses benign error messages Created 8 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/seccomp-bpf/Makefile ('k') | sandbox/linux/seccomp-bpf/bpf_tests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/seccomp-bpf/bpf_tests.h
diff --git a/sandbox/linux/seccomp-bpf/bpf_tests.h b/sandbox/linux/seccomp-bpf/bpf_tests.h
new file mode 100644
index 0000000000000000000000000000000000000000..ace0ce348ef0c7809c33d50a73efe220cf0b77da
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/bpf_tests.h
@@ -0,0 +1,56 @@
+// 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.
+
+#ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
+#define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
+
+#include "sandbox/linux/tests/unit_tests.h"
+#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
+
+
+namespace sandbox {
+
+// BPF_TEST() is a special version of SANDBOX_TEST(). It turns into a no-op,
+// if the host does not have kernel support for running BPF filters.
+// Also, it takes advantage of the Die class to avoid calling LOG(FATAL), from
+// inside our tests, as we don't need or even want all the error handling that
+// LOG(FATAL) would do.
+#define BPF_TEST(test_case_name, test_name, policy) \
+ void BPF_TEST_##test_name(); \
+ TEST(test_case_name, test_name) { \
+ sandbox::BpfTests::TestArgs arg(BPF_TEST_##test_name, policy); \
+ sandbox::BpfTests::RunTestInProcess(sandbox::BpfTests::TestWrapper, &arg);\
+ } \
+ void BPF_TEST_##test_name()
+
+// Assertions are handled exactly the same as with a normal SANDBOX_TEST()
+#define BPF_ASSERT SANDBOX_ASSERT
+
+
+class BpfTests : public UnitTests {
+ public:
+ class TestArgs {
+ public:
+ TestArgs(void (*test)(), playground2::Sandbox::EvaluateSyscall policy)
+ : test_(test),
+ policy_(policy) {
+ }
+
+ void (*test() const)() { return test_; }
+ playground2::Sandbox::EvaluateSyscall policy() const { return policy_; }
+
+ private:
+ void (*test_)();
+ playground2::Sandbox::EvaluateSyscall policy_;
+ };
+
+ static void TestWrapper(void *void_arg);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests);
+};
+
+} // namespace
+
+#endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
« no previous file with comments | « sandbox/linux/seccomp-bpf/Makefile ('k') | sandbox/linux/seccomp-bpf/bpf_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698