Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: tools/nacl-run.py

Issue 13619011: A helper script for testing Native Client builds of V8. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Cleanup and performance fix. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/nacl-run.py
diff --git a/tools/android-run.py b/tools/nacl-run.py
similarity index 57%
copy from tools/android-run.py
copy to tools/nacl-run.py
index 1693c5b064b9008a29a50140b9c521312f213fb5..135172caf90f2c73e61fdfbc68760f0ac7e28db2 100755
--- a/tools/android-run.py
+++ b/tools/nacl-run.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2012 the V8 project authors. All rights reserved.
+# Copyright 2013 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
@@ -27,13 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# This script executes the passed command line on Android device
-# using 'adb shell' command. Unfortunately, 'adb shell' always
-# returns exit code 0, ignoring the exit code of executed command.
-# Since we need to return non-zero exit code if the command failed,
-# we augment the passed command line with exit code checking statement
-# and output special error string in case of non-zero exit code.
-# Then we parse the output of 'adb shell' and look for that error string.
+# This script executes the passed command line using the Native Client
+# 'sel_ldr' container. It is derived from android-run.py.
import os
from os.path import join, dirname, abspath
@@ -83,26 +78,73 @@ def WriteToTemporaryFile(data):
tmp_file.close()
return fname
+def GetNaClArchFromNexe(nexe):
+ try:
+ p = subprocess.Popen(['file', nexe], stdout=subprocess.PIPE)
+ out, err = p.communicate()
+ lines = out.split('\n')
+ if lines[0].find(": ELF 32-bit LSB executable, Intel 80386") > 0:
+ return "x86_32"
+ if lines[0].find(": ELF 64-bit LSB executable, x86-64") > 0:
+ return "x86_64"
+ except:
+ print 'file ' + sys.argv[1] + ' failed'
+ return None
+
+def GetNaClResources(nexe):
+ nacl_sdk_dir = os.environ["NACL_SDK_ROOT"]
+ nacl_arch = GetNaClArchFromNexe(nexe)
+ if sys.platform.startswith("linux"):
+ platform = "linux"
+ elif sys.platform == "darwin":
+ platform = "mac"
+ else:
+ print("NaCl V8 testing is supported on Linux and MacOS only.")
+ sys.exit(1)
+
+ if nacl_arch is "x86_64":
+ toolchain = platform + "_x86_glibc"
+ sel_ldr = "sel_ldr_x86_64"
+ irt = "irt_core_x86_64.nexe"
+ libdir = "lib64"
+ elif nacl_arch is "x86_32":
+ toolchain = platform + "_x86_glibc"
+ sel_ldr = "sel_ldr_x86_32"
+ irt = "irt_core_x86_32.nexe"
+ libdir = "lib32"
+ elif nacl_arch is "arm":
+ print("NaCl V8 ARM support is not ready yet.")
+ sys.exit(1)
+ else:
+ print("Invalid nexe %s" % nexe)
+ sys.exit(1)
+
+ nacl_sel_ldr = os.path.join(nacl_sdk_dir, "tools", sel_ldr)
+ nacl_irt = os.path.join(nacl_sdk_dir, "tools", irt)
+ nacl_ld_so = os.path.join(nacl_sdk_dir, "toolchain", toolchain,
+ "x86_64-nacl", libdir, "runnable-ld.so")
+ nacl_lib_path = os.path.join(nacl_sdk_dir, "toolchain", toolchain,
+ "x86_64-nacl", libdir)
+
+ return (nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so, nacl_lib_path)
+
def Main():
if (len(sys.argv) == 1):
print("Usage: %s <command-to-run-on-device>" % sys.argv[0])
return 1
- workspace = abspath(join(dirname(sys.argv[0]), '..'))
- android_workspace = os.getenv("ANDROID_V8", "/data/local/v8")
+
args = [Escape(arg) for arg in sys.argv[1:]]
- script = (" ".join(args) + "\n"
- "case $? in\n"
- " 0) ;;\n"
- " *) echo \"ANDROID: Error returned by test\";;\n"
- "esac\n")
- script = script.replace(workspace, android_workspace)
- script_file = WriteToTemporaryFile(script)
- android_script_file = android_workspace + "/" + script_file
- command = ("adb push '%s' %s;" % (script_file, android_script_file) +
- "adb shell 'sh %s';" % android_script_file +
- "adb shell 'rm %s'" % android_script_file)
+
+ (nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so,
+ nacl_lib_path) = GetNaClResources(sys.argv[1])
+
+ # sel_ldr Options:
+ # -c -c: disable validation (for performance)
+ # -a: allow file access
+ # -B <irt>: load the IRT
+ command = ' '.join([nacl_sel_ldr, '-c', '-c', '-a', '-B', nacl_irt, '--',
+ nacl_ld_so, '--library-path', nacl_lib_path] + args)
error_code = Execute(command)
- os.unlink(script_file)
return error_code
if __name__ == '__main__':
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698