Skip to content

Commit 8a5e083

Browse files
authored
Merge pull request #2147 from elBoberido/iox-1032-refine-testing-with-new-error-reporting
iox-#1032 Refine testing with new error reporting
2 parents 007bdb3 + 41ec0e7 commit 8a5e083

File tree

31 files changed

+308
-381
lines changed

31 files changed

+308
-381
lines changed

.cirrus.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ ubuntu_22_04_aarch64_build_task:
125125
test_binaries_cache:
126126
folder: iox-tests-bin
127127
reupload_on_changes: true
128-
fingerprint_key: $CIRRUS_OS_ubuntu_22_04_aarch64_test_binaries_cache
128+
fingerprint_key: $CIRRUS_OS_ubuntu_22_04_aarch64_test_binaries_cache_$CIRRUS_BRANCH
129129
build_script:
130130
<<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER
131131
populate_test_binary_folder_script:
@@ -140,7 +140,7 @@ ubuntu_22_04_aarch64_test_task:
140140
test_binaries_cache:
141141
folder: iox-tests-bin
142142
reupload_on_changes: false
143-
fingerprint_key: $CIRRUS_OS_ubuntu_22_04_aarch64_test_binaries_cache
143+
fingerprint_key: $CIRRUS_OS_ubuntu_22_04_aarch64_test_binaries_cache_$CIRRUS_BRANCH
144144
test_script:
145145
<<: *IOX_RUN_TESTS
146146

@@ -157,7 +157,7 @@ arch_linux_x64_gcc_8_3_aka_qnx_canary_build_task:
157157
test_binaries_cache:
158158
folder: iox-tests-bin
159159
reupload_on_changes: true
160-
fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache
160+
fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache_$CIRRUS_BRANCH
161161
env:
162162
# use GCC 8.3 which corresponds to QCC 8.3 on QNX 7.1
163163
CC: gcc-8
@@ -176,7 +176,7 @@ arch_linux_x64_gcc_8_3_aka_qnx_canary_test_task:
176176
test_binaries_cache:
177177
folder: iox-tests-bin
178178
reupload_on_changes: false
179-
fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache
179+
fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache_$CIRRUS_BRANCH
180180
test_script:
181181
<<: *IOX_RUN_TESTS
182182

@@ -194,7 +194,7 @@ arch_linux_x64_build_task:
194194
test_binaries_cache:
195195
folder: iox-tests-bin
196196
reupload_on_changes: true
197-
fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache
197+
fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache_$CIRRUS_BRANCH
198198
build_script:
199199
<<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER
200200
populate_test_binary_folder_script:
@@ -210,7 +210,7 @@ arch_linux_x64_test_task:
210210
test_binaries_cache:
211211
folder: iox-tests-bin
212212
reupload_on_changes: false
213-
fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache
213+
fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache_$CIRRUS_BRANCH
214214
test_script:
215215
<<: *IOX_RUN_TESTS
216216

@@ -227,7 +227,7 @@ freebsd_x64_build_task:
227227
test_binaries_cache:
228228
folder: iox-tests-bin
229229
reupload_on_changes: true
230-
fingerprint_key: $CIRRUS_OS_freebsd_x64_test_binaries_cache
230+
fingerprint_key: $CIRRUS_OS_freebsd_x64_test_binaries_cache_$CIRRUS_BRANCH
231231
setup_script:
232232
- pkg install -y cmake git ncurses bash wget
233233
- ln -s /usr/local/bin/bash /bin/bash
@@ -245,7 +245,7 @@ freebsd_x64_test_task:
245245
test_binaries_cache:
246246
folder: iox-tests-bin
247247
reupload_on_changes: false
248-
fingerprint_key: $CIRRUS_OS_freebsd_x64_test_binaries_cache
248+
fingerprint_key: $CIRRUS_OS_freebsd_x64_test_binaries_cache_$CIRRUS_BRANCH
249249
test_script:
250250
<<: *IOX_RUN_TESTS
251251

@@ -263,7 +263,7 @@ macos_aarch64_build_task:
263263
test_binaries_cache:
264264
folder: iox-tests-bin
265265
reupload_on_changes: true
266-
fingerprint_key: $CIRRUS_OS_macOS_aarch64_test_binaries_cache
266+
fingerprint_key: $CIRRUS_OS_macOS_aarch64_test_binaries_cache_$CIRRUS_BRANCH
267267
setup_script:
268268
- brew install ncurses
269269
build_script:
@@ -281,7 +281,7 @@ macos_aarch64_test_task:
281281
test_binaries_cache:
282282
folder: iox-tests-bin
283283
reupload_on_changes: false
284-
fingerprint_key: $CIRRUS_OS_macOS_aarch64_test_binaries_cache
284+
fingerprint_key: $CIRRUS_OS_macOS_aarch64_test_binaries_cache_$CIRRUS_BRANCH
285285
env:
286286
# No timing tests on macOS
287287
GTEST_FILTER: "-*TimingTest*"

doc/aspice_swe3_4/example/iceoryx_component/test/moduletests/test_component_modules.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
#include <gmock/gmock.h>
18-
#include <gtest/gtest.h>
1917

20-
using namespace ::testing;
21-
using ::testing::_;
18+
#include "iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp"
19+
#include "iceoryx_hoofs/testing/testing_logger.hpp"
2220

21+
#include <gmock/gmock.h>
22+
#include <gtest/gtest.h>
2323

2424
int main(int argc, char* argv[])
2525
{
2626
::testing::InitGoogleTest(&argc, argv);
2727

28+
iox::testing::TestingLogger::init();
29+
iox::testing::TestingErrorHandler::init();
30+
2831
return RUN_ALL_TESTS();
2932
}

doc/design/error_reporting.md

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -157,84 +157,63 @@ Fatal errors can be conditionally reported in a similar way.
157157
IOX_REPORT_FATAL_IF(x<0, Code::OutOfBounds);
158158
```
159159
160-
### Require That a Condition Holds
160+
### Enforce a Condition
161161
162-
Similarly we can conditionally check whether a condition does hold and report a fatal error in
162+
Similarly we can conditionally enforce whether a condition does hold and report a fatal error in
163163
the case that it does not hold
164164
165165
```cpp
166166
int x;
167167
// ...
168-
IOX_REQUIRE(x>=0, "required condition violation message");
168+
IOX_ENFORCE(x>=0, "enforce violation message");
169169
```
170170

171171
The condition is required to hold and this requirement is always checked.
172172
If the condition does not hold, panic is invoked and the execution stops.
173173

174174
This should be used for conditions that may not hold on the correct path, e.g. for error cases.
175175
It should not be used for assumptions that have to be true in correct code
176-
(use `IOX_ASSUME` or `IOX_PRECONDITION` for this).
176+
(use `IOX_ASSERT` for this).
177177

178178
Note that no condition can generally be enforced in the sense that it must be true and no checking is required.
179179

180-
## Using the API to Check Contracts and Assumptions
180+
### Assert a Condition
181181

182-
The following checks can be disabled and are intended to increase safety during incorrect
182+
The following check is disabled for release builds and is intended to increase safety during incorrect
183183
use, specifically detect incorrect use at runtime.
184184

185-
This means they should only be used for checks that are not needed in correct code (i.e. defensive
185+
This means it should only be used for checks that are not needed in correct code (i.e. defensive
186186
programming).
187187

188-
If these checks are disabled, there is no overhead in the code, i.e. no checking or reporting takes place.
189-
190-
### Checking Preconditions
191-
192-
A precondition check
188+
When check is disabled, there is no overhead in the code, i.e. no checking or reporting takes place.
193189

194190
```cpp
195191
int f(int x)
196192
{
197-
IOX_PRECONDITION(x>=0, "precondition violation message");
193+
IOX_ASSERT(x>=0, "precondition violation message");
198194

199-
// ...
195+
// some computation
196+
int y = g(x);
197+
198+
IOX_ASSERT(y>=0, "assumption violation message");
199+
// proceed assuming that y>=0 holds
200200
}
201201
```
202202
203-
is used to verify assumptions **BEFORE** any logic in the function body is executed. Technically copy
203+
Is can be used to verify preconditions before any logic in the function body is executed. Technically copy
204204
constructors may run before any condition can be checked, and there is also the possibility of
205205
reordering if the following code does not depend on the condition at all.
206206
This is not a problem since any reordering is not allowed to affect the observable result.
207207
Specifically it cannot affect the value of the precondition itself as this would change the
208208
observable behaviour.
209209
210+
When used in the middle of a function it serves as documentation of assumptions that should hold at this
211+
point in the code before the next statement and can be used e.g. to check for out-of-bounds accesses. It can
212+
also be used to check postconditions.
213+
210214
In case of violation, the violation and a (potentially empty) message are forwarded to the backend,
211215
panic is invoked and execution stops.
212216
213-
The verification can be optionally disabled, and hence this also documents assumptions of the
214-
function itself.
215-
216-
### Checking Assumptions
217-
218-
Checking assumptions is similar to checking preconditions, but can happen anywhere in the code.
219-
220-
```cpp
221-
int f(int x)
222-
{
223-
// some computation
224-
int y = g(x);
225-
226-
IOX_ASSUME(y>=0, "assumption violation message");
227-
// proceed assuming that y>=0 holds
228-
}
229-
```
230-
231-
These serve as documentation of assumptions that should hold at this point in the code before the
232-
next statement and can be used e.g. to check for out-of-bounds accesses. It can also be used to
233-
check postconditions.
234-
235-
It should not be used at the start of a function body and instead replaced with a precondition check
236-
in this case.
237-
238217
## Marking Unreachable Code
239218
240219
It is also possible to explicitly state that code is supposed to be unreachable.
@@ -394,7 +373,7 @@ Alternatively the shorthand version can be used
394373
int algorithm(int x)
395374
{
396375
// require that the condition holds or raise a fatal error
397-
IOX_REQUIRE(!errorCondition(x), SomeError);
376+
IOX_REPORT_FATAL_IF(errorCondition(x), SomeError);
398377
return 42;
399378
}
400379
```
@@ -425,7 +404,7 @@ These are
425404
8. `errors.hpp` : supported error types and related free functions
426405

427406
Additionally there is the `assertions.hpp` in `iceoryx_hoofs/reporting` which contains the `IOX_PANIC`,
428-
`IOX_UNREACHABLE`, `IOX_REQUIRE`, `IOX_PRECONDITION` and `IOX_ASSUME` macros
407+
`IOX_UNREACHABLE`, `IOX_ASSERT` and `IOX_ENFORCE` macros.
429408

430409
All the files focus on singular aspects to allow fine-grained inclusion.
431410
All definitions have to reside in `iox::er`, which is considered a private (detail) namespace
@@ -463,7 +442,7 @@ The default implementation does not depend on any code that uses the error repor
463442
### Testing
464443

465444
All testing related definitions are located in `iceoryx_hoofs/testing/error_reporting`.
466-
These are the definition of `TestErrorHandler` in `testing_error_handler.hpp` and auxiliary
445+
These are the definition of `TestingErrorHandler` in `testing_error_handler.hpp` and auxiliary
467446
functions in `testing_support.hpp` to be used in tests to verify errors.
468447
The latter can be extended as required.
469448

iceoryx_binding_c/test/moduletests/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//
1616
// SPDX-License-Identifier: Apache-2.0
1717

18+
#include "iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp"
1819
#include "iceoryx_hoofs/testing/testing_logger.hpp"
1920

2021
#include "test.hpp"
@@ -24,9 +25,6 @@
2425

2526
#include "test_types_storage_size.hpp"
2627

27-
using namespace ::testing;
28-
using ::testing::_;
29-
3028
// in case this isn't executed before the other tests, just call
3129
// 'checkIceoryxBindingCStorageSizes' directly in main
3230
TEST(SanityCheck, CheckStorageSizeAndAlingment)
@@ -41,6 +39,7 @@ int main(int argc, char* argv[])
4139
::testing::InitGoogleTest(&argc, argv);
4240

4341
iox::testing::TestingLogger::init();
42+
iox::testing::TestingErrorHandler::init();
4443

4544
return RUN_ALL_TESTS();
4645
}

iceoryx_hoofs/reporting/include/iox/assertions.hpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,35 @@
5151
//* Instead a special internal error type is used.
5252
//************************************************************************************************
5353

54-
/// @brief report fatal required condition violation if expr evaluates to false
55-
/// @note for conditions that may actually happen during correct use
54+
/// @brief only for debug builds: report fatal assert violation if expr evaluates to false
55+
/// @note for conditions that should not happen with correct use
5656
/// @param expr boolean expression that must hold
5757
/// @param message message to be forwarded in case of violation
58-
#define IOX_REQUIRE(expr, message) \
58+
#define IOX_ASSERT(expr, message) \
5959
do \
6060
{ \
61-
if (!(expr)) \
61+
if (iox::er::Configuration::CHECK_ASSERT && !(expr)) \
6262
{ \
63-
iox::er::forwardFatalError(iox::er::Violation::createRequiredConditionViolation(), \
64-
iox::er::REQUIRED_CONDITION_VIOLATION, \
65-
CURRENT_SOURCE_LOCATION, \
66-
message); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \
67-
} \
68-
} while (false)
69-
70-
/// @brief if enabled: report fatal precondition violation if expr evaluates to false
71-
/// @param expr boolean expression that must hold upon entry of the function it appears in
72-
/// @param message message to be forwarded in case of violation
73-
#define IOX_PRECONDITION(expr, message) \
74-
do \
75-
{ \
76-
if (iox::er::Configuration::CHECK_PRECONDITIONS && !(expr)) \
77-
{ \
78-
iox::er::forwardFatalError(iox::er::Violation::createPreconditionViolation(), \
79-
iox::er::PRECONDITION_VIOLATION, \
63+
iox::er::forwardFatalError(iox::er::Violation::createAssertViolation(), \
64+
iox::er::ASSERT_VIOLATION, \
8065
CURRENT_SOURCE_LOCATION, \
8166
message); \
8267
} \
8368
} while (false)
8469

85-
/// @brief if enabled: report fatal assumption violation if expr evaluates to false
86-
/// @note for conditions that should not happen with correct use
70+
/// @brief report fatal enforce violation if expr evaluates to false
71+
/// @note for conditions that may actually happen during correct use
8772
/// @param expr boolean expression that must hold
8873
/// @param message message to be forwarded in case of violation
89-
#define IOX_ASSUME(expr, message) \
74+
#define IOX_ENFORCE(expr, message) \
9075
do \
9176
{ \
92-
if (iox::er::Configuration::CHECK_ASSUMPTIONS && !(expr)) \
77+
if (!(expr)) \
9378
{ \
94-
iox::er::forwardFatalError(iox::er::Violation::createAssumptionViolation(), \
95-
iox::er::ASSUMPTION_VIOLATION, \
79+
iox::er::forwardFatalError(iox::er::Violation::createEnforceViolation(), \
80+
iox::er::ENFORCE_VIOLATION, \
9681
CURRENT_SOURCE_LOCATION, \
97-
message); \
82+
message); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \
9883
} \
9984
} while (false)
10085

iceoryx_hoofs/reporting/include/iox/error_reporting/configuration.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ struct ConfigurationParameters
3939
{
4040
static_assert(std::is_same<T, ConfigurationTag>::value, "Incorrect configuration tag type");
4141

42-
static constexpr bool CHECK_PRECONDITIONS{true};
43-
static constexpr bool CHECK_ASSUMPTIONS{true};
42+
static constexpr bool CHECK_ASSERT{true}; /// @todo iox-#1032 deactive for release builds
4443
};
4544

4645
// used by the API to obtain the compile time parameters

iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/configuration.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ namespace er
3030
template <>
3131
struct ConfigurationParameters<ConfigurationTag>
3232
{
33-
static constexpr bool CHECK_PRECONDITIONS{true};
34-
static constexpr bool CHECK_ASSUMPTIONS{true};
33+
static constexpr bool CHECK_ASSERT{true}; /// @todo iox-#1032 deactive for release builds
3534
};
3635

3736
} // namespace er

iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/error_handler_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#ifndef IOX_HOOFS_REPORTING_ERROR_REPORTING_CUSTOM_ERROR_HANDLER_INTERFACE_HPP
1818
#define IOX_HOOFS_REPORTING_ERROR_REPORTING_CUSTOM_ERROR_HANDLER_INTERFACE_HPP
1919

20-
#include "iox/error_reporting/errors.hpp"
2120
#include "iox/error_reporting/source_location.hpp"
2221
#include "iox/error_reporting/types.hpp"
22+
#include "iox/error_reporting/violation.hpp"
2323

2424
namespace iox
2525
{

0 commit comments

Comments
 (0)