Răsfoiți Sursa

[linux-port] DxilContainer/ModuleTest on Unix (#1474)

* [linux-port] DxilContainer/ModuleTest on Unix

Mostly just excluding portions that require reflection allows this
test to run with the usual corralling of header files behine a WIN32
ifdef and adding the gtest inheritence for non-win.
Change an include file capitalization so it can be found on case
sensitive filesystems.

* require libstdc++-5 for codecvt

The default version of libstdc++ on Ubuntu 14.04 LTS lacks some
c++11 features just as the default gcc compiler does. Even when
using clang, we are still using the GNU c++ libs.

This should install a later version that will have the header.

Also adds a define to Apple builds of DxilContainerTest that will
prevent it from defining two ambiguous wcsstr functions, failing to
discern what such a quixotic action could possibly mean, and
pointing an accusing finger at the developer presumably for expecting
anything different from Apple.
Greg Roth 7 ani în urmă
părinte
comite
2c7b48db88

+ 2 - 2
.travis.yml

@@ -49,8 +49,8 @@ branches:
 
 addons:
   apt:
-    packages:
-      - ninja-build
+    sources: ubuntu-toolchain-r-test
+    packages: ninja-build libstdc++-5-dev
 
 before_install:
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ninja; fi

+ 2 - 2
tools/clang/unittests/HLSL/CMakeLists.txt

@@ -60,8 +60,6 @@ set( LLVM_LINK_COMPONENTS
 
 set(HLSL_IGNORE_SOURCES
   CompilerTest.cpp
-  DxilContainerTest.cpp
-  DxilModuleTest.cpp
   ExecutionTest.cpp
   LinkerTest.cpp
   MSFileSysTest.cpp
@@ -73,6 +71,8 @@ set(HLSL_IGNORE_SOURCES
 add_clang_unittest(clang-hlsl-tests
   AllocatorTest.cpp
   DxcTestUtils.cpp
+  DxilContainerTest.cpp
+  DxilModuleTest.cpp
   DXIsenseTest.cpp
   ExtensionTest.cpp
   FileCheckerTest.cpp

+ 26 - 5
tools/clang/unittests/HLSL/DxilContainerTest.cpp

@@ -13,6 +13,11 @@
 #define UNICODE
 #endif
 
+#ifdef __APPLE__
+// Workaround for ambiguous wcsstr on Mac
+#define _WCHAR_H_CPLUSPLUS_98_CONFORMANCE_
+#endif
+
 #include <memory>
 #include <vector>
 #include <string>
@@ -22,10 +27,14 @@
 #include <algorithm>
 #include "dxc/Support/WinIncludes.h"
 #include "dxc/dxcapi.h"
+#ifdef _WIN32
 #include <atlfile.h>
+#include <d3dcompiler.h>
+#pragma comment(lib, "d3dcompiler.lib")
+#include <filesystem>
+#endif
 
 #include "HLSLTestData.h"
-#include "WexTestClass.h"
 #include "HlslTestUtils.h"
 #include "DxcTestUtils.h"
 
@@ -35,17 +44,14 @@
 #include "dxc/HLSL/DxilContainer.h"
 
 #include <fstream>
-#include <filesystem>
 #include <chrono>
 
-#include <d3dcompiler.h>
-#pragma comment(lib, "d3dcompiler.lib")
-
 #include <codecvt>
 
 
 using namespace std;
 using namespace hlsl_test;
+#ifdef _WIN32
 using namespace std::experimental::filesystem;
 
 static uint8_t MaskCount(uint8_t V) {
@@ -58,8 +64,13 @@ static uint8_t MaskCount(uint8_t V) {
   };
   return Count[V];
 }
+#endif
 
+#ifdef _WIN32
 class DxilContainerTest {
+#else
+class DxilContainerTest : public ::testing::Test {
+#endif
 public:
   BEGIN_TEST_CLASS(DxilContainerTest)
     TEST_CLASS_PROPERTY(L"Parallel", L"true")
@@ -104,6 +115,7 @@ public:
     return m_dllSupport.CreateInstance(CLSID_DxcCompiler, ppResult);
   }
 
+#ifdef _WIN32 // - Reflection Unsupported
   void CompareShaderInputBindDesc(D3D12_SHADER_INPUT_BIND_DESC *pTestDesc,
     D3D12_SHADER_INPUT_BIND_DESC *pBaseDesc) {
     VERIFY_ARE_EQUAL(pTestDesc->BindCount, pBaseDesc->BindCount);
@@ -321,6 +333,7 @@ public:
       VERIFY_ARE_EQUAL(testZ, baseZ);
     }
   }
+#endif // _WIN32 - Reflection unsupported
 
   void split(const wstring &s, wchar_t delim, vector<wstring> &elems) {
     wstringstream ss(s);
@@ -359,6 +372,7 @@ public:
     parts.push_back(P);
   }
 
+#ifdef _WIN32  // - Reflection unsupported
   HRESULT CompileFromFile(LPCWSTR path, bool useDXBC, IDxcBlob **ppBlob) {
     std::vector<FileRunCommandPart> parts;
     //NameParseCommandPartsFromFile(path, parts);
@@ -408,6 +422,7 @@ public:
         D3DReflect(pBlob->GetBufferPointer(), pBlob->GetBufferSize(),
                    __uuidof(ID3D12ShaderReflection), (void **)ppReflection));
   }
+#endif // _WIN32 - Reflection unsupported
 
   void CompileToProgram(LPCSTR program, LPCWSTR entryPoint, LPCWSTR target,
                         LPCWSTR *pArguments, UINT32 argCount,
@@ -489,6 +504,7 @@ public:
     }
   }
 
+#ifdef _WIN32 // Reflection unsupported
   WEX::Common::String WStrFmt(const wchar_t* msg, ...) {
     va_list args;
     va_start(args, msg);
@@ -520,8 +536,10 @@ public:
 
     CompareReflection(pProgramReflection, pProgramReflectionDXBC);
   }
+#endif // _WIN32 - Reflection unsupported
 };
 
+#ifdef _WIN32
 TEST_F(DxilContainerTest, CompileWhenDebugSourceThenSourceMatters) {
   char program1[] = "float4 main() : SV_Target { return 0; }";
   char program2[] = "  float4 main() : SV_Target { return 0; }  ";
@@ -558,6 +576,7 @@ TEST_F(DxilContainerTest, CompileWhenDebugSourceThenSourceMatters) {
   VERIFY_ARE_EQUAL_STR(binName1.c_str(), binName2.c_str());
   VERIFY_IS_FALSE(0 == strcmp(sourceName1Zss.c_str(), binName1.c_str()));
 }
+#endif // _WIN32
 
 TEST_F(DxilContainerTest, CompileWhenOKThenIncludesSignatures) {
   char program[] =
@@ -892,6 +911,7 @@ HRESULT HlslFileVariables::SetFromText(_In_count_(len) const char *pText, size_t
   return S_OK;
 }
 
+#ifdef _WIN32 // Reflection unsupported
 TEST_F(DxilContainerTest, ReflectionMatchesDXBC_CheckIn) {
   WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
   ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\CodeGenHLSL\\Samples\\DX11\\SimpleBezier11DS.hlsl").c_str(), false);
@@ -944,6 +964,7 @@ TEST_F(DxilContainerTest, ReflectionMatchesDXBC_Full) {
     }
   }
 }
+#endif // _WIN32 - Reflection unsupported
 
 TEST_F(DxilContainerTest, ValidateFromLL_Abs2) {
   CodeGenTestCheck(L"abs2_m.ll");

+ 5 - 2
tools/clang/unittests/HLSL/DxilModuleTest.cpp

@@ -8,7 +8,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "CompilationResult.h"
-#include "WexTestClass.h"
 #include "HlslTestUtils.h"
 #include "DxcTestUtils.h"
 #include "dxc/Support/microcom.h"
@@ -24,7 +23,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ErrorOr.h"
-#include "llvm/BitCode/ReaderWriter.h"
+#include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/InstIterator.h"
 
@@ -34,7 +33,11 @@ using namespace llvm;
 ///////////////////////////////////////////////////////////////////////////////
 // DxilModule unit tests.
 
+#ifdef _WIN32
 class DxilModuleTest {
+#else
+class DxilModuleTest : public ::testing::Test {
+#endif
 public:
   BEGIN_TEST_CLASS(DxilModuleTest)
     TEST_CLASS_PROPERTY(L"Parallel", L"true")