Block remapping or unmapping code mappings
[nativeclient.git] / tools / run_simple_tests.py
blobfc1e01be6635fcfc3639c4e970400be0c5dd12a4
1 #!/usr/bin/python
2 # Copyright 2008, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
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
14 # distribution.
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
39 """
41 # python imports
42 import os
43 import sys
44 import xml.dom.minidom
46 # local imports
47 import test_lib
50 def main(argv):
51 # make sure WindowsError is defined
52 try:
53 WindowsError
54 except NameError:
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')
62 try:
63 os.remove(output_file)
64 except (WindowsError, OSError):
65 pass
66 xmlfile = open(output_file,'w')
68 errorcount = 0
69 failcount = 0
70 testcount = 0
71 timecount = 0
73 suite = doc.createElement("testsuite")
74 suite.setAttribute("name", "SimpleTests")
75 suite.setAttribute("disabled", "0")
77 doc.appendChild(suite)
79 for line in listfile:
80 if len(line) < 3:
81 # in case we have empty lines in the end of the file
82 break
83 cmdline = line.split()
84 cmd=cmdline[0]
86 test=doc.createElement("testcase")
87 test.setAttribute("name", str(cmd))
89 path = os.path.join(argv[3], cmd)
90 print path
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")
97 testcount+=1
98 timecount+=total
100 if retcode:
101 failcount+=1
102 failure_msg=doc.createElement("failure")
103 failure_msg.setAttribute("message", "test "+cmd+" failed")
104 test.appendChild(failure_msg)
105 elif failed:
106 errorcount+=1
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())
118 xmlfile.close()
119 listfile.close()
121 return 0
123 if __name__ == '__main__':
124 sys.exit(main(sys.argv))