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

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: Refactored BPF_TEST macro and automatically start the sandbox for all tests 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..45d5a07c03a76ed382df9956a044df73f7c8ce07
--- /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_; }
jln (very slow on Chromium) 2012/08/24 23:05:14 It doesn't compile on Clang. I wonder why though,
+ playground2::Sandbox::EvaluateSyscall policy() const { return policy_; }
+
+ private:
+ void (*test_)();
jln (very slow on Chromium) 2012/08/24 23:05:14 Would you mind renaming it to test_function_pointe
+ playground2::Sandbox::EvaluateSyscall policy_;
jln (very slow on Chromium) 2012/08/24 23:05:14 Can you also add DISALLOW_COPY_AND_ASSIGN?
+ };
+
+ 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