| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 from os.path import dirname | 7 from os.path import dirname |
| 8 import platform | 8 import platform |
| 9 import sys | 9 import sys |
| 10 import tempfile | 10 import tempfile |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 import driver_env | 13 import driver_env |
| 14 import driver_log | 14 import driver_log |
| 15 import driver_temps | 15 import driver_temps |
| 16 import driver_tools | 16 import driver_tools |
| 17 | 17 |
| 18 def CanRunHost(): | 18 def CanRunHost(): |
| 19 # Some of the test+tools require running the host binaries, but that | 19 # Some of the test+tools require running the host binaries, but that |
| 20 # does not work on some bots (e.g., the ARM bots). | 20 # does not work on some bots (e.g., the ARM bots). |
| 21 if platform.machine().startswith('arm'): | 21 if platform.machine().startswith('arm'): |
| 22 return False | 22 return False |
| 23 # We also cannot run some of the Windows binaries directly, since | 23 # We also cannot run some of the Windows binaries directly, since |
| 24 # they depend on cygwin DLLs and the cygwin DLLs are only in the | 24 # they depend on cygwin DLLs and the cygwin DLLs are only in the |
| 25 # path for the installed drivers bin and not for the binaries. | 25 # path for the installed drivers bin and not for the binaries. |
| 26 if sys.platform == 'win32': | 26 if sys.platform == 'win32': |
| 27 return False | 27 return False |
| 28 return True | 28 return True |
| 29 | 29 |
| 30 def _SetupLinuxHostDir(env, nacl_dir): | |
| 31 # Use the 32-bit path by default, but fall back to 64-bit if the 32-bit does | |
| 32 # not exist. | |
| 33 dir_template = os.path.join(nacl_dir, 'toolchain', 'linux_x86', | |
| 34 'pnacl_newlib', 'host_%s') | |
| 35 dir_32 = dir_template % 'x86_32' | |
| 36 dir_64 = dir_template % 'x86_64' | |
| 37 driver_tools.AddHostBinarySearchPath( | |
| 38 dir_32 if os.path.exists(dir_32) else dir_64) | |
| 39 | |
| 40 def SetupNaClDir(env): | 30 def SetupNaClDir(env): |
| 41 test_dir = os.path.abspath(dirname(__file__)) | 31 test_dir = os.path.abspath(dirname(__file__)) |
| 42 nacl_dir = dirname(dirname(dirname(test_dir))) | 32 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 43 env.set('BASE_NACL', nacl_dir) | 33 env.set('BASE_NACL', nacl_dir) |
| 44 | 34 |
| 45 def SetupToolchainDir(env): | 35 def SetupToolchainDir(env): |
| 46 test_dir = os.path.abspath(dirname(__file__)) | 36 test_dir = os.path.abspath(dirname(__file__)) |
| 47 nacl_dir = dirname(dirname(dirname(test_dir))) | 37 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 48 os_name = driver_tools.GetOSName() | 38 os_name = driver_tools.GetOSName() |
| 49 | 39 |
| 50 toolchain_dir = os.path.join(nacl_dir, 'toolchain', '%s_x86' % os_name, | 40 toolchain_dir = os.path.join(nacl_dir, 'toolchain', '%s_x86' % os_name, |
| 51 'pnacl_newlib') | 41 'pnacl_newlib') |
| 52 env.set('BASE_TOOLCHAIN', toolchain_dir) | 42 env.set('BASE_TOOLCHAIN', toolchain_dir) |
| 53 | 43 |
| 54 def SetupHostDir(env): | 44 def SetupHostDir(env): |
| 55 # Some of the tools end up running one of the host binaries. Find the host | 45 # Some of the tools end up running one of the host binaries. Find the host |
| 56 # dir on the test system and inject it into the search path using the | 46 # dir on the test system and inject it into the search path using the |
| 57 # implementation of -B | 47 # implementation of -B |
| 58 test_dir = os.path.abspath(dirname(__file__)) | 48 test_dir = os.path.abspath(dirname(__file__)) |
| 59 nacl_dir = dirname(dirname(dirname(test_dir))) | 49 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 60 if sys.platform == 'darwin': | |
| 61 host_arch = 'x86_64' | |
| 62 elif sys.platform.startswith('linux'): | |
| 63 _SetupLinuxHostDir(env, nacl_dir) | |
| 64 return | |
| 65 elif sys.platform in ('cygwin', 'win32'): | |
| 66 host_arch = 'x86_32' | |
| 67 | 50 |
| 68 os_shortname = driver_tools.GetOSName() | 51 os_shortname = driver_tools.GetOSName() |
| 69 host_dir = os.path.join(nacl_dir, 'toolchain', | 52 host_dir = os.path.join(nacl_dir, 'toolchain', |
| 70 '%s_x86' % os_shortname, | 53 '%s_x86' % os_shortname, |
| 71 'pnacl_newlib', | 54 'pnacl_newlib') |
| 72 'host_%s' % host_arch) | |
| 73 driver_tools.AddHostBinarySearchPath(host_dir) | 55 driver_tools.AddHostBinarySearchPath(host_dir) |
| 74 | 56 |
| 75 # A collection of override methods that mock driver_env.Environment. | 57 # A collection of override methods that mock driver_env.Environment. |
| 76 | 58 |
| 77 # One thing is we prevent having to read a driver.conf file, | 59 # One thing is we prevent having to read a driver.conf file, |
| 78 # so instead we have a base group of variables set for testing. | 60 # so instead we have a base group of variables set for testing. |
| 79 def TestEnvReset(self, more_overrides={}): | 61 def TestEnvReset(self, more_overrides={}): |
| 80 # Call to "super" class method (assumed to be driver_env.Environment). | 62 # Call to "super" class method (assumed to be driver_env.Environment). |
| 81 # TODO(jvoung): We may want a different way of overriding things. | 63 # TODO(jvoung): We may want a different way of overriding things. |
| 82 driver_env.Environment.reset(self) | 64 driver_env.Environment.reset(self) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 123 |
| 142 def getTemp(self, close=True, **kwargs): | 124 def getTemp(self, close=True, **kwargs): |
| 143 """ Get a temporary named file object. | 125 """ Get a temporary named file object. |
| 144 """ | 126 """ |
| 145 # Set delete=False, so that we can close the files and | 127 # Set delete=False, so that we can close the files and |
| 146 # re-open them. Windows sometimes does not allow you to | 128 # re-open them. Windows sometimes does not allow you to |
| 147 # re-open an already opened temp file. | 129 # re-open an already opened temp file. |
| 148 t = tempfile.NamedTemporaryFile(delete=False, **kwargs) | 130 t = tempfile.NamedTemporaryFile(delete=False, **kwargs) |
| 149 self._tempfiles.append(t) | 131 self._tempfiles.append(t) |
| 150 return TempWrapper(t, close=close) | 132 return TempWrapper(t, close=close) |
| OLD | NEW |