Skip to content

Commit

Permalink
Everything working
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm committed Mar 31, 2023
1 parent bdc6508 commit 0528151
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
16 changes: 8 additions & 8 deletions fastddsspy_tool/test/application/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,44 +104,44 @@ def main():
spy, dds = test_function.run()

if (spy == 'wrong output'):
print("ERROR: Wrong output")
print('ERROR: Wrong output')
sys.exit(1)

if (test_function.dds):
if test_function.is_stop(dds):
print("ERROR: DDS Publisher not running")
print('ERROR: DDS Publisher not running')
sys.exit(1)

if not test_function.one_shot:
if test_function.is_stop(spy):
print("ERROR: Fast DDS Spy not running")
print('ERROR: Fast DDS Spy not running')
sys.exit(1)

output = test_function.send_command_tool(spy)

if not test_function.valid_output(output):
print("ERROR: Output command not valid")
print('ERROR: Output command not valid')
sys.exit(1)

test_function.stop_tool(spy)

if not test_function.is_stop(spy):
print("ERROR: Fast DDS Spy still running")
print('ERROR: Fast DDS Spy still running')
sys.exit(1)

if not test_function.valid_returncode(spy.returncode):
print("ERROR: Wrong Fast DDS Spy return code")
print('ERROR: Wrong Fast DDS Spy return code')
sys.exit(1)

if (test_function.dds):
test_function.stop_dds(dds)

if not test_function.is_stop(dds):
print("ERROR: DDS Publisher still running")
print('ERROR: DDS Publisher still running')
sys.exit(1)

if not test_function.valid_returncode(dds.returncode):
print("ERROR: Wrong DDS Publisher return code")
print('ERROR: Wrong DDS Publisher return code')
sys.exit(1)

return 0
Expand Down
34 changes: 20 additions & 14 deletions fastddsspy_tool/test/application/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import subprocess
import signal
import re
import time

DESCRIPTION = """Script to execute Fast DDS Spy executable test"""
USAGE = ('python3 tests.py -e <path/to/fastddsspy-executable>'
Expand Down Expand Up @@ -77,7 +78,8 @@ def run_tool(self):
proc = subprocess.Popen(self.command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
encoding='utf8')

if (self.one_shot):

Expand All @@ -86,8 +88,7 @@ def run_tool(self):
except subprocess.TimeoutExpired:
proc.kill()
output = proc.communicate()[0]

if not self.valid_output(output.decode('utf-8')):
if not self.valid_output(output):
return ('wrong output')

else:
Expand All @@ -104,22 +105,23 @@ def is_stop(self, proc):
def read_output(self, proc):
output = ''
while True:
line = proc.stdout.readline().decode('utf-8')
line = proc.stdout.readline()
if ('Insert a command for Fast DDS Spy:' in line):
break
output = output + f'{line}\n'

return output

def send_command_tool(self, proc):
proc.stdin.write((self.arguments + '\n').encode('utf-8'))
# give time to start publishing
time.sleep(0.5)
proc.stdin.write((self.arguments+'\n'))
proc.stdin.flush()
output = self.read_output(proc)
return (output)

def stop_tool(self, proc):
try:
proc.communicate(input=b'exit\n', timeout=5)
proc.communicate(input='exit\n', timeout=5)[0]
except subprocess.TimeoutExpired:
proc.kill()
proc.communicate()
Expand All @@ -134,7 +136,6 @@ def run_dds(self):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

return proc

def stop_dds(self, proc):
Expand All @@ -154,27 +155,32 @@ def output_command(self):

def valid_guid(self, guid):
pattern = r'^((guid:)\s([0-9a-f]{2}\.){11}[0-9a-f]{2}\|([0-9a-f]\.){3}[0-9a-f]{1,})$'
id_guid = guid[2:]
id_guid = guid[guid.find("guid:"):]
if not re.match(pattern, id_guid):
return False
return True

def valid_rate(self, rate):
pattern = r'^((rate:)\s\d{1,}\s(Hz))$'
id_rate = rate[2:]
id_rate = rate[rate.find("rate:"):]
if not re.match(pattern, id_rate):
return False
return True

def valid_output(self, output):
expected_output = self.output_command()
lines_expected_output = expected_output.splitlines()
lines_output = output.splitlines()
if expected_output == output:
return True
guid = True
rate = True
for i in range(len(lines_expected_output)):
if 'guid:' in lines_expected_output[i]:
return self.valid_guid(lines_expected_output[i])
if 'rate:' in lines_expected_output[i]:
return self.valid_rate(lines_expected_output[i])
guid = self.valid_guid(lines_expected_output[i])
elif 'rate:' in lines_expected_output[i]:
rate = self.valid_rate(lines_expected_output[i])
elif lines_expected_output[i] != lines_output[i]:
return False

return False
return (guid and rate)
5 changes: 3 additions & 2 deletions fastddsspy_tool/test/application/tool_datawriter_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def __init__(self):
command=[],
dds=True,
arguments='datawriter',
output=""">> \x1b[0m
output=""">> \x1b[0m- guid: 01.0f.d8.74.51.14.0a.a3.00.00.00.00|0.0.1.3
participant: Participant_pub
topic: HelloWorldTopic [HelloWorld]
"""
)
5 changes: 2 additions & 3 deletions fastddsspy_tool/test/application/tool_participants_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def __init__(self):
command=[],
dds=True,
arguments='participants',
output=""">> \x1b[0m
output=""">> \x1b[0m- name: Participant_pub
guid: 01.0f.d8.74.09.0b.fa.ae.00.00.00.00|0.0.1.c1
"""
)
4 changes: 2 additions & 2 deletions fastddsspy_tool/test/application/tool_show_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self):
one_shot=False,
command=[],
dds=True,
arguments='show topic',
output=""">> \x1b[0m\x1b[1;31mTopic <topic> does not exist.\x1b[0m
arguments='show HelloWorldTopic',
output=""">> \x1b[0m\x1b[1;31mTopic Type <HelloWorld> has not been discovered, and thus cannot print its data.\x1b[0m
Expand Down
7 changes: 6 additions & 1 deletion fastddsspy_tool/test/application/tool_topics_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ def __init__(self):
command=[],
dds=True,
arguments='topics',
output=""">> \x1b[0m
output=""">> \x1b[0m- name: HelloWorldTopic
type: HelloWorld
datawriters: 1
datareaders: 0
rate: 10 Hz
"""
)

0 comments on commit 0528151

Please sign in to comment.