summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-10-27 11:50:44 -0400
committerGitHub <noreply@github.com>2021-10-27 11:50:44 -0400
commit76a1ec517b24a44c97c33d7e1d67adc5bd086b35 (patch)
treeebe58c9ad60438d18f586ab296dc6df4c42c5231
parent62b1e58a72773fad43e555d7de1bfeaa3f5c6762 (diff)
Small improvements around invoking unit-tests (#1978)
* #include an absolute path didn't work - because paths were taken to always be relative. * Attempt to check if a crash is occurring in a unit test * Small update really to just kick another build.
-rw-r--r--tools/slang-test/slang-test-main.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 49ee7d688..f7f780396 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -17,6 +17,8 @@
#include "../../source/core/slang-process-util.h"
#include "../../source/core/slang-render-api-util.h"
+#include "../../source/core/slang-shared-library.h"
+
#include "tools/unit-test/slang-unit-test.h"
#undef SLANG_UNIT_TEST
@@ -3398,28 +3400,32 @@ static TestResult _asTestResult(ToolReturnCode retCode)
/// Loads a DLL containing unit test functions and run them one by one.
static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOptions, SpawnType spawnType, const char* moduleName)
{
- SharedLibrary::Handle moduleHandle;
- SLANG_RETURN_ON_FAIL(SharedLibrary::load(
+ ISlangSharedLibraryLoader* loader = DefaultSharedLibraryLoader::getSingleton();
+ ComPtr<ISlangSharedLibrary> moduleLibrary;
+
+ SLANG_RETURN_ON_FAIL(loader->loadSharedLibrary(
Path::combine(context->exeDirectoryPath, moduleName).getBuffer(),
- moduleHandle));
+ moduleLibrary.writeRef()));
+
UnitTestGetModuleFunc getModuleFunc =
- (UnitTestGetModuleFunc) SharedLibrary::findSymbolAddressByName(
- moduleHandle, "slangUnitTestGetModule");
+ (UnitTestGetModuleFunc)moduleLibrary->findFuncByName("slangUnitTestGetModule");
if (!getModuleFunc)
return SLANG_FAIL;
IUnitTestModule* testModule = getModuleFunc();
if (!testModule)
return SLANG_FAIL;
- testModule->setTestReporter(TestReporter::get());
+
+ auto reporter = TestReporter::get();
+
+ testModule->setTestReporter(reporter);
+
UnitTestContext unitTestContext;
unitTestContext.slangGlobalSession = context->getSession();
unitTestContext.workDirectory = "";
unitTestContext.enabledApis = context->options.enabledApis;
auto testCount = testModule->getTestCount();
- TestReporter* reporter = TestReporter::get();
-
for (SlangInt i = 0; i < testCount; i++)
{
auto testFunc = testModule->getTestFunc(i);
@@ -3476,11 +3482,24 @@ static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOpti
else
{
TestReporter::TestScope scopeTest(reporter, testOptions.command);
- testFunc(&unitTestContext);
+
+ // TODO(JS): Problem here could be exception not handled properly across
+ // shared library boundary.
+
+ try
+ {
+ testFunc(&unitTestContext);
+ }
+ catch (...)
+ {
+ reporter->message(TestMessageType::TestFailure, "Exception was thrown during execution");
+ reporter->addResult(TestResult::Fail);
+ }
}
}
}
}
+
testModule->destroy();
return SLANG_OK;
}