From d8ab934c3c1383cfa7f9067ab9297879a0983e6d Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Mon, 9 Sep 2024 13:41:12 +0200 Subject: [PATCH] fix ur_bool_t printing Bool values were printed as ascii characters 0 or 1, leading to artifacts. This patch fixes this by printing either 'false' or 'true', depending on the bool's value. This has been annoying me a while when analyzing logs from SYCL apps. --- include/ur_print.hpp | 5 +++++ scripts/templates/print.hpp.mako | 5 +++++ test/unit/utils/params.cpp | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/ur_print.hpp b/include/ur_print.hpp index f71cc12b32..681e8e814d 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -17403,6 +17403,11 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct return os; } +inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const ur_bool_t value) { + os << (value ? "true" : "false"); + return os; +} + namespace ur::details { /////////////////////////////////////////////////////////////////////////////// // @brief Print pointer value diff --git a/scripts/templates/print.hpp.mako b/scripts/templates/print.hpp.mako index 9bf427b889..4180231ea4 100644 --- a/scripts/templates/print.hpp.mako +++ b/scripts/templates/print.hpp.mako @@ -411,6 +411,11 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct %endfor %endfor +inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const ur_bool_t value) { + os << (value ? "true" : "false"); + return os; +} + namespace ${x}::details { /////////////////////////////////////////////////////////////////////////////// // @brief Print pointer value diff --git a/test/unit/utils/params.cpp b/test/unit/utils/params.cpp index c456f69795..e86181344c 100644 --- a/test/unit/utils/params.cpp +++ b/test/unit/utils/params.cpp @@ -27,3 +27,17 @@ TEST(PrintPtr, nested_void_ptrs) { ur::details::printPtr(out, pppreal); EXPECT_THAT(out.str(), MatchesRegex(".+ \\(.+ \\(.+ \\(.+\\)\\)\\)")); } + +TEST(PrintBool, False) { + ur_bool_t value = false; + std::ostringstream out; + out << value; + EXPECT_STREQ(out.str().data(), "false"); +} + +TEST(PrintBool, True) { + ur_bool_t value = 1; + std::ostringstream out; + out << value; + EXPECT_STREQ(out.str().data(), "true"); +}