Last active
October 16, 2019 14:56
-
-
Save pokgak/5505076d74f923405a60731ad5873eb5 to your computer and use it in GitHub Desktop.
Python script using pexpect to test tinydtls client and server in RIOT using examples/dtls-echo example application. There are still lots of hardcoded variables used.
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
#!/bin/bash | |
# specify paths to tinydtls and RIOT repo | |
TINYDTLS_REPO=~/git/tinydtls | |
RIOT_REPO=~/git/RIOT-OS/RIOT | |
# get all commits FROM tinydtls repo since last known good commit | |
cd $TINYDTLS_REPO | |
git checkout develop &> /dev/null | |
hashes=$(git rev-list --reverse dcac93f1b38e74f0a57b5df47647943f3df005c2^1..HEAD) | |
cd $RIOT_REPO/examples/dtls-echo | |
for hash in $hashes | |
do | |
sed -i "s/PKG_VERSION=.*/PKG_VERSION=$hash/" ../../pkg/tinydtls/Makefile | |
./test-send.py &> /dev/null | |
echo $hash $? | |
done |
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
#!/usr/bin/env python3 | |
import sys | |
import os | |
import pexpect | |
import time | |
import signal | |
serverIP = "fe80::20c3:beff:fe9b:5772" | |
env = os.environ | |
# build | |
pexpect.run("make", env=env) | |
# server setup | |
env = os.environ | |
env.update({"PORT": "tap0"}) | |
server_logfile = open("server.log", "w") | |
server = pexpect.spawnu('make term', | |
env=env, | |
codec_errors='replace', | |
echo=False, timeout=10, | |
logfile=server_logfile | |
) | |
# client setup | |
env = os.environ | |
env.update({"PORT": "tap1"}) | |
client_logfile = open("client.log", "w") | |
client = pexpect.spawnu('make term', | |
env=env, | |
codec_errors='replace', | |
echo=False, timeout=10, | |
logfile=client_logfile | |
) | |
time.sleep(1) | |
# start dtls server | |
server.sendline("dtlss start") | |
# send dtls packet from client | |
client.sendline("dtlsc " + serverIP + " TEST") | |
time.sleep(3) | |
client.expect("Client: got DTLS Data App") | |
server.expect("Server: got DTLS Data App") | |
time.sleep(1) | |
try: | |
os.killpg(os.getpgid(server.pid), signal.SIGKILL) | |
os.killpg(os.getpgid(client.pid), signal.SIGKILL) | |
except ProcessLookupError: | |
print("Process already stopped") | |
server.close() | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment