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

Side by Side Diff: sandbox/linux/seccomp-bpf/bpf_tests_unittest.cc

Issue 1849323003: Convert //sandbox to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup nonsfi_sandbox_unittest.cc Created 4 years, 8 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
« no previous file with comments | « sandbox/linux/seccomp-bpf/bpf_tests.h ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 5 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/ptrace.h> 8 #include <sys/ptrace.h>
9 #include <sys/syscall.h> 9 #include <sys/syscall.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include <memory>
14
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/macros.h" 16 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 18 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
18 #include "sandbox/linux/bpf_dsl/policy.h" 19 #include "sandbox/linux/bpf_dsl/policy.h"
19 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 20 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
20 #include "sandbox/linux/services/syscall_wrappers.h" 21 #include "sandbox/linux/services/syscall_wrappers.h"
21 #include "sandbox/linux/system_headers/linux_syscalls.h" 22 #include "sandbox/linux/system_headers/linux_syscalls.h"
22 #include "sandbox/linux/tests/unit_tests.h" 23 #include "sandbox/linux/tests/unit_tests.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 using sandbox::bpf_dsl::Allow; 26 using sandbox::bpf_dsl::Allow;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 TEST(BPFTest, BPFTesterCompatibilityDelegateLeakTest) { 71 TEST(BPFTest, BPFTesterCompatibilityDelegateLeakTest) {
71 // Don't do anything, simply gives dynamic tools an opportunity to detect 72 // Don't do anything, simply gives dynamic tools an opportunity to detect
72 // leaks. 73 // leaks.
73 { 74 {
74 BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo> 75 BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo>
75 simple_delegate(DummyTestFunction); 76 simple_delegate(DummyTestFunction);
76 } 77 }
77 { 78 {
78 // Test polymorphism. 79 // Test polymorphism.
79 scoped_ptr<BPFTesterDelegate> simple_delegate( 80 std::unique_ptr<BPFTesterDelegate> simple_delegate(
80 new BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo>( 81 new BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo>(
81 DummyTestFunction)); 82 DummyTestFunction));
82 } 83 }
83 } 84 }
84 85
85 class EnosysPtracePolicy : public bpf_dsl::Policy { 86 class EnosysPtracePolicy : public bpf_dsl::Policy {
86 public: 87 public:
87 EnosysPtracePolicy() { my_pid_ = sys_getpid(); } 88 EnosysPtracePolicy() { my_pid_ = sys_getpid(); }
88 ~EnosysPtracePolicy() override { 89 ~EnosysPtracePolicy() override {
89 // Policies should be able to bind with the process on which they are 90 // Policies should be able to bind with the process on which they are
(...skipping 16 matching lines...) Expand all
106 private: 107 private:
107 pid_t my_pid_; 108 pid_t my_pid_;
108 DISALLOW_COPY_AND_ASSIGN(EnosysPtracePolicy); 109 DISALLOW_COPY_AND_ASSIGN(EnosysPtracePolicy);
109 }; 110 };
110 111
111 class BasicBPFTesterDelegate : public BPFTesterDelegate { 112 class BasicBPFTesterDelegate : public BPFTesterDelegate {
112 public: 113 public:
113 BasicBPFTesterDelegate() {} 114 BasicBPFTesterDelegate() {}
114 ~BasicBPFTesterDelegate() override {} 115 ~BasicBPFTesterDelegate() override {}
115 116
116 scoped_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { 117 std::unique_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override {
117 return scoped_ptr<bpf_dsl::Policy>(new EnosysPtracePolicy()); 118 return std::unique_ptr<bpf_dsl::Policy>(new EnosysPtracePolicy());
118 } 119 }
119 void RunTestFunction() override { 120 void RunTestFunction() override {
120 errno = 0; 121 errno = 0;
121 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL); 122 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL);
122 BPF_ASSERT(-1 == ret); 123 BPF_ASSERT(-1 == ret);
123 BPF_ASSERT(ENOSYS == errno); 124 BPF_ASSERT(ENOSYS == errno);
124 } 125 }
125 126
126 private: 127 private:
127 DISALLOW_COPY_AND_ASSIGN(BasicBPFTesterDelegate); 128 DISALLOW_COPY_AND_ASSIGN(BasicBPFTesterDelegate);
(...skipping 17 matching lines...) Expand all
145 BPFDeathTestWithInlineTest, 146 BPFDeathTestWithInlineTest,
146 DEATH_MESSAGE(kHelloMessage), 147 DEATH_MESSAGE(kHelloMessage),
147 EnosysPtracePolicy) { 148 EnosysPtracePolicy) {
148 LOG(ERROR) << kHelloMessage; 149 LOG(ERROR) << kHelloMessage;
149 _exit(1); 150 _exit(1);
150 } 151 }
151 152
152 } // namespace 153 } // namespace
153 154
154 } // namespace sandbox 155 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/bpf_tests.h ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698