Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / base / test / launcher / test_results_tracker.h
blob2bddebc56ed03ce7b733fd1789cd0c66f8664fa9
1 // Copyright 2013 The Chromium 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.
5 #ifndef BASE_TEST_LAUNCHER_TEST_RESULTS_TRACKER_H_
6 #define BASE_TEST_LAUNCHER_TEST_RESULTS_TRACKER_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/callback.h"
14 #include "base/test/launcher/test_result.h"
15 #include "base/threading/thread_checker.h"
17 namespace base {
19 class CommandLine;
20 class FilePath;
22 // A helper class to output results.
23 // Note: as currently XML is the only supported format by gtest, we don't
24 // check output format (e.g. "xml:" prefix) here and output an XML file
25 // unconditionally.
26 // Note: we don't output per-test-case or total summary info like
27 // total failed_test_count, disabled_test_count, elapsed_time and so on.
28 // Only each test (testcase element in the XML) will have the correct
29 // failed/disabled/elapsed_time information. Each test won't include
30 // detailed failure messages either.
31 class TestResultsTracker {
32 public:
33 TestResultsTracker();
34 ~TestResultsTracker();
36 // Initialize the result tracker. Must be called exactly once before
37 // calling any other methods. Returns true on success.
38 bool Init(const CommandLine& command_line) WARN_UNUSED_RESULT;
40 // Called when a test iteration is starting.
41 void OnTestIterationStarting();
43 // Adds |test_name| to the set of discovered tests (this includes all tests
44 // present in the executable, not necessarily run).
45 void AddTest(const std::string& test_name);
47 // Adds |test_name| to the set of disabled tests.
48 void AddDisabledTest(const std::string& test_name);
50 // Adds |result| to the stored test results.
51 void AddTestResult(const TestResult& result);
53 // Prints a summary of current test iteration to stdout.
54 void PrintSummaryOfCurrentIteration() const;
56 // Prints a summary of all test iterations (not just the last one) to stdout.
57 void PrintSummaryOfAllIterations() const;
59 // Adds a string tag to the JSON summary. This is intended to indicate
60 // conditions that affect the entire test run, as opposed to individual tests.
61 void AddGlobalTag(const std::string& tag);
63 // Saves a JSON summary of all test iterations results to |path|. Returns
64 // true on success.
65 bool SaveSummaryAsJSON(const FilePath& path) const WARN_UNUSED_RESULT;
67 // Map where keys are test result statuses, and values are sets of tests
68 // which finished with that status.
69 typedef std::map<TestResult::Status, std::set<std::string> > TestStatusMap;
71 // Returns a test status map (see above) for current test iteration.
72 TestStatusMap GetTestStatusMapForCurrentIteration() const;
74 // Returns a test status map (see above) for all test iterations.
75 TestStatusMap GetTestStatusMapForAllIterations() const;
77 private:
78 void GetTestStatusForIteration(int iteration, TestStatusMap* map) const;
80 struct AggregateTestResult {
81 AggregateTestResult();
82 ~AggregateTestResult();
84 std::vector<TestResult> test_results;
87 struct PerIterationData {
88 PerIterationData();
89 ~PerIterationData();
91 // Aggregate test results grouped by full test name.
92 typedef std::map<std::string, AggregateTestResult> ResultsMap;
93 ResultsMap results;
96 ThreadChecker thread_checker_;
98 // Set of global tags, i.e. strings indicating conditions that apply to
99 // the entire test run.
100 std::set<std::string> global_tags_;
102 // Set of all test names discovered in the current executable.
103 std::set<std::string> all_tests_;
105 // Set of all disabled tests in the current executable.
106 std::set<std::string> disabled_tests_;
108 // Store test results for each iteration.
109 std::vector<PerIterationData> per_iteration_data_;
111 // Index of current iteration (starting from 0). -1 before the first
112 // iteration.
113 int iteration_;
115 // File handle of output file (can be NULL if no file).
116 FILE* out_;
118 DISALLOW_COPY_AND_ASSIGN(TestResultsTracker);
121 } // namespace base
123 #endif // BASE_TEST_LAUNCHER_TEST_RESULTS_TRACKER_H_