3 # sum2junit.sh -- convert a .sum file into Junit-compatible XML.
5 # Copyright (C) 2016 Free Software Foundation, Inc.
7 # This file is part of DejaGnu.
9 # DejaGnu is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 if test x
"$1" = x
; then
15 outfile
="/tmp/testrun.xml"
16 infile
="/tmp/testrun.sum"
18 outfile
=${1//\.sum.*/.xml}
22 # Where to put the output file
23 if test x
"$2" = x
; then
26 outfile
="/tmp/${outfile}"
29 if test ! -e "$infile"; then
30 echo "ERROR: no input file specified"
34 tool
=$
(grep "tests ===" "$infile" |
tr -s ' ' | cut
-d ' ' -f 2)
36 # Get the counts for tests that didn't work properly
37 skipped
=$
(grep -E -c '^UNRESOLVED|^UNTESTED|^UNSUPPORTED' "$infile")
38 if test x
"${skipped}" = x
; then
42 # The total of successful results are PASS and XFAIL
43 passes
=$
(grep -E -c '^PASS|XFAIL' "$infile")
44 if test x
"${passes}" = x
; then
48 # The total of failed results are FAIL and XPASS
49 failures
=$
(grep -E -c '^FAIL|XPASS' "$infile")
50 if test x
"${failures}" = x
; then
54 # Calculate the total number of test cases
55 total
=$
((passes
+ failures
))
56 total
=$
((total
+ skipped
))
58 cat <<EOF > "$outfile"
62 <testsuite name="DejaGnu" tests="${total}" failures="${failures}" skipped="${skipped}">
66 # Reduce the size of the file to be parsed to improve performance. Junit
67 # ignores sucessful test results, so we only grab the failures and test
68 # case problem results.
69 tmpfile
="${infile}.tmp"
71 grep -E 'XPASS|FAIL|UNTESTED|UNSUPPORTED|UNRESOLVED' "$infile" > "$tmpfile"
76 result
=$
(echo "$line" | cut
-d ' ' -f 1 |
tr -d ':')
77 name
=$
(echo "$line" | cut
-d ' ' -f 2)
78 message
=$
(echo "$line" | cut
-d ' ' -f 3-50 |
tr -d '\"><;:\[\]^\\&?@')
80 echo " <testcase name=\"${name}\" classname=\"${tool}-${result}\">" >> "$outfile"
82 UNSUPPORTED|UNTESTED|UNRESOLVED
)
83 if test x
"${message}" != x
; then
84 echo -n " <skipped message=\"${message}" >> "$outfile"
86 echo -n " <skipped type=\"$result" >> "$outfile"
90 echo -n " <failure message=\"$message" >> "$outfile"
93 echo -n " <failure message=\"$message" >> "$outfile"
95 echo "\"/>" >> "$outfile"
97 echo " </testcase>" >> "$outfile"
101 # Write the closing tag for the test results
102 echo "</testsuite>" >> "$outfile"
103 echo "</testsuites>" >> "$outfile"