Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Harness] Create IBuildToolTask and use it in the RunTestTask. #8375

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions tests/xharness/AppRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.DotNet.XHarness.iOS.Shared;
using Microsoft.DotNet.XHarness.iOS.Shared.Listeners;
using Microsoft.DotNet.XHarness.iOS.Shared.Hardware;
using Xharness.TestTasks;

namespace Xharness {

Expand All @@ -31,7 +32,7 @@ class AppRunner {
readonly TestTarget target;
readonly IHarness harness;
readonly double timeoutMultiplier;
readonly BuildToolTask buildTask;
readonly IBuildToolTask buildTask;

string deviceName;
string companionDeviceName;
Expand Down Expand Up @@ -77,7 +78,7 @@ public AppRunner (IProcessManager processManager,
bool ensureCleanSimulatorState = false,
double timeoutMultiplier = 1,
string variation = null,
BuildToolTask buildTask = null)
IBuildToolTask buildTask = null)
{
if (appBundleInformationParser is null)
throw new ArgumentNullException (nameof (appBundleInformationParser));
Expand Down
90 changes: 67 additions & 23 deletions tests/xharness/Jenkins/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Microsoft.DotNet.XHarness.iOS.Shared;
using Microsoft.DotNet.XHarness.iOS.Shared.Hardware;
using Xharness.TestTasks;
using MSBuildTask = Xharness.Jenkins.TestTasks.MSBuildTask;
using DotNetBuildTask = Xharness.Jenkins.TestTasks.DotNetBuildTask;

namespace Xharness.Jenkins {
public class Jenkins : IResourceManager, IErrorKnowledgeBase
Expand Down Expand Up @@ -229,7 +227,12 @@ IEnumerable<RunSimulatorTask> CreateRunSimulatorTaskAsync (MSBuildTask buildTask

for (int i = 0; i < targets.Length; i++) {
var sims = simulators.SelectDevices (targets [i], SimulatorLoadLog, false);
runtasks.Add (new RunSimulatorTask (simulators, buildTask, processManager, sims) {
runtasks.Add (new RunSimulatorTask (
jenkins: this,
simulators: simulators,
buildTask: buildTask,
processManager: processManager,
candidates: sims) {
Platform = platforms [i],
Ignored = ignored[i] || buildTask.Ignored
});
Expand Down Expand Up @@ -551,7 +554,12 @@ async Task<IEnumerable<AppleTestTask>> CreateRunSimulatorTasksAsync ()
}

var testVariations = CreateTestVariations (runSimulatorTasks, (buildTask, test, candidates) =>
new RunSimulatorTask (simulators, buildTask, processManager, candidates?.Cast<SimulatorDevice> () ?? test.Candidates)).ToList ();
new RunSimulatorTask (
jenkins: this,
simulators: simulators,
buildTask: buildTask,
processManager: processManager,
candidates: candidates?.Cast<SimulatorDevice> () ?? test.Candidates)).ToList ();

foreach (var tv in testVariations) {
if (!tv.Ignored)
Expand Down Expand Up @@ -589,7 +597,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
build64.CloneTestProject (project);
projectTasks.Add (new RunDeviceTask (devices, build64, processManager, devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS64 });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: build64,
processManager: processManager,
candidates: devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS64 });

var build32 = new MSBuildTask (jenkins: this, testProject: project, processManager: processManager) {
ProjectConfiguration = project.Name != "dont link" ? "Debug32" : "Release32",
Expand All @@ -598,7 +611,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
build32.CloneTestProject (project);
projectTasks.Add (new RunDeviceTask (devices, build32, processManager, devices.Connected32BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS32 });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: build32,
processManager: processManager,
candidates: devices.Connected32BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS32 });

var todayProject = project.AsTodayExtensionProject ();
var buildToday = new MSBuildTask (jenkins: this, testProject: todayProject, processManager: processManager) {
Expand All @@ -608,7 +626,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
buildToday.CloneTestProject (todayProject);
projectTasks.Add (new RunDeviceTask (devices, buildToday, processManager, devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOSExtensions, BuildOnly = ForceExtensionBuildOnly });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: buildToday,
processManager: processManager,
candidates: devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOSExtensions, BuildOnly = ForceExtensionBuildOnly });
}

if (!project.SkiptvOSVariation) {
Expand All @@ -620,7 +643,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
buildTV.CloneTestProject (tvOSProject);
projectTasks.Add (new RunDeviceTask (devices, buildTV, processManager, devices.ConnectedTV.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludetvOS });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: buildTV,
processManager: processManager,
candidates: devices.ConnectedTV.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludetvOS });
}

if (!project.SkipwatchOSVariation) {
Expand All @@ -633,7 +661,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
buildWatch32.CloneTestProject (watchOSProject);
projectTasks.Add (new RunDeviceTask (devices, buildWatch32, processManager, devices.ConnectedWatch) { Ignored = !IncludewatchOS });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: buildWatch32,
processManager: processManager,
candidates: devices.ConnectedWatch) { Ignored = !IncludewatchOS });
}

if (!project.SkipwatchOSARM64_32Variation) {
Expand All @@ -644,7 +677,12 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
TestName = project.Name,
};
buildWatch64_32.CloneTestProject (watchOSProject);
projectTasks.Add (new RunDeviceTask (devices, buildWatch64_32, processManager, devices.ConnectedWatch32_64.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludewatchOS });
projectTasks.Add (new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: buildWatch64_32,
processManager: processManager,
candidates: devices.ConnectedWatch32_64.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludewatchOS });
}
}
foreach (var task in projectTasks) {
Expand All @@ -655,7 +693,13 @@ Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
rv.AddRange (projectTasks);
}

return Task.FromResult<IEnumerable<AppleTestTask>> (CreateTestVariations (rv, (buildTask, test, candidates) => new RunDeviceTask (devices, buildTask, processManager, candidates?.Cast<IHardwareDevice> () ?? test.Candidates)));
return Task.FromResult<IEnumerable<AppleTestTask>> (CreateTestVariations (rv, (buildTask, test, candidates)
=> new RunDeviceTask (
jenkins: this,
devices: devices,
buildTask: buildTask,
processManager: processManager,
candidates: candidates?.Cast<IHardwareDevice> () ?? test.Candidates)));
}

static string AddSuffixToPath (string path, string suffix)
Expand Down Expand Up @@ -942,7 +986,7 @@ Task PopulateTasksAsync ()
SolutionPath = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")),
SupportsParallelExecution = false,
};
var nunitExecutioniOSMSBuild_net461 = new NUnitExecuteTask (buildiOSMSBuild_net461, processManager)
var nunitExecutioniOSMSBuild_net461 = new NUnitExecuteTask (this, buildiOSMSBuild_net461, processManager)
{
TestLibrary = Path.Combine (Harness.RootDirectory, "..", "msbuild", "tests", "Xamarin.iOS.Tasks.Tests", "bin", "Debug-net461", "net461", "Xamarin.iOS.Tasks.Tests.dll"),
TestProject = net461Project,
Expand All @@ -965,7 +1009,7 @@ Task PopulateTasksAsync ()
SolutionPath = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")),
SupportsParallelExecution = false,
};
var nunitExecutioniOSMSBuild_netstandard2 = new NUnitExecuteTask (buildiOSMSBuild_netstandard2, processManager) {
var nunitExecutioniOSMSBuild_netstandard2 = new NUnitExecuteTask (this, buildiOSMSBuild_netstandard2, processManager) {
TestLibrary = Path.Combine (Harness.RootDirectory, "..", "msbuild", "tests", "Xamarin.iOS.Tasks.Tests", "bin", "Debug-netstandard2.0", "net461", "Xamarin.iOS.Tasks.Tests.dll"),
TestProject = netstandard2Project,
ProjectConfiguration = "Debug-netstandard2.0",
Expand All @@ -986,7 +1030,7 @@ Task PopulateTasksAsync ()
Platform = TestPlatform.iOS,
};
buildInstallSources.SolutionPath = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "..", "tools", "install-source", "install-source.sln")); // this is required for nuget restore to be executed
var nunitExecutionInstallSource = new NUnitExecuteTask (buildInstallSources, processManager)
var nunitExecutionInstallSource = new NUnitExecuteTask (this, buildInstallSources, processManager)
{
TestLibrary = Path.Combine (Harness.RootDirectory, "..", "tools", "install-source", "InstallSourcesTests", "bin", "Release", "InstallSourcesTests.dll"),
TestProject = installSourcesProject,
Expand Down Expand Up @@ -1042,7 +1086,7 @@ Task PopulateTasksAsync ()
var ignored_main = ignored;
if (project.IsNUnitProject) {
var dll = Path.Combine (Path.GetDirectoryName (build.TestProject.Path), project.Xml.GetOutputAssemblyPath (build.ProjectPlatform, build.ProjectConfiguration).Replace ('\\', '/'));
exec = new NUnitExecuteTask (build, processManager) {
exec = new NUnitExecuteTask (this, build, processManager) {
Ignored = ignored_main,
TestLibrary = dll,
TestProject = project,
Expand All @@ -1053,14 +1097,14 @@ Task PopulateTasksAsync ()
};
execs = new [] { exec };
} else {
exec = new MacExecuteTask (build, processManager, crashReportSnapshotFactory) {
exec = new MacExecuteTask (this, build, processManager, crashReportSnapshotFactory) {
Ignored = ignored_main,
BCLTest = project.IsBclTest,
TestName = project.Name,
IsUnitTest = true,
};
execs = CreateTestVariations (new [] { exec }, (buildTask, test, candidates) =>
new MacExecuteTask (buildTask, processManager, crashReportSnapshotFactory) { IsUnitTest = true } );
new MacExecuteTask (this, buildTask, processManager, crashReportSnapshotFactory) { IsUnitTest = true } );
}

foreach (var e in execs)
Expand All @@ -1079,7 +1123,7 @@ Task PopulateTasksAsync ()
Target = "dependencies",
WorkingDirectory = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "mtouch")),
};
var nunitExecutionMTouch = new NUnitExecuteTask (buildMTouch, processManager)
var nunitExecutionMTouch = new NUnitExecuteTask (this, buildMTouch, processManager)
{
TestLibrary = Path.Combine (Harness.RootDirectory, "mtouch", "bin", "Debug", "mtouch.dll"),
TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "mtouch", "mtouch.csproj"))),
Expand All @@ -1099,7 +1143,7 @@ Task PopulateTasksAsync ()
Target = "build-unit-tests",
WorkingDirectory = Path.GetFullPath (Path.Combine (Harness.RootDirectory, "generator")),
};
var runGenerator = new NUnitExecuteTask (buildGenerator, processManager) {
var runGenerator = new NUnitExecuteTask (this, buildGenerator, processManager) {
TestLibrary = Path.Combine (Harness.RootDirectory, "generator", "bin", "Debug", "generator-tests.dll"),
TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "generator", "generator-tests.csproj"))),
Platform = TestPlatform.iOS,
Expand All @@ -1117,7 +1161,7 @@ Task PopulateTasksAsync ()
SpecifyConfiguration = false,
Platform = TestPlatform.iOS,
};
var runDotNetGenerator = new DotNetTestTask (buildDotNetGenerator, processManager) {
var runDotNetGenerator = new DotNetTestTask (this, buildDotNetGenerator, processManager) {
TestProject = buildDotNetGeneratorProject,
Platform = TestPlatform.iOS,
TestName = "Generator tests",
Expand Down Expand Up @@ -1163,7 +1207,7 @@ Task PopulateTasksAsync ()
Ignored = !IncludeXtro,
Timeout = TimeSpan.FromMinutes (15),
};
var runXtroReporter = new RunXtroTask (buildXtroTests, processManager, crashReportSnapshotFactory) {
var runXtroReporter = new RunXtroTask (this, buildXtroTests, processManager, crashReportSnapshotFactory) {
Platform = TestPlatform.Mac,
TestName = buildXtroTests.TestName,
Ignored = buildXtroTests.Ignored,
Expand All @@ -1179,7 +1223,7 @@ Task PopulateTasksAsync ()
Ignored = !IncludeCecil,
Timeout = TimeSpan.FromMinutes (5),
};
var runCecilTests = new NUnitExecuteTask (buildCecilTests, processManager) {
var runCecilTests = new NUnitExecuteTask (this, buildCecilTests, processManager) {
TestLibrary = Path.Combine (buildCecilTests.WorkingDirectory, "bin", "Debug", "cecil-tests.dll"),
TestProject = new TestProject (Path.Combine (buildCecilTests.WorkingDirectory, "cecil-tests.csproj")),
Platform = TestPlatform.iOS,
Expand All @@ -1206,7 +1250,7 @@ Task PopulateTasksAsync ()
Platform = TestPlatform.All,
ProjectConfiguration = "Debug",
};
var runSampleTests = new NUnitExecuteTask (buildSampleTests, processManager) {
var runSampleTests = new NUnitExecuteTask (this, buildSampleTests, processManager) {
TestLibrary = Path.Combine (Harness.RootDirectory, "sampletester", "bin", "Debug", "sampletester.dll"),
TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "sampletester", "sampletester.csproj"))),
Platform = TestPlatform.All,
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/BuildProjectTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Xharness.Jenkins.TestTasks {
abstract class BuildProjectTask : BuildToolTask
{
Xharness.TestTasks.BuildProjectTask BuildProject => buildToolTask as Xharness.TestTasks.BuildProjectTask;
BuildProject BuildProject => buildToolTask as BuildProject;

public string SolutionPath {
get => BuildProject.SolutionPath;
Expand All @@ -22,7 +22,7 @@ protected BuildProjectTask (Jenkins jenkins, TestProject testProject, IProcessMa
public override bool SupportsParallelExecution => BuildProject.SupportsParallelExecution;

protected override void InitializeTool ()
=> buildToolTask = new Xharness.TestTasks.BuildProjectTask (ProcessManager, Jenkins, this, this);
=> buildToolTask = new BuildProject (ProcessManager, Jenkins, this, this);

// This method must be called with the desktop resource acquired
// (which is why it takes an IAcquiredResources as a parameter without using it in the function itself).
Expand Down
9 changes: 5 additions & 4 deletions tests/xharness/Jenkins/TestTasks/BuildToolTask.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;

using Xharness.TestTasks;

namespace Xharness.Jenkins.TestTasks
{
public abstract class BuildToolTask : AppleTestTask
public abstract class BuildToolTask : AppleTestTask, IBuildToolTask
{
protected Xharness.TestTasks.BuildToolTask buildToolTask;
protected BuildTool buildToolTask;

public IProcessManager ProcessManager { get; }

Expand Down Expand Up @@ -54,7 +55,7 @@ public override string Mode {
set => buildToolTask.Mode = value;
}

protected virtual void InitializeTool () => buildToolTask = new Xharness.TestTasks.BuildToolTask (ProcessManager);
protected virtual void InitializeTool () => buildToolTask = new Xharness.TestTasks.BuildTool (ProcessManager);
public virtual Task CleanAsync () => buildToolTask.CleanAsync ();
}
}
4 changes: 3 additions & 1 deletion tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Diagnostics;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;

using Xharness.TestTasks;

namespace Xharness.Jenkins.TestTasks {
class DotNetBuildTask : MSBuildTask {

Expand All @@ -23,7 +25,7 @@ public override void SetEnvironmentVariables (Process process)
}

protected override void InitializeTool () =>
buildToolTask = new Xharness.TestTasks.DotNetBuildTask (
buildToolTask = new DotNetBuild (
msbuildPath: ToolName,
processManager: ProcessManager,
resourceManager: Jenkins,
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Xharness.Jenkins.TestTasks {
class DotNetTestTask : RunTestTask {
public DotNetTestTask (DotNetBuildTask build_task, IProcessManager processManager)
: base (build_task, processManager)
public DotNetTestTask (Jenkins jenkins, DotNetBuildTask build_task, IProcessManager processManager)
: base (jenkins, build_task, processManager)
{
DotNetBuildTask.SetDotNetEnvironmentVariables (Environment);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/MSBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class MSBuildTask : BuildProjectTask
protected virtual List<string> ToolArguments =>
MSBuild.GetToolArguments (ProjectPlatform, ProjectConfiguration, ProjectFile, BuildLog);

Xharness.TestTasks.MSBuildTask MSBuild => buildToolTask as Xharness.TestTasks.MSBuildTask;
Xharness.TestTasks.MSBuild MSBuild => buildToolTask as Xharness.TestTasks.MSBuild;

public MSBuildTask (Jenkins jenkins, TestProject testProject, IProcessManager processManager)
: base (jenkins, testProject, processManager) { }

protected override void InitializeTool () =>
buildToolTask = new Xharness.TestTasks.MSBuildTask (
buildToolTask = new Xharness.TestTasks.MSBuild (
msbuildPath: ToolName,
processManager: ProcessManager,
resourceManager: Jenkins,
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/MacExecuteTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class MacExecuteTask : MacTask
public bool BCLTest;
public bool IsUnitTest;

public MacExecuteTask (BuildToolTask build_task, IProcessManager processManager, ICrashSnapshotReporterFactory crashReportSnapshotFactory)
: base (build_task, processManager)
public MacExecuteTask (Jenkins jenkins, BuildToolTask build_task, IProcessManager processManager, ICrashSnapshotReporterFactory crashReportSnapshotFactory)
: base (jenkins, build_task, processManager)
{
this.CrashReportSnapshotFactory = crashReportSnapshotFactory ?? throw new ArgumentNullException (nameof (crashReportSnapshotFactory));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/MacTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Xharness.Jenkins.TestTasks
{
abstract class MacTask : RunTestTask
{
public MacTask (BuildToolTask build_task, IProcessManager processManager)
: base (build_task, processManager)
public MacTask (Jenkins jenkins, BuildToolTask build_task, IProcessManager processManager)
: base (jenkins, build_task, processManager)
{
}

Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class NUnitExecuteTask : RunTestTask
public bool ProduceHtmlReport = true;
public bool InProcess;

public NUnitExecuteTask (BuildToolTask build_task, IProcessManager processManager)
: base (build_task, processManager)
public NUnitExecuteTask (Jenkins jenkins, BuildToolTask build_task, IProcessManager processManager)
: base (jenkins, build_task, processManager)
{
}

Expand Down
Loading