-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e455e0
commit 4f4b952
Showing
4 changed files
with
195 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import argparse | ||
import os | ||
from signal import SIGINT | ||
import subprocess | ||
import sys | ||
import time | ||
|
||
# Specify the directory for the binaries | ||
DIR_EXAMPLES = "build/examples" | ||
|
||
|
||
def pub_and_sub(): | ||
print("*** Pub & sub test ***") | ||
test_status = 0 | ||
|
||
# Expected z_pub output & status | ||
z_pub_expected_status = 0 | ||
z_pub_expected_output = '''Opening session... | ||
Declaring publisher for 'demo/example/zenoh-pico-pub'... | ||
Press CTRL-C to quit... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 0] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 1] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 2] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 3] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 4] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 5] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 6] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 7] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 8] Pub from Pico!')... | ||
Putting Data ('demo/example/zenoh-pico-pub': '[ 9] Pub from Pico!')...''' | ||
|
||
# Expected z_sub output & status | ||
z_sub_expected_status = 0 | ||
z_sub_expected_output = '''Opening session... | ||
Declaring Subscriber on 'demo/example/**'... | ||
Press CTRL-C to quit... | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 0] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 0 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 1] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 1 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 2] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 2 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 3] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 3 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 4] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 4 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 5] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 5 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 6] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 6 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 7] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 7 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 8] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 8 | ||
>> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 9] Pub from Pico!') | ||
with attachment: | ||
0: source, C | ||
1: index, 9''' | ||
|
||
print("Start subscriber") | ||
# Start z_sub in the background | ||
z_sub_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_sub_attachment -n 10" | ||
|
||
z_sub_process = subprocess.Popen( | ||
z_sub_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True | ||
) | ||
|
||
# Introduce a delay to ensure z_sub starts | ||
time.sleep(2) | ||
|
||
print("Start publisher") | ||
# Start z_pub | ||
z_pub_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_pub_attachment -n 10" | ||
z_pub_process = subprocess.Popen( | ||
z_pub_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True | ||
) | ||
|
||
# Wait for z_pub to finish | ||
z_pub_process.wait() | ||
|
||
print("Stop subscriber") | ||
time.sleep(2) | ||
if z_sub_process.poll() is None: | ||
# send SIGINT to group | ||
z_sub_process_gid = os.getpgid(z_sub_process.pid) | ||
os.killpg(z_sub_process_gid, SIGINT) | ||
|
||
# Wait for z_sub to finish | ||
z_sub_process.wait() | ||
|
||
print("Check publisher status & output") | ||
# Check the exit status of z_pub | ||
z_pub_status = z_pub_process.returncode | ||
if z_pub_status == z_pub_expected_status: | ||
print("z_pub status valid") | ||
else: | ||
print(f"z_pub status invalid, expected: {z_pub_expected_status}, received: {z_pub_status}") | ||
test_status = 1 | ||
|
||
# Check output of z_pub | ||
z_pub_output = z_pub_process.stdout.read() | ||
if z_pub_expected_output in z_pub_output: | ||
print("z_pub output valid") | ||
else: | ||
print("z_pub output invalid:") | ||
print(f"Expected: \"{z_pub_expected_output}\"") | ||
print(f"Received: \"{z_pub_output}\"") | ||
test_status = 1 | ||
|
||
print("Check subscriber status & output") | ||
# Check the exit status of z_sub | ||
z_sub_status = z_sub_process.returncode | ||
if z_sub_status == z_sub_expected_status: | ||
print("z_sub status valid") | ||
else: | ||
print(f"z_sub status invalid, expected: {z_sub_expected_status}, received: {z_sub_status}") | ||
test_status = 1 | ||
|
||
# Check output of z_sub | ||
z_sub_output = z_sub_process.stdout.read() | ||
if z_sub_expected_output in z_sub_output: | ||
print("z_sub output valid") | ||
else: | ||
print("z_sub output invalid:") | ||
print(f"Expected: \"{z_sub_expected_output}\"") | ||
print(f"Received: \"{z_sub_output}\"") | ||
test_status = 1 | ||
# Return value | ||
return test_status | ||
|
||
|
||
if __name__ == "__main__": | ||
EXIT_STATUS = 0 | ||
|
||
# Test pub and sub examples | ||
if pub_and_sub() == 1: | ||
EXIT_STATUS = 1 | ||
# Exit | ||
sys.exit(EXIT_STATUS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters