|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Diagnostics; |
| 6 | +using System.IO; |
| 7 | +using System.Reflection; |
| 8 | +using System.Runtime.Loader; |
| 9 | +using System.Threading; |
| 10 | + |
| 11 | +class Program |
| 12 | +{ |
| 13 | + // Normalybehavior is to not print anything on success. |
| 14 | + // |
| 15 | + static bool verbose = false; |
| 16 | + |
| 17 | + // Repeatedly execute a test case's Main method so that methods jitted |
| 18 | + // by the test can get rejitted at Tier1. |
| 19 | + // |
| 20 | + static int Main(string[] args) |
| 21 | + { |
| 22 | + string testAssemblyName = args[0]; |
| 23 | + |
| 24 | + // We'll stop iterating if total test time exceeds this value (in ms). |
| 25 | + // |
| 26 | + int timeout = 10_000; |
| 27 | + |
| 28 | + // Some tests return zero for success. |
| 29 | + // |
| 30 | + int expectedResult = 100; |
| 31 | + |
| 32 | + string[][] zeroReturnValuePatterns = { |
| 33 | + new string[] { "JIT", "jit64", "regress", "vsw", "102754", "test1"}, |
| 34 | + new string[] { "JIT", "Regression", "CLR-x86-JIT", "V1-M09", "b16102", "b16102"}, |
| 35 | + }; |
| 36 | + |
| 37 | + foreach (string[] pattern in zeroReturnValuePatterns) |
| 38 | + { |
| 39 | + if (testAssemblyName.IndexOf(Path.Join(pattern)) > 0) |
| 40 | + { |
| 41 | + expectedResult = 0; |
| 42 | + break; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + // Exclude tests that seem to be incompatible. |
| 47 | + // Todo: root cause these and fix tests if possible. |
| 48 | + // |
| 49 | + // With Full PGO: |
| 50 | + // RngchkStress2_o can hit a jit assert: '!m_failedToConverge' in 'SimpleArray_01.Test:Test1()' during 'Profile incorporation' |
| 51 | + // GitHub_25027 can hit a jit assert: 'verCurrentState.esStackDepth == 0' in 'X:Main():int' during 'Morph - Inlining' |
| 52 | + // |
| 53 | + string[][] exclusionPatterns = { |
| 54 | + new string[] { "JIT", "jit64", "opt", "cse", "VolatileTest_op" }, |
| 55 | + new string[] { "JIT", "jit64", "opt", "rngchk", "ArrayWithThread_o" }, |
| 56 | + new string[] { "baseservices", "threading", "threadstatic", "ThreadStatic01" }, |
| 57 | + new string[] { "GC", "Scenarios", "ReflectObj", "reflectobj"}, |
| 58 | + new string[] { "baseservices", "threading", "mutex", "openexisting", "openmutexpos4"}, |
| 59 | + new string[] { "GC", "Scenarios", "NDPin", "ndpinfinal"}, |
| 60 | + new string[] { "JIT", "Regression", "JitBlue", "GitHub_4044", "GitHub_4044"}, |
| 61 | + new string[] { "JIT", "HardwareIntrinsics", "X86", "Regression", "GitHub_21666", "GitHub_21666_ro"}, |
| 62 | + new string[] { "Interop", "NativeLibrary", "API", "NativeLibraryTests"}, |
| 63 | + new string[] { "baseservices", "compilerservices", "FixedAddressValueType", "FixedAddressValueType"}, |
| 64 | + new string[] { "GC", "LargeMemory", "API", "gc", "gettotalmemory" }, |
| 65 | + |
| 66 | + new string[] { "JIT", "jit64", "opt", "rngchk", "RngchkStress2_o" }, |
| 67 | + new string[] { "JIT", "Regression", "JitBlue", "GitHub_25027", "GitHub_25027" }, |
| 68 | + }; |
| 69 | + |
| 70 | + foreach (string[] pattern in exclusionPatterns) |
| 71 | + { |
| 72 | + if (testAssemblyName.IndexOf(Path.Join(pattern)) > 0) |
| 73 | + { |
| 74 | + if (verbose) |
| 75 | + { |
| 76 | + Console.WriteLine($"Test {Path.Join(pattern)} excluded; marked as incompatible"); |
| 77 | + } |
| 78 | + return expectedResult; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + AssemblyLoadContext alc = AssemblyLoadContext.Default; |
| 83 | + Assembly testAssembly = alc.LoadFromAssemblyPath(testAssemblyName); |
| 84 | + MethodInfo main = testAssembly.EntryPoint; |
| 85 | + |
| 86 | + if (main == null) |
| 87 | + { |
| 88 | + Console.WriteLine($"Can't find entry point in {Path.GetFileName(args[0])}"); |
| 89 | + return -1; |
| 90 | + } |
| 91 | + |
| 92 | + string[] mainArgs = new string[args.Length - 1]; |
| 93 | + Array.Copy(args, 1, mainArgs, 0, mainArgs.Length); |
| 94 | + |
| 95 | + // Console.WriteLine($"Found entry point {main.Name} in {Path.GetFileName(args[0])}"); |
| 96 | + |
| 97 | + // See if main wants any args. |
| 98 | + // |
| 99 | + var mainParams = main.GetParameters(); |
| 100 | + |
| 101 | + int result = 0; |
| 102 | + |
| 103 | + // Repeatedly invoke main to get things to pass through Tier0 and rejit at Tier1 |
| 104 | + // |
| 105 | + int warmup = 40; |
| 106 | + int final = 5; |
| 107 | + int total = warmup + final; |
| 108 | + int i = 0; |
| 109 | + int sleepInterval = 5; |
| 110 | + Stopwatch s = new Stopwatch(); |
| 111 | + s.Start(); |
| 112 | + |
| 113 | + // We might decide to give up on this test, for reasons. |
| 114 | + // |
| 115 | + // If the test fails at iteration 0, assume it's incompatible with the way we're running it |
| 116 | + // and don't report as a failure. |
| 117 | + // |
| 118 | + // If the test fails at iteration 1, assume it's got some bit of state that carries over |
| 119 | + // from one call to main to the next, and so don't report it as failure. |
| 120 | + // |
| 121 | + // If the test takes too long, just give up on iterating it. |
| 122 | + // |
| 123 | + bool giveUp = false; |
| 124 | + |
| 125 | + try |
| 126 | + { |
| 127 | + |
| 128 | + for (; i < warmup && !giveUp; i++) |
| 129 | + { |
| 130 | + if (mainParams.Length == 0) |
| 131 | + { |
| 132 | + result = (int)main.Invoke(null, new object[] { }); |
| 133 | + } |
| 134 | + else |
| 135 | + { |
| 136 | + result = (int)main.Invoke(null, new object[] { mainArgs }); |
| 137 | + } |
| 138 | + |
| 139 | + if (result != expectedResult) |
| 140 | + { |
| 141 | + if (i < 2) |
| 142 | + { |
| 143 | + Console.WriteLine($"[tieringtest] test failed at iteration {i} with result {result}. Test is likely incompatible."); |
| 144 | + result = expectedResult; |
| 145 | + } |
| 146 | + else |
| 147 | + { |
| 148 | + Console.WriteLine($"[tieringtest] test failed at iteration {i}: {result} (expected {expectedResult})"); |
| 149 | + } |
| 150 | + giveUp = true; |
| 151 | + break; |
| 152 | + } |
| 153 | + |
| 154 | + // Don't iterate if test is running long. |
| 155 | + // |
| 156 | + if (s.ElapsedMilliseconds > timeout) |
| 157 | + { |
| 158 | + Console.WriteLine($"[tieringtest] test running long ({s.ElapsedMilliseconds / (i + 1)} ms/iteration). Giving up at iteration {i}"); |
| 159 | + giveUp = true; |
| 160 | + break; |
| 161 | + } |
| 162 | + |
| 163 | + // Give TC a chance to jit some things. |
| 164 | + // |
| 165 | + Thread.Sleep(sleepInterval); |
| 166 | + } |
| 167 | + |
| 168 | + for (; i < total && !giveUp; i++) |
| 169 | + { |
| 170 | + if (mainParams.Length == 0) |
| 171 | + { |
| 172 | + result = (int)main.Invoke(null, new object[] { }); |
| 173 | + } |
| 174 | + else |
| 175 | + { |
| 176 | + result = (int)main.Invoke(null, new object[] { mainArgs }); |
| 177 | + } |
| 178 | + |
| 179 | + if (result != expectedResult) |
| 180 | + { |
| 181 | + Console.WriteLine($"[tieringtest] failed at iteration {i}: {result} (expected {expectedResult})"); |
| 182 | + giveUp = true; |
| 183 | + break; |
| 184 | + } |
| 185 | + |
| 186 | + // Don't iterate if test is running long. |
| 187 | + // |
| 188 | + if (s.ElapsedMilliseconds > timeout) |
| 189 | + { |
| 190 | + Console.WriteLine($"[tieringtest] test running long ({s.ElapsedMilliseconds / (i + 1)} ms/iteration). Giving up at iteration {i}"); |
| 191 | + giveUp = true; |
| 192 | + break; |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + if (result == expectedResult) |
| 197 | + { |
| 198 | + if (verbose) |
| 199 | + { |
| 200 | + Console.WriteLine($"[tieringtest] ran {total} test iterations sucessfully"); |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + catch (Exception e) |
| 205 | + { |
| 206 | + if (i < 2) |
| 207 | + { |
| 208 | + if (verbose) |
| 209 | + { |
| 210 | + Console.WriteLine($"[tieringtest] test failed at iteration {i} with exception {e.Message}. Test is likely incompatible."); |
| 211 | + } |
| 212 | + result = expectedResult; |
| 213 | + } |
| 214 | + else |
| 215 | + { |
| 216 | + Console.WriteLine($"[tieringtest] test failed at iteration {i} with exception {e.Message}"); |
| 217 | + result = -1; |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + return result; |
| 222 | + } |
| 223 | +} |
0 commit comments