Tests: Parallelize output generation where possible

This commit is contained in:
Katy Coe
2020-12-21 06:02:52 +01:00
parent 2f01403dfb
commit 210c4a716b

View File

@@ -72,38 +72,51 @@ 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(() => var imageTasks = inspectors.Select((il2cpp, i) => Task.Run(async () =>
{ {
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);
AppModel appModel; var appModelTask = Task.Run(() => {
using (new Benchmark("Create application model")) using (new Benchmark("Create application model"))
appModel = new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC); return new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC);
});
var nameSuffix = i++ > 0 ? "-" + (i - 1) : ""; var nameSuffix = i++ > 0 ? "-" + (i - 1) : "";
using (new Benchmark("Create C# code stubs")) var csTask = Task.Run(() => {
new CSharpCodeStubs(model) { using (new Benchmark("Create C# code stubs"))
ExcludedNamespaces = Constants.DefaultExcludedNamespaces, new CSharpCodeStubs(model) {
SuppressMetadata = false, ExcludedNamespaces = Constants.DefaultExcludedNamespaces,
MustCompile = true SuppressMetadata = false,
}.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs"); MustCompile = true
}.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs");
});
using (new Benchmark("Create JSON metadata")) var appModel = await appModelTask;
new JSONMetadata(appModel)
var jsonTask = Task.Run(() => {
using (new Benchmark("Create JSON metadata"))
new JSONMetadata(appModel)
.Write(testPath + $@"\test-result{nameSuffix}.json"); .Write(testPath + $@"\test-result{nameSuffix}.json");
});
using (new Benchmark("Create C++ scaffolding")) var cppTask = Task.Run(() => {
new CppScaffolding(appModel) using (new Benchmark("Create C++ scaffolding"))
new CppScaffolding(appModel)
.Write(testPath + $@"\test-cpp-result{nameSuffix}"); .Write(testPath + $@"\test-cpp-result{nameSuffix}");
});
var python = new PythonScript(appModel); var pyTask = Task.Run(() => {
foreach (var target in PythonScript.GetAvailableTargets()) var python = new PythonScript(appModel);
python.WriteScriptToFile(testPath + $@"\test-{target.ToLower()}{nameSuffix}.py", target, foreach (var target in PythonScript.GetAvailableTargets())
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(csTask, jsonTask, cppTask, pyTask);
})); }));
await Task.WhenAll(imageTasks); await Task.WhenAll(imageTasks);