Skip to content

Commit 4d6d814

Browse files
authored
chore: Log timestamps in smoke tests (#2373)
1 parent 2bbb2bc commit 4d6d814

File tree

8 files changed

+156
-127
lines changed

8 files changed

+156
-127
lines changed

scripts/smoke-test-android.ps1

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ function PidOf([string] $deviceId, [string] $processName)
9999
return $processId
100100
}
101101

102-
Write-Host "Process '$processName' not found, retrying in 2 seconds..."
102+
Write-Log "Process '$processName' not found, retrying in 2 seconds..."
103103
Start-Sleep -Seconds 2
104104
}
105105

106-
Write-Host "Could not find PID for process '$processName' after 60 seconds" -ForegroundColor Red
106+
Write-Log "Could not find PID for process '$processName' after 60 seconds" -ForegroundColor Red
107107
return $null
108108
}
109109

110110
function OnError([string] $deviceId, [string] $deviceApi, [string] $appPID)
111111
{
112-
Write-Host "Dumping logs for $device"
112+
Write-Log "Dumping logs for $device"
113113
Write-Host "::group::logcat"
114114
LogCat $deviceId $appPID
115115
Write-Host "::endgroup::"
@@ -140,7 +140,7 @@ If ($DeviceCount -eq 0)
140140
}
141141
Else
142142
{
143-
Write-Host "Found $DeviceCount devices: $DeviceList"
143+
Write-Log "Found $DeviceCount devices: $DeviceList"
144144
}
145145

146146
# Check if APK was built.
@@ -159,13 +159,13 @@ adb -s $device logcat -c
159159

160160
$deviceApi = "$(adb -s $device shell getprop ro.build.version.sdk)".Trim()
161161
$deviceSdk = "$(adb -s $device shell getprop ro.build.version.release)".Trim()
162-
Write-Host "`nChecking device $device with SDK '$deviceSdk' and API '$deviceApi'"
162+
Write-Log "`nChecking device $device with SDK '$deviceSdk' and API '$deviceApi'"
163163

164164
# Uninstall previous installation
165165
$stdout = adb -s $device shell "pm list packages -f"
166166
if ($null -ne ($stdout | Select-String $ProcessName))
167167
{
168-
Write-Host "Uninstalling previous $ProcessName."
168+
Write-Log "Uninstalling previous $ProcessName."
169169
$stdout = adb -s $device uninstall $ProcessName
170170
}
171171

@@ -176,7 +176,7 @@ $stdout = adb -s $device shell input keyevent KEYCODE_HOME
176176
$adbInstallRetry = 5
177177
do
178178
{
179-
Write-Host "Installing test app"
179+
Write-Log "Installing test app"
180180
$stdout = (adb -s $device install -r $BuildDir/$ApkFileName 2>&1)
181181

182182
if ($stdout.Contains("Broken pipe"))
@@ -190,7 +190,7 @@ do
190190
# Validate the installation
191191
If ($stdout -contains "Success")
192192
{
193-
Write-Host "Successfully installed APK"
193+
Write-Log "Successfully installed APK"
194194
}
195195
else
196196
{
@@ -218,18 +218,18 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
218218
{
219219
Write-Host "::group::Test: '$name'"
220220

221-
Write-Host "Clearing logcat from '$device'"
221+
Write-Log "Clearing logcat from '$device'"
222222
adb -s $device logcat -c
223223

224224
$activityName = $TestActivityName
225225

226-
Write-Host "Setting configuration"
226+
Write-Log "Setting configuration"
227227

228228
# Mark the full-screen notification as acknowledged
229229
adb -s $device shell "settings put secure immersive_mode_confirmations confirmed"
230230
adb -s $device shell "input keyevent KEYCODE_HOME"
231231

232-
Write-Host "Starting app '$activityName'"
232+
Write-Log "Starting app '$activityName'"
233233

234234
# Start the adb command as a background job so we can wait for it to finish with a timeout
235235
$job = Start-Job -ScriptBlock {
@@ -242,44 +242,44 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
242242
if ($null -eq $completed) {
243243
Stop-Job $job
244244
Remove-Job $job -Force
245-
Write-Host "Activity start timed out after 60 seconds"
245+
Write-Log "Activity start timed out after 60 seconds"
246246
return $false
247247
}
248248

249249
$output = Receive-Job $job
250250
Remove-Job $job
251-
252-
Write-Host "Checking if activity started"
251+
252+
Write-Log "Checking if activity started"
253253

254254
# Check if the activity failed to start
255255
if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.")
256256
{
257257
$activityName = $FallBackTestActivityName
258-
Write-Host "Trying fallback activity $activityName"
258+
Write-Log "Trying fallback activity $activityName"
259259

260260
$output = & adb -s $device shell am start -n $activityName -e test $Name -W 2>&1
261-
261+
262262
# Check if the fallback activity failed to start
263263
if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.")
264264
{
265-
Write-Host "Activity does not exist"
265+
Write-Log "Activity does not exist"
266266
return $false
267267
}
268268
}
269-
270-
Write-Host "Activity started successfully"
269+
270+
Write-Log "Activity started successfully"
271271

272272
$appPID = PidOf $device $ProcessName
273273
if ($null -eq $appPID)
274274
{
275275
Write-Host "::endgroup::"
276-
Write-Host "Retrieving process ID failed. Skipping test." -ForegroundColor Red
276+
Write-Log "Retrieving process ID failed. Skipping test." -ForegroundColor Red
277277
return $false
278278
}
279279

280-
Write-Host "Retrieved ID for '$ProcessName': $appPID"
280+
Write-Log "Retrieved ID for '$ProcessName': $appPID"
281281

282-
Write-Host "Waiting for tests to run..."
282+
Write-Log "Waiting for tests to run..."
283283

284284
$processFinished = $false
285285
$logCache = @()
@@ -297,7 +297,7 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
297297
# For crash tests, we're checking for `sentry-native` logging "crash has been captured" to reliably inform when tests finished running.
298298
if (($newLogs | Select-String "SmokeTester is quitting.") -or ($newLogs | Select-String "crash has been captured"))
299299
{
300-
Write-Host "Process finished marker detected. Finish waiting for tests to run."
300+
Write-Log "Process finished marker detected. Finish waiting for tests to run."
301301
$processFinished = $true
302302
break
303303
}
@@ -307,11 +307,11 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
307307

308308
if ($processFinished)
309309
{
310-
Write-Host "'$Name' test finished running."
310+
Write-Log "'$Name' test finished running."
311311
}
312312
else
313-
{
314-
Write-Host "'$Name' tests timed out. See logcat for more details."
313+
{
314+
Write-Log "'$Name' tests timed out. See logcat for more details."
315315
}
316316

317317
Write-Host "::endgroup::"
@@ -320,24 +320,24 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
320320
$logCache = ProcessNewLogs -newLogs $newLogs -lastLogCount ([ref]$lastLogCount) -logCache $logCache
321321

322322
Write-Host "::group::logcat"
323-
$logCache | ForEach-Object { Write-Host $_ }
323+
$logCache | ForEach-Object { Write-Host $_ }
324324
Write-Host "::endgroup::"
325325

326326
$lineWithSuccess = $logCache | Select-String $SuccessString
327327
$lineWithFailure = $logCache | Select-String $FailureString
328328

329329
if ($null -ne $lineWithSuccess)
330330
{
331-
Write-Host "'$Name' test passed." -ForegroundColor Green
331+
Write-Log "'$Name' test passed." -ForegroundColor Green
332332
return $true
333333
}
334334
elseif ($null -ne $lineWithFailure)
335335
{
336-
Write-Host "'$Name' test failed. See logcat for more details." -ForegroundColor Red
336+
Write-Log "'$Name' test failed. See logcat for more details." -ForegroundColor Red
337337
return $false
338338
}
339-
340-
Write-Host "'$Name' test execution failed." -ForegroundColor Red
339+
340+
Write-Log "'$Name' test execution failed." -ForegroundColor Red
341341
return $false
342342
}
343343

@@ -347,29 +347,29 @@ function RunTestWithRetry([string] $Name, [string] $SuccessString, [string] $Fai
347347
{
348348
if ($retryCount -gt 0)
349349
{
350-
Write-Host "Retry attempt $retryCount for test '$Name'"
350+
Write-Log "Retry attempt $retryCount for test '$Name'"
351351
Start-Sleep -Seconds 2 # Brief pause between retries
352352
}
353353

354-
Write-Host "Running test attempt $($retryCount + 1)/$MaxRetries"
354+
Write-Log "Running test attempt $($retryCount + 1)/$MaxRetries"
355355
$result = RunTest -Name $Name -SuccessString $SuccessString -FailureString $FailureString
356-
356+
357357
if ($result)
358358
{
359-
Write-Host "'$Name' test passed on attempt $($retryCount + 1)." -ForegroundColor Green
359+
Write-Log "'$Name' test passed on attempt $($retryCount + 1)." -ForegroundColor Green
360360
return $true
361361
}
362-
362+
363363
if ($retryCount + 1 -lt $MaxRetries)
364364
{
365-
Write-Host "'$Name' test failed. Retrying..." -ForegroundColor Yellow
365+
Write-Log "'$Name' test failed. Retrying..." -ForegroundColor Yellow
366366
continue
367367
}
368-
369-
Write-Host "'$Name' test failed after $MaxRetries attempts." -ForegroundColor Red
368+
369+
Write-Log "'$Name' test failed after $MaxRetries attempts." -ForegroundColor Red
370370
return $false
371371
}
372-
372+
373373
return $false
374374
}
375375

@@ -392,35 +392,35 @@ try
392392
}
393393
catch
394394
{
395-
Write-Host "Caught exception: $_"
396-
Write-Host $_.ScriptStackTrace
395+
Write-Log "Caught exception: $_"
396+
Write-Log $_.ScriptStackTrace
397397
OnError $device $deviceApi
398398
exit 1
399399
}
400400

401401
$failed = $false
402402

403-
if (-not $results.smoketestPassed)
403+
if (-not $results.smoketestPassed)
404404
{
405-
Write-Host "Smoke test failed"
405+
Write-Log "Smoke test failed"
406406
$failed = $true
407407
}
408408

409409
if (-not $results.hasntCrashedTestPassed)
410410
{
411-
Write-Host "HasntCrashed test failed"
411+
Write-Log "HasntCrashed test failed"
412412
$failed = $true
413413
}
414414

415415
if (-not $results.crashTestPassed)
416416
{
417-
Write-Host "Crash test failed"
417+
Write-Log "Crash test failed"
418418
$failed = $true
419419
}
420420

421421
if (-not $results.hasCrashTestPassed)
422422
{
423-
Write-Host "HasCrashed test failed"
423+
Write-Log "HasCrashed test failed"
424424
$failed = $true
425425
}
426426

@@ -429,5 +429,5 @@ if ($failed)
429429
exit 1
430430
}
431431

432-
Write-Host "All tests passed" -ForegroundColor Green
432+
Write-Log "All tests passed" -ForegroundColor Green
433433
exit 0

0 commit comments

Comments
 (0)