Răsfoiți Sursa

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 ani în urmă
părinte
comite
590d36d4a6

+ 7 - 0
include/dxc/CMakeLists.txt

@@ -2,6 +2,13 @@ include(HCT)
 
 
 add_hlsl_hctgen(HLSLIntrinsicOp OUTPUT HlslIntrinsicOp.h)
 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(DXIL)
 add_subdirectory(DxilContainer)
 add_subdirectory(DxilContainer)
 add_subdirectory(HLSL)
 add_subdirectory(HLSL)

+ 3 - 1
include/dxc/Test/HlslTestUtils.h

@@ -26,6 +26,7 @@
 #include "WEXAdapter.h"
 #include "WEXAdapter.h"
 #endif
 #endif
 #include "dxc/Support/Unicode.h"
 #include "dxc/Support/Unicode.h"
+#include "dxc/Test/TestConfig.h"
 #include "dxc/DXIL/DxilConstants.h" // DenormMode
 #include "dxc/DXIL/DxilConstants.h" // DenormMode
 
 
 using namespace std;
 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)))
     if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(paramName, HlslDataDirValue)))
       return std::wstring();
       return std::wstring();
   } else {
   } 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];
   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 {
 namespace Common {
 class String : public std::wstring {
 class String : public std::wstring {
 public:
 public:
+  String() = default;
+  String(const wchar_t *S) : std::wstring(S) {}
   size_t GetLength() { return length(); }
   size_t GetLength() { return length(); }
   bool IsEmpty() { return empty(); }
   bool IsEmpty() { return empty(); }
   int CompareNoCase(std::wstring str) const {
   int CompareNoCase(std::wstring str) const {