OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2013 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
11 # copyright notice, this list of conditions and the following | 11 # copyright notice, this list of conditions and the following |
12 # disclaimer in the documentation and/or other materials provided | 12 # disclaimer in the documentation and/or other materials provided |
13 # with the distribution. | 13 # with the distribution. |
14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
15 # contributors may be used to endorse or promote products derived | 15 # contributors may be used to endorse or promote products derived |
16 # from this software without specific prior written permission. | 16 # from this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 # This script executes the passed command line on Android device | 30 # This script executes the passed command line using the Native Client |
31 # using 'adb shell' command. Unfortunately, 'adb shell' always | 31 # 'sel_ldr' container. It is derived from android-run.py. |
32 # returns exit code 0, ignoring the exit code of executed command. | |
33 # Since we need to return non-zero exit code if the command failed, | |
34 # we augment the passed command line with exit code checking statement | |
35 # and output special error string in case of non-zero exit code. | |
36 # Then we parse the output of 'adb shell' and look for that error string. | |
37 | 32 |
38 import os | 33 import os |
39 from os.path import join, dirname, abspath | 34 from os.path import join, dirname, abspath |
40 import subprocess | 35 import subprocess |
41 import sys | 36 import sys |
42 import tempfile | 37 import tempfile |
43 | 38 |
44 def Check(output, errors): | 39 def Check(output, errors): |
45 failed = any([s.startswith('/system/bin/sh:') or s.startswith('ANDROID') | 40 failed = any([s.startswith('/system/bin/sh:') or s.startswith('ANDROID') |
46 for s in output.split('\n')]) | 41 for s in output.split('\n')]) |
(...skipping 29 matching lines...) Expand all Loading... |
76 return arg if not ShouldEscape() else '"%s"' % (arg.replace('"', '\\"')) | 71 return arg if not ShouldEscape() else '"%s"' % (arg.replace('"', '\\"')) |
77 | 72 |
78 def WriteToTemporaryFile(data): | 73 def WriteToTemporaryFile(data): |
79 (fd, fname) = tempfile.mkstemp() | 74 (fd, fname) = tempfile.mkstemp() |
80 os.close(fd) | 75 os.close(fd) |
81 tmp_file = open(fname, "w") | 76 tmp_file = open(fname, "w") |
82 tmp_file.write(data) | 77 tmp_file.write(data) |
83 tmp_file.close() | 78 tmp_file.close() |
84 return fname | 79 return fname |
85 | 80 |
| 81 def GetNaClArchFromNexe(nexe): |
| 82 try: |
| 83 p = subprocess.Popen(['file', nexe], stdout=subprocess.PIPE) |
| 84 out, err = p.communicate() |
| 85 lines = out.split('\n') |
| 86 if lines[0].find(": ELF 32-bit LSB executable, Intel 80386") > 0: |
| 87 return "x86_32" |
| 88 if lines[0].find(": ELF 64-bit LSB executable, x86-64") > 0: |
| 89 return "x86_64" |
| 90 except: |
| 91 print 'file ' + sys.argv[1] + ' failed' |
| 92 return None |
| 93 |
| 94 def GetNaClResources(nexe): |
| 95 nacl_sdk_dir = os.environ["NACL_SDK_ROOT"] |
| 96 nacl_arch = GetNaClArchFromNexe(nexe) |
| 97 if sys.platform.startswith("linux"): |
| 98 platform = "linux" |
| 99 elif sys.platform == "darwin": |
| 100 platform = "mac" |
| 101 else: |
| 102 print("NaCl V8 testing is supported on Linux and MacOS only.") |
| 103 sys.exit(1) |
| 104 |
| 105 if nacl_arch is "x86_64": |
| 106 toolchain = platform + "_x86_glibc" |
| 107 sel_ldr = "sel_ldr_x86_64" |
| 108 irt = "irt_core_x86_64.nexe" |
| 109 libdir = "lib64" |
| 110 elif nacl_arch is "x86_32": |
| 111 toolchain = platform + "_x86_glibc" |
| 112 sel_ldr = "sel_ldr_x86_32" |
| 113 irt = "irt_core_x86_32.nexe" |
| 114 libdir = "lib32" |
| 115 elif nacl_arch is "arm": |
| 116 print("NaCl V8 ARM support is not ready yet.") |
| 117 sys.exit(1) |
| 118 else: |
| 119 print("Invalid nexe %s" % nexe) |
| 120 sys.exit(1) |
| 121 |
| 122 nacl_sel_ldr = os.path.join(nacl_sdk_dir, "tools", sel_ldr) |
| 123 nacl_irt = os.path.join(nacl_sdk_dir, "tools", irt) |
| 124 nacl_ld_so = os.path.join(nacl_sdk_dir, "toolchain", toolchain, |
| 125 "x86_64-nacl", libdir, "runnable-ld.so") |
| 126 nacl_lib_path = os.path.join(nacl_sdk_dir, "toolchain", toolchain, |
| 127 "x86_64-nacl", libdir) |
| 128 |
| 129 return (nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so, nacl_lib_path) |
| 130 |
86 def Main(): | 131 def Main(): |
87 if (len(sys.argv) == 1): | 132 if (len(sys.argv) == 1): |
88 print("Usage: %s <command-to-run-on-device>" % sys.argv[0]) | 133 print("Usage: %s <command-to-run-on-device>" % sys.argv[0]) |
89 return 1 | 134 return 1 |
90 workspace = abspath(join(dirname(sys.argv[0]), '..')) | 135 |
91 android_workspace = os.getenv("ANDROID_V8", "/data/local/v8") | |
92 args = [Escape(arg) for arg in sys.argv[1:]] | 136 args = [Escape(arg) for arg in sys.argv[1:]] |
93 script = (" ".join(args) + "\n" | 137 |
94 "case $? in\n" | 138 (nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so, |
95 " 0) ;;\n" | 139 nacl_lib_path) = GetNaClResources(sys.argv[1]) |
96 " *) echo \"ANDROID: Error returned by test\";;\n" | 140 |
97 "esac\n") | 141 # sel_ldr Options: |
98 script = script.replace(workspace, android_workspace) | 142 # -c -c: disable validation (for performance) |
99 script_file = WriteToTemporaryFile(script) | 143 # -a: allow file access |
100 android_script_file = android_workspace + "/" + script_file | 144 # -B <irt>: load the IRT |
101 command = ("adb push '%s' %s;" % (script_file, android_script_file) + | 145 command = ' '.join([nacl_sel_ldr, '-c', '-c', '-a', '-B', nacl_irt, '--', |
102 "adb shell 'sh %s';" % android_script_file + | 146 nacl_ld_so, '--library-path', nacl_lib_path] + args) |
103 "adb shell 'rm %s'" % android_script_file) | |
104 error_code = Execute(command) | 147 error_code = Execute(command) |
105 os.unlink(script_file) | |
106 return error_code | 148 return error_code |
107 | 149 |
108 if __name__ == '__main__': | 150 if __name__ == '__main__': |
109 sys.exit(Main()) | 151 sys.exit(Main()) |
OLD | NEW |