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

Side by Side Diff: sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h

Issue 588143007: sandbox: Convert remaining legacy tests to use policy classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to jln@ feedback Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_
6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_
7 7
8 #include <fcntl.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11
12 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
13 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_compatibility_policy.h"
14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h" 9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h"
15 #include "sandbox/linux/tests/sandbox_test_runner.h"
16 #include "sandbox/linux/tests/unit_tests.h"
17 10
18 namespace sandbox { 11 namespace sandbox {
19 12
20 // This templated class allows building a BPFTesterDelegate from a 13 // This templated class allows building a BPFTesterDelegate from a
21 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer, 14 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer,
22 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a 15 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a
23 // function pointer to a test in |test_function|. 16 // function pointer to a test in |test_function|.
24 // This allows both the policy and the test function to take a pointer to an 17 // This allows both the policy and the test function to take a pointer to an
25 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST 18 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST
26 // macro and should generally not be used directly. 19 // macro and should generally not be used directly.
27 template <class Aux> 20 template <class Policy, class Aux>
28 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate { 21 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate {
29 public: 22 public:
30 typedef Aux AuxType; 23 typedef void (*TestFunction)(Aux*);
31 BPFTesterCompatibilityDelegate( 24
32 void (*test_function)(AuxType*), 25 explicit BPFTesterCompatibilityDelegate(TestFunction test_function)
33 typename CompatibilityPolicy<AuxType>::SyscallEvaluator policy_function) 26 : aux_(), test_function_(test_function) {}
34 : aux_(),
35 test_function_(test_function),
36 policy_function_(policy_function) {}
37 27
38 virtual ~BPFTesterCompatibilityDelegate() {} 28 virtual ~BPFTesterCompatibilityDelegate() {}
39 29
40 virtual scoped_ptr<SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE { 30 virtual scoped_ptr<SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE {
41 // The current method is guaranteed to only run in the child process 31 // The current method is guaranteed to only run in the child process
42 // running the test. In this process, the current object is guaranteed 32 // running the test. In this process, the current object is guaranteed
43 // to live forever. So it's ok to pass aux_pointer_for_policy_ to 33 // to live forever. So it's ok to pass aux_pointer_for_policy_ to
44 // the policy, which could in turn pass it to the kernel via Trap(). 34 // the policy, which could in turn pass it to the kernel via Trap().
45 return scoped_ptr<SandboxBPFPolicy>( 35 return scoped_ptr<SandboxBPFPolicy>(new Policy(&aux_));
46 new CompatibilityPolicy<AuxType>(policy_function_, &aux_));
47 } 36 }
48 37
49 virtual void RunTestFunction() OVERRIDE { 38 virtual void RunTestFunction() OVERRIDE {
50 // Run the actual test. 39 // Run the actual test.
51 // The current object is guaranteed to live forever in the child process 40 // The current object is guaranteed to live forever in the child process
52 // where this will run. 41 // where this will run.
53 test_function_(&aux_); 42 test_function_(&aux_);
54 } 43 }
55 44
56 private: 45 private:
57 AuxType aux_; 46 Aux aux_;
58 void (*test_function_)(AuxType*); 47 TestFunction test_function_;
59 typename CompatibilityPolicy<AuxType>::SyscallEvaluator policy_function_; 48
60 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate); 49 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate);
61 }; 50 };
62 51
63 } // namespace sandbox 52 } // namespace sandbox
64 53
65 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ 54 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf-helpers/baseline_policy_unittest.cc ('k') | sandbox/linux/seccomp-bpf/bpf_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698