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

Side by Side Diff: sandbox/linux/services/broker_process_unittest.cc

Issue 11647024: Update Linux sandbox tests to pass on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@seccomp-2
Patch Set: Guard the Android path_utils.h. Created 8 years 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/sandbox_bpf_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/services/broker_process.h" 5 #include "sandbox/linux/services/broker_process.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
11 #include <sys/wait.h> 11 #include <sys/wait.h>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #if defined(OS_ANDROID)
16 #include "base/android/path_utils.h"
17 #endif
18 #include "base/file_path.h"
15 #include "base/logging.h" 19 #include "base/logging.h"
16 #include "sandbox/linux/tests/unit_tests.h" 20 #include "sandbox/linux/tests/unit_tests.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
18 22
19 namespace sandbox { 23 namespace sandbox {
20 24
21 TEST(BrokerProcess, CreateAndDestroy) { 25 TEST(BrokerProcess, CreateAndDestroy) {
22 std::vector<std::string> read_whitelist; 26 std::vector<std::string> read_whitelist;
23 read_whitelist.push_back("/proc/cpuinfo"); 27 read_whitelist.push_back("/proc/cpuinfo");
24 28
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // check is performed on the client. 169 // check is performed on the client.
166 TEST(BrokerProcess, OpenCpuinfoWithClientCheck) { 170 TEST(BrokerProcess, OpenCpuinfoWithClientCheck) {
167 TestOpenCpuinfo(true /* fast_check_in_client */); 171 TestOpenCpuinfo(true /* fast_check_in_client */);
168 } 172 }
169 173
170 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) { 174 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) {
171 TestOpenCpuinfo(false /* fast_check_in_client */); 175 TestOpenCpuinfo(false /* fast_check_in_client */);
172 } 176 }
173 177
174 TEST(BrokerProcess, OpenFileRW) { 178 TEST(BrokerProcess, OpenFileRW) {
175 char templatename[] = "BrokerProcessXXXXXX"; 179 const char basename[] = "BrokerProcessXXXXXX";
176 int tempfile = mkstemp(templatename); 180 char template_name[2048];
181 #if defined(OS_ANDROID)
182 FilePath cache_directory;
183 ASSERT_TRUE(base::android::GetCacheDirectory(&cache_directory));
184 ssize_t length = snprintf(template_name, sizeof(template_name),
185 "%s%s",
186 cache_directory.value().c_str(), basename);
187 ASSERT_LT(length, static_cast<ssize_t>(sizeof(template_name)));
188 #else
189 strncpy(template_name, basename, sizeof(basename) - 1);
190 template_name[sizeof(basename) - 1] = '\0';
191 #endif
192 int tempfile = mkstemp(template_name);
177 ASSERT_GE(tempfile, 0); 193 ASSERT_GE(tempfile, 0);
178 char tempfile_name[2048]; 194 char tempfile_name[2048];
179 int written = snprintf(tempfile_name, sizeof(tempfile_name), 195 int written = snprintf(tempfile_name, sizeof(tempfile_name),
180 "/proc/self/fd/%d", tempfile); 196 "/proc/self/fd/%d", tempfile);
181 ASSERT_LT(written, static_cast<int>(sizeof(tempfile_name))); 197 ASSERT_LT(written, static_cast<int>(sizeof(tempfile_name)));
182 198
183 std::vector<std::string> whitelist; 199 std::vector<std::string> whitelist;
184 whitelist.push_back(tempfile_name); 200 whitelist.push_back(tempfile_name);
185 201
186 BrokerProcess open_broker(whitelist, whitelist); 202 BrokerProcess open_broker(whitelist, whitelist);
187 ASSERT_TRUE(open_broker.Init(NULL)); 203 ASSERT_TRUE(open_broker.Init(NULL));
188 204
189 int tempfile2 = -1; 205 int tempfile2 = -1;
190 tempfile2 = open_broker.Open(tempfile_name, O_RDWR); 206 tempfile2 = open_broker.Open(tempfile_name, O_RDWR);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 278
263 TEST(BrokerProcess, ComplexFlagsWithClientCheck) { 279 TEST(BrokerProcess, ComplexFlagsWithClientCheck) {
264 TestComplexFlags(true /* fast_check_in_client */); 280 TestComplexFlags(true /* fast_check_in_client */);
265 } 281 }
266 282
267 TEST(BrokerProcess, ComplexFlagsNoClientCheck) { 283 TEST(BrokerProcess, ComplexFlagsNoClientCheck) {
268 TestComplexFlags(false /* fast_check_in_client */); 284 TestComplexFlags(false /* fast_check_in_client */);
269 } 285 }
270 286
271 } // namespace sandbox 287 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698