示例#1
0
def compile_typescript_test_files():
    tsc_compile_errors_found = False
    cwd = devtools_paths.devtools_root_path()
    env = os.environ.copy()
    shared_path = os.path.join(cwd, 'test/shared')
    e2e_test_path = os.path.join(cwd, 'test/e2e')

    # Compile shared code, e.g. helper and runner.
    print("Compiling shared TypeScript")
    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.typescript_compiler_path(), '-p', shared_path
    ]
    tsc_compile_proc = popen(exec_command, cwd=cwd, env=env, capture=True)
    tsc_compile_proc.communicate()
    if tsc_compile_proc.returncode != 0:
        tsc_compile_errors_found = True

    # Compile e2e tests, e.g. helper and runner.
    print("Compiling e2e TypeScript")
    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.typescript_compiler_path(), '-p', e2e_test_path
    ]
    tsc_compile_proc = popen(exec_command, cwd=cwd, env=env, capture=True)
    tsc_compile_proc.communicate()
    if tsc_compile_proc.returncode != 0:
        tsc_compile_errors_found = True

    return tsc_compile_errors_found
def run_tests(chrome_binary, target, no_text_coverage, coverage):
    cwd = devtools_paths.devtools_root_path()
    karmaconfig_path = os.path.join(cwd, 'out', target, 'gen', 'test',
                                    'unittests', 'front_end', 'karma.conf.js')

    if not os.path.exists(karmaconfig_path):
        print('Unable to find Karma config at ' + karmaconfig_path)
        print(
            'Make sure to set the --ninja-build-name argument to the folder name of "out/target"'
        )
        sys.exit(1)

    print('Using karma config ' + karmaconfig_path)

    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.karma_path(), 'start',
        test_helpers.to_platform_path_exact(karmaconfig_path)
    ]

    env = os.environ.copy()
    env['NODE_PATH'] = devtools_paths.node_path()
    if (no_text_coverage is not False):
        env['NO_TEXT_COVERAGE'] = '1'
    if (coverage is True):
        env['COVERAGE'] = '1'
    if (chrome_binary is not None):
        env['CHROME_BIN'] = chrome_binary

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code == 1:
        return True

    return False
def run_tests(chrome_binary, chrome_features, test_suite, test_suite_list_path, test_file=None):
    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary
    env['TEST_LIST'] = test_suite_list_path
    if chrome_features:
        env['CHROME_FEATURES'] = chrome_features

    if test_file is not None:
        env['TEST_FILE'] = test_file

    cwd = devtools_paths.devtools_root_path()
    if test_suite == 'e2e':
        exec_command = [
            devtools_paths.node_path(),
            devtools_paths.mocha_path(),
            '--config',
            E2E_MOCHA_CONFIGURATION_LOCATION,
        ]
    else:
        runner_path = os.path.join(cwd, 'test', 'shared', 'runner.js')
        exec_command = [devtools_paths.node_path(), runner_path]

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code != 0:
        return True

    return False
示例#4
0
def run_tests(chrome_binary,
              chrome_features,
              test_suite_path,
              test_suite,
              jobs,
              server,
              test_file=None):
    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary
    if chrome_features:
        env['CHROME_FEATURES'] = chrome_features

    if test_file is not None:
        env['TEST_FILE'] = test_file

    if jobs:
        env['JOBS'] = jobs

    env['SERVER'] = server
    cwd = devtools_paths.devtools_root_path()
    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.mocha_path(),
        '--config',
        os.path.join(test_suite_path, '.mocharc.js'),
    ]

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code != 0:
        return True

    return False
def main():
    parser = argparse.ArgumentParser(description='Run unittests on Ninja targets.')
    parser.add_argument(
        '--target', '-t', default='Default', dest='target', help='The name of the Ninja output directory. Defaults to "Default"')
    parser.add_argument(
        '--no-text-coverage', action='store_true', default=False, dest='no_text_coverage', help='Whether to output text coverage')
    parser.add_argument('--no-html-coverage',
                        action='store_true',
                        default=False,
                        dest='no_html_coverage',
                        help='Whether to output html coverage')
    parser.add_argument('--coverage',
                        action='store_true',
                        default=False,
                        dest='coverage',
                        help='Whether to output coverage')
    parser.add_argument('--expanded-reporting',
                        action='store_true',
                        default=False,
                        dest='expanded_reporting',
                        help='Whether to output expanded report info')
    parser.add_argument('--chrome-binary',
                        dest='chrome_binary',
                        help='Path to Chromium binary')
    parser.add_argument('--cwd',
                        dest='cwd',
                        help='Path to the directory containing the out dir',
                        default=devtools_paths.devtools_root_path())
    args = parser.parse_args(sys.argv[1:])

    run_unit_tests_on_ninja_build_target(args.target, args.no_text_coverage,
                                         args.no_html_coverage, args.coverage,
                                         args.expanded_reporting,
                                         args.chrome_binary, args.cwd)
def run_test():
    OPTIONS = parse_options(sys.argv[1:])
    is_cygwin = sys.platform == 'cygwin'
    chrome_binary = None
    test_suite = None
    chrome_features = None

    # Default to the downloaded / pinned Chromium binary
    downloaded_chrome_binary = devtools_paths.downloaded_chrome_binary_path()
    if test_helpers.check_chrome_binary(downloaded_chrome_binary):
        chrome_binary = downloaded_chrome_binary

    # Override with the arg value if provided.
    if OPTIONS.chrome_binary:
        chrome_binary = OPTIONS.chrome_binary
        if not test_helpers.check_chrome_binary(chrome_binary):
            print('Unable to find a Chrome binary at \'%s\'' % chrome_binary)
            sys.exit(1)

    if OPTIONS.chrome_features:
        chrome_features = '--enable-features=%s' % OPTIONS.chrome_features

    if (chrome_binary is None):
        print('Unable to run, no Chrome binary provided')
        sys.exit(1)

    if (OPTIONS.test_suite is None):
        print('Unable to run, no test suite provided')
        sys.exit(1)

    test_suite = OPTIONS.test_suite
    test_file = OPTIONS.test_file

    print('Using Chromium binary ({}{})\n'.format(chrome_binary, ' ' + chrome_features if chrome_features else ''))
    print('Using Test Suite (%s)\n' % test_suite)
    print('Using target (%s)\n' % OPTIONS.target)

    if test_file is not None:
        print('Testing file (%s)' % test_file)

    cwd = devtools_paths.devtools_root_path()
    test_suite_path = os.path.join(cwd, 'out', OPTIONS.target, 'gen', 'test',
                                   test_suite)

    errors_found = False
    try:
        errors_found = run_tests(chrome_binary,
                                 chrome_features,
                                 test_suite_path,
                                 test_suite,
                                 test_file=test_file)
    except Exception as err:
        print(err)

    if errors_found:
        print('ERRORS DETECTED')
        sys.exit(1)
示例#7
0
def run_test():
    OPTIONS = parse_options(sys.argv[1:])
    is_cygwin = sys.platform == 'cygwin'
    chrome_binary = None
    test_suite = None

    # Default to the downloaded / pinned Chromium binary
    downloaded_chrome_binary = devtools_paths.downloaded_chrome_binary_path()
    if test_helpers.check_chrome_binary(downloaded_chrome_binary):
        chrome_binary = downloaded_chrome_binary

    # Override with the arg value if provided.
    if OPTIONS.chrome_binary:
        chrome_binary = OPTIONS.chrome_binary
        if not test_helpers.check_chrome_binary(chrome_binary):
            print('Unable to find a Chrome binary at \'%s\'' % chrome_binary)
            sys.exit(1)

    if (chrome_binary is None):
        print('Unable to run, no Chrome binary provided')
        sys.exit(1)

    if (OPTIONS.test_suite is None):
        print('Unable to run, no test suite provided')
        sys.exit(1)

    test_suite = OPTIONS.test_suite

    print('Using Chromium binary (%s)\n' % chrome_binary)
    print('Using Test Suite (%s)\n' % test_suite)

    cwd = devtools_paths.devtools_root_path()
    shared_path = os.path.join(cwd, 'test', 'shared')
    test_suite_path = os.path.join(cwd, 'test', test_suite)
    typescript_paths = [{
        'name': 'shared',
        'path': shared_path
    }, {
        'name': 'suite',
        'path': test_suite_path
    }]

    errors_found = False
    try:
        errors_found = compile_typescript(typescript_paths)
        if (errors_found):
            raise Exception('Typescript failed to compile')
        test_suite_list_path = os.path.join(test_suite_path, 'test-list.js')
        errors_found = run_tests(chrome_binary, test_suite_list_path)
    except Exception as err:
        print(err)

    if errors_found:
        print('ERRORS DETECTED')
        sys.exit(1)
示例#8
0
def run_unit_tests_on_ninja_build_target(target,
                                         no_text_coverage=True,
                                         no_html_coverage=True,
                                         coverage=False,
                                         expanded_reporting=False,
                                         chrome_binary=None,
                                         cwd=None,
                                         mocha_fgrep=None):
    if chrome_binary and not test_helpers.check_chrome_binary(chrome_binary):
        print(
            'Chrome binary argument path does not exist or is not executable, reverting to downloaded binary'
        )
        chrome_binary = None

    if not chrome_binary:
        # Default to the downloaded / pinned Chromium binary
        downloaded_chrome_binary = devtools_paths.downloaded_chrome_binary_path(
        )
        if test_helpers.check_chrome_binary(downloaded_chrome_binary):
            chrome_binary = downloaded_chrome_binary

    if (chrome_binary is None):
        print('Unable to run, no Chrome binary provided')
        sys.exit(1)

    print('Using Chromium binary (%s)' % chrome_binary)

    if not cwd:
        cwd = devtools_paths.devtools_root_path()

    print('Running tests from %s\n' % cwd)

    errors_found = run_tests(chrome_binary, target, no_text_coverage,
                             no_html_coverage, coverage, expanded_reporting,
                             cwd, mocha_fgrep)

    if coverage and not no_html_coverage:
        print('')
        print(
            '  You can see the coverage results by opening \033[1mkarma-coverage/index.html\033[0m in a browser'
        )
        print('')

    if errors_found:
        print('ERRORS DETECTED')

        if not expanded_reporting:
            print('')
            print(
                '  Run with \033[1m--expanded-reporting\033[0m to get better information about why the tests failed.'
            )
            print('')
        sys.exit(1)
示例#9
0
def run_tests(chrome_binary, test_suite_list_path):
    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary
    env['TEST_LIST'] = test_suite_list_path

    cwd = devtools_paths.devtools_root_path()
    runner_path = os.path.join(cwd, 'test', 'shared', 'runner.js')
    exec_command = [devtools_paths.node_path(), runner_path]

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code != 0:
        return True

    return False
def parse_options(cli_args):
    parser = argparse.ArgumentParser(description='Run tests')
    parser.add_argument('--chrome-binary',
                        dest='chrome_binary',
                        help='path to Chromium binary')
    parser.add_argument(
        '--test-suite',
        dest='test_suite',
        help=
        'test suite name. DEPRECATED: please use --test-suite-path instead.')
    parser.add_argument(
        '--test-suite-path',
        dest='test_suite_path',
        help=
        'path to test suite, starting from the out/TARGET directory. Should use Linux path separators.'
    )
    parser.add_argument('--test-file',
                        dest='test_file',
                        help='an absolute path for the file to test')
    parser.add_argument(
        '--target',
        '-t',
        default='Default',
        dest='target',
        help='The name of the Ninja output directory. Defaults to "Default"')
    parser.add_argument(
        '--chrome-features',
        dest='chrome_features',
        help=
        'comma separated list of strings passed to --enable-features on the chromium commandline'
    )
    parser.add_argument(
        '--jobs',
        default='1',
        dest='jobs',
        help=
        'The number of parallel runners to use (if supported). Defaults to 1')
    parser.add_argument('--cwd',
                        dest='cwd',
                        help='Path to the directory containing the out dir',
                        default=devtools_paths.devtools_root_path())
    parser.add_argument(
        '--node_modules-path',
        dest='node_modules_path',
        help=
        'Path to the node_modules directory for Node to use. Will use Node defaults if not set.',
        default=None)
    parser.add_argument('test_patterns', nargs='*')
    return parser.parse_args(cli_args)
def run_tests(chrome_binary,
              chrome_features,
              test_suite_path,
              test_suite,
              jobs,
              target,
              cwd=None,
              node_modules_path=None,
              test_patterns=None):
    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary
    if chrome_features:
        env['CHROME_FEATURES'] = chrome_features

    if test_patterns:
        env['TEST_PATTERNS'] = ';'.join(test_patterns)

    if jobs:
        env['JOBS'] = jobs

    if target:
        env['TARGET'] = target

    if node_modules_path is not None:
        # Node requires the path to be absolute
        env['NODE_PATH'] = os.path.abspath(node_modules_path)

    if not cwd:
        cwd = devtools_paths.devtools_root_path()

    exec_command = [devtools_paths.node_path()]

    if 'DEBUG' in env:
        exec_command.append('--inspect')

    exec_command = exec_command + [
        devtools_paths.mocha_path(),
        '--config',
        os.path.join(test_suite_path, '.mocharc.js'),
    ]

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code != 0:
        return True

    return False
示例#12
0
def run_e2e_test(chrome_binary):
    e2e_errors_found = False
    cwd = devtools_paths.devtools_root_path()
    e2e_test_path = os.path.join(cwd, 'test/shared/runner.js')
    e2e_test_list = os.path.join(cwd, 'test/e2e/test-list.js')
    exec_command = [devtools_paths.node_path(), e2e_test_path]

    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary
    env['TEST_LIST'] = e2e_test_list

    e2e_proc = popen(exec_command, cwd=cwd, env=env, capture=True)
    e2e_proc.communicate()
    if e2e_proc.returncode != 0:
        e2e_errors_found = True

    return e2e_errors_found
示例#13
0
def run_boot_perf_test(chrome_binary, runs):
    boot_perf_errors_found = False
    exec_command = [devtools_paths.node_path(), devtools_paths.boot_perf_test_path(), '--progress=false', '--runs=%s' % runs]

    env = os.environ.copy()
    env['CHROME_BIN'] = chrome_binary

    cwd = devtools_paths.devtools_root_path()

    boot_perf_proc = popen(exec_command, cwd=cwd, env=env)
    (boot_perf_proc_out, _) = boot_perf_proc.communicate()

    if boot_perf_proc.returncode != 0:
        boot_perf_errors_found = True

    print(boot_perf_proc_out)
    return boot_perf_errors_found
示例#14
0
def run_tests(chrome_binary):
    cwd = devtools_paths.devtools_root_path()
    karmaconfig_path = os.path.join(cwd, 'karma.conf.js')

    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.karma_path(), 'start',
        test_helpers.to_platform_path_exact(karmaconfig_path)
    ]

    env = os.environ.copy()
    env['NODE_PATH'] = devtools_paths.node_path()
    if (chrome_binary is not None):
        env['CHROME_BIN'] = chrome_binary

    exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
    if exit_code == 1:
        return True

    return False
示例#15
0
def popen(arguments,
          cwd=devtools_paths.devtools_root_path(),
          env=os.environ.copy()):
    process = Popen(arguments, cwd=cwd, env=env)

    def handle_signal(signum, frame):
        print '\nSending signal (%i) to process' % signum
        process.send_signal(signum)
        process.terminate()

    # Propagate sigterm / int to the child process.
    original_sigint = signal.getsignal(signal.SIGINT)
    original_sigterm = signal.getsignal(signal.SIGTERM)
    signal.signal(signal.SIGINT, handle_signal)
    signal.signal(signal.SIGTERM, handle_signal)

    process.communicate()

    # Restore the original sigterm / int handlers.
    signal.signal(signal.SIGINT, original_sigint)
    signal.signal(signal.SIGTERM, original_sigterm)

    return process.returncode
def run_unit_tests_on_ninja_build_target(target,
                                         no_text_coverage=True,
                                         no_html_coverage=True,
                                         coverage=False,
                                         expanded_reporting=False,
                                         chrome_binary=None,
                                         cwd=None):
    if chrome_binary and not test_helpers.check_chrome_binary(chrome_binary):
        print(
            'Chrome binary argument path does not exist or is not executable, reverting to downloaded binary'
        )
        chrome_binary = None

    if not chrome_binary:
        # Default to the downloaded / pinned Chromium binary
        downloaded_chrome_binary = devtools_paths.downloaded_chrome_binary_path(
        )
        if test_helpers.check_chrome_binary(downloaded_chrome_binary):
            chrome_binary = downloaded_chrome_binary

    if (chrome_binary is None):
        print('Unable to run, no Chrome binary provided')
        sys.exit(1)

    print('Using Chromium binary (%s)' % chrome_binary)

    if not cwd:
        cwd = devtools_paths.devtools_root_path()

    print('Running tests from %s\n' % cwd)

    errors_found = run_tests(chrome_binary, target, no_text_coverage,
                             no_html_coverage, coverage, expanded_reporting,
                             cwd)
    if errors_found:
        print('ERRORS DETECTED')
        sys.exit(1)
示例#17
0
def to_platform_path(filepath):
    if not is_cygwin:
        return filepath
    return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath)


def to_platform_path_exact(filepath):
    if not is_cygwin:
        return filepath
    output, _ = popen(['cygpath', '-w', filepath]).communicate()
    # pylint: disable=E1103
    return output.strip().replace('\\', '\\\\')


devtools_path = devtools_paths.devtools_root_path()
devtools_frontend_path = path.join(devtools_path, 'front_end')

print('Linting JavaScript with eslint...\n')


def js_lint(files_list=None):
    eslint_errors_found = False

    if files_list is None:
        files_list = [devtools_frontend_path]
    files_list = [
        file_name for file_name in files_list
        if not file_name.endswith('.eslintrc.js')
    ]
示例#18
0
def to_platform_path(filepath):
    if not is_cygwin:
        return filepath
    return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath)


def to_platform_path_exact(filepath):
    if not is_cygwin:
        return filepath
    output, _ = popen(['cygpath', '-w', filepath]).communicate()
    # pylint: disable=E1103
    return output.strip().replace('\\', '\\\\')


DEVTOOLS_PATH = devtools_paths.devtools_root_path()
SCRIPTS_PATH = path.join(DEVTOOLS_PATH, 'scripts')
ROOT_PATH = devtools_paths.root_path()
BROWSER_PROTOCOL_PATH = devtools_paths.browser_protocol_path()
# TODO(dgozman): move these checks to v8.
JS_PROTOCOL_PATH = path.join(ROOT_PATH, 'v8', 'include', 'js_protocol.pdl')
DEVTOOLS_FRONTEND_PATH = path.join(DEVTOOLS_PATH, 'front_end')
GLOBAL_EXTERNS_FILE = to_platform_path(
    path.join(DEVTOOLS_FRONTEND_PATH, 'externs.js'))
DEFAULT_PROTOCOL_EXTERNS_FILE = path.join(DEVTOOLS_FRONTEND_PATH,
                                          'protocol_externs.js')
WASM_SOURCE_MAP_FILE = path.join(DEVTOOLS_FRONTEND_PATH, 'sdk',
                                 'wasm_source_map', 'types.js')
RUNTIME_FILE = to_platform_path(path.join(DEVTOOLS_FRONTEND_PATH,
                                          'Runtime.js'))
ROOT_MODULE_FILE = to_platform_path(