2 # Copyright 2008, Google Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 """This script runs the tests listed in the input file.
34 This script runs the tests listed in the input file
35 and reports the results in jUnit XML format (written to the
36 output file). All tests that return 0 are considered to be successful.
38 main(): The only function, runs the tests
44 import xml
.dom
.minidom
51 # make sure WindowsError is defined
55 class WindowsError: pass
57 input_file
= os
.path
.join(os
.getcwd(), argv
[1])
58 output_file
= os
.path
.join(os
.getcwd(),argv
[2])
59 doc
= xml
.dom
.minidom
.Document()
61 listfile
= open(input_file
,'rU')
63 os
.remove(output_file
)
64 except (WindowsError, OSError):
66 xmlfile
= open(output_file
,'w')
73 suite
= doc
.createElement("testsuite")
74 suite
.setAttribute("name", "SimpleTests")
75 suite
.setAttribute("disabled", "0")
77 doc
.appendChild(suite
)
81 # in case we have empty lines in the end of the file
83 cmdline
= line
.split()
86 test
=doc
.createElement("testcase")
87 test
.setAttribute("name", str(cmd
))
89 path
= os
.path
.join(argv
[3], cmd
)
92 duration
, retcode
, failed
= test_lib
.RunTest([path
] + cmdline
[1:])
94 total
=int(duration
* 1000)
95 test
.setAttribute("time", str(total
))
96 test
.setAttribute("status", "run")
102 failure_msg
=doc
.createElement("failure")
103 failure_msg
.setAttribute("message", "test "+cmd
+" failed")
104 test
.appendChild(failure_msg
)
107 err_msg
=doc
.createElement("error")
108 err_msg
.setAttribute("message", "error: " + str(sys
.exc_info()[1]))
109 test
.appendChild(err_msg
)
111 suite
.appendChild(test
)
113 suite
.setAttribute("time", str(timecount
))
114 suite
.setAttribute("tests", str(testcount
))
115 suite
.setAttribute("failures", str(failcount
))
116 suite
.setAttribute("errors", str(errorcount
))
117 xmlfile
.write(doc
.toprettyxml())
123 if __name__
== '__main__':
124 sys
.exit(main(sys
.argv
))