Tests: Convert tests to use async/await

This commit is contained in:
Katy Coe
2020-12-21 05:53:58 +01:00
parent 4ae17fe365
commit 2f01403dfb
2 changed files with 13 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ namespace Il2CppInspector
[TestFixture] [TestFixture]
public partial class TestRunner public partial class TestRunner
{ {
private async void runTest(string testPath, LoadOptions loadOptions = null) { private async Task runTest(string testPath, LoadOptions loadOptions = null) {
// Android // Android
var testFile = testPath + @"\" + Path.GetFileName(testPath) + ".so"; var testFile = testPath + @"\" + Path.GetFileName(testPath) + ".so";
if (!File.Exists(testFile)) if (!File.Exists(testFile))
@@ -72,8 +72,8 @@ namespace Il2CppInspector
throw new Exception("Could not find any images in the IL2CPP binary"); throw new Exception("Could not find any images in the IL2CPP binary");
// Dump each image in the binary separately // Dump each image in the binary separately
var imageTasks = inspectors.Select((il2cpp, i) => Task.Run(() =>
Parallel.ForEach(inspectors, il2cpp => { {
TypeModel model; TypeModel model;
using (new Benchmark("Create .NET type model")) using (new Benchmark("Create .NET type model"))
model = new TypeModel(il2cpp); model = new TypeModel(il2cpp);
@@ -82,7 +82,7 @@ namespace Il2CppInspector
using (new Benchmark("Create application model")) using (new Benchmark("Create application model"))
appModel = new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC); appModel = new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC);
var nameSuffix = "-" + il2cpp.BinaryImage.Arch.ToLower(); var nameSuffix = i++ > 0 ? "-" + (i - 1) : "";
using (new Benchmark("Create C# code stubs")) using (new Benchmark("Create C# code stubs"))
new CSharpCodeStubs(model) { new CSharpCodeStubs(model) {
@@ -104,13 +104,14 @@ namespace Il2CppInspector
python.WriteScriptToFile(testPath + $@"\test-{target.ToLower()}{nameSuffix}.py", target, python.WriteScriptToFile(testPath + $@"\test-{target.ToLower()}{nameSuffix}.py", target,
testPath + $@"\test-cpp-result{nameSuffix}\appdata\il2cpp-types.h", testPath + $@"\test-cpp-result{nameSuffix}\appdata\il2cpp-types.h",
testPath + $@"\test-result{nameSuffix}.json"); testPath + $@"\test-result{nameSuffix}.json");
}); }));
await Task.WhenAll(imageTasks);
// Compare test results with expected results // Compare test results with expected results
using (new Benchmark("Compare files")) { using (new Benchmark("Compare files")) {
var compareTasks = new List<Task>(); var compareTasks = new List<Task>();
foreach (var il2cpp in inspectors) { for (var i = 0; i < inspectors.Count; i++) {
var suffix = "-" + il2cpp.BinaryImage.Arch.ToLower(); var suffix = i++ > 0 ? "-" + (i - 1) : "";
compareTasks.Add(Task.Run(() => compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs"))); compareTasks.Add(Task.Run(() => compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs")));
compareTasks.Add(Task.Run(() => compareFiles(testPath, suffix + ".json", $"test-result{suffix}.json"))); compareTasks.Add(Task.Run(() => compareFiles(testPath, suffix + ".json", $"test-result{suffix}.json")));

View File

@@ -9,11 +9,12 @@ echo @"
// THIS FILE IS AUTO-GENERATED BY GENERATE-TESTS.PS1 // THIS FILE IS AUTO-GENERATED BY GENERATE-TESTS.PS1
// DO NOT EDIT // DO NOT EDIT
using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
namespace Il2CppInspector namespace Il2CppInspector
{ {
[Parallelizable(ParallelScope.Children)] [Parallelizable(ParallelScope.All)]
public partial class TestRunner public partial class TestRunner
{ {
"@ > $testGen "@ > $testGen
@@ -26,8 +27,8 @@ gci -Directory $bin | % {
} }
echo @" echo @"
[Test] [Test]
public void $($_.Name -Replace '\W','_')() { public async Task $($_.Name -Replace '\W','_')() {
runTest(@"$($_.FullName)", new LoadOptions { $loadOptions }); await runTest(@"$($_.FullName)", new LoadOptions { $loadOptions });
} }
"@ >> $testGen "@ >> $testGen