Add QNX logging wrapper and update SlogCode/SlogSeverity enums#344
Add QNX logging wrapper and update SlogCode/SlogSeverity enums#344Muhammad-Hussein-Morsy wants to merge 1 commit into
Conversation
|
The created documentation from the pull request is available at: docu-html |
| /// @param format Printf-style format string | ||
| /// @param ... Format arguments | ||
| /// @return The number of bytes written on success, or an Error on failure. | ||
| score::cpp::expected<std::int32_t, score::os::Error> slogf(const SlogCode code, |
There was a problem hiding this comment.
The code is not following the given design.
bIt Breaks the OSAL mock/testability design (architectural).
Every other wrapper in this file (slog2_register, slog2c, slog2f, …) is a virtual member of the Slog2 abstract base, implemented in Slog2Impl — precisely so it can be faked/mocked in unit tests. The new slogf is a free function calling ::slogf() directly, so it is unmockable and inconsistent with the entire layer. It should be a virtual method on Slog2 + override in Slog2Impl (+ the corresponding mock), matching slog2f.
There was a problem hiding this comment.
Done. slogf now is a virtual a pure-virtual function of new slog interface and can be mocked via the provided mock and the free func got removed
| } | ||
|
|
||
| // coverity[autosar_cpp14_a8_4_1_violation]: Required for wrapper method | ||
| score::cpp::expected<std::int32_t, score::os::Error> slogf(const SlogCode code, |
There was a problem hiding this comment.
Mixing two different QNX logging subsystems in a class named Slog2.
Slog2 wraps the slogger2 API (<sys/slog2.h>: slog2f, slog2c). The new code wraps the legacy slog API (<sys/slog.h> / <sys/slogcodes.h>: ::slogf, _SLOGC_NETWORK, SLOG*). These are distinct facilities with distinct code/severity macro sets. Putting legacy-slog enums and a legacy slogf wrapper inside the Slog2 (slogger2) header is confusing and conflates concerns. Clarify intent — if legacy slogf is genuinely needed, consider a separate Slog/slogf wrapper unit rather than overloading Slog2.
There was a problem hiding this comment.
Done ins separate classes rather than the slog2 facility
| // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) fixed-size stack buffer for embedded-friendly logging | ||
| char buffer[kMaxLogMessageSize]; | ||
| // NOLINTNEXTLINE(*array-decay, *pro-type-vararg,*array-to-pointer-decay) see comment above | ||
| std::vsnprintf(buffer, sizeof(buffer), format, args); |
There was a problem hiding this comment.
std::vsnprintf return value ignored → possible use of indeterminate buffer.
char buffer[kMaxLogMessageSize]; is uninitialized. std::vsnprintf returns a negative value on encoding error; the code ignores it and unconditionally passes buffer to ::slogf(..., "%s", buffer). On error the buffer is indeterminate. Check the return: < 0 → return an error (and/or zero-initialize the buffer).
There was a problem hiding this comment.
Fixed
| Slog2(Slog2&& other) = delete; | ||
| Slog2& operator=(Slog2&& other) = delete; | ||
|
|
||
| }; |
455d72f to
398723f
Compare
675e3a7 to
507cc2d
Compare
507cc2d to
79fb324
Compare
0a7f8fd to
79fb324
Compare
79fb324 to
e1ded59
Compare
e1ded59 to
a9914f5
Compare
a9914f5 to
147e901
Compare
147e901 to
e897513
Compare
e897513 to
e389c9c
Compare
| /// @param format Printf-style format string | ||
| /// @param ... Format arguments | ||
| /// @return The number of bytes written on success, or an Error on failure. | ||
| virtual score::cpp::expected<std::int32_t, score::os::Error> slogf(const SlogCode code, |
There was a problem hiding this comment.
Just because of slogf, a new Slog class is created. Is it really necessary for this ?
Why couldnt you reuse the slog2 implementation ?
There was a problem hiding this comment.
Currently we are using slogf in tracing infra and migration to slog2 would require new activities, discussions to be done with the tracing team first
| va_start(args, format); | ||
|
|
||
| std::string message{}; | ||
| message.resize(message_length); |
There was a problem hiding this comment.
negative vsnprintf not handled in a noexcept function
slogf here is noexcept, so a throwing resize calls std::terminate. The production SlogImpl guards formatted < 0, but the mock does not. Add the same guard (return make_unexpected / empty message) before resize. Test-only, but it's a real crash path and inconsistent with the impl it mirrors.
There was a problem hiding this comment.
Guarded
e389c9c to
4dfb7a6
Compare
4dfb7a6 to
7811f51
Compare
No description provided.