micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
test-runner.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus/)
4 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from <https://opensource.org/licenses/MIT/>.
11 *
12 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
13 * released under the terms of the Boost Version 1.0 Software License,
14 * which can be obtained from <https://www.boost.org/LICENSE_1_0.txt>.
15 */
16
17// ----------------------------------------------------------------------------
18
19#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
20#include <micro-os-plus/config.h>
21#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
22
24
25#include <stdio.h>
26#include <vector>
27
28// ----------------------------------------------------------------------------
29
30#pragma GCC diagnostic ignored "-Waggregate-return"
31#if defined(__clang__)
32#pragma clang diagnostic ignored "-Wc++98-compat"
33#pragma clang diagnostic ignored "-Wc++98-c++11-c++14-compat"
34#pragma clang diagnostic ignored "-Wunknown-warning-option"
35#endif
36
38{
39 // --------------------------------------------------------------------------
40
42 {
43#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
44 printf ("%s\n", __PRETTY_FUNCTION__);
45#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
46 }
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
51#endif
52 void
53 test_runner::initialize (int argc, char* argv[], const char* name)
54 {
55#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
56 printf ("%s\n", __PRETTY_FUNCTION__);
57#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
58
59 argc_ = argc;
60 argv_ = argv;
61
63
64#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
65#if defined(MICRO_OS_PLUS_DEBUG)
66 printf ("argv[");
67 for (int i = 0; i < argc; ++i)
68 {
69 if (i > 0)
70 {
71 printf (", ");
72 }
73 printf ("'%s'", argv[i]);
74 }
75 puts ("]");
76#endif // defined(MICRO_OS_PLUS_DEBUG)
77#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
78
80 for (int i = 0; i < argc; ++i)
81 {
82 if (strcmp (argv[i], "--verbose") == 0)
83 {
85 }
86 else if (strcmp (argv[i], "--quiet") == 0)
87 {
89 }
90 else if (strcmp (argv[i], "--silent") == 0)
91 {
93 }
94 }
95
96 // Pass the verbosity to the reporter.
98
99 // ------------------------------------------------------------------------
100
101#if !(defined(MICRO_OS_PLUS_INCLUDE_STARTUP) && defined(MICRO_OS_PLUS_TRACE))
103 {
104#if defined(__clang__)
105 printf ("Built with clang " __VERSION__);
106#elif defined(__GNUC__)
107 printf ("Built with GCC " __VERSION__);
108#elif defined(_MSC_VER)
109 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
110 printf ("Built with MSVC %d", _MSC_VER);
111#else
112 printf ("Built with an unknown compiler");
113#endif
114#if !(defined(__APPLE__) || defined(__linux__) || defined(__unix__) \
115 || defined(WIN32))
116// This is relevant only on bare-metal.
117#if defined(__ARM_PCS_VFP) || defined(__ARM_FP)
118 printf (", with FP");
119#else
120 printf (", no FP");
121#endif
122#endif
123#if defined(__EXCEPTIONS)
124 printf (", with exceptions");
125#else
126 printf (", no exceptions");
127#endif
128#if defined(MICRO_OS_PLUS_DEBUG)
129 printf (", with MICRO_OS_PLUS_DEBUG");
130#endif
131 puts (".");
132 }
133#endif // !defined(MICRO_OS_PLUS_INCLUDE_STARTUP)
134
135 // ------------------------------------------------------------------------
136
139
140 // Deferred to first test case or test suite end, to allow various
141 // initialisations to display their messages.
142 // default_test_suite_->begin_test_suite ();
143 }
144#pragma GCC diagnostic pop
145
146 int
148 {
149 bool was_successful = true;
150
152 {
154 was_successful = default_test_suite_->was_successful ();
155 }
156
157 if (suites_ != nullptr)
158 {
159 for (auto suite : *suites_)
160 {
161 current_test_suite = suite;
162
163 suite->begin_test_suite ();
164 suite->run ();
165 suite->end_test_suite ();
166
167 was_successful &= suite->was_successful ();
168 }
170 {
171 // printf ("\n");
172 }
173 }
174 return was_successful ? 0 : 1;
175 }
176
177 void
179 {
180#if 0 // defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
181 printf ("%s\n", __PRETTY_FUNCTION__);
182#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
183
184 if (suites_ == nullptr)
185 {
186 suites_ = new std::vector<test_suite_base*> ();
187 }
188 suites_->push_back (suite);
189 }
190
191 void
193 {
194 ::abort ();
195 }
196
197 // --------------------------------------------------------------------------
198} // namespace micro_os_plus::micro_test_plus
199
200// ----------------------------------------------------------------------------
std::vector< test_suite_base * > * suites_
Pointer to array of registered test suites. Statically initialised to zero as BSS,...
constexpr const char * name(void)
Definition test-runner.h:89
test_suite_base * default_test_suite_
Pointer to the default test suite which groups the main tests.
int exit_code(void)
Return 0 if the all tests were successful, 1 otherwise.
void initialize(int argc, char *argv[], const char *name)
Pass the main arguments explicitly, if the default constructor was used.
void register_test_suite(test_suite_base *suite)
Called by test suite constructors to register them to the runner.
Base class for all test suites.
Definition test-suite.h:51
constexpr bool unused(void)
If all counter are null, it is unused.
Definition test-suite.h:208
void end_test_suite(void)
Mark the end of the test suite.
void begin_test_suite(void)
Begin the execution of the test suite.
constexpr bool was_successful(void)
Get the test suite result.
Definition test-suite.h:195
verbosity
The verbosity levels.