content_shell_crash_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env vpython3
  2. # Copyright 2017 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.
  5. import argparse
  6. import json
  7. import os
  8. import sys
  9. # Add src/testing/ into sys.path for importing xvfb and common.
  10. sys.path.append(
  11. os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  12. import xvfb
  13. from scripts import common
  14. # Unfortunately we need to copy these variables from ../test_env.py.
  15. # Importing it and using its get_sandbox_env breaks test runs on Linux
  16. # (it seems to unset DISPLAY).
  17. CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX'
  18. CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox'
  19. def main(argv):
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument(
  22. '--isolated-script-test-output', type=str,
  23. required=False)
  24. parser.add_argument(
  25. '--isolated-script-test-chartjson-output', type=str,
  26. required=False)
  27. parser.add_argument(
  28. '--isolated-script-test-perf-output', type=str,
  29. required=False)
  30. parser.add_argument(
  31. '--isolated-script-test-filter', type=str,
  32. required=False)
  33. parser.add_argument(
  34. '--platform', type=str, default=sys.platform, required=False)
  35. args = parser.parse_args(argv)
  36. env = os.environ.copy()
  37. # Assume we want to set up the sandbox environment variables all the
  38. # time; doing so is harmless on non-Linux platforms and is needed
  39. # all the time on Linux.
  40. env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH
  41. additional_args = []
  42. if args.platform == 'win32':
  43. exe = os.path.join('.', 'content_shell.exe')
  44. elif args.platform == 'darwin':
  45. exe = os.path.join('.', 'Content Shell.app', 'Contents', 'MacOS',
  46. 'Content Shell')
  47. # The Content Shell binary does not directly link against
  48. # the Content Shell Framework (it is loaded at runtime). Ensure that
  49. # symbols are dumped for the Framework too.
  50. additional_args = [
  51. '--additional-binary',
  52. os.path.join('.', 'Content Shell.app', 'Contents', 'Frameworks',
  53. 'Content Shell Framework.framework', 'Versions',
  54. 'Current', 'Content Shell Framework')
  55. ]
  56. elif args.platform == 'android':
  57. exe = os.path.join('.', 'lib.unstripped',
  58. 'libcontent_shell_content_view.so')
  59. else:
  60. exe = os.path.join('.', 'content_shell')
  61. with common.temporary_file() as tempfile_path:
  62. env['CHROME_HEADLESS'] = '1'
  63. rc = xvfb.run_executable([
  64. sys.executable,
  65. os.path.join(common.SRC_DIR, 'content', 'shell', 'tools',
  66. 'breakpad_integration_test.py'),
  67. '--verbose',
  68. '--build-dir', '.',
  69. '--binary', exe,
  70. '--json', tempfile_path,
  71. '--platform', args.platform,
  72. ] + additional_args, env)
  73. with open(tempfile_path) as f:
  74. failures = json.load(f)
  75. if args.isolated_script_test_output:
  76. with open(args.isolated_script_test_output, 'w') as fp:
  77. common.record_local_script_results(
  78. 'content_shell_crash_test', fp, failures, True)
  79. return rc
  80. def main_compile_targets(args):
  81. json.dump(['content_shell_crash_test'], args.output)
  82. if __name__ == '__main__':
  83. # Conform minimally to the protocol defined by ScriptTest.
  84. if 'compile_targets' in sys.argv:
  85. funcs = {
  86. 'run': None,
  87. 'compile_targets': main_compile_targets,
  88. }
  89. sys.exit(common.run_script(sys.argv[1:], funcs))
  90. sys.exit(main(sys.argv[1:]))