private static MarkupNode CreateRemark( params MarkupNode[] contents) { return(new Paragraph( new MarkupNode[] { DecorationSpan.MakeBold(new ColorSpan("remark: ", Colors.Gray)) } .Concat(contents) .ToArray())); }
private static MarkupNode CreateRemark( params MarkupNode[] contents) { // TODO: deduplicate this logic (it also appears in IL2LLVM and ILOpt) return(new Paragraph( new MarkupNode[] { DecorationSpan.MakeBold(new ColorSpan("remark: ", Colors.Gray)) } .Concat(contents) .ToArray())); }
/// <summary> /// Runs all the tests based on parsed command-line options /// and a log. /// </summary> /// <param name="uri">The URI to test.</param> /// <param name="driverBuilders"> /// A mapping of driver names to functions that each produce /// a driver to run the tests with. /// </param> /// <param name="log">A log to send messages to.</param> /// <param name="progressLog">A log for progress messages.</param> private static void Run( string uri, IReadOnlyDictionary <string, Func <IWebDriver> > driverBuilders, ILog log, ILog progressLog) { var allTestCases = TestCases.ToArray(); int testCaseCount = allTestCases.Length * driverBuilders.Count; int completedTestCases = 0; foreach (var builder in driverBuilders) { using (IWebDriver driver = builder.Value()) { foreach (var testCase in allTestCases) { // Always navigate to the front page first. driver.Navigate().GoToUrl(uri); // Then run the actual test case. bool success = testCase.Run(driver, builder.Key, log); completedTestCases++; var percentage = 100.0 * completedTestCases / testCaseCount; // Print a fancy progress message. progressLog.Log( new Pixie.LogEntry( Severity.Info, DecorationSpan.MakeBold( new ColorSpan( new Sequence( string.Format("[{0,3}%]", Math.Round(percentage)), " ", success ? new DegradableText("✓", new DegradableText("√", "v")) : new DegradableText("✗", "x")), success ? Colors.Green : Colors.Red)), " ", DecorationSpan.MakeBold(new Quotation(testCase.Description, 2)), string.Format(" [{0}]", builder.Key))); } } } }
/// <summary> /// Writes a CIL method body, analyzes it as Flame IR, /// emits that as CIL and checks that the outcome matches /// what we'd expect. /// </summary> /// <param name="returnType"> /// The return type of the method body. /// </param> /// <param name="parameterTypes"> /// The parameter types of the method body. /// </param> /// <param name="localTypes"> /// The local variable types of the method body. /// </param> /// <param name="emitBody"> /// A function that writes the method body. /// </param> /// <param name="oracle"> /// A printed version of the expected method body. /// </param> private void RoundtripStaticMethodBody( TypeReference returnType, IReadOnlyList <TypeReference> parameterTypes, IReadOnlyList <TypeReference> localTypes, Action <Mono.Cecil.Cil.ILProcessor> emitBody, string oracle) { // Define a method. var methodDef = CreateStaticMethodDef(returnType, parameterTypes); // Emit the source CIL. var cilBody = new Mono.Cecil.Cil.MethodBody(methodDef); foreach (var localType in localTypes) { cilBody.Variables.Add(new Mono.Cecil.Cil.VariableDefinition(localType)); } emitBody(cilBody.GetILProcessor()); cilBody.Optimize(); // Analyze it as Flame IR. var irBody = ClrMethodBodyAnalyzer.Analyze( cilBody, new Parameter(TypeHelpers.BoxIfReferenceType(corlib.Resolve(returnType))), default(Parameter), parameterTypes .Select((type, i) => new Parameter(TypeHelpers.BoxIfReferenceType(corlib.Resolve(type)), "param_" + i)) .ToArray(), corlib); // Register analyses. irBody = new global::Flame.Compiler.MethodBody( irBody.ReturnParameter, irBody.ThisParameter, irBody.Parameters, irBody.Implementation .WithAnalysis(LazyBlockReachabilityAnalysis.Instance) .WithAnalysis(NullabilityAnalysis.Instance) .WithAnalysis(new EffectfulInstructionAnalysis()) .WithAnalysis(PredecessorAnalysis.Instance) .WithAnalysis(RelatedValueAnalysis.Instance) .WithAnalysis(LivenessAnalysis.Instance) .WithAnalysis(InterferenceGraphAnalysis.Instance) .WithAnalysis(ValueUseAnalysis.Instance) .WithAnalysis(ConservativeInstructionOrderingAnalysis.Instance)); // Optimize the IR a tiny bit. irBody = irBody.WithImplementation( irBody.Implementation.Transform( AllocaToRegister.Instance, CopyPropagation.Instance, new ConstantPropagation(), SwitchSimplification.Instance, DeadValueElimination.Instance, InstructionSimplification.Instance, new JumpThreading(true), DeadBlockElimination.Instance, new SwitchLowering(corlib.Resolver.TypeEnvironment), CopyPropagation.Instance, InstructionSimplification.Instance, DeadValueElimination.Instance, InstructionReordering.Instance, new JumpThreading(false))); // Turn Flame IR back into CIL. var newCilBody = ClrMethodBodyEmitter.Compile(irBody, methodDef, corlib.Resolver.TypeEnvironment); // Check that the resulting CIL matches the expected CIL. var actual = FormatMethodBody(newCilBody); actual = actual.Trim().Replace("\r", ""); oracle = oracle.Trim().Replace("\r", ""); if (actual != oracle) { var encoder = new EncoderState(); var encodedImpl = encoder.Encode(irBody.Implementation); var actualIr = Les2LanguageService.Value.Print( encodedImpl, options: new LNodePrinterOptions { IndentString = new string(' ', 4) }); log.Log( new LogEntry( Severity.Message, "emitted CIL-oracle mismatch", "round-tripped CIL does not match the oracle. CIL emit output:", new Paragraph(new WrapBox(actual, 0, -actual.Length)), DecorationSpan.MakeBold("remark: Flame IR:"), new Paragraph(new WrapBox(actualIr, 0, -actualIr.Length)))); } Assert.AreEqual(oracle, actual); }