Skip to content

Commit 177b405

Browse files
authored
Include info about the test environment in the log dir. (#96)
1 parent 8c6384d commit 177b405

File tree

11 files changed

+65
-42
lines changed

11 files changed

+65
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FRAMEWORK:=net6.0
1+
FRAMEWORK:=net8.0
22
CONFIGURATION:=Release
33
ARCH:=$(subst aarch64,arm64,$(subst x86_64,x64,$(shell uname -m)))
44
RUNTIME:=linux-$(ARCH)

Samples/FailingXUnitTest/FailingXUnitTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

Samples/PassingXUnitTest/PassingXUnitTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

Samples/PassingXUnitTestWithEnvironmentVariables/PassingXUnitTestWithEnvironmentVariables.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

Samples/TimeOutXUnitTest/TimeOutXUnitTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

Turkey.Tests/ProgramTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static string OSArchitectureName
9494
Architecture.Arm => "arm",
9595
Architecture.Arm64 => "arm64",
9696
Architecture.S390x => "s390x",
97-
(Architecture)8 => "ppc64le", // not defined for 'net6.0' target.
97+
Architecture.Ppc64le => "ppc64le",
9898
_ => throw new NotSupportedException(),
9999
};
100100
}

Turkey.Tests/Turkey.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<RollForward>Major</RollForward>
77
</PropertyGroup>

Turkey/DotNet.cs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,14 @@ public List<Version> RuntimeVersions
3131
{
3232
get
3333
{
34-
ProcessStartInfo startInfo = new ProcessStartInfo()
35-
{
36-
FileName = DotnetFileName,
37-
RedirectStandardOutput = true,
38-
RedirectStandardError = true,
39-
Arguments = "--list-runtimes",
40-
};
41-
using (Process p = Process.Start(startInfo))
42-
{
43-
p.WaitForExit();
44-
string output = p.StandardOutput.ReadToEnd();
45-
var list = output
46-
.Split("\n", StringSplitOptions.RemoveEmptyEntries)
47-
.Where(line => line.StartsWith("Microsoft.NETCore.App", StringComparison.Ordinal))
48-
.Select(line => line.Split(" ")[1])
49-
.Select(versionString => Version.Parse(versionString))
50-
.OrderBy(x => x)
51-
.ToList();
52-
return list;
53-
}
34+
string output = ProcessRunner.Run(DotnetFileName, "--list-runtimes");
35+
return output
36+
.Split("\n", StringSplitOptions.RemoveEmptyEntries)
37+
.Where(line => line.StartsWith("Microsoft.NETCore.App", StringComparison.Ordinal))
38+
.Select(line => line.Split(" ")[1])
39+
.Select(versionString => Version.Parse(versionString))
40+
.OrderBy(x => x)
41+
.ToList();
5442
}
5543
}
5644

@@ -72,25 +60,14 @@ public List<Version> SdkVersions
7260
{
7361
get
7462
{
75-
ProcessStartInfo startInfo = new ProcessStartInfo()
76-
{
77-
FileName = DotnetFileName,
78-
RedirectStandardOutput = true,
79-
RedirectStandardError = true,
80-
Arguments = "--list-sdks",
81-
};
82-
using (Process p = Process.Start(startInfo))
83-
{
84-
p.WaitForExit();
85-
string output = p.StandardOutput.ReadToEnd();
86-
var list = output
63+
64+
string output = ProcessRunner.Run(DotnetFileName, "--list-sdks");
65+
return output
8766
.Split("\n", StringSplitOptions.RemoveEmptyEntries)
8867
.Select(line => line.Split(" ")[0])
8968
.Select(versionString => Version.Parse(versionString))
9069
.OrderBy(x => x)
9170
.ToList();
92-
return list;
93-
}
9471
}
9572
}
9673

Turkey/ProcessExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Threading;
@@ -15,6 +16,33 @@ public static async Task<int> RunAsync(ProcessStartInfo psi, Action<string> logg
1516
await process.WaitForExitAsync(logger, token).ConfigureAwait(false);
1617
return process.ExitCode;
1718
}
19+
20+
public static string Run(string filename, params string[] args)
21+
{
22+
ProcessStartInfo startInfo = new ProcessStartInfo()
23+
{
24+
FileName = filename,
25+
RedirectStandardInput = true,
26+
RedirectStandardOutput = true,
27+
RedirectStandardError = true,
28+
};
29+
foreach (var arg in args)
30+
{
31+
startInfo.ArgumentList.Add(arg);
32+
}
33+
using (Process p = Process.Start(startInfo))
34+
{
35+
p.StandardInput.Close();
36+
string stdout = p.StandardOutput.ReadToEnd();
37+
p.WaitForExit();
38+
if (p.ExitCode != 0)
39+
{
40+
string stderr = p.StandardError.ReadToEnd();
41+
throw new InvalidOperationException($"Executing {filename} {string.Join(' ', args)} failed with exit code {p.ExitCode} and stderr: {stderr}");
42+
}
43+
return stdout;
44+
}
45+
}
1846
}
1947

2048
public static class ProcessExtensions

Turkey/TestRunner.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public TestRunner(SystemUnderTest system, DirectoryInfo root, bool verboseOutput
7171

7272
public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string logDir, TimeSpan defaultTimeout)
7373
{
74+
LogEnvironment(logDir);
7475

7576
await outputs.ForEachAsync(output => output.AtStartupAsync()).ConfigureAwait(false);
7677

@@ -161,5 +162,22 @@ public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string
161162

162163
return results;
163164
}
165+
166+
private static void LogEnvironment(string logDir)
167+
{
168+
foreach (var sourcePath in new[] { "/proc/cpuinfo", "/proc/meminfo", "/etc/os-release" })
169+
{
170+
if (File.Exists(sourcePath))
171+
{
172+
string destinationPath = Path.Combine(logDir, Path.GetFileName(sourcePath));
173+
// Note: we don't use File.Copy because that copies the file permissions,
174+
// which gives issues on successive runs since the files are non-writable.
175+
File.WriteAllBytes(destinationPath, File.ReadAllBytes(sourcePath));
176+
}
177+
}
178+
179+
string unameOutput = ProcessRunner.Run("uname", "-a");
180+
File.WriteAllText(Path.Combine(logDir, "uname"), unameOutput);
181+
}
164182
}
165183
}

0 commit comments

Comments
 (0)