Validator: print message for unsafe indirects
[nativeclient.git] / tools / sel_ldr_tester.py
blobb38cd432a966ea87181a03692ae9e9b1d758c6ff
1 #!/usr/bin/env 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 """Simple testing harness for native client modulers running under sel_ldr
34 The tool expects 5 arguments (in this order):
37 * path to sel_ldr executable
38 * the native client module
39 * a sequence of rpc calls in plain text (e.g. tests/mandel/test.stdin)
40 * the expected out put (e.g. tests/mandel/test.stdout)
41 * a regex to filter the actual output (NYI)
43 The tool reports failure if the native client module exits with
44 an nonzero exit code or if actual and expected output do not match
45 """
48 # python imports
49 import os
50 import re
51 import sys
53 # local imports
54 import test_lib
56 def main(argv):
57 sel_ldr = argv[0]
58 print "Using sel_ldr at ", sel_ldr
60 exe = argv[1]
61 flags = argv[2]
62 stdin_data = argv[3]
63 stdout_data = argv[4]
64 # TODO: NYI
65 regexp = argv[5]
67 short_exe = os.path.abspath(exe)
68 fail_msg = short_exe + ' ' + 'FAILED'
69 pass_msg = short_exe + ' ' + 'PASSED'
71 input_data = ""
72 if stdin_data != "None":
73 input_data = open(stdin_data).read()
75 output_data = ""
76 if stdout_data != "None":
77 output_data = open(stdout_data).read()
79 cmd = [sel_ldr, '-d', '-f', exe] + flags.split()
81 dur, retcode, failed, stdout, stderr = test_lib.RunTestWithInputOutput(
82 cmd, input_data)
84 # TODO: add filter code for stdout here
86 if retcode:
87 print "command retuned nonzero exitcode ", retcode
88 print "STDOUT"
89 print stdout
90 print "STDERR"
91 print stderr
92 print fail_msg
93 return -1
95 if failed:
96 print "command failed"
97 print fail_msg
98 return -1
100 diff = list(test_lib.DiffStringsIgnoringWhiteSpace(stdout, output_data))
101 diff = "\n".join(diff)
102 if diff:
103 print '=' * 70
104 print "Error Diff found"
105 print '=' * 70
106 print diff
107 print '=' * 70
108 print "Potentential New Golden Output"
109 print '=' * 70
110 print stdout
111 print fail_msg
112 return -1
113 print pass_msg
114 return 0
116 if __name__ == '__main__':
117 sys.exit(main(sys.argv[1:]))