Commit 0bf37764 authored by gunsch's avatar gunsch Committed by Commit bot

Chromecast: test support for builders.

Adds GYP targets that dictate which tests should be run on the
builders, and scripts to generate lists of the targets and commands
to run (with filters or other options as needed).

R=lcwu@chromium.org,gusfernandez@chromium.org
BUG=409163

Review URL: https://codereview.chromium.org/719353005

Cr-Commit-Position: refs/heads/master@{#304963}
parent 9f536990
# Copyright 2014 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.
{
'variables': {
'variables': {
'variables': {
# Note: priority can be set from 1 to 9 to indicate precedence for
# filters (larger overrides smaller).
'priority%': 1,
'test_output_folder': '<(SHARED_INTERMEDIATE_DIR)/chromecast/tests',
},
# Copy from previous level.
'test_output_folder': '<(test_output_folder)',
'test_output_file_prefix':
'<(test_output_folder)/<(priority)-<(_target_name)',
},
# Copy from previous level.
'test_output_folder': '<(test_output_folder)',
'test_filters_output_file': '<(test_output_file_prefix).filters',
'test_generator_py': '<(DEPTH)/chromecast/tools/build/generate_test_lists.py',
'test_list_output_file': '<(test_output_file_prefix).tests',
'filters%': [],
},
'actions': [
{
'action_name': 'generate_test_list',
'inputs': ['<(test_generator_py)'],
'outputs': ['<(test_list_output_file)'],
'message': 'Generating test list from <(_target_name)',
'action': [
'python', '<@(_inputs)',
'-o', '<(test_list_output_file)',
'create_list',
'<@(_dependencies)'
],
},
{
'action_name': 'generate_filter_list',
'inputs': ['<(test_generator_py)'],
'outputs': ['<(test_filters_output_file)'],
'message': 'Generating filter list from <(_target_name)',
'action': [
'python', '<@(_inputs)',
'-o', '<(test_filters_output_file)',
'create_list',
'<@(filters)'
],
},
],
}
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
'chromium_code': 1, 'chromium_code': 1,
'chromecast_branding%': 'Chromium', 'chromecast_branding%': 'Chromium',
}, },
'includes': [
'chromecast_tests.gypi',
],
'target_defaults': { 'target_defaults': {
'include_dirs': [ 'include_dirs': [
'..', # Root of Chromium checkout '..', # Root of Chromium checkout
...@@ -247,24 +250,6 @@ ...@@ -247,24 +250,6 @@
}, },
], ],
}, },
{
'target_name': 'cast_metrics_test_support',
'type': '<(component)',
'dependencies': [
'cast_base',
],
'sources': [
'base/metrics/cast_metrics_test_helper.cc',
'base/metrics/cast_metrics_test_helper.h',
],
}, # end of target 'cast_metrics_test_support'
{
'target_name': 'cast_tests',
'type': 'none',
'dependencies': [
'media/media.gyp:cast_media_unittests',
],
},
], # end of targets ], # end of targets
# Targets for Android receiver. # Targets for Android receiver.
...@@ -447,37 +432,6 @@ ...@@ -447,37 +432,6 @@
'app/cast_main.cc', 'app/cast_main.cc',
], ],
}, },
{
'target_name': 'cast_shell_browser_test',
'type': '<(gtest_target_type)',
'dependencies': [
'cast_shell_test_support',
'../testing/gtest.gyp:gtest',
],
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'sources': [
'browser/test/chromecast_shell_browser_test.cc',
],
},
{
'target_name': 'cast_shell_test_support',
'type': '<(component)',
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'dependencies': [
'cast_shell_core',
'../content/content_shell_and_tests.gyp:content_browser_test_support',
'../testing/gtest.gyp:gtest',
],
'sources': [
'browser/test/chromecast_browser_test.cc',
'browser/test/chromecast_browser_test.h',
'browser/test/chromecast_browser_test_runner.cc',
],
},
], # end of targets ], # end of targets
}], }],
], # end of conditions ], # end of conditions
......
# Copyright (c) 2014 Google Inc. All Rights Reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'cast_tests',
'type': 'none',
'dependencies': [
'cast_test_generator',
],
'conditions': [
['chromecast_branding=="Chrome"', {
'dependencies': [
'<(cast_internal_gyp):cast_tests_internal',
],
}],
],
},
# This target only depends on targets that generate test binaries.
{
'target_name': 'cast_test_generator',
'type': 'none',
'dependencies': [
'media/media.gyp:cast_media_unittests',
'../base/base.gyp:base_unittests',
'../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation_unittests',
'../content/content_shell_and_tests.gyp:content_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/media.gyp:media_unittests',
'../net/net.gyp:net_unittests',
'../sandbox/sandbox.gyp:sandbox_linux_unittests',
'../sql/sql.gyp:sql_unittests',
'../sync/sync.gyp:sync_unit_tests',
'../ui/base/ui_base_tests.gyp:ui_base_unittests',
'../url/url.gyp:url_unittests',
],
'conditions': [
['OS!="android"', {
'dependencies': [
'cast_shell_browser_test',
'cast_shell_unittests',
],
}],
],
'includes': ['build/tests/test_list.gypi'],
},
# Builds all tests and the output lists of build/run targets for those tests.
# Note: producing a predetermined list of dependent inputs on which to
# regenerate this output is difficult with GYP. This file is not
# guaranteed to be regenerated outside of a clean build.
{
'target_name': 'cast_test_lists',
'type': 'none',
'dependencies': [
'cast_tests',
],
'variables': {
'test_generator_py': '<(DEPTH)/chromecast/tools/build/generate_test_lists.py',
'test_inputs_dir': '<(SHARED_INTERMEDIATE_DIR)/chromecast/tests',
'test_additional_options': '--ozone-platform=test'
},
'actions': [
{
'action_name': 'generate_combined_test_build_list',
'message': 'Generating combined test build list',
'inputs': ['<(test_generator_py)'],
'outputs': ['<(PRODUCT_DIR)/tests/build_test_list.txt'],
'action': [
'python', '<(test_generator_py)',
'-t', '<(test_inputs_dir)',
'-o', '<@(_outputs)',
'pack_build',
],
},
{
'action_name': 'generate_combined_test_run_list',
'message': 'Generating combined test run list',
'inputs': ['<(test_generator_py)'],
'outputs': ['<(PRODUCT_DIR)/tests/run_test_list.txt'],
'action': [
'python', '<(test_generator_py)',
'-t', '<(test_inputs_dir)',
'-o', '<@(_outputs)',
'-a', '<(test_additional_options)',
'pack_run',
],
}
],
},
{
'target_name': 'cast_metrics_test_support',
'type': '<(component)',
'dependencies': [
'cast_base',
],
'sources': [
'base/metrics/cast_metrics_test_helper.cc',
'base/metrics/cast_metrics_test_helper.h',
],
}, # end of target 'cast_metrics_test_support'
], # end of targets
'conditions': [
['OS=="android"', {
'targets': [
{
'target_name': 'cast_android_tests',
'type': 'none',
'dependencies': [
'../base/base.gyp:base_unittests_apk',
'../cc/cc_tests.gyp:cc_unittests_apk',
'../ipc/ipc.gyp:ipc_tests_apk',
'../media/media.gyp:media_unittests_apk',
'../net/net.gyp:net_unittests_apk',
'../sandbox/sandbox.gyp:sandbox_linux_jni_unittests_apk',
'../sql/sql.gyp:sql_unittests_apk',
'../sync/sync.gyp:sync_unit_tests_apk',
'../ui/events/events.gyp:events_unittests_apk',
'../ui/gfx/gfx_tests.gyp:gfx_unittests_apk',
],
'includes': ['build/tests/test_list.gypi'],
},
{
'target_name': 'cast_android_test_lists',
'type': 'none',
'dependencies': [
'cast_android_tests',
],
'variables': {
'test_generator_py': '<(DEPTH)/chromecast/tools/build/generate_test_lists.py',
'test_inputs_dir': '<(SHARED_INTERMEDIATE_DIR)/chromecast/tests',
},
'actions': [
{
'action_name': 'generate_combined_test_build_list',
'message': 'Generating combined test build list',
'inputs': ['<(test_generator_py)'],
'outputs': ['<(PRODUCT_DIR)/tests/build_test_list_android.txt'],
'action': [
'python', '<(test_generator_py)',
'-t', '<(test_inputs_dir)',
'-o', '<@(_outputs)',
'pack_build',
],
},
],
},
], # end of targets
}, { # OS!="android"
'targets': [
{
'target_name': 'cast_shell_test_support',
'type': '<(component)',
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'dependencies': [
'cast_shell_core',
'../content/content_shell_and_tests.gyp:content_browser_test_support',
'../testing/gtest.gyp:gtest',
],
'sources': [
'browser/test/chromecast_browser_test.cc',
'browser/test/chromecast_browser_test.h',
'browser/test/chromecast_browser_test_runner.cc',
],
}, # end of target 'cast_shell_test_support'
{
'target_name': 'cast_shell_browser_test',
'type': '<(gtest_target_type)',
'dependencies': [
'cast_shell_test_support',
'../testing/gtest.gyp:gtest',
],
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'sources': [
'browser/test/chromecast_shell_browser_test.cc',
],
},
{
'target_name': 'cast_shell_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
'cast_shell_core',
'../base/base.gyp:base_prefs_test_support',
'../base/base.gyp:run_all_unittests',
'../base/base.gyp:test_support_base',
'../components/components.gyp:component_metrics_proto',
'../testing/gtest.gyp:gtest',
],
'sources': [
'browser/metrics/cast_metrics_service_client_unittest.cc',
],
'conditions': [
['use_allocator!="none"', {
'dependencies': [
'../base/allocator/allocator.gyp:allocator',
],
}],
]
}, # end of target 'cast_shell_unittests'
], # end of targets
}],
], # end of conditions
}
#!/usr/bin/env python
# Copyright 2014 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.
"""Helper script to generate unit test lists for the Chromecast build scripts.
"""
import glob
import optparse
import sys
def CombineList(test_files_dir, list_output_file, include_filters,
additional_runtime_options):
"""Writes a unit test file in a format compatible for Chromecast scripts.
If include_filters is True, uses filters to create a test runner list
and also include additional options, if any.
Otherwise, creates a list only of the tests to build.
Args:
test_files_dir: Path to the intermediate directory containing tests/filters.
list_output_file: Path to write the unit test file out to.
include_filters: Whether or not to include the filters when generating
the test list.
"""
# GYP targets may provide a numbered priority for the filename. Sort to
# use that priority.
test_files = sorted(glob.glob(test_files_dir + "/*.tests"))
filter_files = sorted(glob.glob(test_files_dir + "/*.filters"))
test_bin_set = set()
for test_filename in test_files:
with open(test_filename, "r") as test_file:
for test_file_line in test_file:
# Binary name may be a simple test target (cast_net_unittests) or be a
# qualified gyp path (../base.gyp:base_unittests).
test_binary_name = test_file_line.split(":")[-1].strip()
test_bin_set.add(test_binary_name)
test_filters = {}
if include_filters:
for filter_filename in filter_files:
with open(filter_filename, "r") as filter_file:
for filter_line in filter_file:
filter = filter_line.strip()
test_binary_name = filter.split(" ", 1)[0]
if test_binary_name not in test_bin_set:
raise Exception("Filter found for unknown target: " +
test_binary_name)
# Note: This may overwrite a previous rule. This is okay, since higher
# priority files are evaluated after lower priority files.
test_filters[test_binary_name] = filter
test_binaries = (
list(test_bin_set - set(test_filters.keys())) +
test_filters.values())
if additional_runtime_options:
lines = [
binary + " " + additional_runtime_options
for binary in test_binaries
]
else:
lines = test_binaries
with open(list_output_file, "w") as f:
f.write("\n".join(sorted(lines)))
def CreateList(inputs, list_output_file):
with open(list_output_file, "w") as f:
f.write("\n".join(inputs))
def DoMain(argv):
"""Main method. Runs helper commands for generating unit test lists."""
parser = optparse.OptionParser(
"""usage: %prog [<options>] <command> [<test names>]
Valid commands:
create_list prints all given test names/args to a file, one line
per string
pack_build packs all test files from the given output directory
into a single test list file
pack_run packs all test and filter files from the given
output directory into a single test list file
""")
parser.add_option("-o", action="store", dest="list_output_file",
help="Output path in which to write the test list.")
parser.add_option("-t", action="store", dest="test_files_dir",
help="Intermediate test list directory.")
parser.add_option("-a", action="store", dest="additional_runtime_options",
help="Additional options applied to all tests.")
options, inputs = parser.parse_args(argv)
list_output_file = options.list_output_file
test_files_dir = options.test_files_dir
additional_runtime_options = options.additional_runtime_options
if len(inputs) < 1:
parser.error("No command given.\n")
command = inputs[0]
test_names = inputs[1:]
if not list_output_file:
parser.error("Output path (-o) is required.\n")
if command == "create_list":
return CreateList(test_names, list_output_file)
if command == "pack_build":
if not test_files_dir:
parser.error("pack_build require a test files directory (-t).\n")
return CombineList(test_files_dir, list_output_file, False, None)
if command == "pack_run":
if not test_files_dir:
parser.error("pack_run require a test files directory (-t).\n")
return CombineList(test_files_dir, list_output_file, True,
additional_runtime_options)
parser.error("Invalid command specified.")
if __name__ == "__main__":
DoMain(sys.argv[1:])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment