Skip to content

Commit 590d36d

Browse files
authored
Enable running unit tests without extra arguments (#4798)
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.
1 parent f6f90d3 commit 590d36d

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

include/dxc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ include(HCT)
22

33
add_hlsl_hctgen(HLSLIntrinsicOp OUTPUT HlslIntrinsicOp.h)
44

5+
set(HLSL_TEST_DATA_DIR ${LLVM_SOURCE_DIR}/tools/clang/test/HLSL/)
6+
7+
configure_file(
8+
${LLVM_MAIN_INCLUDE_DIR}/dxc/Test/TestConfig.h.in
9+
${LLVM_INCLUDE_DIR}/dxc/Test/TestConfig.h
10+
)
11+
512
add_subdirectory(DXIL)
613
add_subdirectory(DxilContainer)
714
add_subdirectory(HLSL)

include/dxc/Test/HlslTestUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "WEXAdapter.h"
2727
#endif
2828
#include "dxc/Support/Unicode.h"
29+
#include "dxc/Test/TestConfig.h"
2930
#include "dxc/DXIL/DxilConstants.h" // DenormMode
3031

3132
using namespace std;
@@ -212,7 +213,8 @@ inline std::wstring GetPathToHlslDataFile(const wchar_t* relative, LPCWSTR param
212213
if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(paramName, HlslDataDirValue)))
213214
return std::wstring();
214215
} else {
215-
ASSERT_HRESULT_SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(HLSLDATAFILEPARAM, HlslDataDirValue));
216+
if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(HLSLDATAFILEPARAM, HlslDataDirValue)))
217+
HlslDataDirValue = DEFAULT_TEST_DIR;
216218
}
217219

218220
wchar_t envPath[MAX_PATH];

include/dxc/Test/TestConfig.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define DEFAULT_TEST_DIR L"@HLSL_TEST_DATA_DIR@"

include/dxc/Test/WEXAdapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ namespace WEX {
132132
namespace Common {
133133
class String : public std::wstring {
134134
public:
135+
String() = default;
136+
String(const wchar_t *S) : std::wstring(S) {}
135137
size_t GetLength() { return length(); }
136138
bool IsEmpty() { return empty(); }
137139
int CompareNoCase(std::wstring str) const {

0 commit comments

Comments
 (0)