test/helpers.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
New commits: commit a5035a0f7734478a22b383ecab6cb499f53a824f Author: Ashod Nakashian <[email protected]> AuthorDate: Thu Sep 26 16:59:40 2019 -0400 Commit: Jan Holesovsky <[email protected]> CommitDate: Thu Oct 10 16:26:21 2019 +0200 wsd: test: protect std::cerr from multiple threads Some tests fire up multiple threads and access the log, which uses std::cerr, concurrently. This can corrupt the cerr string buffer and cause random failures. Change-Id: I04c68a27a8fff668ab8e7c62ff2d52d85c3a26d5 Reviewed-on: https://gerrit.libreoffice.org/80320 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Jan Holesovsky <[email protected]> diff --git a/test/helpers.hpp b/test/helpers.hpp index 7414b27d4..5b526b01b 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -40,10 +40,12 @@ #endif // Logging in unit-tests go to cerr, for now at least. -#define TST_LOG_NAME_BEGIN(NAME, X) do { std::cerr << NAME << "(@" << helpers::timeSinceTestStartMs() << "ms) " << X; } while (false) +static std::mutex MutexLog; +#define TST_LOG_MUTEX std::unique_lock<std::mutex> lock(MutexLog) +#define TST_LOG_NAME_BEGIN(NAME, X) do { TST_LOG_MUTEX; std::cerr << NAME << "(@" << helpers::timeSinceTestStartMs() << "ms) " << X; } while (false) #define TST_LOG_BEGIN(X) TST_LOG_NAME_BEGIN(testname, X) -#define TST_LOG_APPEND(X) do { std::cerr << X; } while (false) -#define TST_LOG_END do { std::cerr << "| " << __FILE__ << ':' << __LINE__ << std::endl; } while (false) +#define TST_LOG_APPEND(X) do { TST_LOG_MUTEX; std::cerr << X; } while (false) +#define TST_LOG_END do { TST_LOG_MUTEX; std::cerr << "| " << __FILE__ << ':' << __LINE__ << std::endl; } while (false) #define TST_LOG_NAME(NAME, X) TST_LOG_NAME_BEGIN(NAME, X); TST_LOG_END #define TST_LOG(X) TST_LOG_NAME(testname, X) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
