Re-enable a swath of DXIL tests for *nix builds (#3888)

These were disabled at a point that the DXC CI didn't reject builds for
failing on Linux, now that they do, we can enable these tests sure in
the knowledge that any changes to them that break on Linux will be
detected and fixed quickly

Fixed *nix error code return. The previous caused an infinite loop of retries.
This definition more accurately identifies the error that has occurred as not
benefiting from repeated attempts

Skip tests and filechecker elements that entirely depend on reflection or
linker interfaces that aren't implemented on *nix yet.

Correct capitalization in a few places to satisfy a case-sensitive filesystem

Detect directories from test include handler. *nix virtual filesystem will try to
load the file using the include handler when performing stat() on a directory.
The test include handler is pretty basic and would provide the next file, leaving
it without a file to offer when the real include came along.
By detecting a name that looks like a dir and returning failure, it
correctly indicates that the file isn't found by the handler and saves
the virtual file for when its needed.

Don't mark non-debug builds as such. The DEBUG define determines which
tests get run. Some of which depend on consistencies that can only be relied
upon in debug builds. So DEBUG is disabled for all non-debug builds.

Correct free of new() memory. Incidental regex allocations were changed for
HLSL to use the global new() operator, but were still freed using the standard
free(), but replacing the default free() with regex_free() allows the default new()
operator to be paired with the default delete() operator

Correct misnamed test flag. The *nix flag was mistakenly called InputFile instead
of InputPath. By renaming it, the ManualFile test can target a specific HLSL file.

Fix misused ArrayRef in legacy GV replacement. The replacement of the GV with
the legacy form used in libraries collected the arguments into an arrayref without
an array to ref, which caused garbage in release builds. Also moved to using end
vars for loops where the elements can get deleted during the loop.

Fix *nix conversion to utf8. When an unknown codepage is found, it tries to convert
to utf16, but that isn't' actually helpful for *nix for a shader codepage derived from
the BOM, which is correctly identified as utf32
This commit is contained in:
Greg Roth 2022-01-20 13:53:47 -08:00 коммит произвёл GitHub
Родитель 2bd9843e95
Коммит 437ae1e5b6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 104 добавлений и 80 удалений

Просмотреть файл

@ -56,10 +56,6 @@ int main() { return (float)x; }"
endif()
if( LLVM_ENABLE_ASSERTIONS )
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
if( NOT MSVC )
add_definitions( -D_DEBUG )
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDBG") # HLSL Change
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -UNDEBUG") # HLSL Change
if (0) # HLSL Change Starts

Просмотреть файл

@ -118,7 +118,7 @@
#define ERROR_OUT_OF_STRUCTURES ENOMEM
#define ERROR_NOT_CAPABLE EPERM
#define ERROR_NOT_FOUND ENOTSUP
#define ERROR_UNHANDLED_EXCEPTION EINTR
#define ERROR_UNHANDLED_EXCEPTION EBADF
// Used by HRESULT <--> WIN32 error code conversion
#define SEVERITY_ERROR 1

Просмотреть файл

@ -61,6 +61,14 @@
#define VERIFY_IS_GREATER_THAN_OR_EQUAL(greater, less) EXPECT_GE(greater, less)
#define VERIFY_IS_GREATER_THAN_2(greater, less) EXPECT_GT(greater, less)
#define VERIFY_IS_GREATER_THAN_3(greater, less, msg) EXPECT_GT(greater, less) << msg
#define VERIFY_IS_GREATER_THAN(...) MACRO_N(VERIFY_IS_GREATER_THAN_, __VA_ARGS__)
#define VERIFY_IS_LESS_THAN_2(greater, less) EXPECT_LT(greater, less)
#define VERIFY_IS_LESS_THAN_3(greater, less, msg) EXPECT_LT(greater, less) << msg
#define VERIFY_IS_LESS_THAN(...) MACRO_N(VERIFY_IS_LESS_THAN_, __VA_ARGS__)
#define VERIFY_WIN32_BOOL_SUCCEEDED_1(expr) EXPECT_TRUE(expr)
#define VERIFY_WIN32_BOOL_SUCCEEDED_2(expr, msg) EXPECT_TRUE(expr) << msg
#define VERIFY_WIN32_BOOL_SUCCEEDED(...) MACRO_N(VERIFY_WIN32_BOOL_SUCCEEDED_, __VA_ARGS__)

Просмотреть файл

@ -217,7 +217,9 @@ static unsigned CharSizeFromCodePage(UINT32 codePage) {
// We do not handle translation from these code page values.
static bool IsUnsupportedUtfCodePage(UINT32 codePage) {
switch (codePage) {
#ifdef _WIN32
case CP_UTF32LE:
#endif
case CP_UTF32BE:
case CP_UTF16BE:
return true;
@ -473,7 +475,11 @@ static HRESULT CodePageBufferToUtf8(UINT32 codePage, LPCVOID bufferPointer,
CDxcMallocHeapPtr<WCHAR> utf16NewCopy(pMalloc);
UINT32 utf16CharCount = 0;
const WCHAR *utf16Chars = nullptr;
#if _WIN32
if (codePage == CP_UTF16) {
#else
if (codePage == CP_UTF16 || codePage == CP_UTF32LE) {
#endif
if (!IsSizeWcharAligned(bufferSize))
throw hlsl::Exception(DXC_E_STRING_ENCODING_FAILED,
"Error in encoding argument specified");

Просмотреть файл

@ -1821,18 +1821,17 @@ bool UpdateStructTypeForLegacyLayout(DxilResourceBase &Res,
Function *NF = hlslOP->GetOpFunc(hlsl::OP::OpCode::CreateHandleForLib, UpdatedST);
// Replace old GV.
for (auto UserIt = Symbol->user_begin(); UserIt != Symbol->user_end();) {
for (auto UserIt = Symbol->user_begin(), userEnd = Symbol->user_end(); UserIt != userEnd;) {
Value *User = *(UserIt++);
if (LoadInst *ldInst = dyn_cast<LoadInst>(User)) {
if (!ldInst->user_empty()) {
IRBuilder<> Builder = IRBuilder<>(ldInst);
LoadInst *newLoad = Builder.CreateLoad(NewGV);
ArrayRef<Value *> args = {hlslOP->GetI32Const((unsigned)hlsl::OP::OpCode::CreateHandleForLib), newLoad};
Value *args[] = {hlslOP->GetI32Const((unsigned)hlsl::OP::OpCode::CreateHandleForLib), newLoad};
for (auto user = ldInst->user_begin(); user != ldInst->user_end();) {
for (auto user = ldInst->user_begin(), E = ldInst->user_end(); user != E;) {
CallInst *CI = cast<CallInst>(*(user++));
CallInst *newCI = CallInst::Create(NF, args, "", CI);
CI->replaceAllUsesWith(newCI);
CI->eraseFromParent();
@ -1945,7 +1944,7 @@ void ReplaceResourceUserWithHandle(
DxilResource &res,
LoadInst *load, Value *handle)
{
for (auto resUser = load->user_begin(); resUser != load->user_end();) {
for (auto resUser = load->user_begin(), E = load->user_end(); resUser != E;) {
Value *V = *(resUser++);
CallInst *CI = dyn_cast<CallInst>(V);
DxilInst_CreateHandleForLib createHandle(CI);

Просмотреть файл

@ -61,12 +61,12 @@ llvm_regfree(llvm_regex_t *preg)
g->magic = 0; /* mark it invalid */
if (g->strip != NULL)
free((char *)g->strip);
regex_free((char *)g->strip);
if (g->sets != NULL)
free((char *)g->sets);
regex_free((char *)g->sets);
if (g->setbits != NULL)
free((char *)g->setbits);
regex_free((char *)g->setbits);
if (g->must != NULL)
free(g->must);
free((char *)g);
regex_free(g->must);
regex_free((char *)g);
}

Просмотреть файл

@ -59,13 +59,12 @@ set(HLSL_IGNORE_SOURCES
PixTest.cpp
RewriterTest.cpp
ShaderOpTest.cpp
DxilContainerTest.cpp
ValidationTest.cpp
CompilerTest.cpp
)
add_clang_unittest(clang-hlsl-tests
AllocatorTest.cpp
CompilerTest.cpp
DxilContainerTest.cpp
DxilModuleTest.cpp
DxilResourceTests.cpp
DXIsenseTest.cpp
@ -77,6 +76,7 @@ add_clang_unittest(clang-hlsl-tests
OptionsTest.cpp
SystemValueTest.cpp
TestMain.cpp
ValidationTest.cpp
VerifierTest.cpp
)

Просмотреть файл

@ -25,12 +25,19 @@
#include "dxc/DxilContainer/DxilContainer.h"
#include "dxc/Support/WinIncludes.h"
#include "dxc/dxcapi.h"
#include "dxc/dxcpix.h"
#ifdef _WIN32
#include "dxc/dxcpix.h"
#include <atlfile.h>
#include <d3dcompiler.h>
#include "dia2.h"
#endif
#else // _WIN32
#ifndef __ANDROID__
#include <execinfo.h>
#define CaptureStackBackTrace(FramesToSkip, FramesToCapture, BackTrace, \
BackTraceHash) \
backtrace(BackTrace, FramesToCapture)
#endif // __ANDROID__
#endif // _WIN32
#include "dxc/Test/HLSLTestData.h"
#include "dxc/Test/HlslTestUtils.h"
@ -53,6 +60,22 @@
using namespace std;
using namespace hlsl_test;
// Examines a virtual filename to determine if it looks like a dir
// Based on whether the final path segment contains a dot
// Not ironclad, but good enough for testing
static bool LooksLikeDir(std::wstring fileName) {
for(int i = fileName.size() - 1; i > -1; i--) {
wchar_t ch = fileName[i];
if (ch == L'\\' || ch == L'/')
return true;
if (ch == L'.')
return false;
}
// No divider, no dot, assume file
return false;
}
class TestIncludeHandler : public IDxcIncludeHandler {
DXC_MICROCOM_REF_FIELD(m_dwRef)
public:
@ -94,7 +117,15 @@ public:
_In_ LPCWSTR pFilename, // Filename as written in #include statement
_COM_Outptr_ IDxcBlob **ppIncludeSource // Resultant source object for included file
) override {
CallInfos.push_back(LoadSourceCallInfo(pFilename));
LoadSourceCallInfo callInfo = LoadSourceCallInfo(pFilename);
// *nix will call stat() on dirs, which attempts to find it here
// This loader isn't meant for dirs, so return failure
if (LooksLikeDir(callInfo.Filename))
return m_defaultErrorCode;
CallInfos.push_back(callInfo);
*ppIncludeSource = nullptr;
if (callIndex >= CallResults.size()) {
@ -2835,8 +2866,10 @@ public:
// breakpoint for i failure on NN alloc - m_FailAlloc == 1+VAL && m_AllocCount == NN
// breakpoint for happy path for NN alloc - m_AllocCount == NN
P->AllocAtCount = m_AllocCount;
#ifndef __ANDROID__
if (CaptureStacks)
P->AllocFrameCount = CaptureStackBackTrace(1, StackFrameCount, P->AllocFrames, nullptr);
#endif // __ANDROID__
P->Size = cb;
P->Self = P;
return P + 1;
@ -2862,9 +2895,11 @@ public:
m_Size -= P->Size;
P->Entry.Flink->Blink = P->Entry.Blink;
P->Entry.Blink->Flink = P->Entry.Flink;
#ifndef __ANDROID__
if (CaptureStacks)
P->FreeFrameCount =
CaptureStackBackTrace(1, StackFrameCount, P->FreeFrames, nullptr);
#endif // __ANDROID__
}
virtual SIZE_T STDMETHODCALLTYPE GetSize(
@ -2896,7 +2931,12 @@ public:
#if _ITERATOR_DEBUG_LEVEL==0
// CompileWhenNoMemThenOOM can properly detect leaks only when debug iterators are disabled
#ifdef _WIN32
TEST_F(CompilerTest, CompileWhenNoMemThenOOM) {
#else
// Disabled it is ignored above
TEST_F(CompilerTest, DISABLED_CompileWhenNoMemThenOOM) {
#endif
WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
CComPtr<IDxcBlobEncoding> pSource;
@ -3391,6 +3431,7 @@ TEST_F(CompilerTest, CodeGenVectorAtan2) {
CodeGenTestCheck(L"atan2_vector_argument.hlsl");
}
#ifdef _WIN32 // Reflection unsupported
TEST_F(CompilerTest, LibGVStore) {
CComPtr<IDxcCompiler> pCompiler;
CComPtr<IDxcOperationResult> pResult;
@ -3466,6 +3507,7 @@ TEST_F(CompilerTest, LibGVStore) {
std::wstring Text = BlobToUtf16(pTextBlob);
VERIFY_ARE_NOT_EQUAL(std::wstring::npos, Text.find(L"store"));
}
#endif // WIN32 - Reflection unsupported
TEST_F(CompilerTest, PreprocessWhenValidThenOK) {
CComPtr<IDxcCompiler> pCompiler;
@ -3739,6 +3781,7 @@ TEST_F(CompilerTest, DISABLED_ManualFileCheckTest) {
}
#ifdef _WIN32 // Reflection unsupported
TEST_F(CompilerTest, CodeGenHashStability) {
CodeGenTestCheckBatchHash(L"");
}
@ -3746,6 +3789,7 @@ TEST_F(CompilerTest, CodeGenHashStability) {
TEST_F(CompilerTest, BatchD3DReflect) {
CodeGenTestCheckBatchDir(L"d3dreflect");
}
#endif // WIN32 - Reflection unsupported
TEST_F(CompilerTest, BatchDxil) {
CodeGenTestCheckBatchDir(L"dxil");
@ -3772,7 +3816,7 @@ TEST_F(CompilerTest, BatchValidation) {
}
TEST_F(CompilerTest, BatchPIX) {
CodeGenTestCheckBatchDir(L"PIX");
CodeGenTestCheckBatchDir(L"pix");
}
TEST_F(CompilerTest, BatchSamples) {

Просмотреть файл

@ -122,7 +122,7 @@ public:
UINT32 codePage, _Outptr_ IDxcBlobEncoding **ppBlob) {
CComPtr<IDxcLibrary> library;
IFT(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &library));
IFT(library->CreateBlobWithEncodingFromPinned((LPBYTE)data, size, codePage,
IFT(library->CreateBlobWithEncodingFromPinned(data, size, codePage,
ppBlob));
}
@ -351,9 +351,7 @@ public:
VERIFY_ARE_EQUAL(testZ, baseZ);
}
}
#endif // _WIN32 - Reflection unsupported
#ifdef _WIN32 // - Reflection unsupported
HRESULT CompileFromFile(LPCWSTR path, bool useDXBC,
UINT fxcFlags, IDxcBlob **ppBlob) {
std::vector<FileRunCommandPart> parts;
@ -793,6 +791,7 @@ TEST_F(DxilContainerTest, CompileWhenSigSquareThenIncludeSplit) {
#endif
}
#ifdef _WIN32 // - Reflection unsupported
TEST_F(DxilContainerTest, CompileAS_CheckPSV0) {
if (m_ver.SkipDxilVersion(1, 5)) return;
const char asSource[] =
@ -1553,6 +1552,7 @@ TEST_F(DxilContainerTest, DxcUtils_CreateReflection) {
}
}
}
#endif // _WIN32 - Reflection unsupported
TEST_F(DxilContainerTest, CompileWhenOKThenIncludesFeatureInfo) {
CComPtr<IDxcCompiler> pCompiler;

Просмотреть файл

@ -37,7 +37,7 @@ namespace testOptions {
ARGOP(ExperimentalShaders)\
ARGOP(DebugLayer)\
ARGOP(SuitePath)\
ARGOP(InputFile)
ARGOP(InputPath)
ARG_LIST(ARG_DECLARE)

Просмотреть файл

@ -349,7 +349,7 @@ public:
CA2W shWide(pShaderModel, CP_UTF8);
wchar_t *pEntryName = L"main";
const wchar_t *pEntryName = L"main";
llvm::StringRef stage;
unsigned RequiredDxilMajor = 1, RequiredDxilMinor = 0;

Просмотреть файл

@ -12,10 +12,10 @@ add_clang_library(HLSLTestLib
else(WIN32)
set(HLSL_IGNORE_SOURCES
D3DReflectionDumper.cpp
FileCheckerTest.cpp
)
add_clang_library(HLSLTestLib
DxcTestUtils.cpp
FileCheckerTest.cpp
FileCheckForTest.cpp
)
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)

Просмотреть файл

@ -25,7 +25,7 @@
#include <atlfile.h>
#endif
#include "dxc/Test/HlslTestData.h"
#include "dxc/Test/HLSLTestData.h"
#include "dxc/Test/HlslTestUtils.h"
#include "dxc/Test/DxcTestUtils.h"
@ -41,13 +41,16 @@
#include "dxc/Support/Unicode.h"
#include "dxc/Support/microcom.h"
#include "dxc/DxilContainer/DxilContainer.h"
#ifdef _WIN32 // Reflection unsupported
#include "dxc/Test/D3DReflectionDumper.h"
#include "d3d12shader.h"
using namespace refl_dump;
#endif // WIN32 - Reflection unsupported
using namespace std;
using namespace hlsl_test;
using namespace refl_dump;
FileRunCommandPart::FileRunCommandPart(const std::string &command, const std::string &arguments, LPCWSTR commandFileName) :
Command(command), Arguments(arguments), CommandFileName(commandFileName) { }
@ -103,13 +106,25 @@ FileRunCommandResult FileRunCommandPart::Run(dxc::DxcDllSupport &DllSupport, con
return RunOpt(DllSupport, Prior);
}
else if (0 == _stricmp(Command.c_str(), "%D3DReflect")) {
#ifdef _WIN32 // Reflection unsupported
return RunD3DReflect(DllSupport, Prior);
#else
FileRunCommandResult result = FileRunCommandResult::Success("Can't run D3DReflect on non-windows, so just assuming success");
result.AbortPipeline = true;
return result;
#endif // WIN32 - Reflection unsupported
}
else if (0 == _stricmp(Command.c_str(), "%dxr")) {
return RunDxr(DllSupport, Prior);
}
else if (0 == _stricmp(Command.c_str(), "%dxl")) {
#ifdef _WIN32 // Linking unsupported
return RunLink(DllSupport, Prior);
#else
FileRunCommandResult result = FileRunCommandResult::Success("Can't run dxl on non-windows, so just assuming success");
result.AbortPipeline = true;
return result;
#endif // WIN32 - Linking unsupported
}
else if (pPluginToolsPaths != nullptr) {
auto it = pPluginToolsPaths->find(Command.c_str());
@ -208,52 +223,6 @@ FileRunCommandResult FileRunCommandPart::ReadOptsForDxc(
return FileRunCommandResult::Success("");
}
static HRESULT ReAssembleTo(dxc::DxcDllSupport &DllSupport, void *bitcode, UINT32 size, IDxcBlob **pBlob) {
CComPtr<IDxcAssembler> pAssembler;
CComPtr<IDxcLibrary> pLibrary;
IFT(DllSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary));
IFT(DllSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler));
CComPtr<IDxcBlobEncoding> pInBlob;
IFT(pLibrary->CreateBlobWithEncodingFromPinned(bitcode, size, 0, &pInBlob));
CComPtr<IDxcOperationResult> pResult;
pAssembler->AssembleToContainer(pInBlob, &pResult);
HRESULT Result = 0;
IFT(pResult->GetStatus(&Result));
IFT(Result);
IFT(pResult->GetResult(pBlob));
return S_OK;
}
static HRESULT GetDxilBitcode(dxc::DxcDllSupport &DllSupport, IDxcBlob *pCompiledBlob, IDxcBlob **pBitcodeBlob) {
CComPtr<IDxcContainerReflection> pReflection;
CComPtr<IDxcLibrary> pLibrary;
IFT(DllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
IFT(DllSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary));
IFT(pReflection->Load(pCompiledBlob));
UINT32 uIndex = 0;
IFT(pReflection->FindFirstPartKind(hlsl::DFCC_DXIL, &uIndex));
CComPtr<IDxcBlob> pPart;
IFT(pReflection->GetPartContent(uIndex, &pPart));
auto header = (hlsl::DxilProgramHeader*)pPart->GetBufferPointer();
void *bitcode = (char *)&header->BitcodeHeader + header->BitcodeHeader.BitcodeOffset;
UINT32 bitcode_size = header->BitcodeHeader.BitcodeSize;
CComPtr<IDxcBlobEncoding> pBlob;
IFT(pLibrary->CreateBlobWithEncodingFromPinned(bitcode, bitcode_size, 0, &pBlob));
*pBitcodeBlob = pBlob.Detach();
return S_OK;
}
// Simple virtual file system include handler for test, fall back to default include handler
class IncludeHandlerVFSOverlayForTest : public IDxcIncludeHandler {
private:
@ -686,6 +655,7 @@ FileRunCommandResult FileRunCommandPart::RunOpt(dxc::DxcDllSupport &DllSupport,
return FileRunCommandResult::Success(BlobToUtf8(pOutputText));
}
#ifdef _WIN32 // Reflection unsupported
FileRunCommandResult FileRunCommandPart::RunD3DReflect(dxc::DxcDllSupport &DllSupport, const FileRunCommandResult *Prior) {
std::string args(strtrim(Arguments));
if (args != "%s")
@ -758,6 +728,7 @@ FileRunCommandResult FileRunCommandPart::RunD3DReflect(dxc::DxcDllSupport &DllSu
return FileRunCommandResult::Success(ss.str());
}
#endif // _WIN32 - Reflection unsupported
FileRunCommandResult FileRunCommandPart::RunDxr(dxc::DxcDllSupport &DllSupport, const FileRunCommandResult *Prior) {
// Support piping stdin from prior if needed.
@ -930,7 +901,7 @@ FileRunCommandResult FileRunCommandPart::RunTee(const FileRunCommandResult *Prio
void FileRunCommandPart::SubstituteFilenameVars(std::string &args) {
size_t pos;
std::string baseFileName = CW2A(CommandFileName);
std::string baseFileName = LPSTR(CW2A(CommandFileName));
if ((pos = baseFileName.find_last_of(".")) != std::string::npos) {
baseFileName = baseFileName.substr(0, pos);
}
@ -1232,7 +1203,7 @@ FileRunTestResult FileRunTestResult::RunHashTestFromFileCommands(LPCWSTR fileNam
IFT(dllSupport.Initialize());
FileRunTestResultImpl result(dllSupport);
result.RunHashTestFromFileCommands(fileName);
return result;
return std::move(result);
}
FileRunTestResult FileRunTestResult::RunFromFileCommands(LPCWSTR fileName,
@ -1242,7 +1213,7 @@ FileRunTestResult FileRunTestResult::RunFromFileCommands(LPCWSTR fileName,
IFT(dllSupport.Initialize());
FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName);
result.RunFileCheckFromFileCommands(fileName);
return result;
return std::move(result);
}
FileRunTestResult FileRunTestResult::RunFromFileCommands(LPCWSTR fileName, dxc::DxcDllSupport &dllSupport,
@ -1250,7 +1221,7 @@ FileRunTestResult FileRunTestResult::RunFromFileCommands(LPCWSTR fileName, dxc::
LPCWSTR dumpName /*=nullptr*/) {
FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName);
result.RunFileCheckFromFileCommands(fileName);
return result;
return std::move(result);
}
void ParseCommandParts(LPCSTR commands, LPCWSTR fileName,