diff options
| author | Yong He <yonghe@outlook.com> | 2021-09-22 10:06:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-22 10:06:59 -0700 |
| commit | b9b398d038b524f15a86ff27cd6888d54e8754e0 (patch) | |
| tree | 4fe46f864065a58db20edccd261e5794326ab2a1 /tools/unit-test | |
| parent | 6e9cee69b3588ddae09b08b9f580f59ad899983f (diff) | |
Add gfx unit testing framework. (#1943)
* Add gfx unit testing framework.
* Fix compilation error.
* Reset gfxDebugCallback after render_test.
* Pass enabledApi flags through.
* Fix for code review suggestions.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/unit-test')
| -rw-r--r-- | tools/unit-test/slang-unit-test.cpp | 48 | ||||
| -rw-r--r-- | tools/unit-test/slang-unit-test.h | 38 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tools/unit-test/slang-unit-test.cpp b/tools/unit-test/slang-unit-test.cpp new file mode 100644 index 000000000..a31614c05 --- /dev/null +++ b/tools/unit-test/slang-unit-test.cpp @@ -0,0 +1,48 @@ +#include "slang-unit-test.h" +#include "slang.h" +#include "source/core/slang-basic.h" + +struct SlangUnitTest +{ + const char* name; + slang::UnitTestFunc func; +}; + +class SlangUnitTestModule : public slang::IUnitTestModule +{ +public: + Slang::List<SlangUnitTest> tests; + + virtual SlangInt getTestCount() override + { + return tests.getCount(); + } + virtual const char* getTestName(SlangInt index) override + { + return tests[index].name; + } + + virtual slang::UnitTestFunc getTestFunc(SlangInt index) override + { + return tests[index].func; + } +}; + +SlangUnitTestModule* _getTestModule() +{ + static SlangUnitTestModule testModule; + return &testModule; +} + +extern "C" +{ +SLANG_DLL_EXPORT slang::IUnitTestModule* slangUnitTestGetModule() +{ + return _getTestModule(); +} +} + +slang::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 new file mode 100644 index 000000000..7651e6b46 --- /dev/null +++ b/tools/unit-test/slang-unit-test.h @@ -0,0 +1,38 @@ +#pragma once + +#include "slang.h" +#include "source/core/slang-render-api-util.h" + +namespace slang +{ + 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)(); + +#define SLANG_UNIT_TEST(name) \ + SlangResult name(slang::UnitTestContext* context); \ + slang::UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \ + SlangResult name(slang::UnitTestContext* context) +} |
