summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx-unit-test/compute-smoke.cpp (renamed from tools/gfx-test/compute-smoke.cpp)33
-rw-r--r--tools/gfx-unit-test/compute-smoke.slang (renamed from tools/gfx-test/compute-smoke.slang)0
-rw-r--r--tools/gfx-unit-test/gfx-test-util.cpp (renamed from tools/gfx-test/gfx-test-util.cpp)27
-rw-r--r--tools/gfx-unit-test/gfx-test-util.h (renamed from tools/gfx-test/gfx-test-util.h)9
-rw-r--r--tools/slang-test/slang-test-main.cpp55
-rw-r--r--tools/slang-test/test-reporter.cpp9
-rw-r--r--tools/slang-test/test-reporter.h64
-rw-r--r--tools/slang-unit-test/unit-offset-container.cpp (renamed from tools/slang-test/unit-offset-container.cpp)6
-rw-r--r--tools/slang-unit-test/unit-test-byte-encode.cpp (renamed from tools/slang-test/unit-test-byte-encode.cpp)6
-rw-r--r--tools/slang-unit-test/unit-test-command-line-args.cpp (renamed from tools/slang-test/unit-test-command-line-args.cpp)5
-rw-r--r--tools/slang-unit-test/unit-test-compression.cpp (renamed from tools/slang-test/unit-test-compression.cpp)7
-rw-r--r--tools/slang-unit-test/unit-test-find-type-by-name.cpp (renamed from tools/slang-test/unit-test-find-type-by-name.cpp)5
-rw-r--r--tools/slang-unit-test/unit-test-free-list.cpp (renamed from tools/slang-test/unit-test-free-list.cpp)5
-rw-r--r--tools/slang-unit-test/unit-test-json.cpp (renamed from tools/slang-test/unit-test-json.cpp)5
-rw-r--r--tools/slang-unit-test/unit-test-memory-arena.cpp (renamed from tools/slang-test/unit-test-memory-arena.cpp)6
-rw-r--r--tools/slang-unit-test/unit-test-path.cpp (renamed from tools/slang-test/unit-test-path.cpp)6
-rw-r--r--tools/slang-unit-test/unit-test-riff.cpp (renamed from tools/slang-test/unit-test-riff.cpp)5
-rw-r--r--tools/slang-unit-test/unit-test-short-list.cpp (renamed from tools/slang-test/unit-test-short-list.cpp)7
-rw-r--r--tools/slang-unit-test/unit-test-string.cpp (renamed from tools/slang-test/unit-test-string.cpp)6
-rw-r--r--tools/unit-test/slang-unit-test.cpp27
-rw-r--r--tools/unit-test/slang-unit-test.h97
21 files changed, 181 insertions, 209 deletions
diff --git a/tools/gfx-test/compute-smoke.cpp b/tools/gfx-unit-test/compute-smoke.cpp
index bbba72348..b8e027b65 100644
--- a/tools/gfx-test/compute-smoke.cpp
+++ b/tools/gfx-unit-test/compute-smoke.cpp
@@ -9,22 +9,22 @@ using namespace gfx;
namespace gfx_test
{
- SlangResult computeSmokeTestImpl(IDevice* device, slang::UnitTestContext* context)
+ void computeSmokeTestImpl(IDevice* device, UnitTestContext* context)
{
Slang::ComPtr<ITransientResourceHeap> transientHeap;
ITransientResourceHeap::Desc transientHeapDesc = {};
transientHeapDesc.constantBufferSize = 4096;
- SLANG_RETURN_ON_FAIL(
+ GFX_CHECK_CALL_ABORT(
device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef()));
ComPtr<IShaderProgram> shaderProgram;
slang::ProgramLayout* slangReflection;
- SLANG_RETURN_ON_FAIL(loadShaderProgram(device, shaderProgram, context->outputWriter, "compute-smoke", slangReflection));
+ GFX_CHECK_CALL_ABORT(loadShaderProgram(device, shaderProgram, "compute-smoke", slangReflection));
ComputePipelineStateDesc pipelineDesc = {};
pipelineDesc.program = shaderProgram.get();
ComPtr<gfx::IPipelineState> pipelineState;
- SLANG_RETURN_ON_FAIL(
+ GFX_CHECK_CALL_ABORT(
device->createComputePipelineState(pipelineDesc, pipelineState.writeRef()));
const int numberCount = 4;
@@ -42,7 +42,7 @@ namespace gfx_test
bufferDesc.cpuAccessFlags = AccessFlag::Write | AccessFlag::Read;
ComPtr<IBufferResource> numbersBuffer;
- SLANG_RETURN_ON_FAIL(device->createBufferResource(
+ GFX_CHECK_CALL_ABORT(device->createBufferResource(
bufferDesc,
(void*)initialData,
numbersBuffer.writeRef()));
@@ -51,7 +51,7 @@ namespace gfx_test
IResourceView::Desc viewDesc = {};
viewDesc.type = IResourceView::Type::UnorderedAccess;
viewDesc.format = Format::Unknown;
- SLANG_RETURN_ON_FAIL(device->createBufferView(numbersBuffer, viewDesc, bufferView.writeRef()));
+ GFX_CHECK_CALL_ABORT(device->createBufferView(numbersBuffer, viewDesc, bufferView.writeRef()));
// We have done all the set up work, now it is time to start recording a command buffer for
// GPU execution.
@@ -69,7 +69,7 @@ namespace gfx_test
// Now we can use this type to create a shader object that can be bound to the root object.
ComPtr<IShaderObject> transformer;
- SLANG_RETURN_ON_FAIL(device->createShaderObject(
+ GFX_CHECK_CALL_ABORT(device->createShaderObject(
addTransformerType, ShaderObjectContainerType::None, transformer.writeRef()));
// Set the `c` field of the `AddTransformer`.
float c = 1.0f;
@@ -90,17 +90,17 @@ namespace gfx_test
queue->wait();
}
- return compareComputeResult(
+ compareComputeResult(
device,
numbersBuffer,
Slang::makeArray<float>(11.0f, 12.0f, 13.0f, 14.0f));
}
- SlangResult computeSmokeTestAPI(slang::UnitTestContext* context, Slang::RenderApiFlag::Enum api)
+ void computeSmokeTestAPI(UnitTestContext* context, Slang::RenderApiFlag::Enum api)
{
if ((api & context->enabledApis) == 0)
{
- return SLANG_E_NOT_AVAILABLE;
+ SLANG_IGNORE_TEST
}
Slang::ComPtr<IDevice> device;
IDevice::Desc deviceDesc = {};
@@ -116,30 +116,29 @@ namespace gfx_test
deviceDesc.deviceType = gfx::DeviceType::Vulkan;
break;
default:
- return SLANG_E_NOT_AVAILABLE;
+ SLANG_IGNORE_TEST
}
deviceDesc.slang.slangGlobalSession = context->slangGlobalSession;
- const char* searchPaths[] = { "", "../../tools/gfx-test", "tools/gfx-test" };
+ const char* searchPaths[] = { "", "../../tools/gfx-unit-test", "tools/gfx-unit-test" };
deviceDesc.slang.searchPathCount = (SlangInt)SLANG_COUNT_OF(searchPaths);
deviceDesc.slang.searchPaths = searchPaths;
auto createDeviceResult = gfxCreateDevice(&deviceDesc, device.writeRef());
if (SLANG_FAILED(createDeviceResult))
{
- return SLANG_E_NOT_AVAILABLE;
+ SLANG_IGNORE_TEST
}
- SLANG_RETURN_ON_FAIL(computeSmokeTestImpl(device, context));
- return SLANG_OK;
+ computeSmokeTestImpl(device, context);
}
SLANG_UNIT_TEST(computeSmokeD3D11)
{
- return computeSmokeTestAPI(context, Slang::RenderApiFlag::D3D11);
+ computeSmokeTestAPI(unitTestContext, Slang::RenderApiFlag::D3D11);
}
SLANG_UNIT_TEST(computeSmokeVulkan)
{
- return computeSmokeTestAPI(context, Slang::RenderApiFlag::Vulkan);
+ computeSmokeTestAPI(unitTestContext, Slang::RenderApiFlag::Vulkan);
}
}
diff --git a/tools/gfx-test/compute-smoke.slang b/tools/gfx-unit-test/compute-smoke.slang
index 7ecdb4177..7ecdb4177 100644
--- a/tools/gfx-test/compute-smoke.slang
+++ b/tools/gfx-unit-test/compute-smoke.slang
diff --git a/tools/gfx-test/gfx-test-util.cpp b/tools/gfx-unit-test/gfx-test-util.cpp
index 5e77879a9..d01fcdca3 100644
--- a/tools/gfx-test/gfx-test-util.cpp
+++ b/tools/gfx-unit-test/gfx-test-util.cpp
@@ -1,4 +1,5 @@
#include "gfx-test-util.h"
+#include "tools/unit-test/slang-unit-test.h"
#include <slang-com-ptr.h>
@@ -6,18 +7,17 @@ using Slang::ComPtr;
namespace gfx_test
{
- void diagnoseIfNeeded(ISlangWriter* diagnosticWriter, slang::IBlob* diagnosticsBlob)
+ void diagnoseIfNeeded(slang::IBlob* diagnosticsBlob)
{
if (diagnosticsBlob != nullptr)
{
- diagnosticWriter->write((const char*)diagnosticsBlob->getBufferPointer(), diagnosticsBlob->getBufferSize());
+ getTestReporter()->message(TestMessageType::Info, (const char*)diagnosticsBlob->getBufferPointer());
}
}
Slang::Result loadShaderProgram(
gfx::IDevice* device,
Slang::ComPtr<gfx::IShaderProgram>& outShaderProgram,
- ISlangWriter* diagnosticWriter,
const char* shaderModuleName,
slang::ProgramLayout*& slangReflection)
{
@@ -25,7 +25,7 @@ namespace gfx_test
SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef()));
Slang::ComPtr<slang::IBlob> diagnosticsBlob;
slang::IModule* module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef());
- diagnoseIfNeeded(diagnosticWriter, diagnosticsBlob);
+ diagnoseIfNeeded(diagnosticsBlob);
if (!module)
return SLANG_FAIL;
@@ -44,7 +44,7 @@ namespace gfx_test
componentTypes.getCount(),
composedProgram.writeRef(),
diagnosticsBlob.writeRef());
- diagnoseIfNeeded(diagnosticWriter, diagnosticsBlob);
+ diagnoseIfNeeded(diagnosticsBlob);
SLANG_RETURN_ON_FAIL(result);
slangReflection = composedProgram->getLayout();
@@ -58,22 +58,29 @@ namespace gfx_test
return SLANG_OK;
}
- Slang::Result compareComputeResult(gfx::IDevice* device, gfx::IBufferResource* buffer, uint8_t* expectedResult, size_t expectedBufferSize)
+ void compareComputeResult(gfx::IDevice* device, gfx::IBufferResource* buffer, uint8_t* expectedResult, size_t expectedBufferSize)
{
// Read back the results.
ComPtr<ISlangBlob> resultBlob;
- SLANG_RETURN_ON_FAIL(device->readBufferResource(
+ GFX_CHECK_CALL_ABORT(device->readBufferResource(
buffer, 0, expectedBufferSize, resultBlob.writeRef()));
if (resultBlob->getBufferSize() < expectedBufferSize)
- return SLANG_FAIL;
+ {
+ getTestReporter()->addResult(TestResult::Fail);
+ return;
+ }
// Compare results.
auto result = reinterpret_cast<const uint8_t*>(resultBlob->getBufferPointer());
for (int i = 0; i < expectedBufferSize; i++)
{
if (expectedResult[i] != result[i])
- return SLANG_FAIL;
+ {
+ getTestReporter()->addResult(TestResult::Fail);
+ return;
+ }
+
}
- return SLANG_OK;
+ getTestReporter()->addResult(TestResult::Pass);
}
}
diff --git a/tools/gfx-test/gfx-test-util.h b/tools/gfx-unit-test/gfx-test-util.h
index 5223ba773..7709512d5 100644
--- a/tools/gfx-test/gfx-test-util.h
+++ b/tools/gfx-unit-test/gfx-test-util.h
@@ -12,19 +12,18 @@ namespace gfx_test
Slang::Result loadShaderProgram(
gfx::IDevice* device,
Slang::ComPtr<gfx::IShaderProgram>& outShaderProgram,
- ISlangWriter* diagnosticWriter,
const char* shaderModuleName,
slang::ProgramLayout*& slangReflection);
/// Reads back the content of `buffer` and compares it against `expectedResult`.
- Slang::Result compareComputeResult(
+ void compareComputeResult(
gfx::IDevice* device,
gfx::IBufferResource* buffer,
uint8_t* expectedResult,
size_t expectedBufferSize);
template<typename T, Slang::Index count>
- Slang::Result compareComputeResult(
+ void compareComputeResult(
gfx::IDevice* device,
gfx::IBufferResource* buffer,
Slang::Array<T, count> expectedResult)
@@ -35,4 +34,8 @@ namespace gfx_test
memcpy(expectedBuffer.getBuffer(), expectedResult.begin(), bufferSize);
return compareComputeResult(device, buffer, expectedBuffer.getBuffer(), bufferSize);
}
+
+#define GFX_CHECK_CALL(x) {auto callResult = (x); SLANG_CHECK(!SLANG_FAILED(callResult))}
+#define GFX_CHECK_CALL_ABORT(x) {auto callResult = (x); SLANG_CHECK_ABORT(!SLANG_FAILED(callResult))}
+
}
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 9c194afd4..4f96c3a6a 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -3399,25 +3399,23 @@ static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOpti
SLANG_RETURN_ON_FAIL(SharedLibrary::load(
Path::combine(context->exeDirectoryPath, moduleName).getBuffer(),
moduleHandle));
- slang::UnitTestGetModuleFunc getModuleFunc =
- (slang::UnitTestGetModuleFunc) SharedLibrary::findSymbolAddressByName(
+ UnitTestGetModuleFunc getModuleFunc =
+ (UnitTestGetModuleFunc) SharedLibrary::findSymbolAddressByName(
moduleHandle, "slangUnitTestGetModule");
if (!getModuleFunc)
return SLANG_FAIL;
- slang::IUnitTestModule* testModule = getModuleFunc();
+ IUnitTestModule* testModule = getModuleFunc();
if (!testModule)
return SLANG_FAIL;
-
- slang::UnitTestContext unitTestContext;
+ testModule->setTestReporter(TestReporter::get());
+ UnitTestContext unitTestContext;
unitTestContext.slangGlobalSession = context->getSession();
unitTestContext.workDirectory = "";
unitTestContext.enabledApis = context->options.enabledApis;
auto testCount = testModule->getTestCount();
for (SlangInt i = 0; i < testCount; i++)
{
- StringBuilder sb;
- StringWriter messageWriter(&sb, WriterFlag::Enum::AutoFlush);
auto testFunc = testModule->getTestFunc(i);
auto testName = testModule->getTestName(i);
@@ -3430,22 +3428,13 @@ static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOpti
{
if (testPassesCategoryMask(context, testOptions))
{
- unitTestContext.outputWriter = &messageWriter;
- TestReporter::get()->startTest(testOptions.command);
- auto result = testFunc(&unitTestContext);
- if (sb.getLength())
- TestReporter::get()->message(TestMessageType::Info, sb.ProduceString());
-
- if (result == SLANG_E_NOT_AVAILABLE)
- TestReporter::get()->addResult(TestResult::Ignored);
- else if (SLANG_FAILED(result))
- TestReporter::get()->addResult(TestResult::Fail);
- else
- TestReporter::get()->addResult(TestResult::Pass);
+ TestReporter::get()->startTest(testOptions.command.getBuffer());
+ testFunc(&unitTestContext);
TestReporter::get()->endTest();
}
}
}
+ testModule->destroy();
return SLANG_OK;
}
@@ -3623,40 +3612,16 @@ SlangResult innerMain(int argc, char** argv)
TestReporter::set(&reporter);
// Run the unit tests
- TestRegister* cur = TestRegister::s_first;
- while (cur)
{
- StringBuilder filePath;
- filePath << "unit-tests/" << cur->m_name << ".internal";
-
TestOptions testOptions;
testOptions.categories.add(unitTestCategory);
testOptions.categories.add(smokeTestCategory);
- testOptions.command = filePath;
-
- if (shouldRunTest(&context, testOptions.command))
- {
- if (testPassesCategoryMask(&context, testOptions))
- {
- reporter.startTest(testOptions.command);
- // Run the test function
- cur->m_func();
- reporter.endTest();
- }
- else
- {
- reporter.addTest(testOptions.command, TestResult::Ignored);
- }
- }
-
- // Next
- cur = cur->m_next;
+ runUnitTestModule(&context, testOptions, "slang-unit-test-tool");
}
-
{
TestOptions testOptions;
testOptions.categories.add(unitTestCategory);
- runUnitTestModule(&context, testOptions, "gfx-test-tool");
+ runUnitTestModule(&context, testOptions, "gfx-unit-test-tool");
}
TestReporter::set(nullptr);
}
diff --git a/tools/slang-test/test-reporter.cpp b/tools/slang-test/test-reporter.cpp
index 4a7c76c4c..84bcaa32c 100644
--- a/tools/slang-test/test-reporter.cpp
+++ b/tools/slang-test/test-reporter.cpp
@@ -10,7 +10,6 @@
using namespace Slang;
/* static */TestReporter* TestReporter::s_reporter = nullptr;
-/* static */TestRegister* TestRegister::s_first;
static void appendXmlEncode(char c, StringBuilder& out)
{
@@ -106,7 +105,7 @@ bool TestReporter::canWriteStdError() const
}
}
-void TestReporter::startTest(const String& testName)
+void TestReporter::startTest(const char* testName)
{
// Must be in a suite
assert(m_suiteStack.getCount());
@@ -537,6 +536,12 @@ void TestReporter::messageFormat(TestMessageType type, char const* format, ...)
message(type, builder);
}
+void TestReporter::message(TestMessageType type, const char* messageContent)
+{
+ message(type, String(messageContent));
+}
+
+
bool TestReporter::didAllSucceed() const
{
return m_passedTestCount == (m_totalTestCount - m_ignoredTestCount);
diff --git a/tools/slang-test/test-reporter.h b/tools/slang-test/test-reporter.h
index 1ebce81cd..ecf6fbab4 100644
--- a/tools/slang-test/test-reporter.h
+++ b/tools/slang-test/test-reporter.h
@@ -7,36 +7,7 @@
#include "../../source/core/slang-platform.h"
#include "../../source/core/slang-std-writers.h"
#include "../../source/core/slang-dictionary.h"
-
-
-#define SLANG_CHECK(x) TestReporter::get()->addResultWithLocation((x), #x, __FILE__, __LINE__);
-#define SLANG_CHECK_ABORT(x) \
- { \
- bool _slang_check_result = (x); \
- TestReporter::get()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \
- if (!_slang_check_result) return; \
- }
-
-struct TestRegister
-{
- typedef void (*TestFunc)();
-
- TestRegister(const char* name, TestFunc func):
- m_next(s_first),
- m_name(name),
- m_func(func)
- {
- s_first = this;
- }
-
- TestFunc m_func;
- const char* m_name;
- TestRegister* m_next;
-
- static TestRegister* s_first;
-};
-
-#define SLANG_UNIT_TEST(name, func) static TestRegister s_unitTest##__LINE__(name, func)
+#include "tools/unit-test/slang-unit-test.h"
enum class TestOutputMode
{
@@ -48,23 +19,7 @@ enum class TestOutputMode
TeamCity, ///< Output suitable for teamcity
};
-enum class TestResult
-{
- // NOTE! Must keep in order such that combine is meaningful. That is larger values are higher precident - and a series of tests that has lots of passes
- // and a fail, is still a fail overall.
- Ignored,
- Pass,
- Fail,
-};
-
-enum class TestMessageType
-{
- Info, ///< General info (may not be shown depending on verbosity setting)
- TestFailure, ///< Describes how a test failure took place
- RunError, ///< Describes an error that caused a test not to actually correctly run
-};
-
-class TestReporter
+class TestReporter : public ITestReporter
{
public:
@@ -82,7 +37,7 @@ class TestReporter
TestScope(TestReporter* reporter, const Slang::String& testName) :
m_reporter(reporter)
{
- reporter->startTest(testName);
+ reporter->startTest(testName.getBuffer());
}
~TestScope()
{
@@ -113,12 +68,12 @@ class TestReporter
void startSuite(const Slang::String& name);
void endSuite();
- void startTest(const Slang::String& testName);
- void addResult(TestResult result);
- void addResultWithLocation(TestResult result, const char* testText, const char* file, int line);
- void addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line);
- void addExecutionTime(double time);
- void endTest();
+ virtual void startTest(const char* testName) override;
+ virtual void addResult(TestResult result) override;
+ virtual void addResultWithLocation(TestResult result, const char* testText, const char* file, int line) override;
+ virtual void addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) override;
+ virtual void addExecutionTime(double time) override;
+ virtual void endTest() override;
/// Runs start/endTest and outputs the result
TestResult addTest(const Slang::String& testName, bool isPass);
@@ -128,6 +83,7 @@ class TestReporter
// Called for an error in the test-runner (not for an error involving a test itself).
void message(TestMessageType type, const Slang::String& errorText);
void messageFormat(TestMessageType type, char const* message, ...);
+ virtual void message(TestMessageType type, char const* message) override;
void dumpOutputDifference(const Slang::String& expectedOutput, const Slang::String& actualOutput);
diff --git a/tools/slang-test/unit-offset-container.cpp b/tools/slang-unit-test/unit-offset-container.cpp
index d0990d9bb..6a179c319 100644
--- a/tools/slang-test/unit-offset-container.cpp
+++ b/tools/slang-unit-test/unit-offset-container.cpp
@@ -2,7 +2,7 @@
#include "../../source/core/slang-offset-container.h"
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
@@ -30,7 +30,7 @@ struct Root
} // anonymous
-static void offsetContainerUnitTest()
+SLANG_UNIT_TEST(offsetContainer)
{
_checkEncodeDecode(253);
@@ -115,5 +115,3 @@ static void offsetContainerUnitTest()
}
}
}
-
-SLANG_UNIT_TEST("OffsetContainer", offsetContainerUnitTest);
diff --git a/tools/slang-test/unit-test-byte-encode.cpp b/tools/slang-unit-test/unit-test-byte-encode.cpp
index 8ffac3ee3..38bd5561d 100644
--- a/tools/slang-test/unit-test-byte-encode.cpp
+++ b/tools/slang-unit-test/unit-test-byte-encode.cpp
@@ -5,7 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
#include "../../source/core/slang-random-generator.h"
#include "../../source/core/slang-list.h"
@@ -25,7 +25,7 @@ static void checkUInt32(uint32_t value)
SLANG_CHECK(readLen == writeLen && decode == value);
}
-static void byteEncodeUnitTest()
+SLANG_UNIT_TEST(byteEncode)
{
DefaultRandomGenerator randGen(0x5346536a);
@@ -137,5 +137,3 @@ static void byteEncodeUnitTest()
}
}
-
-SLANG_UNIT_TEST("ByteEncode", byteEncodeUnitTest);
diff --git a/tools/slang-test/unit-test-command-line-args.cpp b/tools/slang-unit-test/unit-test-command-line-args.cpp
index fd50ceeef..a4dc8a16c 100644
--- a/tools/slang-test/unit-test-command-line-args.cpp
+++ b/tools/slang-unit-test/unit-test-command-line-args.cpp
@@ -2,11 +2,11 @@
#include "../../source/compiler-core/slang-command-line-args.h"
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
-static void commandLineArgsUnitTest()
+SLANG_UNIT_TEST(commandLineArgs)
{
RefPtr<CommandLineContext> context = new CommandLineContext;
@@ -123,4 +123,3 @@ static void commandLineArgsUnitTest()
}
-SLANG_UNIT_TEST("CommandLineArgs", commandLineArgsUnitTest);
diff --git a/tools/slang-test/unit-test-compression.cpp b/tools/slang-unit-test/unit-test-compression.cpp
index b70bd8545..89716b443 100644
--- a/tools/slang-test/unit-test-compression.cpp
+++ b/tools/slang-unit-test/unit-test-compression.cpp
@@ -1,7 +1,8 @@
// unit-compression.cpp
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
+#include "source/core/slang-io.h"
#include "../../source/core/slang-zip-file-system.h"
#include "../../source/core/slang-lz4-compression-system.h"
@@ -32,7 +33,7 @@ static List<String> _getContents(ISlangFileSystemExt* fileSystem, const char* pa
return objs;
}
-static void compressionUnitTest()
+SLANG_UNIT_TEST(compression)
{
const SlangArchiveType archiveTypes[] =
{
@@ -186,5 +187,3 @@ static void compressionUnitTest()
SLANG_CHECK(memcmp(src, decompressedData.getBuffer(), srcSize) == 0);
}
}
-
-SLANG_UNIT_TEST("Compression", compressionUnitTest);
diff --git a/tools/slang-test/unit-test-find-type-by-name.cpp b/tools/slang-unit-test/unit-test-find-type-by-name.cpp
index ebe5f746b..d12a0d91f 100644
--- a/tools/slang-test/unit-test-find-type-by-name.cpp
+++ b/tools/slang-unit-test/unit-test-find-type-by-name.cpp
@@ -5,11 +5,11 @@
#include <stdio.h>
#include <stdlib.h>
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
-static void findTypeByNameTest()
+SLANG_UNIT_TEST(findTypeByName)
{
const char* testSource =
"struct TestStruct {"
@@ -53,4 +53,3 @@ static void findTypeByNameTest()
spDestroySession(session);
}
-SLANG_UNIT_TEST("findTypeByName", findTypeByNameTest);
diff --git a/tools/slang-test/unit-test-free-list.cpp b/tools/slang-unit-test/unit-test-free-list.cpp
index 28973d9e5..d6c8b47a7 100644
--- a/tools/slang-test/unit-test-free-list.cpp
+++ b/tools/slang-unit-test/unit-test-free-list.cpp
@@ -5,14 +5,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
#include "../../source/core/slang-random-generator.h"
#include "../../source/core/slang-list.h"
using namespace Slang;
-static void freeListUnitTest()
+SLANG_UNIT_TEST(freeList)
{
FreeList freeList;
freeList.init(sizeof(int), sizeof(void*), 10);
@@ -51,4 +51,3 @@ static void freeListUnitTest()
}
}
-SLANG_UNIT_TEST("FreeList", freeListUnitTest);
diff --git a/tools/slang-test/unit-test-json.cpp b/tools/slang-unit-test/unit-test-json.cpp
index dad5153c1..2d2874cc8 100644
--- a/tools/slang-test/unit-test-json.cpp
+++ b/tools/slang-unit-test/unit-test-json.cpp
@@ -4,7 +4,7 @@
#include "../../source/compiler-core/slang-json-parser.h"
#include "../../source/compiler-core/slang-json-value.h"
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
@@ -101,7 +101,7 @@ static bool _areEqual(SourceManager* sourceManager, const List<JSONToken>& toks,
return true;
}
-static void jsonUnitTest()
+SLANG_UNIT_TEST(json)
{
SourceManager sourceManager;
sourceManager.initialize(nullptr, nullptr);
@@ -318,4 +318,3 @@ static void jsonUnitTest()
}
}
-SLANG_UNIT_TEST("JSON", jsonUnitTest);
diff --git a/tools/slang-test/unit-test-memory-arena.cpp b/tools/slang-unit-test/unit-test-memory-arena.cpp
index 2aa898c9d..b2671160a 100644
--- a/tools/slang-test/unit-test-memory-arena.cpp
+++ b/tools/slang-unit-test/unit-test-memory-arena.cpp
@@ -5,7 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
#include "../../source/core/slang-random-generator.h"
#include "../../source/core/slang-list.h"
@@ -105,7 +105,7 @@ static bool hasValue(const uint8_t* data, size_t size, uint8_t value)
return hasValueShort(data + sizeof(size_t) * numWords, size & alignMask, value);
}
-static void memoryArenaUnitTest()
+SLANG_UNIT_TEST(memoryArena)
{
DefaultRandomGenerator randGen(0x5346536a);
@@ -269,5 +269,3 @@ static void memoryArenaUnitTest()
}
}
-
-SLANG_UNIT_TEST("MemoryArena", memoryArenaUnitTest);
diff --git a/tools/slang-test/unit-test-path.cpp b/tools/slang-unit-test/unit-test-path.cpp
index 98f44753e..c27feee9c 100644
--- a/tools/slang-test/unit-test-path.cpp
+++ b/tools/slang-unit-test/unit-test-path.cpp
@@ -2,12 +2,11 @@
#include "../../source/core/slang-io.h"
-
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
-static void pathUnitTest()
+SLANG_UNIT_TEST(path)
{
#if SLANG_WINDOWS_FAMILY
// Disable for now on non windows has some problems on *some* Linux based CI.
@@ -61,4 +60,3 @@ static void pathUnitTest()
}
}
-SLANG_UNIT_TEST("Path", pathUnitTest);
diff --git a/tools/slang-test/unit-test-riff.cpp b/tools/slang-unit-test/unit-test-riff.cpp
index 0fb81113a..2902a9af5 100644
--- a/tools/slang-test/unit-test-riff.cpp
+++ b/tools/slang-unit-test/unit-test-riff.cpp
@@ -4,7 +4,7 @@
#include "../../source/core/slang-random-generator.h"
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
@@ -33,7 +33,7 @@ static void _writeRandom(RandomGenerator* rand, size_t maxSize, RiffContainer& i
SLANG_ASSERT(dataChunk);
}
-static void riffUnitTest()
+SLANG_UNIT_TEST(riff)
{
typedef RiffContainer::ScopeChunk ScopeChunk;
typedef RiffContainer::Chunk::Kind Kind;
@@ -177,4 +177,3 @@ static void riffUnitTest()
#endif
}
-SLANG_UNIT_TEST("Riff", riffUnitTest);
diff --git a/tools/slang-test/unit-test-short-list.cpp b/tools/slang-unit-test/unit-test-short-list.cpp
index 0559419bb..2760d633e 100644
--- a/tools/slang-test/unit-test-short-list.cpp
+++ b/tools/slang-unit-test/unit-test-short-list.cpp
@@ -1,6 +1,7 @@
// unit-test-path.cpp
-#include "test-context.h"
+#include "source/core/slang-basic.h"
+#include "tools/unit-test/slang-unit-test.h"
using namespace Slang;
@@ -15,7 +16,7 @@ static bool _checkArrayView(ArrayView<T> v0, ArrayView<T> v1)
return true;
}
-static void shortListUnitTest()
+SLANG_UNIT_TEST(shortList)
{
{
ShortList<String, 4> shortList = { "a", "b", "c" };
@@ -74,5 +75,3 @@ static void shortListUnitTest()
List<String>{"a", "b", "c", "d", "e"}.getArrayView()));
}
}
-
-SLANG_UNIT_TEST("ShortList", shortListUnitTest);
diff --git a/tools/slang-test/unit-test-string.cpp b/tools/slang-unit-test/unit-test-string.cpp
index e8a33fbbe..629ed2373 100644
--- a/tools/slang-test/unit-test-string.cpp
+++ b/tools/slang-unit-test/unit-test-string.cpp
@@ -2,7 +2,7 @@
#include "../../source/core/slang-string-util.h"
-#include "test-context.h"
+#include "tools/unit-test/slang-unit-test.h"
//#include <math.h>
@@ -112,7 +112,7 @@ static bool _areApproximatelyEqual(double a, double b, double fixedEpsilon = 1e-
return _calcULPDistance(a, b) <= ulpsEpsilon;
}
-static void stringUnitTest()
+SLANG_UNIT_TEST(string)
{
{
UnownedStringSlice checkLines[] = { UnownedStringSlice::fromLiteral("") };
@@ -260,5 +260,3 @@ static void stringUnitTest()
}
}
}
-
-SLANG_UNIT_TEST("String", stringUnitTest);
diff --git a/tools/unit-test/slang-unit-test.cpp b/tools/unit-test/slang-unit-test.cpp
index a31614c05..28eba3a1f 100644
--- a/tools/unit-test/slang-unit-test.cpp
+++ b/tools/unit-test/slang-unit-test.cpp
@@ -5,13 +5,14 @@
struct SlangUnitTest
{
const char* name;
- slang::UnitTestFunc func;
+ UnitTestFunc func;
};
-class SlangUnitTestModule : public slang::IUnitTestModule
+class SlangUnitTestModule : public IUnitTestModule
{
public:
Slang::List<SlangUnitTest> tests;
+ ITestReporter* testReporter = nullptr;
virtual SlangInt getTestCount() override
{
@@ -22,10 +23,21 @@ public:
return tests[index].name;
}
- virtual slang::UnitTestFunc getTestFunc(SlangInt index) override
+ virtual UnitTestFunc getTestFunc(SlangInt index) override
{
return tests[index].func;
}
+
+ virtual void setTestReporter(ITestReporter* reporter) override
+ {
+ testReporter = reporter;
+ }
+
+ virtual void destroy() override
+ {
+ tests = decltype(tests)();
+ }
+
};
SlangUnitTestModule* _getTestModule()
@@ -34,15 +46,20 @@ SlangUnitTestModule* _getTestModule()
return &testModule;
}
+ITestReporter* getTestReporter()
+{
+ return _getTestModule()->testReporter;
+}
+
extern "C"
{
-SLANG_DLL_EXPORT slang::IUnitTestModule* slangUnitTestGetModule()
+SLANG_DLL_EXPORT IUnitTestModule* slangUnitTestGetModule()
{
return _getTestModule();
}
}
-slang::UnitTestRegisterHelper::UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc)
+UnitTestRegisterHelper::UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc)
{
_getTestModule()->tests.add(SlangUnitTest{ name, testFunc });
}
diff --git a/tools/unit-test/slang-unit-test.h b/tools/unit-test/slang-unit-test.h
index 7651e6b46..033fab395 100644
--- a/tools/unit-test/slang-unit-test.h
+++ b/tools/unit-test/slang-unit-test.h
@@ -3,36 +3,73 @@
#include "slang.h"
#include "source/core/slang-render-api-util.h"
-namespace slang
+enum class TestResult
{
- struct UnitTestContext
- {
- slang::IGlobalSession* slangGlobalSession;
- const char* workDirectory;
- ISlangWriter* outputWriter;
- Slang::RenderApiFlags enabledApis;
- };
-
- typedef SlangResult (*UnitTestFunc)(UnitTestContext*);
-
- class IUnitTestModule
- {
- public:
- virtual SlangInt getTestCount() = 0;
- virtual const char* getTestName(SlangInt index) = 0;
- virtual UnitTestFunc getTestFunc(SlangInt index) = 0;
- };
-
- class UnitTestRegisterHelper
- {
- public:
- UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc);
- };
-
- typedef slang::IUnitTestModule* (*UnitTestGetModuleFunc)();
+ // NOTE! Must keep in order such that combine is meaningful. That is larger values are higher precident - and a series of tests that has lots of passes
+ // and a fail, is still a fail overall.
+ Ignored,
+ Pass,
+ Fail,
+};
+
+enum class TestMessageType
+{
+ Info, ///< General info (may not be shown depending on verbosity setting)
+ TestFailure, ///< Describes how a test failure took place
+ RunError, ///< Describes an error that caused a test not to actually correctly run
+};
+
+class ITestReporter
+{
+public:
+ virtual void startTest(const char* testName) = 0;
+ virtual void addResult(TestResult result) = 0;
+ virtual void addResultWithLocation(TestResult result, const char* testText, const char* file, int line) = 0;
+ virtual void addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) = 0;
+ virtual void addExecutionTime(double time) = 0;
+ virtual void message(TestMessageType type, const char* message) = 0;
+ virtual void endTest() = 0;
+};
+
+ITestReporter* getTestReporter();
+
+struct UnitTestContext
+{
+ slang::IGlobalSession* slangGlobalSession;
+ const char* workDirectory;
+ Slang::RenderApiFlags enabledApis;
+};
+
+typedef void (*UnitTestFunc)(UnitTestContext*);
+
+class IUnitTestModule
+{
+public:
+ virtual SlangInt getTestCount() = 0;
+ virtual const char* getTestName(SlangInt index) = 0;
+ virtual UnitTestFunc getTestFunc(SlangInt index) = 0;
+ virtual void setTestReporter(ITestReporter* reporter) = 0;
+ virtual void destroy() = 0;
+};
+
+class UnitTestRegisterHelper
+{
+public:
+ UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc);
+};
+
+typedef IUnitTestModule* (*UnitTestGetModuleFunc)();
#define SLANG_UNIT_TEST(name) \
- SlangResult name(slang::UnitTestContext* context); \
- slang::UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \
- SlangResult name(slang::UnitTestContext* context)
-}
+void name(UnitTestContext* unitTestContext); \
+UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \
+void name(UnitTestContext* unitTestContext)
+
+#define SLANG_CHECK(x) getTestReporter()->addResultWithLocation((x), #x, __FILE__, __LINE__);
+#define SLANG_CHECK_ABORT(x) \
+ { \
+ bool _slang_check_result = (x); \
+ getTestReporter()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \
+ if (!_slang_check_result) return; \
+ }
+#define SLANG_IGNORE_TEST getTestReporter()->addResult(TestResult::Ignored); return;