diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f267b7725c..8de2332df5 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -29,6 +29,9 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/ ### Fixed - Added a guard for sidre-related mint API usage in a quest example +- Removed `std::ends` usage from `SLIC_ASSERT`,`SLIC_ASSERT_MSG`,`SLIC_CHECK`, + and `SLIC_CHECK_MSG` macros that prevented Lumberjack from combining + messages. ## [Version 0.10.0] - Release date 2024-09-27 diff --git a/src/axom/core/utilities/FileUtilities.hpp b/src/axom/core/utilities/FileUtilities.hpp index 48a38666db..9f70620ab5 100644 --- a/src/axom/core/utilities/FileUtilities.hpp +++ b/src/axom/core/utilities/FileUtilities.hpp @@ -88,6 +88,11 @@ void getDirName(std::string& dir, const std::string& path); * \param filename The name of the file. * \return 0 on success, -1 on failure. errno can obtain more information * about the failure. + * + * \note On Windows, this function calls _unlink() and will fail if there are + * any open file handles to the specified file. + * On Linux, this function calls unlink() and will succeed even if + * there are open file handles to the specified file. */ int removeFile(const std::string& filename); diff --git a/src/axom/slic/interface/slic_macros.hpp b/src/axom/slic/interface/slic_macros.hpp index 4086deae7c..58d3485fc8 100644 --- a/src/axom/slic/interface/slic_macros.hpp +++ b/src/axom/slic/interface/slic_macros.hpp @@ -339,7 +339,7 @@ if(!(EXP)) \ { \ std::ostringstream __oss; \ - __oss << "Failed Assert: " << #EXP << std::ends; \ + __oss << "Failed Assert: " << #EXP; \ axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ if(axom::slic::isAbortOnErrorsEnabled()) \ { \ @@ -365,19 +365,19 @@ * \endcode * */ - #define SLIC_ASSERT_MSG(EXP, msg) \ - do \ - { \ - if(!(EXP)) \ - { \ - std::ostringstream __oss; \ - __oss << "Failed Assert: " << #EXP << std::endl << msg << std::ends; \ - axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ - if(axom::slic::isAbortOnErrorsEnabled()) \ - { \ - axom::slic::abort(); \ - } \ - } \ + #define SLIC_ASSERT_MSG(EXP, msg) \ + do \ + { \ + if(!(EXP)) \ + { \ + std::ostringstream __oss; \ + __oss << "Failed Assert: " << #EXP << std::endl << msg; \ + axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ + if(axom::slic::isAbortOnErrorsEnabled()) \ + { \ + axom::slic::abort(); \ + } \ + } \ } while(axom::slic::detail::false_value) ///@} @@ -427,7 +427,7 @@ if(!(EXP)) \ { \ std::ostringstream __oss; \ - __oss << "Failed Check: " << #EXP << std::ends; \ + __oss << "Failed Check: " << #EXP; \ if(axom::slic::debug::checksAreErrors) \ { \ axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ @@ -463,30 +463,30 @@ * \endcode * */ - #define SLIC_CHECK_MSG(EXP, msg) \ - do \ - { \ - if(!(EXP)) \ - { \ - std::ostringstream __oss; \ - __oss << "Failed Check: " << #EXP << std::endl << msg << std::ends; \ - if(axom::slic::debug::checksAreErrors) \ - { \ - axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ - if(axom::slic::isAbortOnErrorsEnabled()) \ - { \ - axom::slic::abort(); \ - } \ - } \ - else \ - { \ - axom::slic::logWarningMessage(__oss.str(), __FILE__, __LINE__); \ - if(axom::slic::isAbortOnWarningsEnabled()) \ - { \ - axom::slic::abort(); \ - } \ - } \ - } \ + #define SLIC_CHECK_MSG(EXP, msg) \ + do \ + { \ + if(!(EXP)) \ + { \ + std::ostringstream __oss; \ + __oss << "Failed Check: " << #EXP << std::endl << msg; \ + if(axom::slic::debug::checksAreErrors) \ + { \ + axom::slic::logErrorMessage(__oss.str(), __FILE__, __LINE__); \ + if(axom::slic::isAbortOnErrorsEnabled()) \ + { \ + axom::slic::abort(); \ + } \ + } \ + else \ + { \ + axom::slic::logWarningMessage(__oss.str(), __FILE__, __LINE__); \ + if(axom::slic::isAbortOnWarningsEnabled()) \ + { \ + axom::slic::abort(); \ + } \ + } \ + } \ } while(axom::slic::detail::false_value) /// @} diff --git a/src/axom/slic/tests/slic_macros.cpp b/src/axom/slic/tests/slic_macros.cpp index 620a5f37b2..6bf45e97a5 100644 --- a/src/axom/slic/tests/slic_macros.cpp +++ b/src/axom/slic/tests/slic_macros.cpp @@ -101,6 +101,8 @@ void check_line(const std::string& msg, int expected_line) size_t start = msg.rfind("@@") + 2; std::string l = msg.substr(start); const int line = std::stoi(l); + + // expected value is the line number of the SLIC message EXPECT_EQ(line, expected_line); } @@ -122,24 +124,28 @@ void check_tag(const std::string& msg, const std::string& expected_tag) //------------------------------------------------------------------------------ TEST(slic_macros, test_error_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_ERROR("test error message"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "test error message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); SLIC_ERROR_IF(false, "this message should not be logged!"); EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_ERROR_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); // Check selective filtering based on root == false @@ -150,11 +156,12 @@ TEST(slic_macros, test_error_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_ERROR_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); // is root, but conditional is false -> no message @@ -171,24 +178,28 @@ TEST(slic_macros, test_error_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_warning_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_WARNING("test warning message"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "test warning message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); SLIC_WARNING_IF(false, "this message should not be logged!"); EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_WARNING_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); // Check selective filtering based on root == false @@ -199,11 +210,12 @@ TEST(slic_macros, test_warning_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_WARNING_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); // is root, but conditional is false -> no message @@ -220,24 +232,28 @@ TEST(slic_macros, test_warning_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_info_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_INFO("test info message"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "test info message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), __LINE__ - 5); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); SLIC_INFO_IF(false, "this message should not be logged!"); EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_INFO_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 5)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); // is root, but conditional is false -> no message @@ -254,14 +270,17 @@ TEST(slic_macros, test_info_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_debug_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_DEBUG("test debug message"); + expected_line_number = __LINE__ - 1; #ifdef AXOM_DEBUG EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "test debug message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 6)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_DEBUG macros only log messages when AXOM_DEBUG is defined @@ -272,12 +291,13 @@ TEST(slic_macros, test_debug_macros) EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_DEBUG_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; #ifdef AXOM_DEBUG EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 6)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_DEBUG macros only log messages when AXOM_DEBUG is defined @@ -292,12 +312,13 @@ TEST(slic_macros, test_debug_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_DEBUG_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; #ifdef AXOM_DEBUG EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 6)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_DEBUG macros only log messages when AXOM_DEBUG is defined @@ -318,16 +339,18 @@ TEST(slic_macros, test_debug_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_assert_macros) { + int expected_line_number; EXPECT_TRUE(slic::internal::is_stream_empty()); constexpr int val = 42; SLIC_ASSERT(val < 0); + expected_line_number = __LINE__ - 1; #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 6)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_ASSERT macros only log messages when AXOM_DEBUG is defined @@ -339,13 +362,14 @@ TEST(slic_macros, test_assert_macros) EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_ASSERT_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 7)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_ASSERT macros only log messages when AXOM_DEBUG is defined @@ -357,16 +381,18 @@ TEST(slic_macros, test_assert_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_check_macros) { + int expected_line_number; EXPECT_TRUE(slic::internal::is_stream_empty()); constexpr int val = 42; SLIC_CHECK(val < 0); + expected_line_number = __LINE__ - 1; #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 6)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_CHECK macros only log messages when AXOM_DEBUG is defined @@ -378,13 +404,14 @@ TEST(slic_macros, test_check_macros) EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_CHECK_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 7)); + check_line(slic::internal::test_stream.str(), expected_line_number); slic::internal::clear(); #else // SLIC_CHECK macros only log messages when AXOM_DEBUG is defined @@ -396,13 +423,16 @@ TEST(slic_macros, test_check_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_tagged_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::is_stream_empty()); SLIC_INFO_TAGGED("test tagged info message", "myTag"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(slic::internal::is_stream_empty()); check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "test tagged info message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), __LINE__ - 5); + check_line(slic::internal::test_stream.str(), expected_line_number); check_tag(slic::internal::test_stream.str(), "myTag"); slic::internal::clear(); @@ -416,6 +446,8 @@ TEST(slic_macros, test_tagged_macros) //------------------------------------------------------------------------------ TEST(slic_macros, test_macros_file_output) { + int expected_line_number; + std::string msgfmt = ""; // GenericOutputStream(std::string stream) and @@ -438,6 +470,7 @@ TEST(slic_macros, test_macros_file_output) // message is buffered but not yet flushed, no files created SLIC_INFO("Test"); + expected_line_number = __LINE__ - 1; EXPECT_FALSE(axom::utilities::filesystem::pathExists(no_fmt)); EXPECT_FALSE(axom::utilities::filesystem::pathExists(with_fmt)); @@ -456,7 +489,8 @@ TEST(slic_macros, test_macros_file_output) std::string no_fmt_expected; no_fmt_expected += "*****\n[INFO]\n\n Test \n\n "; no_fmt_expected += __FILE__; - no_fmt_expected += "\n440\n****\n"; + no_fmt_expected += "\n" + std::to_string(expected_line_number); + no_fmt_expected += "\n****\n"; EXPECT_EQ(no_fmt_buffer.str(), no_fmt_expected); diff --git a/src/axom/slic/tests/slic_macros_parallel.cpp b/src/axom/slic/tests/slic_macros_parallel.cpp index e9b7db50d9..7daf47518e 100644 --- a/src/axom/slic/tests/slic_macros_parallel.cpp +++ b/src/axom/slic/tests/slic_macros_parallel.cpp @@ -83,6 +83,18 @@ void check_msg(const std::string& msg, const std::string& expected_message) { EXPECT_FALSE(msg.empty()); + // message is output only once (combining successful for LumberjackStream) + int count = 0; + size_t pos = 0; + + while((pos = msg.find(expected_message, pos)) != std::string::npos) + { + count++; + pos += expected_message.length(); + } + + EXPECT_EQ(count, 1); + // extract message size_t start = msg.find(";;") + 2; size_t end = expected_message.length(); @@ -117,6 +129,8 @@ void check_line(const std::string& msg, int expected_line) size_t start = msg.rfind("@@") + 2; std::string l = msg.substr(start); const int line = std::stoi(l); + + // expected value is the line number of the SLIC message EXPECT_EQ(line, expected_line); } @@ -131,6 +145,50 @@ void check_tag(const std::string& msg, const std::string& expected_tag) EXPECT_EQ(tag, expected_tag); } +//------------------------------------------------------------------------------ +void check_rank(const std::string& msg, int expected_rank) +{ + EXPECT_FALSE(msg.empty()); + + // extract rank + size_t start = msg.rfind("$$") + 2; + size_t end = msg.rfind("&&"); + std::string ranks_string = msg.substr(start, end - start); + + EXPECT_TRUE(ranks_string.find(std::to_string(expected_rank)) != + std::string::npos); +} + +//------------------------------------------------------------------------------ +void check_ranks(const std::string& msg, int expected_ranks) +{ + // Check all ranks from [0, expected_ranks) are in message + for(int i = 0; i < expected_ranks; i++) + { + check_rank(msg, i); + } +} + +//------------------------------------------------------------------------------ +void check_rank_count(const std::string& msg, + const std::string& streamType, + int expected_rank_count) +{ + EXPECT_FALSE(msg.empty()); + + // Always 1 for SynchronizedStream + if(streamType == "Synchronized") + { + expected_rank_count = 1; + } + + // extract rank + size_t start = msg.rfind("&&") + 2; + std::string rc = msg.substr(start); + const int rank_count = std::stoi(rc); + EXPECT_EQ(rank_count, expected_rank_count); +} + //------------------------------------------------------------------------------ bool has_aborted = false; void custom_abort_function() { has_aborted = true; } @@ -160,11 +218,6 @@ class SlicMacrosParallel : public ::testing::TestWithParam slic::setLoggingMsgLevel(slic::message::Debug); slic::disableAbortOnError(); /* disable abort for testing purposes */ - std::string msgfmt = "[]:;;;;\n@@\n@@"; - - std::string msgtagfmt = - "[]:;;;;\n##\n@@\n@@"; - if(stream_type == "Lumberjack") { slic::addStreamToAllMsgLevels( @@ -203,6 +256,13 @@ class SlicMacrosParallel : public ::testing::TestWithParam int rank; int nranks; const int RLIMIT = 8; + + const std::string msgfmt = + "[]:;;;;\n@@\n@@\n$$\n&&"; + + const std::string msgtagfmt = + "[]:;;;;\n##\n@@\n@@\n$$\n&&"; }; //------------------------------------------------------------------------------ @@ -210,8 +270,11 @@ class SlicMacrosParallel : public ::testing::TestWithParam //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_error_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_ERROR("test error message"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -219,7 +282,16 @@ TEST_P(SlicMacrosParallel, test_error_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "test error message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -228,6 +300,7 @@ TEST_P(SlicMacrosParallel, test_error_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_ERROR_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -235,7 +308,16 @@ TEST_P(SlicMacrosParallel, test_error_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -248,6 +330,7 @@ TEST_P(SlicMacrosParallel, test_error_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_ERROR_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -255,7 +338,16 @@ TEST_P(SlicMacrosParallel, test_error_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -274,6 +366,7 @@ TEST_P(SlicMacrosParallel, test_error_macros) // Check for one rank being root axom::slic::setIsRoot(rank == 0); SLIC_ERROR_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(rank == 0) { @@ -281,7 +374,9 @@ TEST_P(SlicMacrosParallel, test_error_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); } else { @@ -292,6 +387,7 @@ TEST_P(SlicMacrosParallel, test_error_macros) // Check for more than one rank being root for SynchronizedStream axom::slic::setIsRoot((rank % 2) == 0); SLIC_ERROR_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(((rank % 2) == 0 && GetParam() == "Synchronized") || (rank == 0 && GetParam() == "Lumberjack")) @@ -300,7 +396,21 @@ TEST_P(SlicMacrosParallel, test_error_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + for(int i = 0; i < nranks; i += 2) + { + check_rank(slic::internal::test_stream.str(), i); + } + } + check_rank_count(slic::internal::test_stream.str(), + GetParam(), + (nranks / 2) + (nranks % 2)); } else { @@ -312,8 +422,11 @@ TEST_P(SlicMacrosParallel, test_error_macros) //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_warning_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_WARNING("test warning message"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -321,7 +434,16 @@ TEST_P(SlicMacrosParallel, test_warning_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "test warning message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -330,6 +452,7 @@ TEST_P(SlicMacrosParallel, test_warning_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_WARNING_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -337,7 +460,16 @@ TEST_P(SlicMacrosParallel, test_warning_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -350,6 +482,7 @@ TEST_P(SlicMacrosParallel, test_warning_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_WARNING_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -357,7 +490,16 @@ TEST_P(SlicMacrosParallel, test_warning_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -376,6 +518,7 @@ TEST_P(SlicMacrosParallel, test_warning_macros) // Check for one rank being root axom::slic::setIsRoot(rank == 0); SLIC_WARNING_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(rank == 0) { @@ -383,7 +526,9 @@ TEST_P(SlicMacrosParallel, test_warning_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); } else { @@ -394,6 +539,7 @@ TEST_P(SlicMacrosParallel, test_warning_macros) // Check for more than one rank being root for SynchronizedStream axom::slic::setIsRoot((rank % 2) == 0); SLIC_WARNING_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(((rank % 2) == 0 && GetParam() == "Synchronized") || (rank == 0 && GetParam() == "Lumberjack")) @@ -402,7 +548,21 @@ TEST_P(SlicMacrosParallel, test_warning_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + for(int i = 0; i < nranks; i += 2) + { + check_rank(slic::internal::test_stream.str(), i); + } + } + check_rank_count(slic::internal::test_stream.str(), + GetParam(), + (nranks / 2) + (nranks % 2)); } else { @@ -414,8 +574,12 @@ TEST_P(SlicMacrosParallel, test_warning_macros) //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_info_macros) { + int expected_line_number; + int expected_tag_number; + EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_INFO("test info message"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -423,11 +587,21 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "test info message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), __LINE__ - 8); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); SLIC_INFO_TAGGED("test tagged info message", "myTag"); + expected_tag_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -435,14 +609,25 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_tag_stream.str(), "INFO"); check_msg(slic::internal::test_tag_stream.str(), "test tagged info message"); check_file(slic::internal::test_tag_stream.str()); - check_line(slic::internal::test_tag_stream.str(), __LINE__ - 8); + check_line(slic::internal::test_tag_stream.str(), expected_tag_number); check_tag(slic::internal::test_tag_stream.str(), "myTag"); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_tag_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_tag_stream.str(), nranks); + } + check_rank_count(slic::internal::test_tag_stream.str(), GetParam(), nranks); EXPECT_TRUE(slic::internal::is_stream_empty()); } slic::internal::clear_streams(); SLIC_INFO("test info message only for normal message-level stream"); + expected_line_number = __LINE__ - 1; SLIC_INFO_TAGGED("test tagged info message only for tagged stream", "myTag"); + expected_tag_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -451,15 +636,33 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_msg(slic::internal::test_stream.str(), "test info message only for normal message-level stream"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), __LINE__ - 10); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); EXPECT_FALSE(slic::internal::is_tag_stream_empty()); check_level(slic::internal::test_tag_stream.str(), "INFO"); check_msg(slic::internal::test_tag_stream.str(), "test tagged info message only for tagged stream"); check_file(slic::internal::test_tag_stream.str()); - check_line(slic::internal::test_tag_stream.str(), __LINE__ - 16); + check_line(slic::internal::test_tag_stream.str(), expected_tag_number); check_tag(slic::internal::test_tag_stream.str(), "myTag"); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_tag_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_tag_stream.str(), nranks); + } + check_rank_count(slic::internal::test_tag_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -476,6 +679,7 @@ TEST_P(SlicMacrosParallel, test_info_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_INFO_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -483,7 +687,16 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -496,6 +709,7 @@ TEST_P(SlicMacrosParallel, test_info_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_INFO_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) { @@ -503,7 +717,16 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); @@ -522,6 +745,7 @@ TEST_P(SlicMacrosParallel, test_info_macros) // Check for one rank being root axom::slic::setIsRoot(rank == 0); SLIC_INFO_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(rank == 0) { @@ -529,7 +753,9 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); } else { @@ -540,6 +766,7 @@ TEST_P(SlicMacrosParallel, test_info_macros) // Check for more than one rank being root axom::slic::setIsRoot((rank % 2) == 0); SLIC_INFO_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); if(((rank % 2) == 0 && GetParam() == "Synchronized") || (rank == 0 && GetParam() == "Lumberjack")) @@ -548,7 +775,21 @@ TEST_P(SlicMacrosParallel, test_info_macros) check_level(slic::internal::test_stream.str(), "INFO"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + for(int i = 0; i < nranks; i += 2) + { + check_rank(slic::internal::test_stream.str(), i); + } + } + check_rank_count(slic::internal::test_stream.str(), + GetParam(), + (nranks / 2) + (nranks % 2)); } else { @@ -560,8 +801,11 @@ TEST_P(SlicMacrosParallel, test_info_macros) //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_debug_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_DEBUG("test debug message"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #ifdef AXOM_DEBUG if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -570,7 +814,16 @@ TEST_P(SlicMacrosParallel, test_debug_macros) check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "test debug message"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -583,6 +836,7 @@ TEST_P(SlicMacrosParallel, test_debug_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_DEBUG_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #ifdef AXOM_DEBUG if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -591,7 +845,16 @@ TEST_P(SlicMacrosParallel, test_debug_macros) check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -608,6 +871,7 @@ TEST_P(SlicMacrosParallel, test_debug_macros) // Check selective filter based on root == true axom::slic::setIsRoot(true); SLIC_DEBUG_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #ifdef AXOM_DEBUG if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -616,7 +880,16 @@ TEST_P(SlicMacrosParallel, test_debug_macros) check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -639,6 +912,7 @@ TEST_P(SlicMacrosParallel, test_debug_macros) // Check for one rank being root axom::slic::setIsRoot(rank == 0); SLIC_DEBUG_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #ifdef AXOM_DEBUG if(rank == 0) @@ -647,7 +921,9 @@ TEST_P(SlicMacrosParallel, test_debug_macros) check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); } else { @@ -662,6 +938,7 @@ TEST_P(SlicMacrosParallel, test_debug_macros) // Check for more than one rank being root axom::slic::setIsRoot((rank % 2) == 0); SLIC_DEBUG_ROOT_IF(true, "this message is logged!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #ifdef AXOM_DEBUG if(((rank % 2) == 0 && GetParam() == "Synchronized") || @@ -671,7 +948,21 @@ TEST_P(SlicMacrosParallel, test_debug_macros) check_level(slic::internal::test_stream.str(), "DEBUG"); check_msg(slic::internal::test_stream.str(), "this message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 10)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + for(int i = 0; i < nranks; i += 2) + { + check_rank(slic::internal::test_stream.str(), i); + } + } + check_rank_count(slic::internal::test_stream.str(), + GetParam(), + (nranks / 2) + (nranks % 2)); } else { @@ -686,6 +977,8 @@ TEST_P(SlicMacrosParallel, test_debug_macros) TEST_P(SlicMacrosParallel, test_abort_error_macros) { + int expected_line_number; + const int NUM_ABORT_STATES = 2; slic::enableAbortOnError(); /* enable abort for testing purposes */ @@ -717,17 +1010,21 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) if(rank == i) { SLIC_ERROR("SLIC_ERROR message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "SLIC_ERROR message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 7)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); int val = rank == i ? 42 : -42; SLIC_ERROR_IF(val == 42, "SLIC_ERROR_IF message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -735,10 +1032,13 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) check_msg(slic::internal::test_stream.str(), "SLIC_ERROR_IF message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_ERROR_ROOT("SLIC_ERROR_ROOT message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -746,10 +1046,13 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) check_msg(slic::internal::test_stream.str(), "SLIC_ERROR_ROOT message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_ERROR_ROOT_IF(val == 42, "SLIC_ERROR_ROOT_IF message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -757,20 +1060,26 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) check_msg(slic::internal::test_stream.str(), "SLIC_ERROR_ROOT_IF message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_ASSERT(val < 0); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 7)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_ASSERT_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -778,7 +1087,9 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); } axom::slic::setIsRoot(true); @@ -802,6 +1113,8 @@ TEST_P(SlicMacrosParallel, test_abort_error_macros) //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_abort_warning_macros) { + int expected_line_number; + const int NUM_ABORT_STATES = 2; slic::enableAbortOnWarning(); /* enable abort for testing purposes */ @@ -833,6 +1146,7 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) if(rank == i) { SLIC_WARNING("SLIC_WARNING message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -840,11 +1154,14 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) check_msg(slic::internal::test_stream.str(), "SLIC_WARNING message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); int val = rank == i ? 42 : -42; SLIC_WARNING_IF(val == 42, "SLIC_WARNING_IF message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -852,10 +1169,13 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) check_msg(slic::internal::test_stream.str(), "SLIC_WARNING_IF message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_WARNING_ROOT("SLIC_WARNING_ROOT message is logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -863,10 +1183,13 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) check_msg(slic::internal::test_stream.str(), "SLIC_WARNING_ROOT message is logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_WARNING_ROOT_IF(val == 42, "SLIC_WARNING_ROOT_IF msg logged!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -874,20 +1197,26 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) check_msg(slic::internal::test_stream.str(), "SLIC_WARNING_ROOT_IF msg logged!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_CHECK(val < 0); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 7)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); SLIC_CHECK_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_EQ(has_aborted, abort_enabled); EXPECT_FALSE(slic::internal::are_all_streams_empty()); @@ -895,7 +1224,9 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 8)); + check_line(slic::internal::test_stream.str(), expected_line_number); + check_rank(slic::internal::test_stream.str(), rank); + check_rank_count(slic::internal::test_stream.str(), GetParam(), 1); reset_state(); } @@ -916,11 +1247,14 @@ TEST_P(SlicMacrosParallel, test_abort_warning_macros) //------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_assert_macros) { + int expected_line_number; + slic::internal::clear_streams(); EXPECT_TRUE(slic::internal::are_all_streams_empty()); constexpr int val = 42; SLIC_ASSERT(val < 0); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -929,7 +1263,16 @@ TEST_P(SlicMacrosParallel, test_assert_macros) check_level(slic::internal::test_stream.str(), "ERROR"); check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -943,6 +1286,7 @@ TEST_P(SlicMacrosParallel, test_assert_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_ASSERT_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -952,7 +1296,16 @@ TEST_P(SlicMacrosParallel, test_assert_macros) check_msg(slic::internal::test_stream.str(), "Failed Assert: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 10)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -965,10 +1318,13 @@ TEST_P(SlicMacrosParallel, test_assert_macros) // ------------------------------------------------------------------------------ TEST_P(SlicMacrosParallel, test_check_macros) { + int expected_line_number; + EXPECT_TRUE(slic::internal::are_all_streams_empty()); constexpr int val = 42; SLIC_CHECK(val < 0); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -977,7 +1333,16 @@ TEST_P(SlicMacrosParallel, test_check_macros) check_level(slic::internal::test_stream.str(), "WARNING"); check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 9)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -991,6 +1356,7 @@ TEST_P(SlicMacrosParallel, test_check_macros) EXPECT_TRUE(slic::internal::are_all_streams_empty()); SLIC_CHECK_MSG(val < 0, "val should be negative!"); + expected_line_number = __LINE__ - 1; slic::flushStreams(); #if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE) if(GetParam() == "Synchronized" || (GetParam() == "Lumberjack" && rank == 0)) @@ -1000,7 +1366,16 @@ TEST_P(SlicMacrosParallel, test_check_macros) check_msg(slic::internal::test_stream.str(), "Failed Check: val < 0\nval should be negative!"); check_file(slic::internal::test_stream.str()); - check_line(slic::internal::test_stream.str(), (__LINE__ - 10)); + check_line(slic::internal::test_stream.str(), expected_line_number); + if(GetParam() == "Synchronized") + { + check_rank(slic::internal::test_stream.str(), rank); + } + else + { + check_ranks(slic::internal::test_stream.str(), nranks); + } + check_rank_count(slic::internal::test_stream.str(), GetParam(), nranks); } slic::internal::clear_streams(); #else @@ -1015,7 +1390,6 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) { EXPECT_TRUE(slic::internal::are_all_streams_empty()); - std::string msgfmt = ""; std::string no_fmt; std::string with_fmt; @@ -1063,6 +1437,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) // message is buffered but not yet flushed, no files created SLIC_INFO("Test"); + int expected_line_number_flush = __LINE__ - 1; EXPECT_FALSE(axom::utilities::filesystem::pathExists(no_fmt)); EXPECT_FALSE(axom::utilities::filesystem::pathExists(with_fmt)); @@ -1084,7 +1459,8 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) std::string no_fmt_expected; no_fmt_expected += "*****\n[INFO]\n\n Test \n\n "; no_fmt_expected += __FILE__; - no_fmt_expected += "\n1065\n****\n"; + no_fmt_expected += "\n" + std::to_string(expected_line_number_flush); + no_fmt_expected += "\n****\n"; EXPECT_EQ(no_fmt_buffer.str(), no_fmt_expected); @@ -1093,7 +1469,19 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) with_fmt_buffer << with_fmt_contents.rdbuf(); with_fmt_contents.close(); - EXPECT_EQ(with_fmt_buffer.str(), "Test"); + check_level(with_fmt_buffer.str(), "INFO"); + check_msg(with_fmt_buffer.str(), "Test"); + check_file(with_fmt_buffer.str()); + check_line(with_fmt_buffer.str(), expected_line_number_flush); + if(GetParam() == "Synchronized") + { + check_rank(with_fmt_buffer.str(), rank); + } + else + { + check_ranks(with_fmt_buffer.str(), nranks); + } + check_rank_count(with_fmt_buffer.str(), GetParam(), nranks); } else @@ -1107,6 +1495,7 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) // Expect non-output Lumberjack ranks to create files if possible // (cannot guarantee all ranks will output before non-collective MPI Abort) SLIC_INFO("Test outputLocalMessages()"); + int expected_line_number_local = __LINE__ - 1; slic::outputLocalMessages(); EXPECT_TRUE(axom::utilities::filesystem::pathExists(no_fmt)); @@ -1123,11 +1512,13 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) std::string no_fmt_output_expected; no_fmt_output_expected += "*****\n[INFO]\n\n Test \n\n "; no_fmt_output_expected += __FILE__; - no_fmt_output_expected += "\n1065\n****\n"; + no_fmt_output_expected += "\n" + std::to_string(expected_line_number_flush); + no_fmt_output_expected += "\n****\n"; no_fmt_output_expected += "*****\n[INFO]\n\n Test outputLocalMessages() \n\n "; no_fmt_output_expected += __FILE__; - no_fmt_output_expected += "\n1109\n****\n"; + no_fmt_output_expected += "\n" + std::to_string(expected_line_number_local); + no_fmt_output_expected += "\n****\n"; EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected); @@ -1136,7 +1527,18 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) with_fmt_out_buf << with_fmt_output.rdbuf(); with_fmt_output.close(); - EXPECT_EQ(with_fmt_out_buf.str(), "TestTest outputLocalMessages()"); + // Check the next message, "Test outputLocalMessages()" + size_t next_index = with_fmt_out_buf.str().rfind("[INFO]"); + std::string next_msg = with_fmt_out_buf.str().substr(next_index); + check_level(next_msg, "INFO"); + check_msg(next_msg, "Test outputLocalMessages()"); + check_file(next_msg); + check_line(next_msg, (expected_line_number_local)); + + // For outputLocalMessages(), only current rank and rank count of 1 + // output for LumberjackStreams. Behaves like SynchronizedStream. + check_rank(next_msg, rank); + check_rank_count(next_msg, GetParam(), 1); } else @@ -1151,7 +1553,8 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) no_fmt_output_expected += "*****\n[INFO]\n\n Test outputLocalMessages() \n\n "; no_fmt_output_expected += __FILE__; - no_fmt_output_expected += "\n1109\n****\n"; + no_fmt_output_expected += "\n" + std::to_string(expected_line_number_local); + no_fmt_output_expected += "\n****\n"; EXPECT_EQ(no_fmt_out_buf.str(), no_fmt_output_expected); @@ -1160,7 +1563,15 @@ TEST_P(SlicMacrosParallel, test_macros_file_output) with_fmt_out_buf << with_fmt_output.rdbuf(); with_fmt_output.close(); - EXPECT_EQ(with_fmt_out_buf.str(), "Test outputLocalMessages()"); + check_level(with_fmt_out_buf.str(), "INFO"); + check_msg(with_fmt_out_buf.str(), "Test outputLocalMessages()"); + check_file(with_fmt_out_buf.str()); + check_line(with_fmt_out_buf.str(), expected_line_number_local); + + // For outputLocalMessages(), only current rank and rank count of 1 + // output for LumberjackStreams. Behaves like SynchronizedStream. + check_rank(with_fmt_out_buf.str(), rank); + check_rank_count(with_fmt_out_buf.str(), GetParam(), 1); } // Closes open file streams associated with Slic streams when destructors