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..98889154f6673732412260ab59885cadb92c90e7 |
--- /dev/null |
+++ b/sandbox/linux/seccomp-bpf/bpf_tests.h |
@@ -0,0 +1,50 @@ |
+// 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(); \ |
+ void BPF_TEST_##test_name##_wrapper() { \ |
+ Die::EnableSimpleExit(); \ |
+ if (reinterpret_cast<void *>(policy) != NULL) { \ |
+ Sandbox::setSandboxPolicy(policy, NULL); \ |
+ } \ |
+ BPF_TEST_##test_name(); \ |
+ } \ |
+ TEST(test_case_name, test_name) { \ |
+ if (playground2::Sandbox::supportsSeccompSandbox(-1) == \ |
+ Sandbox::STATUS_AVAILABLE) { \ |
+ sandbox::BpfTests::RunTestInProcess(BPF_TEST_##test_name##_wrapper); \ |
+ } else { \ |
+ /* TODO(markus): Call the compiler and verify the policy. That's the */ \ |
jln (very slow on Chromium)
2012/08/24 04:00:32
I'm sorry I wasn't clear: I meant to call setSandb
|
+ /* least we can do, if we don't have kernel support. */ \ |
+ } \ |
+ } \ |
+ 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 { |
+ private: |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); |
+}; |
+ |
+} // namespace |
+ |
+#endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |