run_devtools_check.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # Copyright 2015 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. """Runs a python script under an isolate
  6. This script attempts to emulate the contract of gtest-style tests
  7. invoked via recipes.
  8. If optional argument --isolated-script-test-output=[FILENAME] is passed
  9. to the script, json is written to that file in the format detailed in
  10. //docs/testing/json-test-results-format.md.
  11. This script is intended to be the base command invoked by the isolate,
  12. followed by a subsequent Python script."""
  13. import argparse
  14. import json
  15. import os
  16. import sys
  17. # Add src/testing/ into sys.path for importing xvfb and common.
  18. sys.path.append(
  19. os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  20. import xvfb
  21. from scripts import common
  22. def main():
  23. parser = argparse.ArgumentParser()
  24. parser.add_argument('--isolated-script-test-output', type=str)
  25. args, rest_args = parser.parse_known_args()
  26. # Remove the isolated script extra args this script doesn't care about.
  27. should_ignore_arg = lambda arg: any(to_ignore in arg for to_ignore in (
  28. '--isolated-script-test-chartjson-output',
  29. '--isolated-script-test-perf-output',
  30. '--isolated-script-test-filter',
  31. ))
  32. rest_args = [arg for arg in rest_args if not should_ignore_arg(arg)]
  33. ret = common.run_command([sys.executable] + rest_args)
  34. if args.isolated_Script_test_output:
  35. with open(args.isolated_script_test_output, 'w') as fp:
  36. json.dump({'valid': True,
  37. 'failures': ['failed'] if ret else []}, fp)
  38. return ret
  39. # This is not really a "script test" so does not need to manually add
  40. # any additional compile targets.
  41. def main_compile_targets(args):
  42. json.dump([''], args.output)
  43. if __name__ == '__main__':
  44. # Conform minimally to the protocol defined by ScriptTest.
  45. if 'compile_targets' in sys.argv:
  46. funcs = {
  47. 'run': None,
  48. 'compile_targets': main_compile_targets,
  49. }
  50. sys.exit(common.run_script(sys.argv[1:], funcs))
  51. sys.exit(main())