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_
13 #include "base/callback.h"
14 #include "base/test/launcher/test_result.h"
15 #include "base/threading/thread_checker.h"
23 // A helper class to output results.
24 // Note: as currently XML is the only supported format by gtest, we don't
25 // check output format (e.g. "xml:" prefix) here and output an XML file
27 // Note: we don't output per-test-case or total summary info like
28 // total failed_test_count, disabled_test_count, elapsed_time and so on.
29 // Only each test (testcase element in the XML) will have the correct
30 // failed/disabled/elapsed_time information. Each test won't include
31 // detailed failure messages either.
32 class TestResultsTracker {
35 ~TestResultsTracker();
37 // Initialize the result tracker. Must be called exactly once before
38 // calling any other methods. Returns true on success.
39 bool Init(const CommandLine& command_line) WARN_UNUSED_RESULT;
41 // Called when a test iteration is starting.
42 void OnTestIterationStarting();
44 // Adds |result| to the stored test results.
45 void AddTestResult(const TestResult& result);
47 // Prints a summary of current test iteration to stdout.
48 void PrintSummaryOfCurrentIteration() const;
50 // Prints a summary of all test iterations (not just the last one) to stdout.
51 void PrintSummaryOfAllIterations() const;
53 // Adds a string tag to the JSON summary. This is intended to indicate
54 // conditions that affect the entire test run, as opposed to individual tests.
55 void AddGlobalTag(const std::string& tag);
57 // Saves a JSON summary of all test iterations results to |path|. Returns
59 bool SaveSummaryAsJSON(const FilePath& path) const WARN_UNUSED_RESULT;
62 struct AggregateTestResult {
63 AggregateTestResult();
64 ~AggregateTestResult();
66 std::vector<TestResult> test_results;
69 struct PerIterationData {
73 // Aggregate test results grouped by full test name.
74 typedef std::map<std::string, AggregateTestResult> ResultsMap;
78 ThreadChecker thread_checker_;
80 // Set of global tags, i.e. strings indicating conditions that apply to
81 // the entire test run.
82 std::set<std::string> global_tags_;
84 // Store test results for each iteration.
85 std::vector<PerIterationData> per_iteration_data_;
87 // Index of current iteration (starting from 0). -1 before the first
91 // File handle of output file (can be NULL if no file).
94 DISALLOW_COPY_AND_ASSIGN(TestResultsTracker);
99 #endif // BASE_TEST_LAUNCHER_TEST_RESULTS_TRACKER_H_