diff --git a/eng/cake/dotnet.cake b/eng/cake/dotnet.cake index b142277b10..d3c977ee0b 100644 --- a/eng/cake/dotnet.cake +++ b/eng/cake/dotnet.cake @@ -9,6 +9,7 @@ var localDotnet = GetBuildVariable("workloads", "local") == "local"; var vsVersion = GetBuildVariable("VS", ""); string MSBuildExe = Argument("msbuild", EnvironmentVariable("MSBUILD_EXE", "")); string nugetSource = Argument("nugetsource", ""); +string testFilter = Argument("test-filter", EnvironmentVariable("TEST_FILTER")); string TestTFM = Argument("testtfm", ""); var useNuget = Argument("usenuget", true); @@ -731,6 +732,16 @@ void RunTestWithLocalDotNet(string csproj) void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = null, Dictionary argsExtra = null, bool noBuild = false, string resultsFileNameWithoutExtension = null, string filter = "") { + if (string.IsNullOrWhiteSpace(filter)) + { + filter = testFilter; + } + + if (!string.IsNullOrWhiteSpace(filter)) + { + Information("Run Tests With Filter {0}", filter); + } + string binlog; string results; var name = System.IO.Path.GetFileNameWithoutExtension(csproj); diff --git a/eng/devices/android.cake b/eng/devices/android.cake index 7528526720..a4f41b4290 100644 --- a/eng/devices/android.cake +++ b/eng/devices/android.cake @@ -111,6 +111,7 @@ Setup(context => var sdk = api >= 27 ? "google_apis_playstore" : "google_apis"; if (api == 27 && DEVICE_ARCH == "x86_64") sdk = "default"; + ANDROID_AVD_IMAGE = $"system-images;android-{api};{sdk};{DEVICE_ARCH}"; Information("Going to run image: {0}", ANDROID_AVD_IMAGE); @@ -143,6 +144,12 @@ Setup(context => Information("Starting Emulator: {0}...", ANDROID_AVD); emulatorProcess = AndroidEmulatorStart(ANDROID_AVD, emuSettings); } + + if (IsCIBuild()) + { + AdbLogcat(new AdbLogcatOptions() { Clear = true }); + AdbShell("logcat -G 16M"); + } }); Teardown(context => @@ -343,8 +350,29 @@ Task("uitest") SetEnvironmentVariable("APPIUM_LOG_FILE", $"{BINLOG_DIR}/appium_android.log"); - Information("Run UITests project {0}", PROJECT.FullPath); - RunTestWithLocalDotNet(PROJECT.FullPath, CONFIGURATION, noBuild: true, resultsFileNameWithoutExtension: $"{name}-{CONFIGURATION}-android"); + Information("Run UITests project {0}", PROJECT.FullPath); + + int numOfRetries = 0; + + if (IsCIBuild()) + numOfRetries = 1; + + for(int retryCount = 0; retryCount <= numOfRetries; retryCount++) + { + try + { + RunTestWithLocalDotNet(PROJECT.FullPath, CONFIGURATION, noBuild: true, resultsFileNameWithoutExtension: $"{name}-{CONFIGURATION}-android"); + break; + } + catch(Exception) + { + if (retryCount == numOfRetries) + { + WriteLogCat(); + throw; + } + } + } }); Task("cg-uitest") @@ -392,8 +420,50 @@ Task("cg-uitest") FailRunOnOnlyInconclusiveTests(System.IO.Path.Combine(nunitSettings.Work.FullPath, "TestResult.xml")); }); + +Task("logcat") + .Does(() => +{ + WriteLogCat(); +}); + RunTarget(TARGET); +void WriteLogCat(string filename = null) +{ + if (string.IsNullOrWhiteSpace(filename)) + { + var timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); + filename = $"logcat_{TARGET}_{timeStamp}.log"; + } + + EnsureDirectoryExists(GetLogDirectory()); + // I tried AdbLogcat here but the pipeline kept reporting "cannot create file" + var location = $"{GetLogDirectory()}/{filename}"; + Information("Writing logcat to {0}", location); + + var processSettings = new ProcessSettings(); + processSettings.RedirectStandardOutput = true; + processSettings.RedirectStandardError = true; + var adb = $"{ANDROID_SDK_ROOT}/platform-tools/adb"; + + Information("Running: {0} logcat -d", adb); + processSettings.Arguments = $"logcat -d"; + using (var fs = new System.IO.FileStream(location, System.IO.FileMode.Create)) + using (var sw = new StreamWriter(fs)) + { + processSettings.RedirectedStandardOutputHandler = (output) => { + sw.WriteLine(output); + return output; + }; + + var process = StartProcess($"{adb}", processSettings); + Information("exit code {0}", process); + } + + Information("Logcat written to {0}", location); +} + void SetupAppPackageNameAndResult() { if (string.IsNullOrEmpty(TEST_APP)) { diff --git a/eng/pipelines/common/ui-tests-steps.yml b/eng/pipelines/common/ui-tests-steps.yml index 2a2b9d7fc1..40123cbf9e 100644 --- a/eng/pipelines/common/ui-tests-steps.yml +++ b/eng/pipelines/common/ui-tests-steps.yml @@ -115,7 +115,8 @@ steps: - pwsh: ./build.ps1 -Script eng/devices/${{ parameters.platform }}.cake --target=uitest --project="${{ parameters.path }}" --appproject="${{ parameters.app }}" --device="${{ parameters.device }}" --apiversion="${{ parameters.version }}" --configuration="${{ parameters.configuration }}" --results="$(TestResultsDirectory)" --binlog="$(LogDirectory)" ${{ parameters.cakeArgs }} --verbosity=diagnostic displayName: $(Agent.JobName) - retryCountOnTaskFailure: 1 + ${{ if ne(parameters.platform, 'android')}}: + retryCountOnTaskFailure: 1 - bash: | suffix=$(date +%Y%m%d%H%M%S)