|
| 1 | +using System.Xml.Linq; |
| 2 | + |
| 3 | +namespace GC.Infrastructure.Core.Configurations |
| 4 | +{ |
| 5 | + public static class ReliabilityFrameworkTestSuiteCreator |
| 6 | + { |
| 7 | + public static void CreateTestingAssets(string ReliabilityFrameworkDll, |
| 8 | + string GCPerfSimDll, |
| 9 | + string outputFolder, |
| 10 | + string TestFolder) |
| 11 | + { |
| 12 | + try |
| 13 | + { |
| 14 | + Console.WriteLine($"====== Copy ReliabilityFramework.dll and Tests to `outputFolder` ======"); |
| 15 | + Utilities.CopyFile(ReliabilityFrameworkDll, outputFolder); |
| 16 | + DirectoryInfo testDir = Directory.CreateDirectory(Path.Combine(outputFolder, "Tests")); |
| 17 | + string testfolderPath = testDir.FullName; |
| 18 | + Utilities.CopyFilesRecursively(TestFolder, testfolderPath); |
| 19 | + |
| 20 | + Console.WriteLine($"====== Copy gcperfsim.dll to Tests ======"); |
| 21 | + string destTestsFolder = Path.Combine(outputFolder, "Tests"); |
| 22 | + Utilities.CopyFile(GCPerfSimDll, destTestsFolder); |
| 23 | + } |
| 24 | + catch (Exception ex) |
| 25 | + { |
| 26 | + throw new Exception($"{nameof(ReliabilityFrameworkTestSuiteCreator)}: Fail to generate test assets: {ex}"); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public static void GenerateTestScript(string rid, |
| 31 | + string baseSuiteFolder, |
| 32 | + string coreRoot, |
| 33 | + string configPath, |
| 34 | + string gcMode, |
| 35 | + string outputRoot, |
| 36 | + string scriptPath) |
| 37 | + { |
| 38 | + string scriptFoler = Path.GetDirectoryName(scriptPath); |
| 39 | + string osName = rid.Split("-") |
| 40 | + .FirstOrDefault(""); |
| 41 | + |
| 42 | + string configName = Path.GetFileName(configPath).Split("-") |
| 43 | + .FirstOrDefault(""); |
| 44 | + |
| 45 | + (string DOTNET_gcServer, string DOTNET_GCDynamicAdaptationMode) = |
| 46 | + gcMode switch |
| 47 | + { |
| 48 | + "Datas" => ("1", "1"), |
| 49 | + "Server" => ("1", "0"), |
| 50 | + "Workstation" => ("0", "0"), |
| 51 | + _ => throw new Exception($"{nameof(ReliabilityFrameworkTestSuiteCreator)}: Unknow GC mode: {gcMode}") |
| 52 | + }; |
| 53 | + |
| 54 | + string scriptSettingSegment; |
| 55 | + string scriptBaseContent; |
| 56 | + |
| 57 | + if (osName == "win") |
| 58 | + { |
| 59 | + scriptSettingSegment = |
| 60 | +$""" |
| 61 | +########## setting start ########## |
| 62 | +$Env:DOTNET_gcServer={DOTNET_gcServer} |
| 63 | +$Env:DOTNET_GCDynamicAdaptationMode={DOTNET_GCDynamicAdaptationMode} |
| 64 | +
|
| 65 | +$OutputRoot="{outputRoot}" |
| 66 | +$CORE_ROOT="{coreRoot}" |
| 67 | +
|
| 68 | +# set config path |
| 69 | +$config_path=Join-Path -Path $PSScriptRoot -ChildPath "{Path.GetRelativePath(scriptFoler, configPath)}" |
| 70 | +
|
| 71 | +# set test folder |
| 72 | +$test_folder=Join-Path -Path $OutputRoot -ChildPath "Tests" |
| 73 | +
|
| 74 | +# set ReliabilityFramework.dll path |
| 75 | +$reliability_framework_dll=Join-Path -Path $OutputRoot -ChildPath "ReliabilityFramework.dll" |
| 76 | +
|
| 77 | +# set output folder |
| 78 | +$output_folder=$PSScriptRoot |
| 79 | +########## setting end ########## |
| 80 | +"""; |
| 81 | + string baseScriptPath = Path.Combine(baseSuiteFolder, "TestingScript.ps1.txt"); |
| 82 | + scriptBaseContent = File.ReadAllText(baseScriptPath); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + scriptSettingSegment = |
| 87 | +$""" |
| 88 | +#!/bin/bash |
| 89 | +
|
| 90 | +script_root=$(dirname $(realpath $0)) |
| 91 | +########## setting start ########## |
| 92 | +# set gc mode |
| 93 | +export DOTNET_gcServer={DOTNET_gcServer} |
| 94 | +export DOTNET_GCDynamicAdaptationMode={DOTNET_GCDynamicAdaptationMode} |
| 95 | +
|
| 96 | +# set core_root |
| 97 | +Output_Root={outputRoot} |
| 98 | +CORE_ROOT={coreRoot} |
| 99 | +
|
| 100 | +# set config path |
| 101 | +config_path=$script_root/{Path.GetRelativePath(scriptFoler, configPath)} |
| 102 | +
|
| 103 | +# set test folder |
| 104 | +test_folder=$Output_Root/Tests |
| 105 | +
|
| 106 | +# set ReliabilityFramework.dll path |
| 107 | +reliability_framework_dll=$Output_Root/ReliabilityFramework.dll |
| 108 | +
|
| 109 | +# set output folder |
| 110 | +output_folder=$script_root |
| 111 | +
|
| 112 | +########## setting end ########## |
| 113 | +"""; |
| 114 | + string baseScriptPath = Path.Combine(baseSuiteFolder, "TestingScript.sh.txt"); |
| 115 | + scriptBaseContent = File.ReadAllText(baseScriptPath); |
| 116 | + } |
| 117 | + |
| 118 | + string content = $"{scriptSettingSegment}\n\n{scriptBaseContent}"; |
| 119 | + File.WriteAllText(scriptPath, content); |
| 120 | + } |
| 121 | + |
| 122 | + public static void GenerateTestConfig(string rid, string baseSuiteFolder, string configName, bool enableStress, string gcMode, string configPath) |
| 123 | + { |
| 124 | + try |
| 125 | + { |
| 126 | + string osName = rid.Split("-") |
| 127 | + .FirstOrDefault(""); |
| 128 | + |
| 129 | + string maximumWaitTime = |
| 130 | + (osName, enableStress) switch |
| 131 | + { |
| 132 | + ("win", false) => Windows[configName][gcMode], |
| 133 | + ("win", true) => WindowsStress[configName][gcMode], |
| 134 | + ("linux", false) => Linux[configName][gcMode], |
| 135 | + ("linux", true) => LinuxStress[configName][gcMode], |
| 136 | + _ => throw new Exception($"{nameof(ReliabilityFrameworkTestSuiteCreator)}: Unknown OS {osName}") |
| 137 | + }; |
| 138 | + |
| 139 | + string baseConfigPath = Path.Combine(baseSuiteFolder, $"{configName}.config"); |
| 140 | + string baseConfigContent = File.ReadAllText(baseConfigPath); |
| 141 | + XElement config = XElement.Parse(baseConfigContent); |
| 142 | + config.SetAttributeValue("maximumWaitTime", maximumWaitTime); |
| 143 | + config.SetAttributeValue("maximumExecutionTime", "24:00:00"); |
| 144 | + config.SetAttributeValue("maximumTestRuns", "-1"); |
| 145 | + |
| 146 | + config.Save(configPath, SaveOptions.OmitDuplicateNamespaces); |
| 147 | + } |
| 148 | + catch (Exception e) |
| 149 | + { |
| 150 | + throw new Exception($"{nameof(ReliabilityFrameworkTestSuiteCreator)}: Fail to generate test config: {e.Message}"); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + private static Dictionary<string, Dictionary<string, string>> Windows { get; } = new() |
| 155 | + { |
| 156 | + { "loh", new() { { "Server", "00:10:00"}, { "Workstation", "01:45:00"}, { "Datas", "00:10:00"} } }, |
| 157 | + { "poh", new() { { "Server", "00:05:00"}, { "Workstation", "00:50:00" }, { "Datas", "00:05:00" } } }, |
| 158 | + { "non_induced", new() { { "Server", "00:30:00"}, { "Workstation", "03:30:00"}, { "Datas", "00:20:00"} } }, |
| 159 | + { "finalization", new() { { "Server", "00:05:00"}, { "Workstation", "00:50:00"}, { "Datas", "00:15:00" } } } |
| 160 | + }; |
| 161 | + private static Dictionary<string, Dictionary<string, string>> WindowsStress { get; } = new() |
| 162 | + { |
| 163 | + { "loh", new() { { "Server", "00:02:00"}, { "Workstation", "00:10:00"}, { "Datas", "00:05:00"} } }, |
| 164 | + { "poh", new() { { "Server", "00:02:00"}, { "Workstation", "00:10:00" }, { "Datas", "00:05:00" } } }, |
| 165 | + { "non_induced", new() { { "Server", "00:25:00"}, { "Workstation", "04:00:00"}, { "Datas", "00:35:00"} } }, |
| 166 | + { "finalization", new() { { "Server", "00:05:00"}, { "Workstation", "00:40:00"}, { "Datas", "01:40:00" } } } |
| 167 | + }; |
| 168 | + private static Dictionary<string, Dictionary<string, string>> Linux { get; } = new() |
| 169 | + { |
| 170 | + { "loh", new() { { "Server", "00:25:00"}, { "Workstation", "00:20:00"}, { "Datas", "00:20:00"} } }, |
| 171 | + { "poh", new() { { "Server", "00:10:00"}, { "Workstation", "00:10:00" }, { "Datas", "00:10:00" } } }, |
| 172 | + { "non_induced", new() { { "Server", "00:25:00"}, { "Workstation", "00:55:00"}, { "Datas", "00:15:00"} } }, |
| 173 | + { "finalization", new() { { "Server", "00:20:00"}, { "Workstation", "01:30:00"}, { "Datas", "00:25:00" } } } |
| 174 | + }; |
| 175 | + private static Dictionary<string, Dictionary<string, string>> LinuxStress { get; } = new() |
| 176 | + { |
| 177 | + { "loh", new() { { "Server", "00:10:00"}, { "Workstation", "00:25:00"}, { "Datas", "00:08:00"} } }, |
| 178 | + { "poh", new() { { "Server", "00:05:00"}, { "Workstation", "00:15:00" }, { "Datas", "00:05:00" } } }, |
| 179 | + { "non_induced", new() { { "Server", "00:25:00"}, { "Workstation", "01:10:00"}, { "Datas", "00:30:00"} } }, |
| 180 | + { "finalization", new() { { "Server", "00:20:00"}, { "Workstation", "00:50:00"}, { "Datas", "04:00:00" } } } |
| 181 | + }; |
| 182 | + } |
| 183 | +} |
0 commit comments