public void run_graph_process_data_jump_back_restore_state() { var g = new Graph(); var node = new BasicTestNode(g); var source = new SourceNode(g); var sink = new SinkNode(g); g.Connect(source.OutputPorts[0], node.InputPorts[0]); g.Connect(node.OutputPorts[0], sink.InputPorts[0]); Assert.IsTrue(g.Run()); Assert.AreEqual(node.Factor, 0); source.SendData(source.Samplerate); System.Threading.Thread.Sleep(1000); var state = g.SaveState(); var factor = node.Factor; var stamp = ((DataInputPort)sink.InputPorts[0]).Queue.BeginTime; source.SendData(source.Samplerate); System.Threading.Thread.Sleep(1000); Assert.AreNotEqual(node.Factor, factor); g.LoadState(state); Assert.AreEqual(node.Factor, factor); Assert.AreEqual(stamp, ((DataInputPort)sink.InputPorts[0]).Queue.BeginTime); g.Stop(); }
public void run_filenode_save_state_and_restore() { var g = new Graph(); var node = new FileNode(g); var sink = new SinkNode(g); node.FileName = @"C:\tmp\set 1\signal 0.bin"; node.Samplerate = 1000000; g.Connect(node.OutputPorts[0], sink.InputPorts[0]); Assert.IsTrue(g.Run()); var fileSize = new System.IO.FileInfo(node.FileName).Length; node.TargetPosition = (fileSize / 3) - (fileSize / 3) % 8; while (node.Seeking) { System.Threading.Thread.Sleep(10); } var state = g.SaveState(); node.TargetPosition = fileSize * 3 / 4 - (fileSize * 3 / 4) % 8; while (node.Seeking) { System.Threading.Thread.Sleep(10); } g.LoadState(state); }
public void send_nice_data_and_test_if_sink_recieves_all() { var graph = new Graph(); var source = new SourceNode(graph); var sink = new SinkNode(graph); graph.Connect(source.OutputPorts[0], sink.InputPorts[0]); Assert.IsTrue(graph.Run(), "Graph.Run() must succeed"); const int PaketsPerSecond = 4; const int Seconds = 1; for (int i = 0; i < Seconds * PaketsPerSecond; i++) { source.SendData(source.Samplerate / PaketsPerSecond); System.Threading.Thread.Sleep(1000 / PaketsPerSecond); } graph.Stop(); var sumShouldBe = source.Samplerate * Seconds; var sumIs = sink.Sum; var diff = Math.Abs(sumIs - sumShouldBe); Assert.IsTrue(diff < 0.0000001, $"Sum Diff should be 0, but is {diff}"); }
public void send_nice_data_and_test_if_all_stopped_and_empty_also_unconnected_nodes() { var graph = new Graph(); var source = new SourceNode(graph); var sink = new SinkNode(graph); var sink2 = new SinkNode(graph); var pass1 = new PassThroughNode(graph); var pass2 = new PassThroughNode(graph); graph.Connect(source.OutputPorts[0], pass1.InputPorts[0]); graph.Connect(pass1.OutputPorts[0], sink.InputPorts[0]); // pass2 is not connected a source graph.Connect(pass2.OutputPorts[0], sink2.InputPorts[0]); ((DataInputPort)pass2.InputPorts[0]).Samplerate = 100; Assert.IsTrue(graph.Run(), "Graph.Run() must succeed"); const int PaketsPerSecond = 4; const int Seconds = 1; for (int i = 0; i < Seconds * PaketsPerSecond; i++) { System.Threading.Thread.Sleep(1000 / PaketsPerSecond); source.SendData(source.Samplerate / PaketsPerSecond); } System.Diagnostics.Debug.WriteLine("Graph Stop"); graph.Stop(); System.Diagnostics.Debug.WriteLine("All Done"); foreach (var node in graph.Nodes) { Assert.IsTrue(node.State == Node.ProcessingState.Stopped, "All nodes must stop"); } Assert.IsTrue((sink.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((sink2.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((pass1.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((pass2.InputPorts[0] as DataInputPort).Queue.Length == 0); }
public void send_nice_data_and_test_if_all_stopped_and_empty_multi_way() { var graph = new Graph(); var source1 = new SourceNode(graph); var source2 = new SourceNode(graph); var sink = new SinkNode(graph); var pass = new PassThroughNode(graph); var adder = new MetricAdder.Adder(graph); graph.Connect(source1.OutputPorts[0], adder.InputPorts[0]); graph.Connect(source2.OutputPorts[0], adder.InputPorts[1]); graph.Connect(adder.OutputPorts[0], pass.InputPorts[0]); graph.Connect(pass.OutputPorts[0], sink.InputPorts[0]); Assert.IsTrue(graph.Run(), "Graph.Run() must succeed"); const int PaketsPerSecond = 4; const int Seconds = 1; for (int i = 0; i < Seconds * PaketsPerSecond; i++) { System.Threading.Thread.Sleep(1000 / PaketsPerSecond); source1.SendData(source1.Samplerate / PaketsPerSecond); source2.SendData(source2.Samplerate / PaketsPerSecond); } System.Diagnostics.Debug.WriteLine("Graph Stop"); graph.Stop(); System.Diagnostics.Debug.WriteLine("All Done"); foreach (var node in graph.Nodes) { Assert.IsTrue(node.State == Node.ProcessingState.Stopped, "All nodes must stop"); } Assert.IsTrue((sink.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((pass.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((adder.InputPorts[0] as DataInputPort).Queue.Length == 0); Assert.IsTrue((adder.InputPorts[1] as DataInputPort).Queue.Length == 0); }
public void send_unfriendly_data_and_test_if_sink_recieves_all() { var graph = new Graph(); var source = new SourceNode(graph); var sink = new SinkNode(graph); graph.Connect(source.OutputPorts[0], sink.InputPorts[0]); Assert.IsTrue(graph.Run(), "Graph.Run() must succeed"); const int PaketsPerSecond = 7; const int Seconds = 1; double SamplesPerPaket = source.Samplerate / (double)PaketsPerSecond; double SampleCounter = SamplesPerPaket; int samplesToSend = (int)SamplesPerPaket; for (int i = 0; i < Seconds * PaketsPerSecond; i++) { source.SendData(samplesToSend); samplesToSend = (int)((SampleCounter + SamplesPerPaket) - Math.Floor(SampleCounter)); SampleCounter += SamplesPerPaket; System.Threading.Thread.Sleep(1000 / PaketsPerSecond); } graph.Stop(); var sumShouldBe = source.Samplerate * Seconds; var sumIs = sink.Sum; var diff = Math.Abs(sumIs - sumShouldBe); Assert.IsTrue(diff < 0.0000001, $"Sum Diff should be 0, but is {diff}"); }