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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
12 #include "base/test/multiprocess_test.h" | 12 #include "base/test/multiprocess_test.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/multiprocess_func_list.h" | 16 #include "testing/multiprocess_func_list.h" |
17 | 17 |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
19 #include "base/mac/scoped_nsautorelease_pool.h" | 19 #include "base/mac/scoped_nsautorelease_pool.h" |
20 #endif | 20 #endif |
21 | 21 |
22 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
| 23 #include <errno.h> |
23 #include <sys/mman.h> | 24 #include <sys/mman.h> |
24 #include <sys/stat.h> | 25 #include <sys/stat.h> |
25 #include <sys/types.h> | 26 #include <sys/types.h> |
26 #include <unistd.h> | 27 #include <unistd.h> |
27 #endif | 28 #endif |
28 | 29 |
29 static const int kNumThreads = 5; | 30 static const int kNumThreads = 5; |
30 static const int kNumTasks = 5; | 31 static const int kNumTasks = 5; |
31 | 32 |
32 namespace base { | 33 namespace base { |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 else | 355 else |
355 EXPECT_EQ(0, pointers[j][0]); | 356 EXPECT_EQ(0, pointers[j][0]); |
356 } | 357 } |
357 } | 358 } |
358 | 359 |
359 for (int i = 0; i < count; i++) { | 360 for (int i = 0; i < count; i++) { |
360 memories[i].Close(); | 361 memories[i].Close(); |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
| 365 TEST(SharedMemoryTest, AndroidFiles) { |
| 366 EXPECT_EQ(0, access("/dev", X_OK)) << strerror(errno); |
| 367 EXPECT_EQ(0, access("/dev/fd", X_OK)) << strerror(errno); |
| 368 EXPECT_EQ(0, access("/proc", X_OK)) << strerror(errno); |
| 369 EXPECT_EQ(0, access("/proc/self", X_OK)) << strerror(errno); |
| 370 EXPECT_EQ(0, access("/proc/self/fd", X_OK)) << strerror(errno); |
| 371 } |
| 372 |
364 TEST(SharedMemoryTest, MapAt) { | 373 TEST(SharedMemoryTest, MapAt) { |
365 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32)); | 374 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32)); |
366 const size_t kCount = SysInfo::VMAllocationGranularity(); | 375 const size_t kCount = SysInfo::VMAllocationGranularity(); |
367 const size_t kDataSize = kCount * sizeof(uint32); | 376 const size_t kDataSize = kCount * sizeof(uint32); |
368 | 377 |
369 SharedMemory memory; | 378 SharedMemory memory; |
370 ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize)); | 379 ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize)); |
371 ASSERT_TRUE(memory.Map(kDataSize)); | 380 ASSERT_TRUE(memory.Map(kDataSize)); |
372 uint32* ptr = static_cast<uint32*>(memory.memory()); | 381 uint32* ptr = static_cast<uint32*>(memory.memory()); |
373 ASSERT_NE(ptr, static_cast<void*>(NULL)); | 382 ASSERT_NE(ptr, static_cast<void*>(NULL)); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 SharedMemoryProcessTest::CleanUp(); | 561 SharedMemoryProcessTest::CleanUp(); |
553 } | 562 } |
554 | 563 |
555 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 564 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
556 return SharedMemoryProcessTest::TaskTestMain(); | 565 return SharedMemoryProcessTest::TaskTestMain(); |
557 } | 566 } |
558 | 567 |
559 #endif // !OS_IOS | 568 #endif // !OS_IOS |
560 | 569 |
561 } // namespace base | 570 } // namespace base |
OLD | NEW |