diff options
author | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:48:14 +0000 |
---|---|---|
committer | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:48:14 +0000 |
commit | 76361be452ca4b7a5c5e2fee55f2c8ce2cfdbdd0 (patch) | |
tree | 5b83dadb77339fba7eb6e19c0f1198f7af4e2648 /testing | |
parent | 72d1875bebe90cf74a722d16c90ecbdd3d8963a1 (diff) | |
download | chromium_src-76361be452ca4b7a5c5e2fee55f2c8ce2cfdbdd0.zip chromium_src-76361be452ca4b7a5c5e2fee55f2c8ce2cfdbdd0.tar.gz chromium_src-76361be452ca4b7a5c5e2fee55f2c8ce2cfdbdd0.tar.bz2 |
Enable Chrome Sandbox with in test_env.py
Properly setup the chrome sandbox when running test_env.py, if it is required.
R=maruel@chromium.org
BUG=
Review URL: https://chromiumcodereview.appspot.com/10911014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing')
-rwxr-xr-x | testing/test_env.py | 38 | ||||
-rwxr-xr-x | testing/xvfb.py | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/testing/test_env.py b/testing/test_env.py index b18313e5..feca609 100755 --- a/testing/test_env.py +++ b/testing/test_env.py @@ -6,12 +6,48 @@ """Sets environment variables needed to run a chromium unit test.""" import os +import stat import subprocess import sys # This is hardcoded to be src/ relative to this script. ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' +CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' + + +def should_enable_sandbox(sandbox_path): + """Return a boolean indicating that the current slave is capable of using the + sandbox and should enable it. This should return True iff the slave is a + Linux host with the sandbox file present and configured correctly.""" + if not (sys.platform.startswith('linux') and + os.path.exists(sandbox_path)): + return False + sandbox_stat = os.stat(sandbox_path) + if ((sandbox_stat.st_mode & stat.S_ISUID) and + (sandbox_stat.st_mode & stat.S_IRUSR) and + (sandbox_stat.st_mode & stat.S_IXUSR) and + (sandbox_stat.st_uid == 0)): + return True + return False + + +def enable_sandbox_if_required(env, verbose=False): + """Checks enables the sandbox if it is required, otherwise it disables it.""" + chrome_sandbox_path = env.get(CHROME_SANDBOX_ENV, CHROME_SANDBOX_PATH) + + if should_enable_sandbox(chrome_sandbox_path): + if verbose: + print 'Enabling sandbox. Setting environment variable:' + print ' %s="%s"' % (CHROME_SANDBOX_ENV, chrome_sandbox_path) + env[CHROME_SANDBOX_ENV] = chrome_sandbox_path + else: + if verbose: + print 'Disabling sandbox. Setting environment variable:' + print ' %s=""' % CHROME_SANDBOX_ENV + env[CHROME_SANDBOX_ENV] = '' + def fix_python_path(cmd): """Returns the fixed command line to call the right python executable.""" @@ -27,6 +63,7 @@ def run_executable(cmd, env): """Runs an executable with: - environment variable CR_SOURCE_ROOT set to the root directory. - environment variable LANGUAGE to en_US.UTF-8. + - environment variable CHROME_DEVEL_SANDBOX set if need - Reuses sys.executable automatically. """ # Many tests assume a English interface... @@ -34,6 +71,7 @@ def run_executable(cmd, env): # Used by base/base_paths_linux.cc as an override. Just make sure the default # logic is used. env.pop('CR_SOURCE_ROOT', None) + enable_sandbox_if_required(env) # Ensure paths are correctly separated on windows. cmd[0] = cmd[0].replace('/', os.path.sep) cmd = fix_python_path(cmd) diff --git a/testing/xvfb.py b/testing/xvfb.py index e8feaac..6ac0056 100755 --- a/testing/xvfb.py +++ b/testing/xvfb.py @@ -113,7 +113,7 @@ def run_executable(cmd, build_dir, env): subprocess.Popen( ice_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) except OSError: - print >> sys.stderr, 'Failed to run %s' % ' '.join(cmd) + print >> sys.stderr, 'Failed to run %s' % ' '.join(ice_cmd) return 1 return test_env.run_executable(cmd, env) finally: |