-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle bugreport generation for different APIs (#685)
* Handle bugreport generation for different APIs * address review feedback * Apply suggestions from code review Co-authored-by: Přemek Vysoký <[email protected]> * return full file name for bug report * Update src/Microsoft.DotNet.XHarness.Android/Execution/IReportManager.cs Co-authored-by: Přemek Vysoký <[email protected]> Co-authored-by: Přemek Vysoký <[email protected]>
- Loading branch information
Showing
7 changed files
with
134 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Microsoft.DotNet.XHarness.Android/Execution/AdbReportFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.DotNet.XHarness.Android.Execution | ||
{ | ||
internal class AdbReportFactory | ||
{ | ||
// This method return proper ReportManager based on API number of current device | ||
// It allows to apply different logic for bugreport generation on API 21-23 and above | ||
internal static IReportManager CreateReportManager(ILogger log, int api) | ||
{ | ||
if (api > 23) return new NewReportManager(log); | ||
else return new Api23AndOlderReportManager(log); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Microsoft.DotNet.XHarness.Android/Execution/Api23AndOlderReportManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.DotNet.XHarness.Android.Execution | ||
{ | ||
internal class Api23AndOlderReportManager : IReportManager | ||
{ | ||
private readonly ILogger _log; | ||
|
||
public Api23AndOlderReportManager(ILogger log) | ||
{ | ||
_log = log; | ||
} | ||
|
||
public string DumpBugReport(AdbRunner runner, string outputFilePathWithoutFormat) | ||
{ | ||
// give some time for bug report to be available | ||
Thread.Sleep(3000); | ||
|
||
var result = runner.RunAdbCommand($"bugreport", TimeSpan.FromMinutes(5)); | ||
|
||
if (result.ExitCode != 0) | ||
{ | ||
// Could throw here, but it would tear down a possibly otherwise acceptable execution. | ||
_log.LogError($"Error getting ADB bugreport:{Environment.NewLine}{result}"); | ||
return string.Empty; | ||
} | ||
else | ||
{ | ||
File.WriteAllText($"{outputFilePathWithoutFormat}.txt", result.StandardOutput); | ||
_log.LogInformation($"Wrote ADB bugreport to {outputFilePathWithoutFormat}.txt"); | ||
return $"{outputFilePathWithoutFormat}.txt"; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Microsoft.DotNet.XHarness.Android/Execution/IReportManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Microsoft.DotNet.XHarness.Android.Execution | ||
{ | ||
internal interface IReportManager | ||
{ | ||
string DumpBugReport(AdbRunner runner, string outputFilePathWithoutFormat); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Microsoft.DotNet.XHarness.Android/Execution/NewReportManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.DotNet.XHarness.Android.Execution | ||
{ | ||
class NewReportManager : IReportManager | ||
{ | ||
private readonly ILogger _log; | ||
public NewReportManager(ILogger log) | ||
{ | ||
_log = log; | ||
} | ||
|
||
public string DumpBugReport(AdbRunner runner, string outputFilePathWithoutFormat) | ||
{ | ||
// give some time for bug report to be available | ||
Thread.Sleep(3000); | ||
|
||
var result = runner.RunAdbCommand($"bugreport {outputFilePathWithoutFormat}.zip", TimeSpan.FromMinutes(5)); | ||
|
||
if (result.ExitCode != 0) | ||
{ | ||
// Could throw here, but it would tear down a possibly otherwise acceptable execution. | ||
_log.LogError($"Error getting ADB bugreport:{Environment.NewLine}{result}"); | ||
return string.Empty; | ||
} | ||
else | ||
{ | ||
_log.LogInformation($"Wrote ADB bugreport to {outputFilePathWithoutFormat}.zip"); | ||
return $"{outputFilePathWithoutFormat}.zip"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters