1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
base / test / launcher / test_results_tracker_unittest.cc [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/launcher/test_results_tracker.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::HasSubstr;
namespace base {
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithLinkInResult) {
TestResultsTracker tracker;
TestResult result;
result.AddLink("link", "http://google.com");
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back(
TestResultsTracker::PerIterationData());
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
std::string expected_content = R"raw("links":{"link":)raw"
R"raw({"content":"http://google.com"}})raw";
EXPECT_TRUE(content.find(expected_content) != std::string::npos)
<< expected_content << " not found in " << content;
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithTagInResult) {
TestResultsTracker tracker;
TestResult result;
result.AddTag("tag_name", "tag_value");
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.push_back({});
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
std::string expected_content = R"raw("tags":{"tag_name":)raw"
R"raw({"values":["tag_value"]}})raw";
EXPECT_TRUE(content.find(expected_content) != std::string::npos)
<< expected_content << " not found in " << content;
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithMultiTagsInResult) {
TestResultsTracker tracker;
TestResult result;
result.AddTag("tag_name1", "tag_value1");
result.AddTag("tag_name2", "tag_value2");
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back();
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
std::string expected_content = R"raw("tags":{"tag_name1":)raw"
R"raw({"values":["tag_value1"]})raw"
R"raw(,"tag_name2":)raw"
R"raw({"values":["tag_value2"]}})raw";
EXPECT_TRUE(content.find(expected_content) != std::string::npos)
<< expected_content << " not found in " << content;
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithMultiTagsSameNameInResult) {
TestResultsTracker tracker;
TestResult result;
result.AddTag("tag_name", "tag_value1");
result.AddTag("tag_name", "tag_value2");
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back();
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
std::string expected_content = R"raw("tags":{"tag_name":)raw"
R"raw({"values":)raw"
R"raw(["tag_value1","tag_value2"]}})raw";
EXPECT_TRUE(content.find(expected_content) != std::string::npos)
<< expected_content << " not found in " << content;
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithPropertyInResult) {
TestResultsTracker tracker;
TestResult result;
result.AddProperty("test_property_name", "test_property_value");
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back(
TestResultsTracker::PerIterationData());
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
std::string expected_content = R"raw("properties":{"test_property_name":)raw"
R"raw({"value":"test_property_value"}})raw";
EXPECT_TRUE(content.find(expected_content) != std::string::npos)
<< expected_content << " not found in " << content;
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithOutTimestampInResult) {
TestResultsTracker tracker;
TestResult result;
result.full_name = "A.B";
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back(
TestResultsTracker::PerIterationData());
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
for (auto* not_expected_content : {"thread_id", "process_num", "timestamp"}) {
EXPECT_THAT(content, ::testing::Not(HasSubstr(not_expected_content)));
}
}
TEST(TestResultsTrackerTest, SaveSummaryAsJSONWithTimestampInResult) {
TestResultsTracker tracker;
TestResult result;
result.full_name = "A.B";
result.thread_id = 123;
result.process_num = 456;
result.timestamp = Time::Now();
TestResultsTracker::AggregateTestResult aggregate_result;
aggregate_result.test_results.push_back(result);
tracker.per_iteration_data_.emplace_back(
TestResultsTracker::PerIterationData());
tracker.per_iteration_data_.back().results["dummy"] = aggregate_result;
FilePath temp_file;
CreateTemporaryFile(&temp_file);
ASSERT_TRUE(tracker.SaveSummaryAsJSON(temp_file, std::vector<std::string>()));
std::string content;
ASSERT_TRUE(ReadFileToString(temp_file, &content));
EXPECT_THAT(content, HasSubstr(R"raw("thread_id":123)raw"));
EXPECT_THAT(content, HasSubstr(R"raw("process_num":456)raw"));
EXPECT_THAT(content, HasSubstr(R"raw("timestamp":)raw"));
}
TEST(TestResultsTrackerTest, RepeatDisabledTests) {
constexpr char TEST_NAME[] = "DISABLED_Test1";
constexpr char TEST_NAME_WITHOUT_PREFIX[] = "Test1";
TestResultsTracker tracker;
tracker.AddTestPlaceholder(TEST_NAME);
tracker.OnTestIterationStarting();
tracker.GeneratePlaceholderIteration();
TestResult result;
result.full_name = TEST_NAME;
result.status = TestResult::TEST_SUCCESS;
for (int i = 0; i < 10; i++) {
tracker.AddTestResult(result);
}
TestResultsTracker::TestStatusMap results =
tracker.GetTestStatusMapForAllIterations();
ASSERT_TRUE(results[TestResult::TEST_SUCCESS].find(TEST_NAME) ==
results[TestResult::TEST_SUCCESS].end());
ASSERT_TRUE(
results[TestResult::TEST_SUCCESS].find(TEST_NAME_WITHOUT_PREFIX) !=
results[TestResult::TEST_SUCCESS].end());
}
} // namespace base