From 0ac19741937e007ebb45791f53d413d21055feda Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 10 Jan 2022 13:16:30 -0800 Subject: Enable running tests in parallel. (#2078) * Enable running tests in parallel. * Fix linux build. * Add pthread dependency for slang-test. * Fix teamcity output. * Fix race condition. * Make testReporter thread safe. * Clean up. * Fix. * trigger build * Fix. Co-authored-by: Yong He Co-authored-by: Theresa Foley --- tools/slang-test/test-reporter.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'tools/slang-test/test-reporter.cpp') diff --git a/tools/slang-test/test-reporter.cpp b/tools/slang-test/test-reporter.cpp index 83df0fb0b..ee8421e81 100644 --- a/tools/slang-test/test-reporter.cpp +++ b/tools/slang-test/test-reporter.cpp @@ -7,6 +7,8 @@ #include #include +#include + using namespace Slang; /* static */TestReporter* TestReporter::s_reporter = nullptr; @@ -82,9 +84,10 @@ TestReporter::TestReporter() : m_isVerbose = false; } -Result TestReporter::init(TestOutputMode outputMode) +Result TestReporter::init(TestOutputMode outputMode, bool isSubReporter) { m_outputMode = outputMode; + m_isSubReporter = isSubReporter; return SLANG_OK; } @@ -191,6 +194,15 @@ TestResult TestReporter::addTest(const String& testName, bool isPass) return res; } +void TestReporter::consolidateWith(TestReporter* other) +{ + m_testInfos.addRange(other->m_testInfos); + m_failedTestCount += other->m_failedTestCount; + m_ignoredTestCount += other->m_ignoredTestCount; + m_passedTestCount += other->m_passedTestCount; + m_totalTestCount += other->m_totalTestCount; +} + void TestReporter::dumpOutputDifference(const String& expectedOutput, const String& actualOutput) { StringBuilder builder; @@ -493,6 +505,8 @@ void TestReporter::addTest(const String& testName, TestResult testResult) void TestReporter::message(TestMessageType type, const String& message) { + static std::mutex mutex; + std::lock_guard lock(mutex); if (type == TestMessageType::Info) { if (m_isVerbose && canWriteStdError()) @@ -666,9 +680,12 @@ void TestReporter::startSuite(const String& name) { case TestOutputMode::TeamCity: { - StringBuilder escapedSuiteName; - _appendEncodedTeamCityString(name.getUnownedSlice(), escapedSuiteName); - printf("##teamcity[testSuiteStarted name='%s']\n", escapedSuiteName.begin()); + if (!m_isSubReporter) + { + StringBuilder escapedSuiteName; + _appendEncodedTeamCityString(name.getUnownedSlice(), escapedSuiteName); + printf("##teamcity[testSuiteStarted name='%s']\n", escapedSuiteName.begin()); + } break; } default: break; @@ -683,10 +700,13 @@ void TestReporter::endSuite() { case TestOutputMode::TeamCity: { - const String& name = m_suiteStack.getLast(); - StringBuilder escapedSuiteName; - _appendEncodedTeamCityString(name.getUnownedSlice(), escapedSuiteName); - printf("##teamcity[testSuiteFinished name='%s']\n", escapedSuiteName.begin()); + if (!m_isSubReporter) + { + const String& name = m_suiteStack.getLast(); + StringBuilder escapedSuiteName; + _appendEncodedTeamCityString(name.getUnownedSlice(), escapedSuiteName); + printf("##teamcity[testSuiteFinished name='%s']\n", escapedSuiteName.begin()); + } break; } default: break; -- cgit v1.2.3