Skip to content

Commit 671db77

Browse files
committed
[#493] Added Functional Safety Features documentation in C++ README.md
1 parent 87f93ab commit 671db77

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

compiler/extensions/cpp/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,80 @@ For a **quick start** see the [C++ Tutorial](https://github.com/ndsev/zserio-tut
66

77
For an **API documentation** see the [C++ Runtime Library](https://zserio.org/doc/runtime/latest/cpp).
88

9+
## Functional Safety Features
10+
11+
### C++ Runtime Library
12+
13+
The following describes features which minimize the risk of Zserio C++ runtime library malfunctioning behavior:
14+
15+
- Supported compilers (minimum versions): gcc 5.4.0, clang 8, MinGW 5.4.0, MSVC 2017
16+
- Warnings are treaded as errors for all supported compilers
17+
- All features are properly tested by unit tests for all supported compilers (>600 tests)
18+
- Implemented automatic check of test coverage threshold with the for
19+
[clang](https://zserio.org/doc/runtime/latest/cpp/coverage/clang/index.html) builds (>98%)
20+
- AddressSanitizer is run with no findings
21+
- UndefinedBehaviourSanitizer is run with no findings
22+
- C++ runtime library sources are checked by static analysis tool clang-tidy version 14
23+
24+
#### Clang-tidy Usage
25+
26+
Clang-tidy tool is run using [this configuration](https://github.com/ndsev/zserio/blob/master/compiler/extensions/cpp/runtime/ClangTidyConfig.txt).
27+
The clang-tidy report from the latest C++ runtime library is available [here](https://zserio.org/doc/runtime/latest/cpp/clang-tidy/clang-tidy-report.txt).
28+
29+
Because C++ runtime library is very low level (e.g. it mimic `std::span` or `std::string_view` standard
30+
abstraction from C++17), it was not possible to fix all clang-tidy findings.
31+
32+
Therefore all clang-tidy findings have been carefully checked and filtered out using definitions in clang-tidy
33+
[suppression file](https://github.com/ndsev/zserio/blob/master/compiler/extensions/cpp/runtime/ClangTidySuppressions.txt).
34+
This suppression file contains as well the brief reasoning why these findings cannot be fixed. This solution
35+
with suppression file has been chosen not to pollute C++ runtime sources with `// NOLINT` comments and to
36+
allow implementation of warnings-as-error feature. The clang-tidy suppression file is automatically used
37+
during compilation using `CMake`.
38+
39+
40+
### C++ Generated Code
41+
42+
The following describes features which minimize the risk of Zserio C++ generated code malfunctioning behavior:
43+
44+
- Supported compilers (minimum versions): gcc 5.4.0, clang 8, MinGW 5.4.0, MSVC 2017
45+
- Warnings are treaded as errors for all supported compilers
46+
- All features are properly tested by unit tests for all supported compilers (>1700 tests)
47+
- Generated C++ sources are checked by static analysis tool clang-tidy version 14 using
48+
[this configuration](https://github.com/ndsev/zserio/blob/master/compiler/extensions/cpp/runtime/ClangTidyConfig.txt)
49+
50+
### Exceptions
51+
52+
Zserio C++ runtime library together with the C++ generated code can throw a `zserio::CppRuntimeException` in
53+
some rare circumstances, mainly
54+
55+
- during parsing (reading)
56+
- during writing
57+
- in reflection code
58+
- in type info code
59+
60+
Because there are hundreds possibilities when exception `zserio::CppRuntimeException` can be thrown, the
61+
following section contains only description of exceptions during parsing.
62+
63+
#### Exceptions During Parsing
64+
65+
The following table describes all possibilities when C++ generated code can throw
66+
a `zserio::CppRuntimeException` during parsing of binary data:
67+
68+
| Module | Method | Exception Message | Description |
69+
| ------ | ------ | ----------------- | ----------- |
70+
| `BitStreamReader.cpp` | constructor | "BitStreamReader: Buffer size exceeded limit '[MAX_BUFFER_SIZE]' bytes!" | Throws if provided buffer is bigger that 536870908 bytes (cca 511MB) on 32-bit OS or 2**64/8-4 bytes on 64-bit OS. |
71+
| `BitStreamReader.cpp` | constructor | "BitStreamReader: Wrong buffer bit size ('[BUFFER_SIZE]' < '[SPECIFIED_BYTE_SIZE]')!" | Throws if provided buffer is smaller than specified bit size. This could happen only in case of wrong arguments. |
72+
| `BitStreamReader.cpp` | `throwNumBitsIsNotValid()` | "BitStreamReader: ReadBits #[NUM_BITS] is not valid, reading from stream failed!" | Throws if `readBits()`, `readSignedBits()`, `readBits64()` or `readSignedBits64()` has been called with wrong (too big) `numBits` argument. This could happen only in case of data inconsistency, e.g. if dynamic bit field has length bigger than 32 or 64 bits respectively. |
73+
| `BitStreamReader.cpp` | `throwEof()` | "BitStreamReader: Reached eof(), reading from stream failed!" | Throws if end of underlying buffer has been reached (reading beyond stream). This could happen only in case of data inconsistency, e.g. if array length is defined bigger than is actually stored in the stream). |
74+
| `BitStreamReader.cpp` | `readVarSize()` | "BitStreamReader: Read value '[VARSIZE_VALUE]' is out of range for varsize type!" | Throws if `varsize` value stored in stream is bigger than 2147483647. This could happen only in case of data inconsistency when `varsize` value stored in the stream is wrong. |
75+
| `OptionalHolder.h` | `throwNonPresentException()` | "Trying to access value of non-present optional field!" | Throws if optional value is not present during access. This could happen only in case of data inconsistency when optional field is not present in the stream and there is a reference to it in some expression. |
76+
| Generated Sources | Object read constructor | "Read: Wrong offset for field [COMPOUND_NAME].[FIELD_NAME]: [STREAM_BYTE_POSITION] != [OFFSET_VALUE]!" | Throws in case of wrong offset. This could happen only in case of data inconsistency when offset value stored in the stream is wrong. |
77+
| Generated Sources | Object read constructor | "Read: Constraint violated at [COMPOUND_NAME].[FIELD_NAME]!" | Throws in case of wrong constraint. This could happen only in case of data inconsistency when some constraint is violated. |
78+
| Generated Sources | Object read constructor | "No match in choice [NAME]!" | Throws in case of wrong choice selector. This could happen only in case of data inconsistency when choice selector stored in the stream is wrong. |
79+
| Generated Sources | Object read constructor | "No match in union [NAME]!" | Throws in case of wrong union tag. This could happen only in case of data inconsistency when union tag stored in the stream is wrong. |
80+
| Generated Sources | Bitmask constructor | "Value for bitmask [NAME] out of bounds: [VALUE]!" | Throws if value stored in stream is bigger than bitmask upper bound. This could happen only in case of data inconsistency when bitmask value stored in the stream is wrong. |
81+
| Generated Sources | `valueToEnum` | "Unknown value for enumeration [NAME]: [VALUE]!" | Throws in case of unknown enumeration value. This could happen only in case of data inconsistency when enumeration value stored in the stream is wrong. |
82+
983
## Compatibility check
1084

1185
C++ generator honors the `zserio_compatibility_version` specified in the schema. However note that only

0 commit comments

Comments
 (0)