Skip to content

Add QNX logging wrapper and update SlogCode/SlogSeverity enums#344

Open
Muhammad-Hussein-Morsy wants to merge 1 commit into
eclipse-score:mainfrom
Muhammad-Hussein-Morsy:mumo_slog2_osal_wrapper
Open

Add QNX logging wrapper and update SlogCode/SlogSeverity enums#344
Muhammad-Hussein-Morsy wants to merge 1 commit into
eclipse-score:mainfrom
Muhammad-Hussein-Morsy:mumo_slog2_osal_wrapper

Conversation

@Muhammad-Hussein-Morsy

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

@4og 4og added the comp-osal Related to score/os component label Jul 7, 2026
Comment thread score/os/qnx/slog2.h Outdated
/// @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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread score/os/qnx/slog2.cpp Outdated
}

// coverity[autosar_cpp14_a8_4_1_violation]: Required for wrapper method
score::cpp::expected<std::int32_t, score::os::Error> slogf(const SlogCode code,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ins separate classes rather than the slog2 facility

Comment thread score/os/qnx/slog2.cpp Outdated
// 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread score/os/qnx/slog2.h
Slog2(Slog2&& other) = delete;
Slog2& operator=(Slog2&& other) = delete;

};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Unit tests provided.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread score/os/qnx/slog.h
/// @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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because of slogf, a new Slog class is created. Is it really necessary for this ?
Why couldnt you reuse the slog2 implementation ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread score/os/mocklib/qnx/mock_slog.cpp Outdated
va_start(args, format);

std::string message{};
message.resize(message_length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guarded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-osal Related to score/os component

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants