summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/test_all.py
blob: 88b549f244214bd376eb4c5cb69f8da1b74aca7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Top level script for running all python unittests in the NaCl SDK.
"""

from __future__ import print_function

import argparse
import os
import subprocess
import sys
import unittest

# add tools folder to sys.path
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.join(SCRIPT_DIR, 'tools')
BUILD_TOOLS_DIR = os.path.join(SCRIPT_DIR, 'build_tools')

sys.path.append(TOOLS_DIR)
sys.path.append(os.path.join(TOOLS_DIR, 'tests'))
sys.path.append(os.path.join(TOOLS_DIR, 'lib', 'tests'))
sys.path.append(BUILD_TOOLS_DIR)
sys.path.append(os.path.join(BUILD_TOOLS_DIR, 'tests'))

import build_paths

PKG_VER_DIR = os.path.join(build_paths.NACL_DIR, 'build', 'package_version')
TAR_DIR = os.path.join(build_paths.NACL_DIR, 'toolchain', '.tars')

PKG_VER = os.path.join(PKG_VER_DIR, 'package_version.py')

EXTRACT_PACKAGES = ['nacl_x86_glibc', 'nacl_arm_glibc']
TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain')

# List of modules containing unittests. The goal is to keep the total
# runtime of these tests under 2 seconds. Any slower tests should go
# in TEST_MODULES_BIG.
TEST_MODULES = [
    'build_artifacts_test',
    'build_version_test',
    'create_html_test',
    'create_nmf_test',
    'easy_template_test',
    'elf_test',
    'fix_deps_test',
    'getos_test',
    'get_shared_deps_test',
    'httpd_test',
    'nacl_config_test',
    'oshelpers_test',
    'parse_dsc_test',
    'quote_test',
    'sdktools_config_test',
    'sel_ldr_test',
    'test_projects_test',
    'update_nacl_manifest_test',
    'verify_filelist_test',
    'verify_ppapi_test',
]


# Slower tests. For example the 'sdktools' are mostly slower system tests
# that longer to run.  If --quick is passed then we don't run these.
TEST_MODULES_BIG = [
    'sdktools_commands_test',
    'sdktools_test',
]


def ExtractToolchains():
  cmd = [sys.executable, PKG_VER,
         '--packages', ','.join(EXTRACT_PACKAGES),
         '--tar-dir', TAR_DIR,
         '--dest-dir', TOOLCHAIN_OUT,
         'extract']
  subprocess.check_call(cmd)


def main(args):
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('-v', '--verbose', action='store_true')
  parser.add_argument('--quick', action='store_true')
  options = parser.parse_args(args)

  # Some of the unit tests use parts of toolchains. Extract to TOOLCHAIN_OUT.
  print('Extracting toolchains...')
  ExtractToolchains()

  suite = unittest.TestSuite()
  modules = TEST_MODULES
  if not options.quick:
    modules += TEST_MODULES_BIG

  for module_name in modules:
    module = __import__(module_name)
    suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module))

  if options.verbose:
    verbosity = 2
  else:
    verbosity = 1

  print('Running unittests...')
  result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
  return int(not result.wasSuccessful())


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))