|
| 1 | +#include "App.h" |
| 2 | +#include "ModuleSnapshot.h" |
| 3 | + |
| 4 | +#include <Babylon/DebugTrace.h> |
| 5 | +#include <Babylon/Graphics/Device.h> |
| 6 | + |
| 7 | +#include <Windows.h> |
| 8 | + |
| 9 | +#include <iostream> |
| 10 | +#include <string_view> |
| 11 | + |
| 12 | +namespace ModuleLoadTest |
| 13 | +{ |
| 14 | + namespace |
| 15 | + { |
| 16 | + LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 17 | + { |
| 18 | + return ::DefWindowProc(hWnd, msg, wParam, lParam); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + bool IsBeingTraced() |
| 23 | + { |
| 24 | + return ::IsDebuggerPresent() != FALSE; |
| 25 | + } |
| 26 | + |
| 27 | + // Expected set of modules loaded during BabylonNative boot, as a delta |
| 28 | + // from the baseline snapshot captured by the TLS callback before any C++ |
| 29 | + // static initializer in this binary has run. Base names only, lower case. |
| 30 | + // |
| 31 | + // This list targets optimized builds (Release and RelWithDebInfo, which |
| 32 | + // produce identical module sets). Debug builds load additional debug CRT |
| 33 | + // and diagnostic DLLs and are not supported — main() returns a SKIP in |
| 34 | + // that config. CI runs only in RelWithDebInfo (see CMakeLists.txt's |
| 35 | + // `add_test ... CONFIGURATIONS Release RelWithDebInfo`). |
| 36 | + // |
| 37 | + // Launch-environment noise (e.g. VS's Start Without Debugging injecting |
| 38 | + // kernel.appcore.dll) is filtered via IsAllowedOptionalModule so devs |
| 39 | + // see the same verdict from Ctrl-F5 as CI does from a plain cmd launch. |
| 40 | + // |
| 41 | + // The assertion is asymmetric: we FAIL on modules not in this list (a new |
| 42 | + // module was pulled in — the regression signal we want), and we IGNORE |
| 43 | + // modules in this list that did not load (environmental variance across |
| 44 | + // GPU SKUs, Windows patch levels, VS vs cmd launch, etc.). This lets the |
| 45 | + // list be a permissive superset that works on both dev machines and CI. |
| 46 | + // |
| 47 | + // Motivating example: a dependency quietly pulling in dbghelp.dll on boot. |
| 48 | + // dbghelp.dll lives in System32, so a path-based OS filter would miss it; |
| 49 | + // we therefore golden-list the full delta (including OS modules) and only |
| 50 | + // allow a narrow name-pattern carve-out for GPU driver ICDs whose exact |
| 51 | + // names differ per runner SKU (see IsAllowedOptionalModule). |
| 52 | + const ModuleSnapshot& GetExpectedBootModules() |
| 53 | + { |
| 54 | + // Seeded from a local RelWithDebInfo run on Windows 11 x64 with D3D11 |
| 55 | + // and Chakra. CI may add more entries for other Win32 configs |
| 56 | + // (V8/JSI/D3D12) — those should be appended as the draft PR runs. |
| 57 | + static const ModuleSnapshot kModules{ |
| 58 | + "bcryptprimitives.dll", |
| 59 | + "cfgmgr32.dll", |
| 60 | + "crypt32.dll", |
| 61 | + "cryptbase.dll", |
| 62 | + "cryptnet.dll", |
| 63 | + "d3d10warp.dll", |
| 64 | + "d3d11.dll", |
| 65 | + "d3d11_3sdklayers.dll", |
| 66 | + "d3d12.dll", |
| 67 | + "d3d12core.dll", |
| 68 | + "d3d12sdklayers.dll", |
| 69 | + "d3dscache.dll", |
| 70 | + // TODO: bgfx loads dbghelp.dll at boot (callstack/crash helper). Drop this |
| 71 | + // entry once bgfx stops pulling it in. |
| 72 | + "dbghelp.dll", |
| 73 | + "dcomp.dll", |
| 74 | + "devobj.dll", |
| 75 | + "directxdatabasehelper.dll", |
| 76 | + "drvstore.dll", |
| 77 | + "dwmapi.dll", |
| 78 | + "dxcore.dll", |
| 79 | + "dxgi.dll", |
| 80 | + "dxgidebug.dll", |
| 81 | + "dxilconv.dll", |
| 82 | + "iertutil.dll", |
| 83 | + "imagehlp.dll", |
| 84 | + "msasn1.dll", |
| 85 | + "msctf.dll", |
| 86 | + "netutils.dll", |
| 87 | + "ntmarta.dll", |
| 88 | + "powrprof.dll", |
| 89 | + "profapi.dll", |
| 90 | + "rsaenh.dll", |
| 91 | + "setupapi.dll", |
| 92 | + "shcore.dll", |
| 93 | + "shell32.dll", |
| 94 | + "srvcli.dll", |
| 95 | + "umpdc.dll", |
| 96 | + "userenv.dll", |
| 97 | + "uxtheme.dll", |
| 98 | + "version.dll", |
| 99 | + "windows.storage.dll", |
| 100 | + "winmm.dll", |
| 101 | + "wintrust.dll", |
| 102 | + "wintypes.dll", |
| 103 | + "wldp.dll", |
| 104 | + }; |
| 105 | + return kModules; |
| 106 | + } |
| 107 | + |
| 108 | + // Name patterns for modules whose presence in the delta is allowed but |
| 109 | + // not required. Covers two classes: |
| 110 | + // |
| 111 | + // * GPU driver ICDs, whose exact base name depends on which GPU the |
| 112 | + // runner has (NVIDIA/Intel/AMD/ATI). |
| 113 | + // * Environmental/ambient DLLs that some launchers (e.g. Visual Studio's |
| 114 | + // Start Without Debugging) inject into the process but which a plain |
| 115 | + // cmd.exe launch does not. These are not introduced by BabylonNative. |
| 116 | + // |
| 117 | + // Prefixes match at the start of the base name; exacts match the whole |
| 118 | + // name. |
| 119 | + bool IsAllowedOptionalModule(std::string_view name) |
| 120 | + { |
| 121 | + static constexpr std::string_view kPrefixes[] = { |
| 122 | + // GPU driver ICDs |
| 123 | + "nv", // NVIDIA (nvoglv64.dll, nvapi64.dll, nvd3dum.dll, ...) |
| 124 | + "ig", // Intel (igdumd64.dll, igxelpicd64.dll, ...) |
| 125 | + "amd", // AMD (amdvlk64.dll, amdxc64.dll, ...) |
| 126 | + "atio", // AMD/ATI (atio6axx.dll, ...) |
| 127 | + // Ambient WARP variants |
| 128 | + "microsoft.internal.warppal", |
| 129 | + }; |
| 130 | + static constexpr std::string_view kExact[] = { |
| 131 | + // GPU driver ICD |
| 132 | + "dxil.dll", |
| 133 | + // VS Start-Without-Debugging launch environment |
| 134 | + "kernel.appcore.dll", |
| 135 | + }; |
| 136 | + for (const auto& prefix : kPrefixes) |
| 137 | + { |
| 138 | + if (name.size() >= prefix.size() && name.compare(0, prefix.size(), prefix) == 0) |
| 139 | + { |
| 140 | + return true; |
| 141 | + } |
| 142 | + } |
| 143 | + for (const auto& exact : kExact) |
| 144 | + { |
| 145 | + if (name == exact) |
| 146 | + { |
| 147 | + return true; |
| 148 | + } |
| 149 | + } |
| 150 | + return false; |
| 151 | + } |
| 152 | + std::optional<Babylon::Graphics::Configuration> CreateGraphicsConfig() |
| 153 | + { |
| 154 | + ::SetConsoleOutputCP(CP_UTF8); |
| 155 | + |
| 156 | + // bgfx D3D12 implementation requires an HWND to avoid a device refcount |
| 157 | + // leak on shutdown. Create a hidden window to satisfy that requirement. |
| 158 | + // Parked in function-local static storage so the handle lives for the |
| 159 | + // duration of the process. |
| 160 | + static WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, |
| 161 | + ::GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, |
| 162 | + "BabylonNativeModuleLoadTest", nullptr }; |
| 163 | + ::RegisterClassEx(&wc); |
| 164 | + static HWND hWnd = ::CreateWindow(wc.lpszClassName, "BabylonNativeModuleLoadTest", |
| 165 | + WS_OVERLAPPEDWINDOW, -1, -1, -1, -1, nullptr, nullptr, wc.hInstance, nullptr); |
| 166 | + |
| 167 | + Babylon::DebugTrace::EnableDebugTrace(true); |
| 168 | + Babylon::DebugTrace::SetTraceOutput([](const char* trace) { |
| 169 | + ::OutputDebugStringA(trace); |
| 170 | + ::OutputDebugStringA("\n"); |
| 171 | + }); |
| 172 | + |
| 173 | + Babylon::Graphics::Configuration config{}; |
| 174 | + config.Window = hWnd; |
| 175 | + config.Width = 600; |
| 176 | + config.Height = 400; |
| 177 | + return config; |
| 178 | + } |
| 179 | +} |
0 commit comments