2
0
Эх сурвалжийг харах

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.
Chris B 2 жил өмнө
parent
commit
590d36d4a6

+ 7 - 0
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)

+ 3 - 1
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];

+ 1 - 0
include/dxc/Test/TestConfig.h.in

@@ -0,0 +1 @@
+#define DEFAULT_TEST_DIR L"@HLSL_TEST_DATA_DIR@"

+ 2 - 0
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 {