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

Side by Side 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, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp-bpf/Makefile ('k') | sandbox/linux/seccomp-bpf/bpf_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
7
8 #include "sandbox/linux/tests/unit_tests.h"
9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
10
11
12 namespace sandbox {
13
14 // BPF_TEST() is a special version of SANDBOX_TEST(). It turns into a no-op,
15 // if the host does not have kernel support for running BPF filters.
16 // Also, it takes advantage of the Die class to avoid calling LOG(FATAL), from
17 // inside our tests, as we don't need or even want all the error handling that
18 // LOG(FATAL) would do.
19 #define BPF_TEST(test_case_name, test_name, policy) \
20 void BPF_TEST_##test_name(); \
21 TEST(test_case_name, test_name) { \
22 sandbox::BpfTests::TestArgs arg(BPF_TEST_##test_name, policy); \
23 sandbox::BpfTests::RunTestInProcess(sandbox::BpfTests::TestWrapper, &arg);\
24 } \
25 void BPF_TEST_##test_name()
26
27 // Assertions are handled exactly the same as with a normal SANDBOX_TEST()
28 #define BPF_ASSERT SANDBOX_ASSERT
29
30
31 class BpfTests : public UnitTests {
32 public:
33 class TestArgs {
34 public:
35 TestArgs(void (*test)(), playground2::Sandbox::EvaluateSyscall policy)
36 : test_(test),
37 policy_(policy) {
38 }
39
40 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,
41 playground2::Sandbox::EvaluateSyscall policy() const { return policy_; }
42
43 private:
44 void (*test_)();
jln (very slow on Chromium) 2012/08/24 23:05:14 Would you mind renaming it to test_function_pointe
45 playground2::Sandbox::EvaluateSyscall policy_;
jln (very slow on Chromium) 2012/08/24 23:05:14 Can you also add DISALLOW_COPY_AND_ASSIGN?
46 };
47
48 static void TestWrapper(void *void_arg);
49
50 private:
51 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests);
52 };
53
54 } // namespace
55
56 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__
OLDNEW
« 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