From e944a243812eda8fda5cbd3248d46e84ee7533c7 Mon Sep 17 00:00:00 2001 From: Przemog1 Date: Thu, 16 Apr 2026 18:47:17 +0200 Subject: [PATCH 1/2] Added option to use custom seed --- common/include/nbl/examples/Tester/ITester.h | 78 ++++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/common/include/nbl/examples/Tester/ITester.h b/common/include/nbl/examples/Tester/ITester.h index afdb01633..1556e2690 100644 --- a/common/include/nbl/examples/Tester/ITester.h +++ b/common/include/nbl/examples/Tester/ITester.h @@ -176,38 +176,14 @@ class ITester bool performTestsAndVerifyResults(const std::string& logFileName) { - m_logFile.open(logFileName, std::ios::out | std::ios::trunc); - if (!m_logFile.is_open()) - m_logger->log("Failed to open log file!", system::ILogger::ELL_ERROR); - - core::vector inputTestValues; - core::vector exceptedTestResults; - - inputTestValues.reserve(m_testIterationCount); - exceptedTestResults.reserve(m_testIterationCount); - - m_logger->log("TESTS:", system::ILogger::ELL_PERFORMANCE); - for (int i = 0; i < m_testIterationCount; ++i) - { - // Set input thest values that will be used in both CPU and GPU tests - InputTestValues testInput = generateInputTestValues(); - // use std library or glm functions to determine expected test values, the output of functions from intrinsics.hlsl will be verified against these values - TestResults expected = determineExpectedResults(testInput); - - inputTestValues.push_back(testInput); - exceptedTestResults.push_back(expected); - } - - core::vector cpuTestResults = performCpuTests(inputTestValues); - core::vector gpuTestResults = performGpuTests(inputTestValues); - - bool pass = verifyAllTestResults(cpuTestResults, gpuTestResults, exceptedTestResults); - - m_logger->log("TESTS DONE.", system::ILogger::ELL_PERFORMANCE); reloadSeed(); + return performTestsAndVerifyResults_impl(logFileName); + } - m_logFile.close(); - return pass; + bool performTestsAndVerifyResults(const std::string& logFileName, const uint32_t seed) + { + reloadSeed(seed); + return performTestsAndVerifyResults_impl(logFileName); } virtual ~ITester() @@ -228,7 +204,6 @@ class ITester ITester(const uint32_t testBatchCount) : m_testBatchCount(testBatchCount), m_testIterationCount(testBatchCount * m_WorkgroupSize) { - reloadSeed(); }; virtual bool verifyTestResults(const TestResults& expectedTestValues, const TestResults& testValues, const size_t testIteration, const uint32_t seed, TestType testType) = 0; @@ -355,6 +330,41 @@ class ITester exit(-1); } + bool performTestsAndVerifyResults_impl(const std::string& logFileName) + { + m_logFile.open(logFileName, std::ios::out | std::ios::trunc); + if (!m_logFile.is_open()) + m_logger->log("Failed to open log file!", system::ILogger::ELL_ERROR); + + core::vector inputTestValues; + core::vector exceptedTestResults; + + inputTestValues.reserve(m_testIterationCount); + exceptedTestResults.reserve(m_testIterationCount); + + m_logger->log("TESTS:", system::ILogger::ELL_PERFORMANCE); + for (int i = 0; i < m_testIterationCount; ++i) + { + // Set input thest values that will be used in both CPU and GPU tests + InputTestValues testInput = generateInputTestValues(); + // use std library or glm functions to determine expected test values, the output of functions from intrinsics.hlsl will be verified against these values + TestResults expected = determineExpectedResults(testInput); + + inputTestValues.push_back(testInput); + exceptedTestResults.push_back(expected); + } + + core::vector cpuTestResults = performCpuTests(inputTestValues); + core::vector gpuTestResults = performGpuTests(inputTestValues); + + bool pass = verifyAllTestResults(cpuTestResults, gpuTestResults, exceptedTestResults); + + m_logger->log("TESTS DONE.", system::ILogger::ELL_PERFORMANCE); + + m_logFile.close(); + return pass; + } + core::vector performCpuTests(const core::vector& inputTestValues) { core::vector output(m_testIterationCount); @@ -404,6 +414,12 @@ class ITester m_mersenneTwister = std::mt19937(m_seed); } + void reloadSeed(uint32_t seed) + { + m_seed = seed; + m_mersenneTwister = std::mt19937(seed); + } + template bool compareTestValues(const T& lhs, const T& rhs, const float64_t maxAllowedDifference) { From a811c162907137fa6dcc98b676cbb183ca893479 Mon Sep 17 00:00:00 2001 From: Przemog1 Date: Thu, 16 Apr 2026 19:16:04 +0200 Subject: [PATCH 2/2] Added documentation for ITester.h --- common/include/nbl/examples/Tester/ITester.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/include/nbl/examples/Tester/ITester.h b/common/include/nbl/examples/Tester/ITester.h index 1556e2690..84d968c86 100644 --- a/common/include/nbl/examples/Tester/ITester.h +++ b/common/include/nbl/examples/Tester/ITester.h @@ -174,12 +174,25 @@ class ITester m_queue = m_device->getQueue(m_queueFamily, 0); } + /** + * @brief Runs tests and verifies their results using a randomly generated seed for test value generation. + * + * @param logFileName Name of the file where test logs will be saved. + * @return true if all tests pass and results are valid, false otherwise. + */ bool performTestsAndVerifyResults(const std::string& logFileName) { reloadSeed(); return performTestsAndVerifyResults_impl(logFileName); } + /** + * @brief Runs tests and verifies their results using a user-provided seed for test value generation. + * + * @param logFileName Name of the file where test logs will be saved. + * @param seed Custom seed used for generating test values, ensures deterministic and reproducible results + * @return true if all tests pass and results are valid, false otherwise. + */ bool performTestsAndVerifyResults(const std::string& logFileName, const uint32_t seed) { reloadSeed(seed);