OLD | NEW |
---|---|
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 #include "base/android/path_utils.h" | |
jln (very slow on Chromium)
2012/12/20 01:49:30
Erg, it's failing. I guess you need to wrap this i
| |
16 #include "base/file_path.h" | |
15 #include "base/logging.h" | 17 #include "base/logging.h" |
16 #include "sandbox/linux/tests/unit_tests.h" | 18 #include "sandbox/linux/tests/unit_tests.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 | 20 |
19 namespace sandbox { | 21 namespace sandbox { |
20 | 22 |
21 TEST(BrokerProcess, CreateAndDestroy) { | 23 TEST(BrokerProcess, CreateAndDestroy) { |
22 std::vector<std::string> read_whitelist; | 24 std::vector<std::string> read_whitelist; |
23 read_whitelist.push_back("/proc/cpuinfo"); | 25 read_whitelist.push_back("/proc/cpuinfo"); |
24 | 26 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 // check is performed on the client. | 167 // check is performed on the client. |
166 TEST(BrokerProcess, OpenCpuinfoWithClientCheck) { | 168 TEST(BrokerProcess, OpenCpuinfoWithClientCheck) { |
167 TestOpenCpuinfo(true /* fast_check_in_client */); | 169 TestOpenCpuinfo(true /* fast_check_in_client */); |
168 } | 170 } |
169 | 171 |
170 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) { | 172 TEST(BrokerProcess, OpenCpuinfoNoClientCheck) { |
171 TestOpenCpuinfo(false /* fast_check_in_client */); | 173 TestOpenCpuinfo(false /* fast_check_in_client */); |
172 } | 174 } |
173 | 175 |
174 TEST(BrokerProcess, OpenFileRW) { | 176 TEST(BrokerProcess, OpenFileRW) { |
175 char templatename[] = "BrokerProcessXXXXXX"; | 177 const char basename[] = "BrokerProcessXXXXXX"; |
176 int tempfile = mkstemp(templatename); | 178 char template_name[2048]; |
179 #if defined(OS_ANDROID) | |
180 FilePath cache_directory; | |
181 ASSERT_TRUE(base::android::GetCacheDirectory(&cache_directory)); | |
182 ssize_t length = snprintf(template_name, sizeof(template_name), | |
183 "%s%s", | |
184 cache_directory.value().c_str(), basename); | |
185 ASSERT_LT(length, static_cast<ssize_t>(sizeof(template_name))); | |
186 #else | |
187 strncpy(template_name, basename, sizeof(basename) - 1); | |
188 template_name[sizeof(basename) - 1] = '\0'; | |
189 #endif | |
190 int tempfile = mkstemp(template_name); | |
177 ASSERT_GE(tempfile, 0); | 191 ASSERT_GE(tempfile, 0); |
178 char tempfile_name[2048]; | 192 char tempfile_name[2048]; |
179 int written = snprintf(tempfile_name, sizeof(tempfile_name), | 193 int written = snprintf(tempfile_name, sizeof(tempfile_name), |
180 "/proc/self/fd/%d", tempfile); | 194 "/proc/self/fd/%d", tempfile); |
181 ASSERT_LT(written, static_cast<int>(sizeof(tempfile_name))); | 195 ASSERT_LT(written, static_cast<int>(sizeof(tempfile_name))); |
182 | 196 |
183 std::vector<std::string> whitelist; | 197 std::vector<std::string> whitelist; |
184 whitelist.push_back(tempfile_name); | 198 whitelist.push_back(tempfile_name); |
185 | 199 |
186 BrokerProcess open_broker(whitelist, whitelist); | 200 BrokerProcess open_broker(whitelist, whitelist); |
187 ASSERT_TRUE(open_broker.Init(NULL)); | 201 ASSERT_TRUE(open_broker.Init(NULL)); |
188 | 202 |
189 int tempfile2 = -1; | 203 int tempfile2 = -1; |
190 tempfile2 = open_broker.Open(tempfile_name, O_RDWR); | 204 tempfile2 = open_broker.Open(tempfile_name, O_RDWR); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 | 276 |
263 TEST(BrokerProcess, ComplexFlagsWithClientCheck) { | 277 TEST(BrokerProcess, ComplexFlagsWithClientCheck) { |
264 TestComplexFlags(true /* fast_check_in_client */); | 278 TestComplexFlags(true /* fast_check_in_client */); |
265 } | 279 } |
266 | 280 |
267 TEST(BrokerProcess, ComplexFlagsNoClientCheck) { | 281 TEST(BrokerProcess, ComplexFlagsNoClientCheck) { |
268 TestComplexFlags(false /* fast_check_in_client */); | 282 TestComplexFlags(false /* fast_check_in_client */); |
269 } | 283 } |
270 | 284 |
271 } // namespace sandbox | 285 } // namespace sandbox |
OLD | NEW |