Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions tests/xharness/.vscode/launch.json

This file was deleted.

12 changes: 0 additions & 12 deletions tests/xharness/.vscode/tasks.json

This file was deleted.

24 changes: 14 additions & 10 deletions tests/xharness/AppBundleLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AppBundleLocator (IProcessManager processManager, Func<ILog> getLog, stri
this.dotnetPath = dotnetPath;
}

public async Task<string> LocateAppBundle (XmlDocument projectFile, string projectFilePath, TestTarget target, string buildConfiguration)
public async Task<string?> LocateAppBundle (XmlDocument projectFile, string projectFilePath, TestTarget target, string buildConfiguration)
{
string platform = string.Empty;
if (target != TestTarget.None)
Expand All @@ -47,7 +47,7 @@ public async Task<string> LocateAppBundle (XmlDocument projectFile, string proje

return await GetPropertyByMSBuildEvaluationAsync (projectFile, projectFilePath, "OutputPath", "_GenerateBundleName", properties);
} else {
return projectFile.GetOutputPath (platform, buildConfiguration).Replace ('\\', Path.DirectorySeparatorChar);
return projectFile.GetOutputPath (platform, buildConfiguration)?.Replace ('\\', Path.DirectorySeparatorChar);
}
}

Expand All @@ -56,7 +56,7 @@ public async Task<string> LocateAppBundle (XmlDocument projectFile, string proje
// * Will import the project file we're inspecting
// * Has a target that will print a given property
// and then executing MSBuild on this custom MSBuild file.
private async Task<string> GetPropertyByMSBuildEvaluationAsync (XmlDocument csproj, string projectPath, string evaluateProperty, string dependsOnTargets = "", Dictionary<string, string> properties = null)
async Task<string> GetPropertyByMSBuildEvaluationAsync (XmlDocument csproj, string projectPath, string evaluateProperty, string dependsOnTargets = "", Dictionary<string, string>? properties = null)
{
var xml =
@"<Project DefaultTargets='WriteProperty' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
Expand All @@ -74,7 +74,7 @@ private async Task<string> GetPropertyByMSBuildEvaluationAsync (XmlDocument cspr
</Project>
";

var dir = Path.GetDirectoryName (projectPath);
var dir = Path.GetDirectoryName (projectPath)!;
var inspector = Path.Combine (dir, "PropertyInspector.csproj");
var output = Path.Combine (dir, "PropertyInspector.txt");
try {
Expand All @@ -94,12 +94,14 @@ private async Task<string> GetPropertyByMSBuildEvaluationAsync (XmlDocument cspr
args.Add ("/p:ProjectFile=" + projectPath);
args.Add ("/p:OutputFile=" + output);

foreach (var prop in properties)
args.Add ($"/p:{prop.Key}={prop.Value}");
if (properties is not null) {
foreach (var prop in properties)
args.Add ($"/p:{prop.Key}={prop.Value}");
}

args.Add (inspector);

var env = new Dictionary<string, string> {
var env = new Dictionary<string, string?> {
{ "MSBUILD_EXE_PATH", null },
};

Expand Down Expand Up @@ -146,13 +148,13 @@ public string GetDotNetExecutable (string directory)
}

// Find the first global.json up the directory hierarchy (stopping at the root directory)
string global_json = null;
string? global_json = null;
var dir = directory;
while (dir.Length > 2) {
global_json = Path.Combine (dir, "global.json");
if (File.Exists (global_json))
break;
dir = Path.GetDirectoryName (dir);
dir = Path.GetDirectoryName (dir)!;
}
if (!File.Exists (global_json))
throw new Exception ($"Could not find any global.json file in {directory} or above");
Expand All @@ -164,7 +166,9 @@ public string GetDotNetExecutable (string directory)
var doc = new XmlDocument ();
doc.Load (reader);

var version = doc.SelectSingleNode ("/root/sdk").InnerText;
var version = doc.SelectSingleNode ("/root/sdk")?.InnerText;
if (version is null)
throw new Exception ($"Could not find SDK version in {global_json}");
string executable;

switch (version [0]) {
Expand Down
53 changes: 28 additions & 25 deletions tests/xharness/AppRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,41 @@ public class AppRunner {
readonly ISimulatorLoaderFactory simulatorsLoaderFactory;
readonly ISimpleListenerFactory listenerFactory;
readonly IDeviceLoaderFactory devicesLoaderFactory;
readonly ICrashSnapshotReporterFactory snapshotReporterFactory;
readonly CrashSnapshotReporterFactory snapshotReporterFactory;
readonly ICaptureLogFactory captureLogFactory;
readonly IDeviceLogCapturerFactory deviceLogCapturerFactory;
readonly DeviceLogCapturerFactory deviceLogCapturerFactory;
readonly ITestReporterFactory testReporterFactory;
readonly IAppBundleInformationParser appBundleInformationParser;

readonly RunMode runMode;
readonly bool isSimulator;
readonly TestTarget target;
readonly IHarness harness;
readonly Harness harness;
readonly double timeoutMultiplier;
readonly IBuildToolTask buildTask;
readonly string variation;
readonly BuildToolTask? buildTask;
readonly string? variation;
readonly string projectFilePath;
readonly string buildConfiguration;
readonly string? buildConfiguration;

string deviceName;
ISimulatorDevice simulator;
string? deviceName;
ISimulatorDevice? simulator;

bool ensureCleanSimulatorState = true;
bool EnsureCleanSimulatorState {
get => ensureCleanSimulatorState && string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("SKIP_SIMULATOR_SETUP"));
set => ensureCleanSimulatorState = value;
}

public AppBundleInformation AppInformation { get; private set; }
AppBundleInformation? appInformation;
public AppBundleInformation AppInformation {
get => appInformation!;
}

bool IsExtension => AppInformation.Extension.HasValue;
bool IsExtension => AppInformation?.Extension.HasValue ?? false;

public TestExecutingResult Result { get; private set; }

public string FailureMessage { get; private set; }
public string? FailureMessage { get; private set; }

public IFileBackedLog MainLog { get; set; }

Expand All @@ -67,22 +70,22 @@ public AppRunner (IMlaunchProcessManager processManager,
ISimulatorLoaderFactory simulatorsFactory,
ISimpleListenerFactory simpleListenerFactory,
IDeviceLoaderFactory devicesFactory,
ICrashSnapshotReporterFactory snapshotReporterFactory,
CrashSnapshotReporterFactory snapshotReporterFactory,
ICaptureLogFactory captureLogFactory,
IDeviceLogCapturerFactory deviceLogCapturerFactory,
DeviceLogCapturerFactory deviceLogCapturerFactory,
ITestReporterFactory reporterFactory,
TestTarget target,
IHarness harness,
Harness harness,
IFileBackedLog mainLog,
ILogs logs,
string projectFilePath,
string buildConfiguration,
ISimulatorDevice simulator = null,
string deviceName = null,
string? buildConfiguration,
ISimulatorDevice? simulator = null,
string? deviceName = null,
bool ensureCleanSimulatorState = false,
double timeoutMultiplier = 1,
string variation = null,
IBuildToolTask buildTask = null)
string? variation = null,
BuildToolTask? buildTask = null)
{
this.processManager = processManager ?? throw new ArgumentNullException (nameof (processManager));
this.simulatorsLoaderFactory = simulatorsFactory ?? throw new ArgumentNullException (nameof (simulatorsFactory));
Expand Down Expand Up @@ -112,7 +115,7 @@ public AppRunner (IMlaunchProcessManager processManager,

public async Task InitializeAsync ()
{
AppInformation = await appBundleInformationParser.ParseFromProject2 (harness.AppBundleLocator, projectFilePath, target, buildConfiguration);
appInformation = await appBundleInformationParser.ParseFromProject2 (harness.AppBundleLocator, projectFilePath, target, buildConfiguration!);
AppInformation.Variation = variation;
Comment thread
rolfbjarne marked this conversation as resolved.
}

Expand Down Expand Up @@ -307,7 +310,7 @@ public async Task<int> RunAsync ()
args.Add (new SetStdoutArgument (stdout_log));
args.Add (new SetStderrArgument (stderr_log));

var simulators = new [] { simulator };
var simulators = new [] { simulator! };
var systemLogs = new List<ICaptureLog> ();
foreach (var sim in simulators) {
// Upload the system log
Expand Down Expand Up @@ -344,7 +347,7 @@ public async Task<int> RunAsync ()
}
MainLog.WriteLine ("Enabled verbose logging");

args.Add (new SimulatorUDIDArgument (simulator.UDID));
args.Add (new SimulatorUDIDArgument (simulator!.UDID));

await crashReporter.StartCaptureAsync ();

Expand Down Expand Up @@ -373,7 +376,7 @@ public async Task<int> RunAsync ()
args.Add (new DeviceNameArgument (deviceName));

var deviceSystemLog = Logs.Create ($"device-{deviceName}-{Harness.Helpers.Timestamp}.log", "Device log");
var deviceLogCapturer = deviceLogCapturerFactory.Create (harness.HarnessLog, deviceSystemLog, deviceName);
var deviceLogCapturer = deviceLogCapturerFactory.Create (harness.HarnessLog!, deviceSystemLog, deviceName);
deviceLogCapturer.StartCapture ();

try {
Expand Down Expand Up @@ -429,14 +432,14 @@ public async Task<int> RunAsync ()
FailureMessage = "Test app failed to launch.";
}

return testReporter.Success.Value ? 0 : 1;
return testReporter?.Success == true ? 0 : 1;
}

static bool IsLaunchFailure (IFileBackedLog log)
{
try {
using var reader = log.GetReader ();
string line;
string? line;
while ((line = reader.ReadLine ()) is not null) {
if (line.Contains ("Could not launch the app", StringComparison.Ordinal))
return true;
Expand Down
8 changes: 2 additions & 6 deletions tests/xharness/CrashSnapshotReporterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Logging;

namespace Xharness {
public interface ICrashSnapshotReporterFactory {
ICrashSnapshotReporter Create (ILog log, ILogs logs, bool isDevice, string deviceName);
}

public class CrashSnapshotReporterFactory : ICrashSnapshotReporterFactory {
public class CrashSnapshotReporterFactory {
readonly IMlaunchProcessManager processManager;

public CrashSnapshotReporterFactory (IMlaunchProcessManager processManager)
{
this.processManager = processManager ?? throw new ArgumentNullException (nameof (processManager));
}

public ICrashSnapshotReporter Create (ILog log, ILogs logs, bool isDevice, string deviceName) =>
public ICrashSnapshotReporter Create (ILog log, ILogs logs, bool isDevice, string? deviceName) =>
new CrashSnapshotReporter (processManager, log, logs, isDevice, deviceName);
}
}
8 changes: 2 additions & 6 deletions tests/xharness/DeviceLogCapturerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Logging;

namespace Xharness {
public interface IDeviceLogCapturerFactory {
IDeviceLogCapturer Create (ILog mainLog, ILog deviceLog, string deviceName);
}

public class DeviceLogCapturerFactory : IDeviceLogCapturerFactory {
public IDeviceLogCapturer Create (ILog mainLog, ILog deviceLog, string deviceName)
public class DeviceLogCapturerFactory {
public IDeviceLogCapturer Create (ILog mainLog, ILog deviceLog, string? deviceName)
{
return new DeviceLogCapturer (mainLog, deviceLog, deviceName);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/xharness/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public class GitHub : IVersionControlSystem {

const string PullsApiUrl = "https://api.github.com/repos/dotnet/macios/pulls";

readonly IHarness harness;
readonly Harness harness;
readonly IProcessManager processManager;

public GitHub (IHarness harness, IProcessManager processManager)
public GitHub (Harness harness, IProcessManager processManager)
{
if (harness is null)
throw new ArgumentNullException (nameof (harness));
Expand Down Expand Up @@ -196,7 +196,7 @@ IEnumerable<string> GetModifiedFilesRemotely (int pullRequest)
var output = new MemoryLog () {
Timestamp = false // ensure we do not add the timestap or the logic for the file check will be hard and having it adds no value
};
var rv = processManager.RunAsync (git, harness.HarnessLog, stdoutLog: output, stderrLog: output).Result;
var rv = processManager.RunAsync (git, harness.HarnessLog!, stdoutLog: output, stderrLog: output).Result;
if (rv.Succeeded)
return output.ToString ().Split (new char [] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

Expand Down
Loading
Loading