KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
tester.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 #pragma once
15 
16 // System includes
17 #include <string>
18 #include <iostream>
19 #include <map>
20 
21 // External includes
22 
23 // Project includes
25 
26 namespace Kratos::Testing
27 {
28 
31 
34 
35 class TestCase; // Forward declaration of TestCase class
36 class TestSuite; // Forward declaration of TestSuite class
37 
39 
43 class KRATOS_API(KRATOS_CORE) Tester
44 {
45 public:
48 
49  using TestCasesContainerType = std::map<std::string, TestCase*>;
50 
51  using TestSuitesContainerType = std::map<std::string, TestSuite*>;
52 
56 
57  enum class Verbosity {QUITE, PROGRESS, TESTS_LIST, FAILED_TESTS_OUTPUTS, TESTS_OUTPUTS};
58 
62 
64  Tester(Tester const& rOther) = delete;
65 
67  virtual ~Tester();
68 
72 
74  Tester& operator=(Tester const& rOther) = delete;
75 
79 
80  static void ResetAllTestCasesResults();
81 
82  static int RunAllTestCases();
83 
84  static int RunAllDistributedTestCases();
85 
86  static int ProfileAllTestCases();
87 
88  static int ProfileAllDistributedTestCases();
89 
90  static int RunTestSuite(std::string const& TestSuiteName);
91 
92  static int ProfileTestSuite(std::string const& TestSuiteName);
93 
95  static int RunTestCases(std::string const& TestCasesNamePattern);
96 
98  static int ProfileTestCases(std::string const& TestCasesNamePattern);
99 
100  static std::size_t NumberOfFailedTestCases();
101 
102  static std::size_t NumberOfSkippedTestCases();
103 
106  static void AddTestCase(TestCase* pHeapAllocatedTestCase);
107 
108  static TestCase& GetTestCase(std::string const& TestCaseName);
109 
110  static TestCase* pGetTestCase(std::string const& TestCaseName);
111 
113  static TestSuite* CreateTestSuite(std::string const& TestSuiteName);
114 
116  static TestSuite* CreateNewTestSuite(std::string const& TestSuiteName);
117 
120  static void AddTestSuite(TestSuite* pHeapAllocatedTestSuite);
121 
122  static TestSuite& GetTestSuite(std::string const& TestSuiteName);
123 
124  static TestSuite* pGetTestSuite(std::string const& TestSuiteName);
125 
127  static void AddTestToTestSuite(std::string const& TestName, std::string const& TestSuiteName);
128 
132 
133  static Tester& GetInstance();
134 
135  static void SetVerbosity(Verbosity TheVerbosity);
136 
140 
141  static bool HasTestCase(std::string const& TestCaseName);
142 
143  static bool HasTestSuite(std::string const& TestSuiteName);
144 
148 
150  virtual std::string Info() const;
151 
153  virtual void PrintInfo(std::ostream& rOStream) const;
154 
156  virtual void PrintData(std::ostream& rOStream) const;
157 
159 private:
162 
164  Tester();
165 
169 
170  TestCasesContainerType mTestCases;
171 
172  TestSuitesContainerType mTestSuites;
173 
174  Verbosity mVerbosity;
175 
179 
184  static void UnSelectAllTestCases();
185 
190  static void SelectOnlyEnabledTestCases();
191 
196  static void SelectOnlyDistributedTestCases();
197 
202  static void SelectTestCasesByPattern(std::string const& rTestCasesNamePattern);
203 
208  static int RunSelectedTestCases();
209 
215  static int ProfileSelectedTestCases();
216 
225  static std::size_t NumberOfSelectedTestCases();
226 
233  static void StartShowProgress(
234  const std::size_t Current,
235  const std::size_t Total,
236  const TestCase* pTheTestCase
237  );
238 
245  static void EndShowProgress(
246  const std::size_t Current,
247  const std::size_t Total,
248  const TestCase* pTheTestCase
249  );
250 
259  static int ReportResults(
260  std::ostream& rOStream,
261  const std::size_t NumberOfRunTests,
262  const double ElapsedTime
263  );
264 
269  static void ReportFailures(std::ostream& rOStream);
270 
276  static void ReportDistributedFailureDetails(
277  std::ostream& rOStream,
278  const TestCase* pTheTestCase
279  );
280 
281 }; // Class Tester
282 
284 
287 
289 inline std::ostream& operator << (std::ostream& rOStream,
290  const Tester& rThis)
291 {
292  rThis.PrintInfo(rOStream);
293  rOStream << std::endl;
294  rThis.PrintData(rOStream);
295 
296  return rOStream;
297 }
301 
303 
305 } // namespace Kratos::Testing.
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
The test case base class.
Definition: test_case.h:53
This class holds an array of test cases and run them one by one in its Run method.
Definition: test_suite.h:47
Tester class manages all tests and provide interface to run them.
Definition: tester.h:44
Tester & operator=(Tester const &rOther)=delete
Preventing the assignment of the tests.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: tester.cpp:218
Verbosity
Definition: tester.h:57
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: tester.cpp:223
std::map< std::string, TestSuite * > TestSuitesContainerType
Definition: tester.h:51
Tester(Tester const &rOther)=delete
The Tester cannot be copied to avoid duplications.
std::map< std::string, TestCase * > TestCasesContainerType
Definition: tester.h:49
static int ProfileTestCases(std::string const &TestCasesNamePattern)
The test case pattern can apply * as any number of any character.
std::ostream & operator<<(std::ostream &rOStream, const TestCase &rThis)
output stream function
Definition: test_case.h:174
Definition: distributed_test_case.cpp:24