From 48e15e9d1d11ea09dc453e1f58735e6c9533b9ed Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 18 Nov 2022 11:39:42 -0600 Subject: [PATCH] Enable running unit tests without extra arguments This change provides a default value based on the build configuration which can be used in the absence of a specified HLSL Data Dir when running the tests. This does not change any existing functionality, but enables the common configuration of running the tests inside the configured source directory to omit specifiying a path. --- include/dxc/CMakeLists.txt | 7 +++++++ include/dxc/Test/HlslTestUtils.h | 4 +++- include/dxc/Test/TestConfig.h.in | 1 + include/dxc/Test/WEXAdapter.h | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 include/dxc/Test/TestConfig.h.in diff --git a/include/dxc/CMakeLists.txt b/include/dxc/CMakeLists.txt index c40a662c89..501739bb2d 100644 --- a/include/dxc/CMakeLists.txt +++ b/include/dxc/CMakeLists.txt @@ -2,6 +2,13 @@ include(HCT) add_hlsl_hctgen(HLSLIntrinsicOp OUTPUT HlslIntrinsicOp.h) +set(HLSL_TEST_DATA_DIR ${LLVM_SOURCE_DIR}/tools/clang/test/HLSL/) + +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/dxc/Test/TestConfig.h.in + ${LLVM_INCLUDE_DIR}/dxc/Test/TestConfig.h + ) + add_subdirectory(DXIL) add_subdirectory(DxilContainer) add_subdirectory(HLSL) diff --git a/include/dxc/Test/HlslTestUtils.h b/include/dxc/Test/HlslTestUtils.h index 822424aca8..61eb5a8432 100644 --- a/include/dxc/Test/HlslTestUtils.h +++ b/include/dxc/Test/HlslTestUtils.h @@ -26,6 +26,7 @@ #include "WEXAdapter.h" #endif #include "dxc/Support/Unicode.h" +#include "dxc/Test/TestConfig.h" #include "dxc/DXIL/DxilConstants.h" // DenormMode using namespace std; @@ -212,7 +213,8 @@ inline std::wstring GetPathToHlslDataFile(const wchar_t* relative, LPCWSTR param if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(paramName, HlslDataDirValue))) return std::wstring(); } else { - ASSERT_HRESULT_SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(HLSLDATAFILEPARAM, HlslDataDirValue)); + if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(HLSLDATAFILEPARAM, HlslDataDirValue))) + HlslDataDirValue = DEFAULT_TEST_DIR; } wchar_t envPath[MAX_PATH]; diff --git a/include/dxc/Test/TestConfig.h.in b/include/dxc/Test/TestConfig.h.in new file mode 100644 index 0000000000..b04984a506 --- /dev/null +++ b/include/dxc/Test/TestConfig.h.in @@ -0,0 +1 @@ +#define DEFAULT_TEST_DIR L"@HLSL_TEST_DATA_DIR@" diff --git a/include/dxc/Test/WEXAdapter.h b/include/dxc/Test/WEXAdapter.h index 847665240a..a886cd0005 100644 --- a/include/dxc/Test/WEXAdapter.h +++ b/include/dxc/Test/WEXAdapter.h @@ -132,6 +132,8 @@ namespace WEX { namespace Common { class String : public std::wstring { public: + String() = default; + String(const wchar_t *S) : std::wstring(S) {} size_t GetLength() { return length(); } bool IsEmpty() { return empty(); } int CompareNoCase(std::wstring str) const {