| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (strncmp(cat.name(), "__test_basic_", 13) == 0) { | 111 if (strncmp(cat.name(), "__test_basic_", 13) == 0) { |
| 112 ASSERT_FALSE(CategoryRegistry::IsBuiltinCategory(&cat)); | 112 ASSERT_FALSE(CategoryRegistry::IsBuiltinCategory(&cat)); |
| 113 num_test_categories_seen++; | 113 num_test_categories_seen++; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 ASSERT_EQ(3, num_test_categories_seen); | 116 ASSERT_EQ(3, num_test_categories_seen); |
| 117 ASSERT_TRUE(g_initializer_check); | 117 ASSERT_TRUE(g_initializer_check); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Tries to cover the case of multiple threads creating the same category | 120 // Tries to cover the case of multiple threads creating the same category |
| 121 // simultaeously. Should never end up with distinct entries with the same name. | 121 // simultaneously. Should never end up with distinct entries with the same name. |
| 122 TEST_F(TraceCategoryTest, ThreadRaces) { | 122 TEST_F(TraceCategoryTest, ThreadRaces) { |
| 123 const int kNumThreads = 32; | 123 const int kNumThreads = 32; |
| 124 std::unique_ptr<Thread> threads[kNumThreads]; | 124 std::unique_ptr<Thread> threads[kNumThreads]; |
| 125 for (int i = 0; i < kNumThreads; i++) { | 125 for (int i = 0; i < kNumThreads; i++) { |
| 126 threads[i].reset(new Thread("test thread")); | 126 threads[i].reset(new Thread("test thread")); |
| 127 threads[i]->Start(); | 127 threads[i]->Start(); |
| 128 } | 128 } |
| 129 WaitableEvent sync_event(WaitableEvent::ResetPolicy::MANUAL, | 129 WaitableEvent sync_event(WaitableEvent::ResetPolicy::MANUAL, |
| 130 WaitableEvent::InitialState::NOT_SIGNALED); | 130 WaitableEvent::InitialState::NOT_SIGNALED); |
| 131 for (int i = 0; i < kNumThreads; i++) { | 131 for (int i = 0; i < kNumThreads; i++) { |
| 132 threads[i]->task_runner()->PostTask( | 132 threads[i]->task_runner()->PostTask( |
| 133 FROM_HERE, BindOnce(&TestRaceThreadMain, Unretained(&sync_event))); | 133 FROM_HERE, BindOnce(&TestRaceThreadMain, Unretained(&sync_event))); |
| 134 } | 134 } |
| 135 sync_event.Signal(); | 135 sync_event.Signal(); |
| 136 for (int i = 0; i < kNumThreads; i++) | 136 for (int i = 0; i < kNumThreads; i++) |
| 137 threads[i]->Stop(); | 137 threads[i]->Stop(); |
| 138 | 138 |
| 139 int num_times_seen = 0; | 139 int num_times_seen = 0; |
| 140 for (const TraceCategory& cat : GetAllCategories()) { | 140 for (const TraceCategory& cat : GetAllCategories()) { |
| 141 if (strcmp(cat.name(), "__test_race") == 0) | 141 if (strcmp(cat.name(), "__test_race") == 0) |
| 142 num_times_seen++; | 142 num_times_seen++; |
| 143 } | 143 } |
| 144 ASSERT_EQ(1, num_times_seen); | 144 ASSERT_EQ(1, num_times_seen); |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace trace_event | 147 } // namespace trace_event |
| 148 } // namespace base | 148 } // namespace base |
| OLD | NEW |