Files
StarterNG/StarterNG.Tests/SimulatorExitTests.cs
T
Hirek 43600f29c6 fix(exit): no box of the starter after eu07_starter.exe or the simulator already said why
Started through eu07_starter.exe, a simulator that failed got two boxes in a
row: the one of eu07_starter.exe, then the starter's own with the exit code.
The starter's box is now left out where the player already has one:
- an error code of the system (0xC...) through eu07_starter.exe: it explained
  the code, or caught the crash the simulator then reported in its own box;
  Ctrl+C (0xC000013A), which it leaves without a word, still gets the box;
- code 1 through eu07_starter.exe with the simulator's log not written since
  the start: eu07_starter.exe did not start it (missing, refused by its checks,
  or the player's No) and said why;
- 0xE0450010, the simulator's own notice of a processor it cannot run on,
  with or without eu07_starter.exe.
The log of the starter still records each of these exits.
2026-11-30 20:37:23 +01:00

116 lines
4.3 KiB
C#

using StarterNG.Application;
using StarterNG.Infrastructure.Adapters;
using StarterNG.Tests.Fakes;
namespace StarterNG.Tests;
public class SimulatorExitTests
{
private static readonly TimeSpan Session = TimeSpan.FromMinutes(20);
[Fact]
public void A_session_ended_cleanly_is_no_failure()
{
Assert.False(new SimulatorExit(0, Session, []).Failed);
}
[Fact]
public void An_error_code_is_a_failure()
{
Assert.True(new SimulatorExit(1, Session, []).Failed);
}
[Fact]
public void A_window_that_only_flashed_is_a_failure_even_with_a_clean_code()
{
var exit = new SimulatorExit(0, TimeSpan.FromSeconds(0.2), []);
Assert.True(exit.Failed);
Assert.True(exit.Quick);
}
[Theory]
[InlineData(139, "139 (SIGSEGV)")]
[InlineData(134, "134 (SIGABRT)")]
[InlineData(-1073741819, "0xC0000005 (access violation)")]
[InlineData(3, "3")]
public void The_code_says_what_killed_it(int code, string described)
{
Assert.Equal(described, new SimulatorExit(code, Session, []).DescribeCode());
}
[Fact]
public void Colour_codes_and_blank_lines_are_dropped_from_the_errors()
{
var exit = new SimulatorExit(1, Session, ["\u001b[31mBad file: texture\u001b[0m", "", " "]);
Assert.Equal(["Bad file: texture"], exit.CleanErrors);
}
private static SimulatorExit Ended(uint code) => new(unchecked((int)code), Session, []);
[Theory]
[InlineData(0xC0000135u)] // a library missing, explained by eu07_starter.exe
[InlineData(0xC000001Du)] // an instruction the processor lacks
[InlineData(0xC0000005u)] // a crash: its minidump by eu07_starter.exe, its box by the simulator
public void An_error_code_of_the_system_was_explained_by_the_simulators_starter(uint code)
{
Assert.True(Ended(code).AlreadyExplained(throughStarter: true, simulatorRan: true));
Assert.False(Ended(code).AlreadyExplained(throughStarter: false, simulatorRan: true));
}
[Fact]
public void A_close_by_ctrl_c_is_left_without_a_word_by_the_simulators_starter()
{
Assert.False(Ended(0xC000013A).AlreadyExplained(throughStarter: true, simulatorRan: true));
}
[Fact]
public void A_refusal_of_the_simulators_starter_is_one_where_the_simulator_never_ran()
{
Assert.True(Ended(1).AlreadyExplained(throughStarter: true, simulatorRan: false));
Assert.False(Ended(1).AlreadyExplained(throughStarter: true, simulatorRan: true));
Assert.False(Ended(1).AlreadyExplained(throughStarter: false, simulatorRan: false));
Assert.False(Ended(3).AlreadyExplained(throughStarter: true, simulatorRan: false));
}
[Fact]
public void A_processor_the_simulator_cannot_run_on_it_tells_of_itself()
{
Assert.True(Ended(SimulatorExit.UnsupportedProcessor).AlreadyExplained(throughStarter: false, simulatorRan: true));
}
[Fact]
public async Task A_real_process_leaves_its_exit_code_and_error_stream()
{
var launcher = new SystemProcessLauncher(new TestInstallation().Log);
var (shell, script) = OperatingSystem.IsWindows()
? ("cmd", new[] { "/c", "echo boom 1>&2 & exit 3" })
: ("/bin/sh", new[] { "-c", "echo boom >&2; exit 3" });
var process = launcher.Start(shell, script, null, new Dictionary<string, string>(), captureErrors: true,
out string? error);
Assert.Null(error);
await process!.WaitForExitAsync();
Assert.Equal(3, process.ExitCode);
Assert.Equal("boom", Assert.Single(process.ErrorTail).Trim());
}
[Fact]
public async Task A_real_process_gets_the_environment_it_was_given()
{
var launcher = new SystemProcessLauncher(new TestInstallation().Log);
var (shell, script) = OperatingSystem.IsWindows()
? ("cmd", new[] { "/c", "echo %__NV_PRIME_RENDER_OFFLOAD% 1>&2" })
: ("/bin/sh", new[] { "-c", "echo $__NV_PRIME_RENDER_OFFLOAD >&2" });
var process = launcher.Start(shell, script, null,
new Dictionary<string, string> { ["__NV_PRIME_RENDER_OFFLOAD"] = "1" },
captureErrors: true, out _);
await process!.WaitForExitAsync();
Assert.Equal("1", Assert.Single(process.ErrorTail).Trim());
}
}