• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_LAUNCHER_TEST_RESULT_H_
6 #define BASE_TEST_LAUNCHER_TEST_RESULT_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h"
14 #include "third_party/abseil-cpp/absl/types/optional.h"
15 
16 namespace base {
17 
18 // Structure contains result of a single EXPECT/ASSERT/SUCCESS/SKIP.
19 struct TestResultPart {
20   enum Type {
21     kSuccess,          // SUCCESS
22     kNonFatalFailure,  // EXPECT
23     kFatalFailure,     // ASSERT
24     kSkip,             // SKIP
25   };
26   Type type;
27 
28   TestResultPart();
29   ~TestResultPart();
30 
31   TestResultPart(const TestResultPart& other);
32   TestResultPart(TestResultPart&& other);
33   TestResultPart& operator=(const TestResultPart& other);
34   TestResultPart& operator=(TestResultPart&& other);
35 
36   // Convert type to string and back.
37   static bool TypeFromString(const std::string& str, Type* type);
38   std::string TypeAsString() const;
39 
40   // Filename and line of EXPECT/ASSERT.
41   std::string file_name;
42   int line_number;
43 
44   // Message without stacktrace, etc.
45   std::string summary;
46 
47   // Complete message.
48   std::string message;
49 };
50 
51 // Structure containing result of a single test.
52 struct TestResult {
53   enum Status {
54     TEST_UNKNOWN,           // Status not set.
55     TEST_SUCCESS,           // Test passed.
56     TEST_FAILURE,           // Assertion failure (e.g. EXPECT_TRUE, not DCHECK).
57     TEST_FAILURE_ON_EXIT,   // Passed but executable exit code was non-zero.
58     TEST_TIMEOUT,           // Test timed out and was killed.
59     TEST_CRASH,             // Test crashed (includes CHECK/DCHECK failures).
60     TEST_SKIPPED,           // Test skipped (not run at all).
61     TEST_EXCESSIVE_OUTPUT,  // Test exceeded output limit.
62     TEST_NOT_RUN,           // Test has not yet been run.
63   };
64 
65   TestResult();
66   ~TestResult();
67 
68   TestResult(const TestResult& other);
69   TestResult(TestResult&& other);
70   TestResult& operator=(const TestResult& other);
71   TestResult& operator=(TestResult&& other);
72 
73   // Returns the test status as string (e.g. for display).
74   std::string StatusAsString() const;
75 
76   // Returns the test name (e.g. "B" for "A.B").
77   std::string GetTestName() const;
78 
79   // Returns the test case name (e.g. "A" for "A.B").
80   std::string GetTestCaseName() const;
81 
82   // Add link in the xml output.
83   // See more in gtest_links.h.
84   void AddLink(const std::string& name, const std::string& url);
85 
86   // Add tag in the xml output.
87   // See more in gtest_tags.h.
88   void AddTag(const std::string& name, const std::string& value);
89 
90   // Add property in the xml output.
91   void AddProperty(const std::string& name, const std::string& value);
92 
93   // Returns true if the test has completed (i.e. the test binary exited
94   // normally, possibly with an exit code indicating failure, but didn't crash
95   // or time out in the middle of the test).
completedTestResult96   bool completed() const {
97     return status == TEST_SUCCESS ||
98         status == TEST_FAILURE ||
99         status == TEST_FAILURE_ON_EXIT ||
100         status == TEST_EXCESSIVE_OUTPUT;
101   }
102 
103   // Full name of the test (e.g. "A.B").
104   std::string full_name;
105 
106   Status status;
107 
108   // Start time of child test process, the field is optional the test could be
109   // NOT_RUN.
110   absl::optional<base::Time> timestamp;
111 
112   // Thread id of the runner that launching the child process, which is also
113   // recorded in TestLauncherTracer.
114   absl::optional<base::PlatformThreadId> thread_id;
115 
116   // The process num of child process launched it's recorded as event name in
117   // TestLauncherTracer.
118   // It's used instead of process id to distinguish processes that process id
119   // might be reused by OS.
120   absl::optional<int> process_num;
121 
122   // Time it took to run the test.
123   base::TimeDelta elapsed_time;
124 
125   // Output of just this test (optional).
126   std::string output_snippet;
127 
128   // Information about failed expectations.
129   std::vector<TestResultPart> test_result_parts;
130 
131   // The key is link name.
132   std::map<std::string, std::string> links;
133 
134   // The key is property name.
135   std::map<std::string, std::string> properties;
136 
137   // The key is tag name.
138   std::map<std::string, std::vector<std::string>> tags;
139 };
140 
141 }  // namespace base
142 
143 #endif  // BASE_TEST_LAUNCHER_TEST_RESULT_H_
144