public void LoadingAssemblyWithInvalidPath_ShouldFail() { InstrumentationAPI Instrumentation = new InstrumentationAPI(); Assert.Throws <FileNotFoundException>(() => { Instrumentation.AddAssemblyFromPath( TestContext.CurrentContext.TestDirectory + "non-existing.dll" ); }); }
public void ExampleEchoServer_SnapshotValue_ShouldCollectInternalFields() { InstrumentationAPI Instrumentation = new InstrumentationAPI(); SystemUnderTestDeploymentAPI Driver = new SystemUnderTestDeploymentAPI(); string stagingPath = Path.Combine( TestUtility.getRelativeSolutionPath(TestContext.CurrentContext.TestDirectory), "staging/" ); string echoClientServerExamplePath = Path.Combine( stagingPath, "ExampleClientServerEchoApp.exe" ); string instrumentedAppPath = Path.Combine( stagingPath, "Instrumented_SnapshotTest_ExampleClientServerEchoApp.exe" ); Console.WriteLine("Instrumenting system: {0}", echoClientServerExamplePath); Console.WriteLine("Writing to: {0}", instrumentedAppPath); Instrumentation.AddAssemblyFromPath(echoClientServerExamplePath); Instrumentation.SetAssemblyOutputPath( "ExampleClientServerEchoApp", instrumentedAppPath ); // TODO --- make it easier to capture multiple snapshot values at one IP InstrumentationPoint snapshotPrivateInner = Instrumentation.AddNamedInstrumentationPoint("snapshotClient") .FindInAssemblyNamed("ExampleClientServerEchoApp") .FindInTypeNamed("EchoServer") .FindMethodNamed("RespondToMessage"); Instrumentation.Snapshot .ValueOfField("theAnswer") .StartingAtExit(snapshotPrivateInner); InstrumentationPoint snapshotNMessagesSent = Instrumentation.AddNamedInstrumentationPoint("countMessagesSent") .FindInAssemblyNamed("ExampleClientServerEchoApp") .FindInTypeNamed("EchoServer") .FindMethodNamed("RespondToMessage"); Instrumentation.Snapshot .ValueOfField("nMessagesSent") .StartingAtExit(snapshotNMessagesSent); Instrumentation.EnableBootstrap(); using (SystemProcessWrapperWithInput sut = Driver.ExecuteWithArguments(instrumentedAppPath, "server 60011")) { Assert.That(Driver.CaptureValueBlocking(snapshotPrivateInner), Is.EqualTo(42)); Assert.That(Driver.CaptureValueBlocking(snapshotNMessagesSent), Is.EqualTo(0)); TestUtility.mockUdpClientMessageRequest("127.0.0.1", 60011, "test 1"); Assert.That(Driver.CaptureValueBlocking(snapshotNMessagesSent), Is.EqualTo(1)); } }
public void ExampleEchoServer_MeasureStopwatch_ShouldCollectRoundtripMessageTimes() { InstrumentationAPI Instrumentation = new InstrumentationAPI(); SystemUnderTestDeploymentAPI Driver = new SystemUnderTestDeploymentAPI(); string stagingPath = Path.Combine( TestUtility.getRelativeSolutionPath(TestContext.CurrentContext.TestDirectory), "staging/" ); string echoClientServerExamplePath = Path.Combine( stagingPath, "ExampleClientServerEchoApp.exe" ); string instrumentedAppPath = Path.Combine( stagingPath, "Instrumented_StopWatchTest_ExampleClientServerEchoApp.exe" ); Console.WriteLine("Instrumenting system: {0}", echoClientServerExamplePath); Console.WriteLine("Writing to: {0}", instrumentedAppPath); Instrumentation.AddAssemblyFromPath(echoClientServerExamplePath); Instrumentation.SetAssemblyOutputPath( "ExampleClientServerEchoApp", instrumentedAppPath ); InstrumentationPoint stopwatchStartPoint = Instrumentation.AddNamedInstrumentationPoint("startStopwatchGotMessage") .FindInAssemblyNamed("ExampleClientServerEchoApp") .FindInTypeNamed("EchoServer") .FindMethodNamed("GetAvailableMessage"); InstrumentationPoint stopwatchEndPoint = Instrumentation.AddNamedInstrumentationPoint("stopStopwatchSentMessage") .FindInAssemblyNamed("ExampleClientServerEchoApp") .FindInTypeNamed("EchoServer") .FindMethodNamed("RespondToMessage"); Instrumentation.Delay .AddSecondsOfSleep(3) .StartingAtEntry(stopwatchEndPoint); Instrumentation.Measure .WithStopWatch() .StartingAtEntry(stopwatchStartPoint) .UntilExit(stopwatchEndPoint); Instrumentation.EnableBootstrap(); using (SystemProcessWrapperWithInput sut = Driver.ExecuteWithArguments(instrumentedAppPath, "server 60012")) { TestUtility.mockUdpClientMessageRequest("127.0.0.1", 60012, "test"); Assert.That(Driver.CaptureValueBlocking(stopwatchEndPoint), Is.GreaterThanOrEqualTo(3000).And.LessThanOrEqualTo(4000)); } }
public void TestReferenceApplication() { SystemUnderTestDeploymentAPI Driver = new SystemUnderTestDeploymentAPI(); InstrumentationAPI Instrumentation = new InstrumentationAPI(); // Deployment prep string referenceApplicationPath = Assembly.ReflectionOnlyLoad("NFBench.Benchmark.ReferenceImplementation").Location; string weaveToApplicationPath = Directory.GetParent(referenceApplicationPath).FullName + "/wovenReferenceImplementation.exe"; string referenceApplicationArgumentString = "reference 127.0.0.1 60708"; string testClientApplicationPath = Assembly.ReflectionOnlyLoad("TestClientApplications").Location; string client1Arguments = "127.0.0.1 60708 1"; string client2Arguments = "127.0.0.1 60708 2"; // Instrumentation // Instrumentation points in ReferenceApplicationServer // * // * (timer) stopwatch: receiveMessageCallback -> endSendMessageCallback Console.WriteLine("Instrumenting system: {0}", referenceApplicationPath); Console.WriteLine("Writing to: {0}", weaveToApplicationPath); Instrumentation.AddAssemblyFromPath(referenceApplicationPath); Instrumentation.SetAssemblyOutputPath( "NFBench.Benchmark.ReferenceImplementation", weaveToApplicationPath ); InstrumentationPoint stopwatchStartPoint = Instrumentation.AddNamedInstrumentationPoint("startStopwatchGotMessage") .FindInAssemblyNamed("NFBench.Benchmark.ReferenceImplementation") .FindInTypeNamed("ReferenceApplicationServer") .FindMethodNamed("receiveMessageCallback"); InstrumentationPoint stopwatchEndPoint = Instrumentation.AddNamedInstrumentationPoint("stopStopwatchSentMessage") .FindInAssemblyNamed("NFBench.Benchmark.ReferenceImplementation") .FindInTypeNamed("ReferenceApplicationServer") .FindMethodNamed("endSendMessageCallback"); Instrumentation.Measure .WithStopWatch() .StartingAtEntry(stopwatchStartPoint) .UntilExit(stopwatchEndPoint); // * (val) nMessagesSent -> endSendMessageCallback // * (val) nMessagesReceived -> receiveMessageCallback // Test using (SystemProcessWrapperWithInput sut = Driver.ExecuteWithArguments(weaveToApplicationPath, referenceApplicationArgumentString)) using (SystemProcessWrapperWithInput client1 = Driver.ExecuteWithArguments(testClientApplicationPath, client1Arguments)) using (SystemProcessWrapperWithInput client2 = Driver.ExecuteWithArguments(testClientApplicationPath, client2Arguments)) { client1.ConsoleInput("#1 Hello World"); long elapsedMilliseconds = (long)Driver.captureValue(stopwatchEndPoint); Assert.GreaterOrEqual(100, elapsedMilliseconds); // client2.ConsoleInput("#2 Hello World"); // client1.ConsoleInput("@2 #1 Private message for @2"); // client1.ConsoleInput("@7 #1 Private message for @7"); Thread.Sleep(5000); } }