From 6178b488430ef900b56f3d5c1c9e5d92c0235c4f Mon Sep 17 00:00:00 2001 From: gpotter2 Date: Sat, 13 May 2017 13:13:37 +0200 Subject: [PATCH] Added high push tests + drainers --- scapy/pipetool.py | 7 ++-- test/pipetool.uts | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/scapy/pipetool.py b/scapy/pipetool.py index 56c0de75f..903c88577 100644 --- a/scapy/pipetool.py +++ b/scapy/pipetool.py @@ -316,6 +316,8 @@ class Source(Pipe): self._send(msg) def fileno(self): return None + def checkRecv(self): + return False def exhausted(self): return self.is_exhausted def start(self): @@ -418,14 +420,15 @@ class RawConsoleSink(Sink): def __init__(self, name=None, newlines=True): Sink.__init__(self, name=name) self.newlines = newlines + self._write_pipe = 1 def push(self, msg): if self.newlines: msg += "\n" - os.write(1, str(msg)) + os.write(self._write_pipe, str(msg)) def high_push(self, msg): if self.newlines: msg += "\n" - os.write(1, str(msg)) + os.write(self._write_pipe, str(msg)) class CLIFeeder(AutoSource): """Send messages from python command line diff --git a/test/pipetool.uts b/test/pipetool.uts index 7b25042b9..5b0a7103b 100644 --- a/test/pipetool.uts +++ b/test/pipetool.uts @@ -126,3 +126,94 @@ s = AutoSource() p = PipeEngine(s) p.list_pipes() p.list_pipes_detailed() + += Test RawConsoleSink with CLIFeeder + +p = PipeEngine() +p.start() + +s = CLIFeeder() +s.send("hello") +s.is_exhausted = True + +r, w = os.pipe() + +d1 = Drain(name="d1") +c = RawConsoleSink(name="c") +c._write_pipe = w +s > d1 > c + +p.add(s) +time.sleep(1) +p.wait_and_stop() +assert os.read(r, 20) == "hello\n" + += Test QueueSink with CLIFeeder + +p = PipeEngine() +p.start() + +s = CLIFeeder() +s.send("hello") +s.is_exhausted = True + +d1 = Drain(name="d1") +c = QueueSink(name="c") +s > d1 > c + +p.add(s) +time.sleep(1) +p.wait_and_stop() +assert c.recv() == "hello" + += Test UpDrain + +test_val = None + +class TestSink(Sink): + def high_push(self, msg): + global test_val + test_val = msg + +p = PipeEngine() +p.start() + +s = CLIFeeder() +s.send("hello") +s.is_exhausted = True + +d1 = UpDrain(name="d1") +c = TestSink(name="c") +s > d1 +d1 >> c + +p.add(s) +time.sleep(1) +p.wait_and_stop() +assert test_val == "hello" + += Test DownDrain + +test_val = None + +class TestSink(Sink): + def push(self, msg): + global test_val + test_val = msg + +p = PipeEngine() +p.start() + +s = CLIHighFeeder() +s.send("hello") +s.is_exhausted = True + +d1 = DownDrain(name="d1") +c = TestSink(name="c") +s >> d1 +d1 > c + +p.add(s) +time.sleep(1) +p.wait_and_stop() +assert test_val == "hello"