Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions include/log/catalog/mipi_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,20 @@ template <packer P> struct builder<defn::catalog_msg_t, P> {
template <auto Level, typename... Ts>
static auto build(string_id id, module_id m, Ts... args) {
using namespace msg;
if constexpr ((0 + ... + sizeof(Ts)) <= sizeof(std::uint32_t) * 2) {
constexpr auto payload_size =
(sizeof(id) + ... + sizeof(typename P::template pack_as_t<Ts>));
if constexpr (payload_size <= sizeof(uint32_t) * 3) {
constexpr auto header_size =
defn::catalog_msg_t::size<std::uint32_t>::value;
constexpr auto payload_size =
stdx::sized8{(sizeof(id) + ... +
sizeof(typename P::template pack_as_t<Ts>))}
.in<std::uint32_t>();
using storage_t =
std::array<std::uint32_t, header_size + payload_size>;
std::array<std::uint32_t,
header_size +
stdx::sized8{payload_size}.in<std::uint32_t>()>;
return catalog_builder<storage_t, P>{}.template build<Level>(
id, m, args...);
} else {
constexpr auto header_size =
defn::catalog_msg_t::size<std::uint8_t>::value;
constexpr auto payload_size =
(sizeof(id) + ... + sizeof(typename P::template pack_as_t<Ts>));
using storage_t =
std::array<std::uint8_t, header_size + payload_size>;
return catalog_builder<storage_t, P>{}.template build<Level>(
Expand Down
11 changes: 11 additions & 0 deletions test/log/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ TEST_CASE("log more than two arguments", "[mipi]") {
}
}

TEST_CASE("log more than two arguments whose size fits in two uint32_ts",
"[mipi]") {
CIB_LOG_ENV(logging::get_level, logging::level::TRACE);
test_critical_section::count = 0;
auto cfg = logging::binary::config{
test_log_buf_destination<logging::level::TRACE, log_env, 42u, 'a', 'b',
'c'>{}};
cfg.logger.log_msg<log_env>(stdx::ct_format<"{} {} {}">('a', 'b', 'c'));
CHECK(test_critical_section::count == 2);
}

TEST_CASE("log to multiple destinations", "[mipi]") {
CIB_LOG_ENV(logging::get_level, logging::level::TRACE);
test_critical_section::count = 0;
Expand Down
Loading