OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/base/platform/platform.h" | |
6 | |
7 #if V8_OS_POSIX | |
8 #include <unistd.h> // NOLINT | |
9 #endif | |
10 | |
11 #if V8_OS_WIN | |
12 #include "src/base/win32-headers.h" | |
13 #endif | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace v8 { | |
17 namespace base { | |
18 | |
19 TEST(OS, GetCurrentProcessId) { | |
20 #if V8_OS_POSIX | |
21 EXPECT_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId()); | |
22 #endif | |
23 | |
24 #if V8_OS_WIN | |
Sven Panne
2014/08/06 09:33:28
Again: #elif (perhaps)
Benedikt Meurer
2014/08/06 09:35:06
See earlier comment.
| |
25 EXPECT_EQ(static_cast<int>(::GetCurrentProcessId()), | |
26 OS::GetCurrentProcessId()); | |
27 #endif | |
28 } | |
29 | |
30 | |
31 TEST(OS, NumberOfProcessorsOnline) { | |
32 EXPECT_GT(OS::NumberOfProcessorsOnline(), 0); | |
33 } | |
34 | |
35 | |
36 namespace { | |
37 | |
38 class SelfJoinThread V8_FINAL : public Thread { | |
39 public: | |
40 SelfJoinThread() : Thread("SelfJoinThread") {} | |
41 virtual void Run() V8_OVERRIDE { Join(); } | |
42 }; | |
43 | |
44 } | |
45 | |
46 | |
47 TEST(Thread, SelfJoin) { | |
48 SelfJoinThread thread; | |
49 thread.Start(); | |
50 thread.Join(); | |
51 } | |
52 | |
53 | |
54 namespace { | |
55 | |
56 class ThreadLocalStorageTest : public Thread, public ::testing::Test { | |
57 public: | |
58 ThreadLocalStorageTest() : Thread("ThreadLocalStorageTest") { | |
59 for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) { | |
60 keys_[i] = Thread::CreateThreadLocalKey(); | |
61 } | |
62 } | |
63 ~ThreadLocalStorageTest() { | |
64 for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) { | |
65 Thread::DeleteThreadLocalKey(keys_[i]); | |
66 } | |
67 } | |
68 | |
69 virtual void Run() V8_FINAL V8_OVERRIDE { | |
70 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
71 CHECK(!Thread::HasThreadLocal(keys_[i])); | |
72 } | |
73 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
74 Thread::SetThreadLocal(keys_[i], GetValue(i)); | |
75 } | |
76 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
77 CHECK(Thread::HasThreadLocal(keys_[i])); | |
78 } | |
79 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
80 CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys_[i])); | |
81 CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys_[i])); | |
82 } | |
83 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
84 Thread::SetThreadLocal(keys_[i], GetValue(ARRAY_SIZE(keys_) - i - 1)); | |
85 } | |
86 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
87 CHECK(Thread::HasThreadLocal(keys_[i])); | |
88 } | |
89 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | |
90 CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1), | |
91 Thread::GetThreadLocal(keys_[i])); | |
92 CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1), | |
93 Thread::GetExistingThreadLocal(keys_[i])); | |
94 } | |
95 } | |
96 | |
97 private: | |
98 static void* GetValue(size_t x) { | |
99 return reinterpret_cast<void*>(static_cast<uintptr_t>(x + 1)); | |
100 } | |
101 | |
102 Thread::LocalStorageKey keys_[256]; | |
103 }; | |
104 | |
105 } | |
106 | |
107 | |
108 TEST_F(ThreadLocalStorageTest, DoTest) { | |
109 Run(); | |
110 Start(); | |
111 Join(); | |
112 } | |
113 | |
114 } // namespace base | |
115 } // namespace v8 | |
OLD | NEW |