enowars5-service-stldoctor

STL-Analyzing A/D Service for ENOWARS5 in 2021
git clone https://git.sinitax.com/sinitax/enowars5-service-stldoctor
Log | Files | Refs | README | LICENSE | sfeed.txt

test.sh (2123B)


      1#!/bin/sh
      2
      3set -e
      4
      5if [ -z "$SRCDIR" -o -z "$DATADIR" ]; then
      6	echo "Missing either SRCDIR or DATADIR env vars"
      7	exit 1
      8fi
      9
     10export RESULTDIR="$DATADIR/uploads"
     11export ECHO_INPUT=1
     12
     13SCRIPTPATH="$(dirname $(readlink -f "$0"))"
     14TESTDATA="$SCRIPTPATH/data"
     15
     16shopt -s expand_aliases
     17alias pushd="pushd &>/dev/null"
     18alias popd="popd &>/dev/null"
     19
     20pushd "$SRCDIR"
     21
     22announce() {
     23	count=$(echo "$1" | wc -c)
     24	python3 -c "
     25import math
     26s = '$1'
     27c = 80
     28print()
     29print('#'*c)
     30print('#' + ' '*math.floor((c - len(s))/2-1) + s + ' '*math.ceil((c - len(s))/2-1) + '#')
     31print('#'*c)
     32print()
     33	"
     34}
     35
     36checkleaks() {
     37	valgrind --leak-check=full --show-leak-kinds=all ./build/stldoctor 2>&1 | tee /tmp/testlog
     38	if [ -z "$(grep "no leaks are possible" /tmp/testlog)" ]; then
     39		echo "Valgrind exited with errors!"
     40		exit 1
     41	fi
     42}
     43
     44connect() {
     45	if [ "$RUNTYPE" == "remote" ]; then
     46		nc localhost 9090
     47	elif [ "$RUNTYPE" == "debug" ]; then
     48		checkleaks
     49	else
     50		./build/stldoctor
     51	fi
     52}
     53
     54cleanuploads() {
     55	[ ! -z "$RESULTDIR" ] && rm -rf "$RESULTDIR"
     56	mkdir -p "$RESULTDIR"
     57}
     58
     59[ ! -z "$CLEAN" ] && cleanuploads
     60
     61if [ "$1" == "stl-leaks" ]; then
     62	announce "Testing ASCII STL Parsing"
     63	(
     64		echo "echo"
     65		echo "upload"
     66		echo "ASCII-testname"
     67		cat "$TESTDATA/sample-ascii.stl" | wc -c
     68		cat "$TESTDATA/sample-ascii.stl"
     69	) | checkleaks
     70
     71	announce "Testing BIN STL Parsing"
     72	(
     73		echo "echo"
     74		echo "upload"
     75		echo "BIN-testname"
     76		cat "$TESTDATA/sample-binary.stl" | wc -c
     77		cat "$TESTDATA/sample-binary.stl"
     78	) | checkleaks
     79
     80elif [ "$1" == "stl-upload" ]; then
     81	popd
     82	file="$(realpath $2)"
     83	if [ ! -e "$file" ]; then
     84		echo "Supply a file to upload"
     85		exit 1
     86	fi
     87	pushd "$SRCDIR"
     88
     89	name="${3:-samplefile}"
     90	(
     91		echo "echo"
     92		[ ! -z "$AUTH" ] && echo "auth $AUTH"
     93		echo "upload"
     94		echo "$name"
     95		cat "$file" | wc -c
     96		cat "$file"
     97	) | connect
     98
     99elif [ "$1" == "auth-upload" ]; then
    100	(
    101		echo "echo"
    102
    103		echo "auth test"
    104		echo "upload"
    105		echo "testname"
    106		cat "$TESTDATA/sample-ascii.stl" | wc -c
    107		cat "$TESTDATA/sample-ascii.stl"
    108	) | connect
    109
    110	(
    111		echo "echo"
    112
    113		echo "auth test"
    114		echo "list"
    115		echo "search testname"
    116	) | connect
    117else
    118	connect
    119fi
    120
    121popd