diff options
| author | Yong He <yonghe@outlook.com> | 2022-01-10 13:16:30 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-10 13:16:30 -0800 |
| commit | 0ac19741937e007ebb45791f53d413d21055feda (patch) | |
| tree | e058c07fef9138941b253116c1d8a434c334ab67 /tools/slang-test/test-context.cpp | |
| parent | 36e9276b1799b476f12db9b24d3073ceef3b7594 (diff) | |
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 <yhe@nvidia.com>
Co-authored-by: Theresa Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools/slang-test/test-context.cpp')
| -rw-r--r-- | tools/slang-test/test-context.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index 3e61287cf..cdafbc30d 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -12,6 +12,8 @@ using namespace Slang; +thread_local int slangTestThreadIndex = 0; + TestContext::TestContext() { m_session = nullptr; @@ -23,6 +25,39 @@ TestContext::TestContext() #endif } +void TestContext::setThreadIndex(int index) { slangTestThreadIndex = index; } + +void TestContext::setMaxTestRunnerThreadCount(int count) +{ + m_jsonRpcConnections.setCount(count); + m_testRequirements.setCount(count); + m_reporters.setCount(count); + for (auto& reporter : m_reporters) + { + reporter = nullptr; + } +} + +void TestContext::setTestRequirements(TestRequirements* req) +{ + m_testRequirements[slangTestThreadIndex] = req; +} + +TestRequirements* TestContext::getTestRequirements() const +{ + return m_testRequirements[slangTestThreadIndex]; +} + +void TestContext::setTestReporter(TestReporter* reporter) +{ + m_reporters[slangTestThreadIndex] = reporter; +} + +TestReporter* TestContext::getTestReporter() +{ + return m_reporters[slangTestThreadIndex]; +} + Result TestContext::init(const char* exePath) { m_session = spCreateSession(nullptr); @@ -91,6 +126,7 @@ void TestContext::setInnerMainFunc(const String& name, InnerMainFunc func) DownstreamCompilerSet* TestContext::getCompilerSet() { + std::lock_guard<std::mutex> lock(mutex); if (!compilerSet) { compilerSet = new DownstreamCompilerSet; @@ -138,24 +174,24 @@ SlangResult TestContext::_createJSONRPCConnection(RefPtr<JSONRPCConnection>& out void TestContext::destroyRPCConnection() { - if (m_jsonRpcConnection) + if (m_jsonRpcConnections[slangTestThreadIndex]) { - m_jsonRpcConnection->disconnect(); - m_jsonRpcConnection.setNull(); + m_jsonRpcConnections[slangTestThreadIndex]->disconnect(); + m_jsonRpcConnections[slangTestThreadIndex].setNull(); } } Slang::JSONRPCConnection* TestContext::getOrCreateJSONRPCConnection() { - if (!m_jsonRpcConnection) + if (!m_jsonRpcConnections[slangTestThreadIndex]) { - if (SLANG_FAILED(_createJSONRPCConnection(m_jsonRpcConnection))) + if (SLANG_FAILED(_createJSONRPCConnection(m_jsonRpcConnections[slangTestThreadIndex]))) { return nullptr; } } - return m_jsonRpcConnection; + return m_jsonRpcConnections[slangTestThreadIndex]; } |
