Skip to content

Commit 066aa9b

Browse files
committed
Simulate crash
1 parent 50cfd92 commit 066aa9b

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

.ado/jobs/e2e-test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ parameters:
88
- Continuous
99
- name: AgentPool
1010
type: object
11+
- name: simulateCrashForTesting
12+
# !!! TEMPORARY DEFAULT: true !!!
13+
# This branch (PR/0.84-fix-e2e-test-flakiness) flips the default to true so
14+
# that PR validation actually exercises the crash-dump-collection path end
15+
# to end. MUST be flipped back to false before merging anywhere — with it
16+
# enabled the E2E app crashes on startup and no real tests run.
17+
type: boolean
18+
default: true
19+
# When true, drops a sentinel file that RNTesterApp-Fabric reads on startup
20+
# and uses to trigger a deliberate access violation. Used to validate that
21+
# the crash-dump collection path (WER LocalDumps + artifact publish)
22+
# actually produces a usable .dmp in CI.
1123
- name: buildMatrix
1224
type: object
1325
default:
@@ -76,12 +88,33 @@ jobs:
7688
echo ##vso[task.setvariable variable=StartedFabricTests]true
7789
displayName: Set StartedFabricTests
7890
91+
# Test-only: arm the crash-simulation sentinel so RNTesterApp-Fabric
92+
# crashes on startup. Validates the WER LocalDumps artifact path.
93+
- ${{ if eq(parameters.simulateCrashForTesting, true) }}:
94+
- pwsh: |
95+
$flagPath = Join-Path $env:ProgramData 'rnw-e2e-simulate-crash.flag'
96+
New-Item -Path $flagPath -ItemType File -Force | Out-Null
97+
Write-Host "Crash-simulation sentinel created at $flagPath"
98+
displayName: Arm crash-simulation sentinel (TEST ONLY)
99+
79100
- script: |
80101
yarn e2etest
81102
displayName: yarn e2etest
82103
workingDirectory: packages/e2e-test-app-fabric
83104
timeoutInMinutes: 10 # Time to wait for this task to complete before the server kills it.
84105
106+
# Always disarm the crash sentinel so it cannot leak to a rerun on
107+
# the same agent.
108+
- ${{ if eq(parameters.simulateCrashForTesting, true) }}:
109+
- pwsh: |
110+
$flagPath = Join-Path $env:ProgramData 'rnw-e2e-simulate-crash.flag'
111+
if (Test-Path $flagPath) {
112+
Remove-Item $flagPath -Force
113+
Write-Host "Removed crash-simulation sentinel at $flagPath"
114+
}
115+
displayName: Disarm crash-simulation sentinel (TEST ONLY)
116+
condition: always()
117+
85118
# On test failure, snapshot any lingering RNTesterApp-Fabric / node
86119
# processes before subsequent steps (or the agent) tear them down.
87120
# WER LocalDumps only fires on actual crashes; this catches hangs

packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,33 @@ winrt::Microsoft::ReactNative::ReactNativeHost CreateReactNativeHost(
9999
return host;
100100
}
101101

102+
// Test-only: if the sentinel file exists, deliberately crash the app on startup.
103+
// Used by the E2E pipeline (see .ado/jobs/e2e-test.yml `simulateCrashForTesting`
104+
// parameter) to validate that the WER LocalDumps path produces a usable crash
105+
// dump artifact. File-based trigger is used because environment variables do
106+
// not reliably propagate through the packaged-app activation flow used by the
107+
// automation test driver.
108+
static void MaybeSimulateCrashForTesting() {
109+
wchar_t flagPath[MAX_PATH];
110+
DWORD len = GetEnvironmentVariableW(L"ProgramData", flagPath, MAX_PATH);
111+
if (len == 0 || len >= MAX_PATH) {
112+
return;
113+
}
114+
if (FAILED(PathCchAppend(flagPath, MAX_PATH, L"rnw-e2e-simulate-crash.flag"))) {
115+
return;
116+
}
117+
if (GetFileAttributesW(flagPath) == INVALID_FILE_ATTRIBUTES) {
118+
return;
119+
}
120+
// Deliberate null-pointer write to trigger an access violation. Volatile so
121+
// the optimizer keeps it.
122+
*reinterpret_cast<volatile int *>(nullptr) = 0xC0FFEE;
123+
}
124+
102125
_Use_decl_annotations_ int CALLBACK
103126
WinMain(HINSTANCE /* instance */, HINSTANCE, PSTR /* commandLine */, int /* showCmd */) {
127+
MaybeSimulateCrashForTesting();
128+
104129
// Initialize WinRT.
105130
winrt::init_apartment(winrt::apartment_type::single_threaded);
106131

0 commit comments

Comments
 (0)