mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
fix: without AVX2 the starter starts the simulator built without it
The simulator now also comes built without AVX2, its file name ending in _noavx2 (eu07-x64_<date>_<hash>_noavx2.exe, eu07_noavx2 on Linux), and both builds can lie side by side in the game folder. The automatic choice took eu07.exe or the shortest name and never that one, so a processor without AVX2 got a simulator that stops at its first instruction and a notice telling it to build its own. Without AVX2 the automatic choice now takes the newest _noavx2 build, even one through Wine before a native build that would not run. With AVX2 the build made for it stays first and a _noavx2 one is used only when it is all there is. The notice comes only when what would start still needs AVX2. With a _noavx2 build in the folder but another chosen by hand it names both and offers to go back to the automatic choice; with none it says what such a build is called and that the starter picks it up from the game folder.
This commit is contained in:
82
StarterNG.Tests/ExecutableNoAvx2Tests.cs
Normal file
82
StarterNG.Tests/ExecutableNoAvx2Tests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using StarterNG.Domain.Settings;
|
||||
using StarterNG.Infrastructure.Settings;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class ExecutableNoAvx2Tests
|
||||
{
|
||||
private const string Elf = "\u007fELF binary";
|
||||
private static readonly DateTime Older = new(2026, 11, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime Newer = new(2026, 11, 15, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
private static InMemoryFileSystem With(params string[] names)
|
||||
{
|
||||
var files = new InMemoryFileSystem();
|
||||
foreach (string name in names)
|
||||
files.WithExecutable(TestInstallation.At(name), Elf);
|
||||
return files;
|
||||
}
|
||||
|
||||
private static string Automatic(InMemoryFileSystem files, bool lacksAvx2) =>
|
||||
Path.GetFileName(new TestInstallation(files, lacksAvx2: lacksAvx2).Executables
|
||||
.Resolve(new SimulatorSettings(), out _));
|
||||
|
||||
[Theory]
|
||||
[InlineData("eu07_noavx2", true)]
|
||||
[InlineData("eu07-x64_20261115_abc1234_noavx2.exe", true)]
|
||||
[InlineData("EU07_NOAVX2.EXE", true)]
|
||||
[InlineData("eu07", false)]
|
||||
[InlineData("eu07-x64_20261115_abc1234.exe", false)]
|
||||
[InlineData("eu07_noavx2_old.exe", false)]
|
||||
public void A_build_without_avx2_is_known_by_the_end_of_its_name(string name, bool noAvx2) =>
|
||||
Assert.Equal(noAvx2, ExecutableLocator.IsNoAvx2(name));
|
||||
|
||||
[Fact]
|
||||
public void Without_avx2_the_build_without_it_is_chosen_over_the_canonical_one() =>
|
||||
Assert.Equal("eu07_noavx2", Automatic(With("eu07", "eu07_noavx2"), lacksAvx2: true));
|
||||
|
||||
[Fact]
|
||||
public void With_avx2_the_build_made_for_it_stays_first() =>
|
||||
Assert.Equal("eu07", Automatic(With("eu07", "eu07_noavx2"), lacksAvx2: false));
|
||||
|
||||
[Fact]
|
||||
public void With_avx2_a_build_without_it_is_used_when_it_is_the_only_one() =>
|
||||
Assert.Equal("eu07_noavx2", Automatic(With("eu07_noavx2"), lacksAvx2: false));
|
||||
|
||||
[Fact]
|
||||
public void Without_avx2_the_newest_build_without_it_is_chosen()
|
||||
{
|
||||
var files = With("eu07_20261101_aaa_noavx2", "eu07_20261115_bbb_noavx2")
|
||||
.WrittenAt(TestInstallation.At("eu07_20261101_aaa_noavx2"), Older)
|
||||
.WrittenAt(TestInstallation.At("eu07_20261115_bbb_noavx2"), Newer);
|
||||
|
||||
Assert.Equal("eu07_20261115_bbb_noavx2", Automatic(files, lacksAvx2: true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_avx2_and_no_build_without_it_the_usual_choice_stands() =>
|
||||
Assert.Equal("eu07", Automatic(With("eu07-dev", "eu07"), lacksAvx2: true));
|
||||
|
||||
[Fact]
|
||||
public void Only_a_build_with_avx2_on_a_processor_without_it_will_not_run()
|
||||
{
|
||||
var lacking = new TestInstallation(lacksAvx2: true).Executables;
|
||||
var able = new TestInstallation(lacksAvx2: false).Executables;
|
||||
|
||||
Assert.True(lacking.WillNotRunHere("eu07.exe"));
|
||||
Assert.False(lacking.WillNotRunHere("eu07-x64_noavx2.exe"));
|
||||
Assert.False(able.WillNotRunHere("eu07.exe"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_newest_build_without_avx2_is_offered_by_name()
|
||||
{
|
||||
var files = With("eu07", "eu07_20261101_aaa_noavx2", "eu07_20261115_bbb_noavx2")
|
||||
.WrittenAt(TestInstallation.At("eu07_20261101_aaa_noavx2"), Older)
|
||||
.WrittenAt(TestInstallation.At("eu07_20261115_bbb_noavx2"), Newer);
|
||||
|
||||
Assert.Equal("eu07_20261115_bbb_noavx2", new TestInstallation(files).Executables.NewestNoAvx2());
|
||||
Assert.Null(new TestInstallation(With("eu07")).Executables.NewestNoAvx2());
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public sealed class TestInstallation
|
||||
{
|
||||
public const string Root = "game";
|
||||
|
||||
public TestInstallation(InMemoryFileSystem? files = null, DateTime? now = null)
|
||||
public TestInstallation(InMemoryFileSystem? files = null, DateTime? now = null, bool lacksAvx2 = false)
|
||||
{
|
||||
Files = files ?? new InMemoryFileSystem();
|
||||
Paths = new GamePaths(Root);
|
||||
@@ -35,7 +35,8 @@ public sealed class TestInstallation
|
||||
SettingsPaths.VehicleCacheDirectory());
|
||||
Library = new GameLibrary(VehicleCache, Sceneries, MiniTextures, Physics, Log);
|
||||
|
||||
Executables = new ExecutableLocator(Files, Paths, Environment, Log);
|
||||
// The processor of the machine running the tests is not the one tested.
|
||||
Executables = new ExecutableLocator(Files, Paths, Environment, Log, lacksAvx2);
|
||||
SettingsStore = new SettingsStore(Files, Clock, Log, SettingsPaths, new SettingsSerializer(), Executables);
|
||||
Tapes = new HaslerTapes(Files, Paths, Log, Clock, new TimetableLocator(Files), () => SimulatorRunning);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user