@@ -26,6 +26,17 @@ import (
2626 "github.com/stretchr/testify/suite"
2727)
2828
29+ // isWERDumpCollectionEnabled returns true by default; it is disabled when DD_E2E_SKIP_WER_DUMPS is truthy
30+ func isWERDumpCollectionEnabled () bool {
31+ val := os .Getenv ("DD_E2E_SKIP_WER_DUMPS" )
32+ switch strings .ToLower (strings .TrimSpace (val )) {
33+ case "1" , "true" , "yes" , "on" :
34+ return false
35+ default :
36+ return true
37+ }
38+ }
39+
2940// BaseSuite the base suite for all installer tests on Windows (install script, MSI, exe etc...).
3041// To run the test suites locally, pick a pipeline and define the following environment variables:
3142// E2E_PIPELINE_ID: the ID of the pipeline
@@ -111,15 +122,19 @@ func (s *BaseSuite) SetupSuite() {
111122 s .T ().Logf ("stable agent version: %s" , s .StableAgentVersion ())
112123
113124 // Enable crash dumps
114- host := s .Env ().RemoteHost
115- s .dumpFolder = `C:\dumps`
116- err := windowscommon .EnableWERGlobalDumps (host , s .dumpFolder )
117- s .Require ().NoError (err , "should enable WER dumps" )
118- // Set the environment variable at the machine level.
119- // The tests will be re-installing services so the per-service environment
120- // won't be persisted.
121- _ , err = host .Execute (`[Environment]::SetEnvironmentVariable("GOTRACEBACK", "wer", "Machine")` )
122- s .Require ().NoError (err , "should set GOTRACEBACK environment variable" )
125+ if isWERDumpCollectionEnabled () {
126+ host := s .Env ().RemoteHost
127+ s .dumpFolder = `C:\dumps`
128+ err := windowscommon .EnableWERGlobalDumps (host , s .dumpFolder )
129+ s .Require ().NoError (err , "should enable WER dumps" )
130+ // Set the environment variable at the machine level.
131+ // The tests will be re-installing services so the per-service environment
132+ // won't be persisted.
133+ _ , err = host .Execute (`[Environment]::SetEnvironmentVariable("GOTRACEBACK", "wer", "Machine")` )
134+ s .Require ().NoError (err , "should set GOTRACEBACK environment variable" )
135+ } else {
136+ s .T ().Log ("WER dump collection disabled via DD_E2E_SKIP_WER_DUMPS" )
137+ }
123138}
124139
125140// createCurrentAgent sets the current agent version for the test suite.
@@ -276,14 +291,66 @@ func (s *BaseSuite) AfterTest(suiteName, testName string) {
276291 }
277292
278293 // look for and download crashdumps
279- dumps , err := windowscommon .DownloadAllWERDumps (s .Env ().RemoteHost , s .dumpFolder , s .SessionOutputDir ())
280- s .Assert ().NoError (err , "should download crash dumps" )
281- if ! s .Assert ().Empty (dumps , "should not have crash dumps" ) {
282- s .T ().Logf ("Found crash dumps:" )
283- for _ , dump := range dumps {
284- s .T ().Logf (" %s" , dump )
294+ if isWERDumpCollectionEnabled () {
295+ // Poll for up to ~30s (1s interval) to allow WER to finish writing full dumps (DumpType=2)
296+ h := s .Env ().RemoteHost
297+ deadline := time .Now ().Add (30 * time .Second )
298+ for time .Now ().Before (deadline ) {
299+ entries , _ := h .ReadDir (s .dumpFolder )
300+ hasDump := false
301+ for _ , e := range entries {
302+ if ! e .IsDir () && strings .HasSuffix (strings .ToLower (e .Name ()), ".dmp" ) {
303+ hasDump = true
304+ break
305+ }
306+ }
307+ if hasDump {
308+ break
309+ }
310+ time .Sleep (1 * time .Second )
311+ }
312+ dumps , err := windowscommon .DownloadAllWERDumps (s .Env ().RemoteHost , s .dumpFolder , s .SessionOutputDir ())
313+ s .Assert ().NoError (err , "should download crash dumps" )
314+ if ! s .Assert ().Empty (dumps , "should not have crash dumps" ) {
315+ s .T ().Logf ("Found crash dumps:" )
316+ for _ , dump := range dumps {
317+ s .T ().Logf (" %s" , dump )
318+ }
285319 }
286320 }
321+ // Collect WER ReportArchive entries for powershell.exe if present.
322+ // Synchronously scan the WER ReportArchive for PowerShell crash
323+ // reports and copy any found files into the test’s output directory.
324+ func () {
325+ host := s .Env ().RemoteHost
326+ base := `C:\ProgramData\Microsoft\Windows\WER\ReportArchive`
327+ entries , derr := host .ReadDir (base )
328+ if derr != nil {
329+ return
330+ }
331+ for _ , e := range entries {
332+ if ! e .IsDir () {
333+ continue
334+ }
335+ name := e .Name ()
336+ if ! strings .HasPrefix (strings .ToLower (name ), strings .ToLower ("AppCrash_powershell.exe" )) {
337+ continue
338+ }
339+ dir := filepath .Join (base , name )
340+ files , derr2 := host .ReadDir (dir )
341+ if derr2 != nil {
342+ continue
343+ }
344+ for _ , f := range files {
345+ if f .IsDir () {
346+ continue
347+ }
348+ src := filepath .Join (dir , f .Name ())
349+ dst := filepath .Join (s .SessionOutputDir (), fmt .Sprintf ("WER_%s_%s" , name , f .Name ()))
350+ _ = host .GetFile (src , dst )
351+ }
352+ }
353+ }()
287354
288355 if s .T ().Failed () {
289356 // If the test failed, export the event logs for debugging
0 commit comments