Adding verification code to prevent studies with repeated experiments.
[chromium-blink-merge.git] / testing / test_env.py
blob84967d16fcd9122944c99cacc4a2e90568620159
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Sets environment variables needed to run a chromium unit test."""
8 import os
9 import subprocess
10 import sys
12 # This is hardcoded to be src/ relative to this script.
13 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
16 def run_executable(cmd, env):
17 """Runs an executable with:
18 - environment variable CR_SOURCE_ROOT set to the root directory.
19 - environment variable LANGUAGE to en_US.UTF-8.
20 - Reuses sys.executable automatically.
21 """
22 # Many tests assume a English interface...
23 env['LANGUAGE'] = 'en_US.UTF-8'
24 # Used by base/base_paths_linux.cc
25 env['CR_SOURCE_ROOT'] = os.path.abspath(ROOT_DIR).encode('utf-8')
26 # Ensure paths are correctly separated on windows.
27 cmd[0] = cmd[0].replace('/', os.path.sep)
28 if cmd[0].endswith('.py'):
29 cmd.insert(0, sys.executable)
30 try:
31 return subprocess.call(cmd, env=env)
32 except OSError:
33 print >> sys.stderr, 'Failed to start %s' % cmd
34 raise
37 def main():
38 return run_executable(sys.argv[1:], os.environ.copy())
41 if __name__ == "__main__":
42 sys.exit(main())