python/cmd2: update to 2.5.6
[oi-userland.git] / components / runtime / erlang / run_erlang_tests.sh
blob31ebf28257b155c800a1e7db27741f73177a4a12
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2020, 2021, Oracle and/or its affiliates.
27 if [ $# -ne 1 ]; then
28 echo "Please specify the path to Erlang source directory!"
29 exit 1
32 SOURCE_DIR="$(realpath $1)"
33 if [ ! -e "${SOURCE_DIR}/bin/erl" ]; then
34 echo "Please build Erlang first by using './otp_build setup -a' command!"
35 exit 2
38 export ERL_TOP="${SOURCE_DIR}"
39 export TESTROOT="${SOURCE_DIR}/tests"
40 # to get stable sorting
41 export LC_ALL=C
43 # Build the release tests.
44 cd "${SOURCE_DIR}"
45 gmake release_tests > /dev/null 2>&1;
46 if [ $? -ne 0 ]; then
47 echo "Failed to build Erlang release tests!"
48 exit 3
51 # Remove the previous logs.
52 gfind . -name 'suite.log' -delete 2>/dev/null
54 # Execute the Erlang tests (it takes many hours).
55 cd "${TESTROOT}/test_server"
56 rm -f ${SOURCE_DIR}/progress.log
57 "${SOURCE_DIR}/bin/erl" -s ts install -s init stop > ${SOURCE_DIR}/progress.log 2>&1
58 for group in $(ls .. | grep _test\$ | sed s@_test\$@@); do
59 for i in `ls ../${group}_test/|grep _SUITE.erl|sed s@\.erl@@`; do
60 echo "Running group $group suite $i" >> ${SOURCE_DIR}/progress.log 2>&1
61 # emulator/trace_local seems to get stuck
62 # mnesia_test takes over 1 hour to finish
63 timeout -k 30s 10800s "${SOURCE_DIR}/bin/erl" -pa ebin -eval "ts:run($group, $i, [batch]), init:stop()." >> ${SOURCE_DIR}/progress.log 2>&1
64 [ "$?" = "124" ] && echo "Test $group $i was killed"
65 done
66 done
68 # Find the generated logs for Erlang modules.
69 cd "${SOURCE_DIR}"
70 ok=0 skipped=0 failed=0 total=0
71 SUITE_LOGS=$(find . -name 'suite.log' 2>/dev/null | grep -v 'log_private' | gsort)
73 for LOG_PATH in $(echo "${SUITE_LOGS}"); do
74 # Extract the name of the tested module from the path.
75 MODULE=$(echo "${LOG_PATH}" | gcut -d'/' -f5 | gcut -d'.' -f2)
76 echo "***** Results for ${MODULE} *****"
78 # Filter the relevant results from the log file and ensure reproducibility.
79 FILTER_REGEXP="^(=case|=result|=== TEST COMPLETE,|=== EXIT,)[[:space:]]"
80 ggrep -E "${FILTER_REGEXP}" "${LOG_PATH}" | perl -pe "s/$(hostname)/HOSTNAME/g" | \
81 perl -pe "s|${SOURCE_DIR}|BUILD_DIR|" | perl -pe 'if(/^=result/) { $_ =~ s/\d*\.?\d+/NUMBER/g; }'
83 # Count the overall statistics to print it after the test logs are processed.
84 results=$(grep '=== TEST COMPLETE' "${LOG_PATH}")
85 if [ -n "${results}" ]; then
86 suite_ok=$(echo "${results}" | perl -ne 'if(/([\d]+) ok/) { print $1 } else { print 0 }')
87 suite_failed=$(echo "${results}" | perl -ne 'if(/([\d]+) failed/) { print $1 } else { print 0 }')
88 suite_skipped=$(echo "${results}" | perl -ne 'if(/([\d]+) skipped/) { print $1 } else { print 0 }')
89 suite_total=$(echo "${results}" | perl -ne 'if(/of ([\d]+) test cases/) { print $1 } else { print 0 }')
90 ok=$((ok+${suite_ok}))
91 failed=$((failed+${suite_failed}))
92 skipped=$((skipped+${suite_skipped}))
93 total=$((total+${suite_total}))
94 else
95 echo "Cannot find the result line for ${MODULE}!"
98 echo ""
99 done
101 echo "##### RESULTS SUMMARY #####"
102 echo "ok: ${ok} cases"
103 echo "skipped: ${skipped} cases"
104 echo "failed: ${failed} cases"
105 echo "total: ${total} cases"
107 exit 0