1212
1313#include " dxc/Support/WinIncludes.h"
1414#include < algorithm>
15+ #include < filesystem>
1516#include < memory>
1617#include < string>
1718#include < vector>
@@ -4221,13 +4222,17 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) {
42214222 _wputenv_s (VarName.c_str (), VarValue.c_str ());
42224223}
42234224
4224- // For now, 3 things are tested:
4225+ // For now, 4 things are tested:
42254226// 1. The environment variable is not set. GetDxilDllPath() is empty and
42264227// DxilDllFailedToLoad() returns false
42274228// 2. Given a bogus path in the environment variable, and an initialized
42284229// DxcDllExtValidationSupport object, GetDxilDllPath()
42294230// retrieves the bogus path despite DxcDllExtValidationSupport failing to load
42304231// it as a dll, and DxilDllFailedToLoad() returns true.
4232+ // 3. Given a valid path in the environment variable to a non-dll file,
4233+ // and an initialized DxcDllExtValidationSupport object, GetDxilDllPath()
4234+ // retrieves the valid path despite DxcDllExtValidationSupport failing to load
4235+ // it as a dll, and DxilDllFailedToLoad() returns true.
42314236// 3. CLSID_DxcCompiler, CLSID_DxcLinker, CLSID_DxcValidator
42324237// may be created through DxcDllExtValidationSupport.
42334238// This is all to simply test that the new class, DxcDllExtValidationSupport,
@@ -4236,6 +4241,7 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) {
42364241TEST_F (ValidationTest, UnitTestExtValidationSupport) {
42374242 dxc::DxcDllExtValidationLoader ExtSupportEmpty;
42384243 dxc::DxcDllExtValidationLoader ExtSupportBogus;
4244+ dxc::DxcDllExtValidationLoader ExtSupportValidNonDLLPath;
42394245
42404246 // capture any existing value in the environment variable,
42414247 // so that it can be restored after the test
@@ -4250,23 +4256,41 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) {
42504256 VERIFY_SUCCEEDED (ExtSupportEmpty.initialize ());
42514257
42524258 VERIFY_IS_FALSE (ExtSupportEmpty.dxilDllFailedToLoad ());
4253- std::string EmptyPath = ExtSupportBogus .getDxilDllPath ();
4259+ std::string EmptyPath = ExtSupportEmpty .getDxilDllPath ();
42544260 VERIFY_ARE_EQUAL_STR (EmptyPath.c_str (), " " );
42554261
42564262 // 2. Test with a bogus path in the environment variable
42574263 SetEnvVarW (L" DXC_DXIL_DLL_PATH" , L" bogus" );
42584264
42594265 if (!ExtSupportBogus.IsEnabled ()) {
42604266 VERIFY_FAILED (ExtSupportBogus.initialize ());
4267+ VERIFY_ARE_EQUAL (ExtSupportBogus.getFailureReason (),
4268+ ExtSupportBogus.FailedDxilPath );
42614269 }
42624270
4263- // validate that m_dllExtSupport2 was able to capture the environment
4271+ // validate that ExtSupportBogus was able to capture the environment
42644272 // variable's value, and that loading the bogus path was unsuccessful
42654273 std::string BogusPath = ExtSupportBogus.getDxilDllPath ();
42664274 VERIFY_ARE_EQUAL_STR (BogusPath.c_str (), " bogus" );
42674275 VERIFY_IS_TRUE (ExtSupportBogus.dxilDllFailedToLoad ());
42684276
4269- // 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker,
4277+ // 3. Test with a valid path to this file in the environment variable
4278+ std::filesystem::path p = std::filesystem::absolute (__FILE__);
4279+ SetEnvVarW (L" DXC_DXIL_DLL_PATH" , p.wstring ());
4280+
4281+ if (!ExtSupportValidNonDLLPath.IsEnabled ()) {
4282+ VERIFY_FAILED (ExtSupportValidNonDLLPath.initialize ());
4283+ VERIFY_ARE_EQUAL (ExtSupportValidNonDLLPath.getFailureReason (),
4284+ ExtSupportValidNonDLLPath.FailedDxilLoad );
4285+ }
4286+
4287+ // validate that ExtSupportValidNonDLLPath was able to capture the environment
4288+ // variable's value, and that loading the valid non-dll path was unsuccessful
4289+ std::string ValidNonDLLPath = ExtSupportValidNonDLLPath.getDxilDllPath ();
4290+ VERIFY_ARE_EQUAL_STR (ValidNonDLLPath.c_str (), __FILE__);
4291+ VERIFY_IS_TRUE (ExtSupportValidNonDLLPath.dxilDllFailedToLoad ());
4292+
4293+ // 4. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker,
42704294 // and CLSID_DxcValidator through DxcDllExtValidationSupport.
42714295 CComPtr<IDxcCompiler> Compiler;
42724296 CComPtr<IDxcLinker> Linker;
0 commit comments