From b5bb82411cc6101b66283f7d0abca7ceb58aa2f6 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:18:44 -0500 Subject: Feature/capture unit test (#4898) * record/replay: Add tests Modify the hello-world example to generate the hash code for the entry point spirv code, so that we can compare it with replaying the example. Add the test script to run the example and compare the hash code with replaying it. * Check nullptr for out Diagnostics We need to check whether the output Diagnostics is a nullptr, because it's allowed. * Fix the double free pointers * Add triangle example as the new test for record-replay Change the example base to add the offline rendering path because we don't want to display anything when we're in the test mode. This change involves introducing a TestBase that will parse the command line option. It will decide whether we are in the test mode. Disable all the swapchain and windows related creation, instead we will only create one single framebuffer for the render target. * Address comments TODO: In the follow up patches, I will add more tests and integrate the test flow into slang-unit-test. --- examples/example-base/test-base.cpp | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/example-base/test-base.cpp (limited to 'examples/example-base/test-base.cpp') diff --git a/examples/example-base/test-base.cpp b/examples/example-base/test-base.cpp new file mode 100644 index 000000000..5c727aabe --- /dev/null +++ b/examples/example-base/test-base.cpp @@ -0,0 +1,50 @@ +#include "test-base.h" + +#ifdef _WIN32 +#include +#include +#endif + +int TestBase::parseOption(int argc, char** argv) +{ + // We only make the parse in a very loose way for only extracting the test option. +#ifdef _WIN32 + wchar_t** szArglist; + szArglist = CommandLineToArgvW(GetCommandLineW(), &argc); +#endif + + for (int i = 0; i < argc; i++) + { +#ifdef _WIN32 + if (wcscmp(szArglist[i], L"--test-mode") == 0) +#else + if (strcmp(argv[i], "--test-mode") == 0) +#endif + { + m_isTestMode = true; + } + } + return 0; +} + +void TestBase::printEntrypointHashes(int entryPointCount, int targetCount, ComPtr& composedProgram) +{ + for (int targetIndex = 0; targetIndex < targetCount; targetIndex++) + { + for (int entryPointIndex = 0; entryPointIndex < entryPointCount; entryPointIndex++) + { + ComPtr entryPointHashBlob; + composedProgram->getEntryPointHash(entryPointIndex, targetIndex, entryPointHashBlob.writeRef()); + + Slang::StringBuilder strBuilder; + strBuilder << "entrypoint: "<< entryPointIndex << ", target: " << targetIndex << ", hash: "; + + uint8_t* buffer = (uint8_t*)entryPointHashBlob->getBufferPointer(); + for (size_t i = 0; i < entryPointHashBlob->getBufferSize(); i++) + { + strBuilder<