Merge branch 'main' of feistymeow.org:feisty_meow
[feisty_meow.git] / testkit / test_driver.sh
1 #!/bin/bash
2
3 # This script runs through all the known tests by performing a test sweep.
4 # It should claim that all tests succeeded for a new build/configuration/etc.
5 # to be considered successful.
6 #
7 # The way to add tests to the full test set is to add full paths to the
8 # "TESTKIT_TEST_SUITE" variable.  This can be done in your personal
9 # testkit.config file or in an exported variable set prior to running
10 # this script.
11 #
12 # Author: Chris Koeritz
13
14 export TESTKIT_DIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
15 cd $TESTKIT_DIR
16
17 TIME_START="$(date +"%s")"
18
19 source prepare_tools.sh prepare_tools.sh
20
21 # if that didn't work, complain.
22 if [ -z "$TESTKIT_SENTINEL" ]; then echo Please run prepare_tools.sh before testing.; exit 3; fi
23 source "$TESTKIT_ROOT/library/establish_environment.sh"
24
25 verbosity="$1"; shift
26
27 VERBOSE=1
28
29 if [ "$verbosity" == "--help" -o "$verbosity" == "-help" -o "$verbosity" == "-h" ]; then
30   echo "$(basename $0): Runs the available suite of tests."
31   echo
32   echo "   $(basename $0) {summary | [full]}"
33   echo
34   echo "By default, the report will be a 'full' listing that includes all test"
35   echo "run logging.  If 'summary' is passed as the first parameter, then only"
36   echo "the test results will be displayed."
37   exit 0
38 fi
39
40 if [ "$verbosity" == "summary" ]; then
41   VERBOSE=0
42 fi
43
44 ##############
45
46 # clean up any conglomerated log file.
47 \rm -f "$CONGLOMERATED_TESTKIT_OUTPUT"
48
49 ##############
50
51 # define the sets of tests we'd like to run.
52
53 NETBADGE_TESTS=( \
54   netbadge_integrations/basic_integrations_test.sh \
55 )
56
57 ##############
58
59 if [ ! -z "$AUTOBUILD_RUNNING" ]; then
60   # only add some tests for automated, testing, bootstrap builds based on their needs.
61
62 true  # placeholder
63
64 fi
65
66 ##############
67
68 # now that all tests have been defined, we build up our total list of tests.
69
70 echo Full set of tests:
71 for ((test_iter=0; $test_iter < ${#TESTKIT_TEST_SUITE[*]}; test_iter++)); do
72   echo "$(expr $test_iter + 1): ${TESTKIT_TEST_SUITE[$test_iter]}"
73 done
74
75 ##############
76
77 FAIL_COUNT=0
78
79 REG_TEMP="$TEST_TEMP/run_$(date +"%Y_%m_%d")"
80 if [ ! -d "$REG_TEMP" ]; then
81   mkdir "$REG_TEMP"
82 fi
83
84 # go to the top of the hierarchy.
85 cd "$TESTKIT_ROOT"
86
87 for ((test_iter=0; $test_iter < ${#TESTKIT_TEST_SUITE[*]}; test_iter++)); do
88   echo -e "\n======================================================================"
89   echo -n `date`": " 
90   echo "Now running test $(expr $test_iter + 1): ${TESTKIT_TEST_SUITE[$test_iter]}"
91   output_file="$(mktemp $REG_TEMP/test_log.XXXXXX)"
92   echo "  Test output file: $output_file"
93
94 #
95 #hmmm: no real way to check for errors in the general case, unless we define a
96 #      set of sentinels for this.  not done yet.
97 #-->
98 #  echo "==============" >"$output_file"
99 #  echo "Log state prior to test:" >>"$output_file"
100 #  check_logs_for_errors >>"$output_file"
101 #  echo "==============" >>"$output_file"
102
103   if [ $VERBOSE -ne 1 ]; then
104     bash "${TESTKIT_TEST_SUITE[$test_iter]}" >>"$output_file" 2>&1
105     retval=$?
106   else
107     bash "${TESTKIT_TEST_SUITE[$test_iter]}" 2>&1 | tee -a "$output_file"
108     retval=${PIPESTATUS[0]}
109   fi
110
111   if [ $retval -ne 0 ]; then
112     ((FAIL_COUNT++))
113     echo "FAILURE: exit code $retval for test ${TESTKIT_TEST_SUITE[$test_iter]}"
114     TEST_RESULTS[$test_iter]="FAIL"
115   else
116     echo "OK: successful test run for test ${TESTKIT_TEST_SUITE[$test_iter]}"
117     TEST_RESULTS[$test_iter]="OKAY"
118   fi
119
120 #hmmm: same comment re error checking...  define some tags to look for!
121 #  echo "==============" >>"$output_file"
122 #  echo "Log state after test:" >>"$output_file"
123 #  check_logs_for_errors >>"$output_file"
124 #  echo "==============" >>"$output_file"
125
126 done
127
128 # final analysis--how did the test run do?
129
130 echo -e "\n\nResults table for this test run:\n"
131 for ((test_iter=0; $test_iter < ${#TESTKIT_TEST_SUITE[*]}; test_iter++)); do
132   num=$(expr $test_iter + 1)
133   if [ $num -lt 10 ]; then num="0$num"; fi
134   echo "$num: ${TEST_RESULTS[$test_iter]} -- ${TESTKIT_TEST_SUITE[$test_iter]}"
135 done
136 echo
137
138 # figure out how long things took.
139 TIME_END="$(date +"%s")"
140 duration="$(($TIME_END - $TIME_START))"
141 # prepare to print duration in hours and minutes.
142 minutes="$(($duration / 60))"
143 hours="$(($minutes / 60))"
144 # grab out the hours we calculated from the minutes sum.
145 minutes="$(($minutes - $hours * 60))"
146 if (($minutes < 10)); then minutes="0$minutes"; fi
147 if (($hours < 10)); then hours="0$hours"; fi
148 echo "Total testing duration: $hours:$minutes hh:mm ($duration seconds total)"
149
150 if [ $FAIL_COUNT -ne 0 ]; then
151   echo "FAILURE: $FAIL_COUNT Tests Failed out of ${#TESTKIT_TEST_SUITE[*]} Tests."
152   exit 1
153 else
154   echo "OK: All ${#TESTKIT_TEST_SUITE[*]} Tests Ran Successfully."
155   exit 0
156 fi
157
158