From c38aca268244d3c7004d6987a63d5756df148209 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 15 Dec 2016 14:49:38 +0100 Subject: Add tests for ratox, importing z3bra's tests. Add a target check for the makefile for running the tests. --- Makefile | 6 ++++++ tests/README | 15 ++++++++++++++ tests/common | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/test-chat | 9 ++++++++ tests/test-file | 9 ++++++++ tests/test-request | 8 +++++++ 6 files changed, 108 insertions(+) create mode 100644 tests/README create mode 100644 tests/common create mode 100755 tests/test-chat create mode 100755 tests/test-file create mode 100755 tests/test-request diff --git a/Makefile b/Makefile index 75fb613..ffd8af2 100644 --- a/Makefile +++ b/Makefile @@ -62,3 +62,9 @@ uninstall: clean: @echo cleaning @rm -f $(BIN) $(OBJ) $(LIB) util.a + +check: all + @echo testing + @cd tests; sh test-chat && sh test-file && sh test-request + +.PHONY: all binlib bin install uninstall clean check diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..e491c53 --- /dev/null +++ b/tests/README @@ -0,0 +1,15 @@ +ratox[0] text suite. + +0. move this folder in the ratox source dir +1. build ratox +2. run your tests + +WARNING: spawing a test creates two throw-away IDs, and opens two +connections by default. If starting too much test, it could make it to +the point your router might not be able to forward traffic correctly to +the DHT, rendering your users incapable of seeing each others online. + +In case it happens, simply wait for the stale connections to close +themselves, or reboot your computer. + +[0] http://git.z3bra.org/ratox/log.html diff --git a/tests/common b/tests/common new file mode 100644 index 0000000..462677d --- /dev/null +++ b/tests/common @@ -0,0 +1,61 @@ +BIN="$(cd ..; pwd)/ratox" +test -x $BIN || exit 1 + +echolor() { + printf '[1;3%dm%s\n' "$1" "$2" +} + +cleanup() { + echo ":: cleaning" + kill $(pgrep -f 'abduco -n test-u1') + kill $(pgrep -f 'abduco -n test-u2') + rm -rf u1 u2 +} + +trap cleanup INT + +spawn_users() { + for u in u1 u2; do + echo ":: creating user $u" + mkdir -p $u + abduco -n test-$u sh -c "cd $u;$BIN 2>&1|tee LOG" + done + sleep 1 +} + +add_friends() { + echo ":: send u2 a friend request from u1" + id1=$(cut -b-64 < u1/id) + id2=$(cut -b-64 < u2/id) + cat u2/id > u1/request/in + while [ ! -p u2/request/out/$id1 ]; do sleep 1; done + echo ":: accepting request from $id1" + echo 1 > u2/request/out/$id1 + while [ ! -d u2/$id1 ]; do sleep 1; done + echo ":: u1: waiting for u2 to come online" + while [ $(cat u1/$id2/online) -eq 0 ]; do sleep 1; done +} + +send_text() { + RND=$(tr -cd 'A-F0-9' u1/$id2/text_in + while ! grep -q "$RND" u2/$id1/text_out; do sleep 1; done +} + +send_file() { + TMP1=$(mktemp) + TMP2=$(mktemp) + /dev/null + id1=$(cut -b-64 < u1/id) + id2=$(cut -b-64 < u2/id) + echo ":: u1: sending file $TMP1" + cat $TMP1 > u1/$id2/file_in & + while [ $(wc -c $TMP2 + echo ":: verifying $TMP1 and $TMP2" + sha1sum $TMP1 | sed "s,$TMP1,$TMP2," | sha1sum -c +} diff --git a/tests/test-chat b/tests/test-chat new file mode 100755 index 0000000..97bc838 --- /dev/null +++ b/tests/test-chat @@ -0,0 +1,9 @@ +. ./common + +spawn_users +add_friends +send_text +echo :: $(basename $0) - $(echolor 2 OK) + +cleanup +exit 0 diff --git a/tests/test-file b/tests/test-file new file mode 100755 index 0000000..2499aa6 --- /dev/null +++ b/tests/test-file @@ -0,0 +1,9 @@ +. ./common + +spawn_users +add_friends +send_file +echo :: $(basename $0) - $(echolor 2 OK) + +cleanup +exit 0 diff --git a/tests/test-request b/tests/test-request new file mode 100755 index 0000000..63b9312 --- /dev/null +++ b/tests/test-request @@ -0,0 +1,8 @@ +. ./common + +spawn_users +add_friends +echo :: $(basename $0) - $(echolor 2 OK) + +cleanup +exit 0 -- cgit v1.2.3