test_all.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env vpython3
  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.
  5. """Top level script for running all python unittests in the NaCl SDK.
  6. """
  7. from __future__ import print_function
  8. import argparse
  9. import os
  10. import subprocess
  11. import sys
  12. import unittest
  13. # add tools folder to sys.path
  14. SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
  15. TOOLS_DIR = os.path.join(SCRIPT_DIR, 'tools')
  16. BUILD_TOOLS_DIR = os.path.join(SCRIPT_DIR, 'build_tools')
  17. sys.path.append(TOOLS_DIR)
  18. sys.path.append(os.path.join(TOOLS_DIR, 'tests'))
  19. sys.path.append(os.path.join(TOOLS_DIR, 'lib', 'tests'))
  20. sys.path.append(BUILD_TOOLS_DIR)
  21. sys.path.append(os.path.join(BUILD_TOOLS_DIR, 'tests'))
  22. import build_paths
  23. PKG_VER_DIR = os.path.join(build_paths.NACL_DIR, 'build', 'package_version')
  24. TAR_DIR = os.path.join(build_paths.NACL_DIR, 'toolchain', '.tars')
  25. PKG_VER = os.path.join(PKG_VER_DIR, 'package_version.py')
  26. EXTRACT_PACKAGES = ['nacl_x86_glibc', 'nacl_arm_glibc']
  27. TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain')
  28. # List of modules containing unittests. The goal is to keep the total
  29. # runtime of these tests under 2 seconds. Any slower tests should go
  30. # in TEST_MODULES_BIG.
  31. TEST_MODULES = [
  32. 'build_artifacts_test',
  33. 'build_version_test',
  34. 'create_html_test',
  35. 'create_nmf_test',
  36. 'easy_template_test',
  37. 'elf_test',
  38. 'fix_deps_test',
  39. 'getos_test',
  40. 'get_shared_deps_test',
  41. 'httpd_test',
  42. 'nacl_config_test',
  43. 'oshelpers_test',
  44. 'parse_dsc_test',
  45. 'quote_test',
  46. 'sdktools_config_test',
  47. 'sel_ldr_test',
  48. 'test_projects_test',
  49. 'update_nacl_manifest_test',
  50. 'verify_filelist_test',
  51. 'verify_ppapi_test',
  52. ]
  53. # Slower tests. For example the 'sdktools' are mostly slower system tests
  54. # that longer to run. If --quick is passed then we don't run these.
  55. TEST_MODULES_BIG = [
  56. 'sdktools_commands_test',
  57. 'sdktools_test',
  58. ]
  59. def ExtractToolchains():
  60. cmd = [sys.executable, PKG_VER,
  61. '--packages', ','.join(EXTRACT_PACKAGES),
  62. '--tar-dir', TAR_DIR,
  63. '--dest-dir', TOOLCHAIN_OUT,
  64. 'extract']
  65. subprocess.check_call(cmd)
  66. def main(args):
  67. parser = argparse.ArgumentParser(description=__doc__)
  68. parser.add_argument('-v', '--verbose', action='store_true')
  69. parser.add_argument('--quick', action='store_true')
  70. options = parser.parse_args(args)
  71. # Some of the unit tests use parts of toolchains. Extract to TOOLCHAIN_OUT.
  72. print('Extracting toolchains...')
  73. ExtractToolchains()
  74. suite = unittest.TestSuite()
  75. modules = TEST_MODULES
  76. if not options.quick:
  77. modules += TEST_MODULES_BIG
  78. for module_name in modules:
  79. module = __import__(module_name)
  80. suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module))
  81. if options.verbose:
  82. verbosity = 2
  83. else:
  84. verbosity = 1
  85. print('Running unittests...')
  86. result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
  87. return int(not result.wasSuccessful())
  88. if __name__ == '__main__':
  89. sys.exit(main(sys.argv[1:]))