Skip to content

Commit

Permalink
#8379: fixed tt_assert_message
Browse files Browse the repository at this point in the history
  • Loading branch information
arakhmati committed May 10, 2024
1 parent a1f4578 commit 334fc76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void CheckHostSanitization(Device *device) {
try {
llrt::read_hex_vec_from_core(device->id(), core, addr, sz_bytes);
} catch (std::runtime_error& e) {
const string expected = "Host watcher: bad {} NOC coord {}\nread\n" + core.str();
const string expected = fmt::format("Host watcher: bad {} NOC coord {}\n", "read", core.str());
const string error = string(e.what());
log_info(tt::LogTest, "Caught exception (one is expected in this test)");
EXPECT_TRUE(error.find(expected) != string::npos);
Expand Down
25 changes: 20 additions & 5 deletions tt_metal/common/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,27 @@ inline std::string backtrace_to_string(int size = 64, int skip = 2, const std::s
return ss.str();
}

inline void tt_assert_message(std::ostream& os) {}
template <typename... Ts>
void tt_assert_message(std::ostream& os, Ts const&... ts) {
std::string fmt;
for (int i = 0; i < sizeof...(ts); i++) {
fmt += "{} ";
}
log_fatal(fmt.c_str(), ts...);
os << fmt::format(fmt, ts...);
os << std::endl;
}

template <typename T, typename... Ts>
void tt_assert_message(std::ostream& os, T const& t, Ts const&... ts) {
os << fmt::format("{}", t) << std::endl;
tt_assert_message(os, ts...);
template <typename... Ts>
void tt_assert_message(std::ostream& os, const char* t, Ts const&... ts) {
os << fmt::format(t, ts...);
os << std::endl;
}

template <typename... Ts>
void tt_assert_message(std::ostream& os, const std::string& t, Ts const&... ts) {
os << fmt::format(t, ts...);
os << std::endl;
}

template <typename... Ts>
Expand Down

0 comments on commit 334fc76

Please sign in to comment.