libusbgx: tests: Add options parsing to running script
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:44:45 +0000 (21:44 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:44:45 +0000 (21:44 +0100)
Change-Id: I1658663e8b7f14b5595ef806c5fca03ae10c830d
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
tests/test.sh [new file with mode: 0755]

diff --git a/tests/test.sh b/tests/test.sh
new file mode 100755 (executable)
index 0000000..1385f23
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+USE_CONFIG=0
+GENERATE_CONFIG=0
+HELP=0
+
+function usage {
+       echo "libusbgx test suit"
+       echo "Usage:    ./test.sh [option]"
+       echo "Options:"
+       echo "  --generate-config filename - generates config to given file and exit"
+       echo "  --use-config filename - runs test suit using config from given file"
+       echo "  -h --help - print this message"
+}
+
+# Parse arguments
+
+ARGS=$(getopt --long generate-config:,use-config:,help -o h -- "$@" )
+
+if [ $? -ne 0 ]
+then
+       HELP=1
+fi
+
+eval set -- $ARGS
+
+while true; do
+       case $1 in
+               -h|--help)
+                       HELP=1
+                       shift
+                       ;;
+               --use-config)
+                       USE_CONFIG=1
+                       CONFIG_FILE=$2
+                       shift 2
+                       ;;
+               --generate-config)
+                       GENERATE_CONFIG=1
+                       CONFIG_FILE=$2
+                       shift 2
+                       ;;
+               --)
+                       shift
+                       break
+                       ;;
+               *)
+                       HELP=1
+                       shift
+                       ;;
+       esac
+done
+
+# Run test with io functions ovverride
+
+if [ $USE_CONFIG -ne 0 ]
+then
+       LD_LIBRARY_PATH=. LD_PRELOAD=./usbg-io-wrappers.so ./test --use-config < $CONFIG_FILE
+elif [ $GENERATE_CONFIG -ne 0 ]
+then
+       LD_LIBRARY_PATH=. LD_PRELOAD=./usbg-io-wrappers.so ./test --generate-config > $CONFIG_FILE
+elif [ $HELP -ne 0 ]
+then
+       usage
+else
+       LD_LIBRARY_PATH=. LD_PRELOAD=./usbg-io-wrappers.so ./test
+fi
+