aboutsummaryrefslogtreecommitdiff
path: root/sum2junit.sh
blob: 02fd40c755c98ff83d2d328f398eb88c4b949253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
# 
#   Copyright (C) 2013, 2014 Linaro, Inc
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 

#
# This script converts a DejaGnu .sum file into a Junit copatible
# XML file.
#

if test x"$1" = x; then
  outfile="/tmp/testrun.xml"
  infile="/tmp/testrun.sum"
else
  outfile=`echo $1 | sed -e 's/\.sum.*/.junit/'`
  infile=$1
fi

# Where to put the output file
if test x"$2" != x; then
  outfile=$2
else
  outfile="/tmp/${outfile}"
fi

if test ! -e ${infile}; then
  echo "ERROR: no input file specified!"
  exit
fi

# If compressed, uncompress it
type="`file ${infile}`"
count=`echo ${type} | grep -c "XZ compressed data"`
if test ${count} -gt 0; then
  catprog="xzcat"
  decomp="xz -d"
  comp="xz"
else
  count=`echo ${type} | grep -c "XZ compressed data"`
  if test ${count} -gt 0; then
    catprog="gzcat"
    decomp="gzip"
    comp="gunzip"
  else
    catprog="cat"
  fi
fi

#
#${decomp} ${infile}
#infile="`echo ${infile} | sed -e 's:\.xz::' -e 's:\.gz::'`"
tool="`grep "tests ===" ${infile} | tr -s ' ' | cut -d ' ' -f 2`"

# Get the counts for tests that didn't work properly
skipped="`egrep -c '^UNRESOLVED|^UNTESTED|^UNSUPPORTED' ${infile}`"
if test x"${skipped}" = x; then
    skipped=0
fi

# The total of successful results are PASS and XFAIL
passes="`egrep -c '^PASS|XFAIL' ${infile}`"
if test x"${passes}" = x; then
    passes=0
fi

# The total of failed results are FAIL and XPASS
failures="`egrep -c '^XFAIL|XPASS' ${infile}`"
if test x"${failures}" = x; then
    failures=0
fi

# Calculate the total number of test cases
total="`expr ${passes} + ${failures}`"
total="`expr ${total} + ${skipped}`"    

cat <<EOF > ${outfile}
<?xml version="1.0"?>

<testsuites>
<testsuite name="DejaGnu" tests="${total}" failures="${failures}" skipped="${skipped}">

EOF

# Reduce the size of the file to be parsed to improve performance. Junit
# ignores sucessful test results, so we only grab the failures and test
# case problem results.
tmpfile="${infile}.tmp"
rm -f ${tmpfile}
egrep 'XPASS|FAIL|UNTESTED|UNSUPPORTED|UNRESOLVED' ${infile} > ${tmpfile}

while read line
do
    echo -n "."
    result="`echo ${line} | cut -d ' ' -f 1 | tr -d ':'`"
    name="`echo ${line} | cut -d ' ' -f 2`"
    message="`echo ${line} | cut -d ' ' -f 3-50 | tr -d '\"><;:\[\]^\\&?@'`"

    echo "    <testcase name=\"${name}\" classname=\"${tool}-${result}\">" >> ${outfile}
    case "${result}" in
	UNSUPPORTED|UNTESTED|UNRESOLVED)
	    if test x"${message}" != x; then
		echo -n "        <skipped message=\"${message}" >> ${outfile}  
	    else
		echo -n "        <skipped type=\"${result}" >> ${outfile}  
	    fi
	    ;;
	XPASS|XFAIL)
	    echo -n "        <failure message=\"${message}" >> ${outfile}  
	    ;;
	*)
	    echo -n "        <failure message=\"${message}" >> ${outfile}  
    esac
    echo "\"/>" >> ${outfile}  

    echo "    </testcase>" >> ${outfile}
done < ${tmpfile}
rm -f ${tmpfile}

# Write the closing tag for the test results
echo "</testsuite>" >> ${outfile}
echo "</testsuites>" >> ${outfile}

# compress the file again
#${comp} ${infile}