-
-
Save miri64/fac4df86be36f0a65d9bdb4d2f09d5c7 to your computer and use it in GitHub Desktop.
WIP test scripts for RIOT release specs 3.4
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 | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2019 Martine Lenders <m.lenders@fu-berlin.de> | |
# | |
# Distributed under terms of the MIT license. | |
import os | |
import pexpect | |
import signal | |
import sys | |
import time | |
if __name__ == "__main__": | |
childs = [] | |
try: | |
for i in range(11): | |
env = os.environ.copy() | |
env["PORT"] = "tap{}".format(i) | |
childs.append(pexpect.spawnu("make term", env=env, | |
codec_errors='replace', | |
timeout=1000 if i > 0 else 3)) | |
childs[-1].logfile = sys.stdout | |
time.sleep(3) | |
childs[0].sendline("ifconfig") | |
childs[0].expect(r"inet6 addr: ([0-9a-f:]+) scope: local VAL") | |
child0_addr = childs[0].match.group(1) | |
for i in range(1, 11): | |
childs[i].sendline("ping6 1000 {} 1452 0".format(child0_addr)) | |
for i in range(1, 11): | |
childs[i].expect(r"--- [0-9a-f:]+ ping statistics ---") | |
childs[i].expect(r"1000 packets transmitted, \d+ received, \d+% packet loss, time \d+.\d+ s") | |
childs[0].sendline("pktbuf") | |
childs[0].expect(r"packet buffer: first byte: 0x([0-9a-f]+), last byte: 0x5668c580 \(size: (\d+)\)") | |
first = childs[0].match.group(1) | |
size = childs[0].match.group(2) | |
childs[0].expect(r"~ unused: 0x{:x} \(next: \(nil\), size: {}\) ~".format(first, size)) | |
finally: | |
for child in childs: | |
child.close() | |
child.terminate() | |
try: | |
os.killpg(os.getpgid(child.pid), signal.SIGKILL) | |
except ProcessLookupError: | |
print("Process already stopped") | |
time.sleep(3) |
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/sh | |
# | |
# 01-test.sh | |
# Copyright (C) 2019 Martine Lenders <m.lenders@fu-berlin.de> | |
# | |
# Distributed under terms of the MIT license. | |
# | |
TMUX_SESSION="test-4-3-$(date +%s)" | |
TEMP_DIR=$(mktemp -d "test-4-3.XXXXXXXXXX") | |
PING_COUNT=1000 | |
sendline() { | |
TAP="$1" | |
LINE="$2" | |
tmux send-keys -t "${TMUX_SESSION}:${TAP}" "${LINE}" Enter | |
} | |
expect() { | |
TAP="$1" | |
PATTERN="$2" | |
TIMEOUT="$3" | |
if [ -z "${TIMEOUT}" ]; then | |
TIMEOUT=3s | |
fi | |
RES=$(timeout ${TIMEOUT} tail -f -n 3000 ${TEMP_DIR}/${TAP}.out | \ | |
grep -oPe "${PATTERN}" || \ | |
echo "Pattern \"${PATTERN}\" not found on ${TAP}" 1>&2) | |
if [ -z "$RES" ]; then | |
exit 1 | |
fi | |
echo "$RES" | |
} | |
clean() { | |
tmux kill-session -t ${TMUX_SESSION} | |
} | |
trap clean INT TERM KILL EXIT | |
for i in $(seq 0 10); do | |
TAP="tap$i" | |
if tmux ls 2> /dev/null | grep -q "${TMUX_SESSION}"; then | |
tmux new-window -t "${TMUX_SESSION}" -n "${TAP}" | |
else | |
tmux new-session -d -s "${TMUX_SESSION}" -n "${TAP}" | |
fi | |
tmux send-keys -t "${TMUX_SESSION}:${TAP}" "cd '${PWD}'" Enter | |
tmux send-keys -t "${TMUX_SESSION}:${TAP}" "PORT=${TAP} make term | tee ${TEMP_DIR}/${TAP}.out" Enter | |
done | |
echo "tmux session '${TMUX_SESSION}' started." | |
echo "Output of all terminals is tracked in ${TEMP_DIR}" | |
sleep 5 | |
sendline tap0 ifconfig | |
RES=$(expect tap0 "inet6 addr: [0-9a-f:]+ scope: local") | |
TAP0_ADDR=$(echo ${RES} | sed 's/inet6 addr: \([0-9a-f:]\+\).*$/\1/') | |
for i in $(seq 1 10); do | |
TAP="tap$i" | |
sendline ${TAP} "ping6 ${PING_COUNT} ${TAP0_ADDR} 1452 0" | |
done | |
for i in $(seq 1 10); do | |
TAP="tap$i" | |
expect ${TAP} "--- [0-9a-f:]+ ping statistics ---" ${PING_COUNT}s | |
done | |
sendline tap0 "pktbuf" | |
expect tap0 "next: \(nil\), size: 6144" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment