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
33 changes: 17 additions & 16 deletions tests/xharness/Jenkins/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Utilities;
using Microsoft.DotNet.XHarness.iOS.Shared;
using Microsoft.DotNet.XHarness.iOS.Shared.Hardware;
using Xharness.TestTasks;

namespace Xharness.Jenkins {
public class Jenkins
Expand Down Expand Up @@ -76,7 +77,7 @@ public ILogs Logs {
}
}

List<TestTask> Tasks = new List<TestTask> ();
List<AppleTestTask> Tasks = new List<AppleTestTask> ();
Dictionary<string, MakeTask> DependencyTasks = new Dictionary<string, MakeTask> ();

internal static Resource DesktopResource = new Resource ("Desktop", Environment.ProcessorCount);
Expand Down Expand Up @@ -502,7 +503,7 @@ IEnumerable<T> CreateTestVariations<T> (IEnumerable<T> tests, Func<MSBuildTask,
return rv;
}

async Task<IEnumerable<TestTask>> CreateRunSimulatorTasksAsync ()
async Task<IEnumerable<AppleTestTask>> CreateRunSimulatorTasksAsync ()
{
var runSimulatorTasks = new List<RunSimulatorTask> ();

Expand Down Expand Up @@ -568,7 +569,7 @@ async Task<IEnumerable<TestTask>> CreateRunSimulatorTasksAsync ()
return rv;
}

Task<IEnumerable<TestTask>> CreateRunDeviceTasksAsync ()
Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
{
var rv = new List<RunDeviceTask> ();
var projectTasks = new List<RunDeviceTask> ();
Expand Down Expand Up @@ -662,7 +663,7 @@ Task<IEnumerable<TestTask>> CreateRunDeviceTasksAsync ()
rv.AddRange (projectTasks);
}

return Task.FromResult<IEnumerable<TestTask>> (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 (devices, buildTask, processManager, candidates?.Cast<IHardwareDevice> () ?? test.Candidates)));
}

static string AddSuffixToPath (string path, string suffix)
Expand Down Expand Up @@ -1371,17 +1372,17 @@ Task RunTestServer ()
try {
var allTasks = Tasks.SelectMany ((v) =>
{
var rv = new List<TestTask> ();
var rv = new List<AppleTestTask> ();
var runsim = v as AggregatedRunSimulatorTask;
if (runsim != null)
rv.AddRange (runsim.Tasks);
rv.Add (v);
return rv;
});

IEnumerable<TestTask> find_tasks (StreamWriter writer, string ids)
IEnumerable<AppleTestTask> find_tasks (StreamWriter writer, string ids)
{
IEnumerable<TestTask> tasks;
IEnumerable<AppleTestTask> tasks;
switch (request.Url.Query) {
case "?all":
tasks = Tasks;
Expand All @@ -1394,10 +1395,10 @@ IEnumerable<TestTask> find_tasks (StreamWriter writer, string ids)
break;
case "?":
writer.WriteLine ("No tasks specified");
return Array.Empty<TestTask> ();
return Array.Empty<AppleTestTask> ();
default:
var id_inputs = ids.Substring (1).Split (',');
var rv = new List<TestTask> (id_inputs.Length);
var rv = new List<AppleTestTask> (id_inputs.Length);
foreach (var id_input in id_inputs) {
if (int.TryParse (id_input, out var id)) {
var task = Tasks.FirstOrDefault ((t) => t.ID == id);
Expand Down Expand Up @@ -1677,7 +1678,7 @@ IEnumerable<TestTask> find_tasks (StreamWriter writer, string ids)
return tcs.Task;
}

string GetTestColor (IEnumerable<TestTask> tests)
string GetTestColor (IEnumerable<AppleTestTask> tests)
{
if (!tests.Any ())
return "black";
Expand Down Expand Up @@ -1707,7 +1708,7 @@ string GetTestColor (IEnumerable<TestTask> tests)
return "black";
}

string GetTestColor (TestTask test)
string GetTestColor (AppleTestTask test)
{
if (test.NotStarted) {
return "black";
Expand Down Expand Up @@ -1861,7 +1862,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null)
throw new NotImplementedException ();
}

var allTasks = new List<TestTask> ();
var allTasks = new List<AppleTestTask> ();
if (!populating) {
allTasks.AddRange (allExecuteTasks);
allTasks.AddRange (allSimulatorTasks);
Expand Down Expand Up @@ -2115,7 +2116,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null)

writer.WriteLine ("<div id='test-table' style='width: 100%; display: flex;'>");
writer.WriteLine ("<div id='test-list'>");
var orderedTasks = allTasks.GroupBy ((TestTask v) => v.TestName);
var orderedTasks = allTasks.GroupBy ((AppleTestTask v) => v.TestName);

if (IsServerMode) {
// In server mode don't take into account anything that can change during a test run
Expand Down Expand Up @@ -2404,7 +2405,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null)
writer.WriteLine ("<div id='test-status' style='margin-left: 100px;' class='autorefreshable'>");
if (failedTests.Count () == 0) {
foreach (var group in failedTests.GroupBy ((v) => v.TestName)) {
var enumerableGroup = group as IEnumerable<TestTask>;
var enumerableGroup = group as IEnumerable<AppleTestTask>;
if (enumerableGroup != null) {
writer.WriteLine ("<a href='#test_{2}'>{0}</a> ({1})<br />", group.Key, string.Join (", ", enumerableGroup.Select ((v) => string.Format ("<span style='color: {0}'>{1}</span>", GetTestColor (v), string.IsNullOrEmpty (v.Mode) ? v.ExecutionResult.ToString () : v.Mode)).ToArray ()), group.Key.Replace (' ', '-'));
continue;
Expand Down Expand Up @@ -2467,11 +2468,11 @@ static string LinkEncode (string path)
return System.Web.HttpUtility.UrlEncode (path).Replace ("%2f", "/").Replace ("+", "%20");
}

string RenderTextStates (IEnumerable<TestTask> tests)
string RenderTextStates (IEnumerable<AppleTestTask> tests)
{
// Create a collection of all non-ignored tests in the group (unless all tests were ignored).
var allIgnored = tests.All ((v) => v.ExecutionResult == TestExecutingResult.Ignored);
IEnumerable<TestTask> relevantGroup;
IEnumerable<AppleTestTask> relevantGroup;
if (allIgnored) {
relevantGroup = tests;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Xharness.Jenkins.TestTasks {
// This class groups simulator run tasks according to the
// simulator they'll run from, so that we minimize switching
// between different simulators (which is slow).
class AggregatedRunSimulatorTask : TestTask
class AggregatedRunSimulatorTask : AppleTestTask
{
public IEnumerable<RunSimulatorTask> Tasks;

Expand Down
88 changes: 88 additions & 0 deletions tests/xharness/Jenkins/TestTasks/AppleTestTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared.Logging;
using Xharness.TestTasks;

namespace Xharness.Jenkins.TestTasks {
public abstract class AppleTestTask : Xharness.TestTasks.TestTasks
{
public Jenkins Jenkins;
public Harness Harness { get { return Jenkins.Harness; } }


public override string LogDirectory {
get {
var rv = Path.Combine (Jenkins.LogDirectory, TestName, ID.ToString ());
Directory.CreateDirectory (rv);
return rv;
}
}

public override void GenerateReport () => Jenkins.GenerateReport ();

protected override void WriteLineToRunnerLog (string message) => Harness.HarnessLog.WriteLine (message);

protected override void SetEnvironmentVariables (Process process)
{
var xcodeRoot = Harness.XcodeRoot;

switch (Platform) {
case TestPlatform.iOS:
case TestPlatform.iOS_Unified:
case TestPlatform.iOS_Unified32:
case TestPlatform.iOS_Unified64:
case TestPlatform.iOS_TodayExtension64:
case TestPlatform.tvOS:
case TestPlatform.watchOS:
case TestPlatform.watchOS_32:
case TestPlatform.watchOS_64_32:
process.StartInfo.EnvironmentVariables ["MD_APPLE_SDK_ROOT"] = xcodeRoot;
process.StartInfo.EnvironmentVariables ["MD_MTOUCH_SDK_ROOT"] = Path.Combine (Harness.IOS_DESTDIR, "Library", "Frameworks", "Xamarin.iOS.framework", "Versions", "Current");
process.StartInfo.EnvironmentVariables ["TargetFrameworkFallbackSearchPaths"] = Path.Combine (Harness.IOS_DESTDIR, "Library", "Frameworks", "Mono.framework", "External", "xbuild-frameworks");
process.StartInfo.EnvironmentVariables ["MSBuildExtensionsPathFallbackPathsOverride"] = Path.Combine (Harness.IOS_DESTDIR, "Library", "Frameworks", "Mono.framework", "External", "xbuild");
break;
case TestPlatform.Mac:
case TestPlatform.Mac_Modern:
case TestPlatform.Mac_Full:
case TestPlatform.Mac_System:
process.StartInfo.EnvironmentVariables ["MD_APPLE_SDK_ROOT"] = xcodeRoot;
process.StartInfo.EnvironmentVariables ["TargetFrameworkFallbackSearchPaths"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Mono.framework", "External", "xbuild-frameworks");
process.StartInfo.EnvironmentVariables ["MSBuildExtensionsPathFallbackPathsOverride"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Mono.framework", "External", "xbuild");
process.StartInfo.EnvironmentVariables ["XamarinMacFrameworkRoot"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current");
process.StartInfo.EnvironmentVariables ["XAMMAC_FRAMEWORK_PATH"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current");
break;
case TestPlatform.All:
// Don't set:
// MSBuildExtensionsPath
// TargetFrameworkFallbackSearchPaths
// because these values used by both XM and XI and we can't set it to two different values at the same time.
// Any test that depends on these values should not be using 'TestPlatform.All'
process.StartInfo.EnvironmentVariables ["MD_APPLE_SDK_ROOT"] = xcodeRoot;
process.StartInfo.EnvironmentVariables ["MD_MTOUCH_SDK_ROOT"] = Path.Combine (Harness.IOS_DESTDIR, "Library", "Frameworks", "Xamarin.iOS.framework", "Versions", "Current");
process.StartInfo.EnvironmentVariables ["XamarinMacFrameworkRoot"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current");
process.StartInfo.EnvironmentVariables ["XAMMAC_FRAMEWORK_PATH"] = Path.Combine (Harness.MAC_DESTDIR, "Library", "Frameworks", "Xamarin.Mac.framework", "Versions", "Current");
break;
default:
throw new NotImplementedException ();
}

foreach (var kvp in Environment)
process.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
}


protected override void LogEvent (ILog log, string text, params object [] args)
{
base.LogEvent (log, text, args);
Jenkins.MainLog.WriteLine (text, args);
}

protected override Task<IAcquiredResource> NotifyAndAcquireDesktopResourceAsync ()
{
return NotifyBlockingWaitAsync (SupportsParallelExecution ? Jenkins.DesktopResource.AcquireConcurrentAsync () : Jenkins.DesktopResource.AcquireExclusiveAsync ());
}

}
}
1 change: 1 addition & 0 deletions tests/xharness/Jenkins/TestTasks/BuildProjectTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;
using Microsoft.DotNet.XHarness.iOS.Shared.Logging;
using Microsoft.DotNet.XHarness.iOS.Shared.Utilities;
using Xharness.TestTasks;

namespace Xharness.Jenkins.TestTasks {
abstract class BuildProjectTask : BuildToolTask
Expand Down
2 changes: 1 addition & 1 deletion tests/xharness/Jenkins/TestTasks/BuildToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Xharness.Jenkins.TestTasks
{
public abstract class BuildToolTask : TestTask
public abstract class BuildToolTask : AppleTestTask
{
protected readonly IProcessManager ProcessManager;

Expand Down
2 changes: 1 addition & 1 deletion tests/xharness/Jenkins/TestTasks/MakeTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override async Task ExecuteAsync ()
}
}
using (var reader = log.GetReader ())
AddWrenchLogFiles (reader);
AddCILogFiles (reader);
Jenkins.MainLog.WriteLine ("Made {0} ({1})", TestName, Mode);
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down
1 change: 1 addition & 0 deletions tests/xharness/Jenkins/TestTasks/RunSimulatorTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Listeners;
using Microsoft.DotNet.XHarness.iOS.Shared.Collections;
using Microsoft.DotNet.XHarness.iOS.Shared.Hardware;
using Xharness.TestTasks;

namespace Xharness.Jenkins.TestTasks {
class RunSimulatorTask : RunXITask<ISimulatorDevice>
Expand Down
2 changes: 1 addition & 1 deletion tests/xharness/Jenkins/TestTasks/RunTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.DotNet.XHarness.iOS.Shared.Utilities;

namespace Xharness.Jenkins.TestTasks {
internal abstract class RunTestTask : TestTask
internal abstract class RunTestTask : AppleTestTask
{
protected IProcessManager ProcessManager { get; }
IResultParser ResultParser { get; } = new XmlResultParser ();
Expand Down
4 changes: 2 additions & 2 deletions tests/xharness/TestProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public virtual TestProject Clone ()
return rv;
}

internal async Task<TestProject> CreateCloneAsync (TestTask test)
internal async Task<TestProject> CreateCloneAsync (AppleTestTask test)
{
var rv = Clone ();
await rv.CreateCopyAsync (test);
return rv;
}

internal async Task CreateCopyAsync (TestTask test = null)
internal async Task CreateCopyAsync (AppleTestTask test = null)
{
var directory = DirectoryUtilities.CreateTemporaryDirectory (test?.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path));
Directory.CreateDirectory (directory);
Expand Down
7 changes: 7 additions & 0 deletions tests/xharness/TestTasks/IAcquiredResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;
namespace Xharness.TestTasks {
public interface IAcquiredResource : IDisposable
{
Resource Resource { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Xharness.Jenkins
namespace Xharness.TestTasks
{
// This is a very simple class to manage the general concept of 'resource'.
// Performance isn't important, so this is very simple.
Expand Down Expand Up @@ -90,9 +90,4 @@ void IDisposable.Dispose ()
public Resource Resource { get; }
}
}

public interface IAcquiredResource : IDisposable
{
Resource Resource { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;

namespace Xharness.Jenkins
namespace Xharness.TestTasks
{
class Resources
{
Expand Down
Loading