| Index: base/tracked_objects_unittest.cc
|
| diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc
|
| index 70d9601cd0f9be78570cabab1ce23d7b6413917e..20f57b370cd8b3c811d500443a43ff91991d1e25 100644
|
| --- a/base/tracked_objects_unittest.cc
|
| +++ b/base/tracked_objects_unittest.cc
|
| @@ -11,14 +11,17 @@
|
|
|
| #include <memory>
|
|
|
| +#include "base/macros.h"
|
| #include "base/process/process_handle.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/threading/thread.h"
|
| #include "base/time/time.h"
|
| #include "base/tracking_info.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| const int kLineNumber = 1776;
|
| const char kFile[] = "FixedUnitTestFileName";
|
| -const char kWorkerThreadName[] = "WorkerThread-1";
|
| +const char kWorkerThreadName[] = "WorkerThread-*";
|
| const char kMainThreadName[] = "SomeMainThreadName";
|
| const char kStillAlive[] = "Still_Alive";
|
|
|
| @@ -108,6 +111,16 @@ class TrackedObjectsTest : public testing::Test {
|
| // Sets time that will be returned by ThreadData::Now().
|
| static void SetTestTime(unsigned int test_time) { test_time_ = test_time; }
|
|
|
| + int GetNumThreadData() {
|
| + int num_thread_data = 0;
|
| + ThreadData* current = ThreadData::first();
|
| + while (current) {
|
| + ++num_thread_data;
|
| + current = current->next();
|
| + }
|
| + return num_thread_data;
|
| + }
|
| +
|
| private:
|
| // Returns test time in milliseconds.
|
| static unsigned int GetTestTime() { return test_time_; }
|
| @@ -1184,4 +1197,25 @@ TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
|
| EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
|
| }
|
|
|
| +// Repetitively create and stop named threads. Verify that the number of
|
| +// instantiated ThreadData instance is equal to the number of different
|
| +// sanitized thread names used in the test.
|
| +TEST_F(TrackedObjectsTest, ReuseRetiredThreadData) {
|
| + const char* const kThreadNames[] = {"Foo%d", "Bar%d", "123Dummy%d",
|
| + "456Dummy%d"};
|
| + constexpr int kNumIterations = 10;
|
| + EXPECT_EQ(0, GetNumThreadData());
|
| +
|
| + for (int i = 0; i < kNumIterations; ++i) {
|
| + for (const char* thread_name : kThreadNames) {
|
| + base::Thread thread(base::StringPrintf(thread_name, i));
|
| + EXPECT_TRUE(thread.Start());
|
| + }
|
| + }
|
| +
|
| + // Expect one ThreadData instance for each element in |kThreadNames| and one
|
| + // ThreadData instance for the main thread.
|
| + EXPECT_EQ(static_cast<int>(arraysize(kThreadNames) + 1), GetNumThreadData());
|
| +}
|
| +
|
| } // namespace tracked_objects
|
|
|