Initial main skeleton with a single example
[platform/upstream/SSAT.git] / ssat.sh
1 #!/usr/bin/env bash
2 ##
3 # @file ssat.sh
4 # @author MyungJoo Ham <myungjoo.ham@gmail.com>
5 # @date Jun 22 2018
6 # @license Apache-2.0
7 # @brief This executes test groups and reports aggregated test results.
8 # @exit 0 if all PASSED. Positive if some FAILED.
9 #
10 # If there is no arguments specified, this will search for all "runTest.sh" in
11 # the subdirectory of this file and regard them as the test groups.
12 #
13 # If --help or -h is given, this will show detailed description.
14
15 TARGET=$(pwd)
16 BASEPATH=`dirname "$0"`
17 BASENAME=`basename "$0"`
18 TESTCASE="runTest.sh"
19 source ${BASEPATH}/ssat-api.sh
20
21 #
22 DOTEST=1
23 SILENT=1
24
25 # Handle arguments
26 POSITIONAL=()
27 while [[ $# -gt 0 ]]
28 do
29         key="$1"
30         case $key in
31         -h|--help)
32                 printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>]\n\n"
33                 printf "These are common ${Red}ssat${NC} commands used:\n\n"
34                 printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
35                 printf "    (no options specified)\n"
36                 printf "    $ ${BASENAME}\n"
37                 printf "\n"
38                 printf "Test all test-groups in the specified directory, recursively\n"
39                 printf "    <path>\n"
40                 printf "    $ ${BASENAME} /home/username/test\n"
41                 printf "    If there are multiple paths, the last one will be used\n"
42                 printf "\n"
43                 printf "Search for \"filename\" as the testcase scripts\n"
44                 printf "    --testcase or -t\n"
45                 printf "    $ ${BASENAME} --testcase cases.sh\n"
46                 printf "    Search for cases.sh instead of runTest.sh\n"
47                 printf "\n"
48                 printf "Shows this message\n"
49                 printf "    --help or -h\n"
50                 printf "    $ ${BASENAME} --help \n"
51                 printf "\n\n"
52                 exit 0
53         ;;
54         -t|--testcase)
55         TESTCASE="$2"
56         shift
57         shift
58         ;;
59         *) # Unknown, which is probably target (the path to root-dir of test groups).
60         TARGET="$1"
61         esac
62 done
63
64 if [[ ${#TARGET} -eq 0 ]]
65 then
66         TARGET="."
67 fi
68
69 find $TARGET -name $TESTCASE -print0 | while read -d $'\0' file
70 do
71         CASEBASEPATH=`dirname "$file"`
72         pushd $CASEBASEPATH
73         source $file
74         popd
75 done
76                 
77
78 # gather reports & publish them.