Skip to content

Commit

Permalink
add test no hash when validation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bob80905 committed Jan 16, 2025
1 parent 3c4b566 commit 0370c17
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tools/clang/unittests/HLSL/ValidationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class ValidationTest : public ::testing::Test {
TEST_METHOD(SimpleGs1Fail)
TEST_METHOD(UavBarrierFail)
TEST_METHOD(UndefValueFail)
TEST_METHOD(ValidationFailNoHash)
TEST_METHOD(UpdateCounterFail)
TEST_METHOD(LocalResCopy)
TEST_METHOD(ResCounter)
Expand Down Expand Up @@ -1178,6 +1179,57 @@ TEST_F(ValidationTest, UavBarrierFail) {
TEST_F(ValidationTest, UndefValueFail) {
TestCheck(L"..\\CodeGenHLSL\\UndefValue.hlsl");
}
// verify that containers that are not valid DXIL do not
// get assigned a hash.
TEST_F(ValidationTest, ValidationFailNoHash) {
if (m_ver.SkipDxilVersion(1, 8))
return;
CComPtr<IDxcBlob> pProgram;
LPCSTR pSource = "float main(snorm float b : B) : SV_DEPTH \
{ \
float a; \
return b + a; \
}";

CComPtr<IDxcBlobEncoding> pSourceBlob;
Utf8ToBlob(m_dllSupport, pSource, &pSourceBlob);
std::vector<LPCWSTR> pArguments = {L"-Vd"};
LPCSTR pShaderModel = "ps_6_0";
bool result = CompileSource(pSourceBlob, pShaderModel, pArguments.data(), 1,
nullptr, 0, &pProgram);

VERIFY_IS_TRUE(result);

CComPtr<IDxcValidator> pValidator;
CComPtr<IDxcOperationResult> pResult;
unsigned Flags = 0;
VERIFY_SUCCEEDED(
m_dllSupport.CreateInstance(CLSID_DxcValidator, &pValidator));

VERIFY_SUCCEEDED(pValidator->Validate(pProgram, Flags, &pResult));
HRESULT status;
VERIFY_IS_NOT_NULL(pResult);
CComPtr<IDxcBlob> pValidationOutput;
pResult->GetStatus(&status);

// expect validation to fail
VERIFY_FAILED(status);
pResult->GetResult(&pValidationOutput);
// Make sure the validation output is not null when hashing.
VERIFY_SUCCEEDED(pValidationOutput != nullptr);

hlsl::DxilContainerHeader *pHeader =
(hlsl::DxilContainerHeader *)pProgram->GetBufferPointer();
// Validate the hash.
constexpr uint32_t HashStartOffset =
offsetof(struct DxilContainerHeader, Version);
auto *DataToHash = (const BYTE *)pHeader + HashStartOffset;
UINT AmountToHash = pHeader->ContainerSizeInBytes - HashStartOffset;
BYTE Result[DxilContainerHashSize];
ComputeHashRetail(DataToHash, AmountToHash, Result);
// Should be unequal, this proves the hash isn't written when validation fails
VERIFY_ARE_NOT_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0);
}
TEST_F(ValidationTest, UpdateCounterFail) {
if (m_ver.SkipIRSensitiveTest())
return;
Expand Down

0 comments on commit 0370c17

Please sign in to comment.