summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/autobahn/autobahn-server.sh61
1 files changed, 54 insertions, 7 deletions
diff --git a/tests/autobahn/autobahn-server.sh b/tests/autobahn/autobahn-server.sh
index b634a767..9596e72b 100755
--- a/tests/autobahn/autobahn-server.sh
+++ b/tests/autobahn/autobahn-server.sh
@@ -1,4 +1,6 @@
-#!/bin/sh
+#!/usr/bin/env bash
+
+# set -x
REPORTS_DIR="${PWD}/reports"
@@ -6,9 +8,54 @@ cd "$(dirname "$0")"
[ ! -d "${REPORTS_DIR}" ] && mkdir "${REPORTS_DIR}"
-docker run -it --rm \
- -v "${PWD}:/config" \
- -v "${REPORTS_DIR}:/reports" \
- -p 9001:9001 \
- --name fuzzingserver \
- crossbario/autobahn-testsuite
+ACTION=${1:---start}
+PORT=${2:-9001}
+
+autobahn_pid() {
+ echo $(lsof -i:$PORT | tail -1 | awk '{ print $2 }')
+}
+
+ensure_autobahn_is_not_running() {
+ local pid=$(autobahn_pid)
+ if [[ $pid -gt 0 ]]; then
+ autobahn_stop
+ pid=$(autobahn_pid)
+ if [[ $pid -gt 0 ]]; then
+ echo "Cannot start autobahn server: $PORT already in use"
+ exit 1
+ fi
+ fi
+}
+
+autobahn_start() {
+ ensure_autobahn_is_not_running
+
+ if [[ -n "${USE_DOCKER}" ]]; then
+ docker run -it --rm \
+ -v "${PWD}:/config" \
+ -v "${REPORTS_DIR}:/reports" \
+ -p $PORT:$PORT \
+ --name fuzzingserver \
+ crossbario/autobahn-testsuite
+ else
+ virtualenv ~/wstest
+ wstest -m fuzzingserver &> autobahn-server.log
+ fi
+}
+
+autobahn_stop() {
+ local pid=$(autobahn_pid)
+ kill $pid &> /dev/null
+}
+
+case "$ACTION" in
+ "--start")
+ autobahn_start
+ ;;
+ "--stop")
+ autobahn_stop
+ ;;
+ *)
+ echo "Unknown argument: $ACTION"
+ exit 1
+esac