diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/build/android/test | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/build/android/test')
6 files changed, 518 insertions, 0 deletions
diff --git a/third_party/libwebrtc/build/android/test/BUILD.gn b/third_party/libwebrtc/build/android/test/BUILD.gn new file mode 100644 index 0000000000..b4bda3d8c4 --- /dev/null +++ b/third_party/libwebrtc/build/android/test/BUILD.gn @@ -0,0 +1,95 @@ +# Copyright 2021 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. + +import("//build/config/android/android_nocompile.gni") +import("missing_symbol_test.gni") +import("nocompile_gn/nocompile_sources.gni") + +if (enable_java_templates) { + group("android_nocompile_tests") { + testonly = true + + # No-compile tests use an output directory dedicated to no-compile tests. + # All test suites use targets in nocompile_gn/BUILD.gn in order to share the + # same target output directory and avoid running 'gn gen' for each + # android_nocompile_test_suite(). + deps = [ + ":android_lint_tests", + ":android_lookup_dep_tests", + ] + } + + android_nocompile_test_suite("android_lint_tests") { + # Depend on lint script so that the action is re-run whenever the script is modified. + pydeps = [ "//build/android/gyp/lint.pydeps" ] + + tests = [ + { + target = "nocompile_gn:default_locale_lint_test" + nocompile_sources = + rebase_path(default_locale_lint_test_nocompile_sources, + "", + "nocompile_gn") + expected_compile_output_regex = "Warning:.*DefaultLocale" + }, + { + target = "nocompile_gn:new_api_lint_test" + nocompile_sources = + rebase_path(new_api_lint_test_nocompile_sources, "", "nocompile_gn") + expected_compile_output_regex = "Error:.*NewApi" + }, + ] + } + + android_nocompile_test_suite("android_lookup_dep_tests") { + sources = [ rebase_path( + missing_symbol_generated_importer_template_nocompile_source, + "", + "nocompile_gn") ] + + tests = [ + { + target = "nocompile_gn:import_child_missing_symbol_test_java" + nocompile_sources = + rebase_path(import_child_missing_symbol_test_nocompile_sources, + "", + "nocompile_gn") + expected_compile_output_regex = "error: package test\.missing_symbol\.sub does not exist\nPlease add //build/android/test/nocompile_gn:sub_b_java dep to //build/android/test/nocompile_gn:import_child_missing_symbol_test_java\." + }, + { + target = "nocompile_gn:import_parent_missing_symbol_test_java" + nocompile_sources = [] + expected_compile_output_regex = "error: cannot find symbol test\.missing_symbol\.B\nPlease add //build/android/test/nocompile_gn:b_java dep to //build/android/test/nocompile_gn:import_parent_missing_symbol_test_java\." + }, + { + target = "nocompile_gn:import_turbine_missing_symbol_test_java" + nocompile_sources = + rebase_path(import_turbine_missing_symbol_test_nocompile_sources, + "", + "nocompile_gn") + expected_compile_output_regex = "error: symbol not found test\.missing_symbol\.B\nPlease add //build/android/test/nocompile_gn:b_java dep to //build/android/test/nocompile_gn:import_turbine_missing_symbol_test_java\." + }, + { + target = "nocompile_gn:prebuilt_missing_symbol_test_java" + nocompile_sources = [] + expected_compile_output_regex = "error: cannot find symbol test\.missing_symbol\.C\nPlease add //build/android/test/nocompile_gn:c_prebuilt_java dep to //build/android/test/nocompile_gn:prebuilt_missing_symbol_test_java\." + }, + { + target = "nocompile_gn:cpp_template_missing_symbol_test_java" + nocompile_sources = [] + expected_compile_output_regex = "error: cannot find symbol test\.missing_symbol\.D\nPlease add //build/android/test/nocompile_gn:d_java dep to //build/android/test/nocompile_gn:cpp_template_missing_symbol_test_java\." + }, + ] + } + + # Tests that builds which use incremental javac are valid. + junit_binary("incremental_javac_junit_tests") { + sources = [ "../java/test/IncrementalJavacTest.java" ] + deps = [ + "incremental_javac_gn:no_signature_change_prebuilt_java", + "//base:base_junit_test_support", + "//third_party/junit", + ] + } +} diff --git a/third_party/libwebrtc/build/android/test/incremental_javac_gn/BUILD.gn b/third_party/libwebrtc/build/android/test/incremental_javac_gn/BUILD.gn new file mode 100644 index 0000000000..18c6374486 --- /dev/null +++ b/third_party/libwebrtc/build/android/test/incremental_javac_gn/BUILD.gn @@ -0,0 +1,98 @@ +# Copyright 2021 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. + +import("//build/config/android/rules.gni") + +declare_args() { + incremental_javac_test_toggle_gn = false +} + +all_test_sources = [ + "../../java/test/NoSignatureChangeIncrementalJavacTestHelper.template", + "../../java/test/NoSignatureChangeIncrementalJavacTestHelper2.java", +] + +template("incremental_javac_prebuilt") { + _out_jar = "${target_gen_dir}/${target_name}.jar" + + action(target_name) { + script = "incremental_javac_test_android_library.py" + forward_variables_from(invoker, + [ + "sources", + "testonly", + ]) + deps = [ invoker.toggle_gn_target ] + + inputs = [] + if (defined(invoker.pydeps)) { + foreach(_pydeps_file, invoker.pydeps) { + _pydeps_file_lines = [] + _pydeps_file_lines = read_file(_pydeps_file, "list lines") + _pydeps_entries = [] + _pydeps_entries = filter_exclude(_pydeps_file_lines, [ "#*" ]) + _pydeps_file_dir = get_path_info(_pydeps_file, "dir") + inputs += rebase_path(_pydeps_entries, ".", _pydeps_file_dir) + } + } + + outputs = [ _out_jar ] + + args = [ + "--target-name", + get_label_info("${invoker.toggle_gn_target}", "label_no_toolchain"), + "--gn-args-path", + "args.gn", + "--out-dir", + rebase_path("${target_out_dir}/${target_name}/incremental_javac_out", + root_build_dir), + "--out-jar", + rebase_path(_out_jar, root_build_dir), + ] + } +} + +# Use jinja_template() instead of java_cpp_template() because incremental builds +# are not done when non-.java files change. +jinja_template("changing_javagen") { + input = "../../java/test/NoSignatureChangeIncrementalJavacTestHelper.template" + assert(filter_include(all_test_sources, [ input ]) != []) + output = + "${target_gen_dir}/test/NoSignatureChangeIncrementalJavacTestHelper.java" + if (incremental_javac_test_toggle_gn) { + variables = [ "foo_return_value=foo2" ] + } else { + variables = [ "foo_return_value=foo" ] + } +} + +android_library("changing_java") { + testonly = true + + # Should not be re-compiled during incremental build. + sources = + [ "../../java/test/NoSignatureChangeIncrementalJavacTestHelper2.java" ] + assert(filter_include(all_test_sources, sources) != []) + + # Should be recompiled during incremental build. + sources += get_target_outputs(":changing_javagen") + deps = [ ":changing_javagen" ] +} + +# Compiles :changing_java with and without |incremental_javac_test_toggle_gn|. +incremental_javac_prebuilt("no_signature_change_prebuilt_generator") { + testonly = true + sources = all_test_sources + toggle_gn_target = ":changing_java" + pydeps = [ "//build/android/gyp/compile_java.pydeps" ] +} + +android_java_prebuilt("no_signature_change_prebuilt_java") { + testonly = true + _generator_outputs = + get_target_outputs(":no_signature_change_prebuilt_generator") + jar_paths = filter_include(_generator_outputs, [ "*.jar" ]) + jar_path = jar_paths[0] + deps = [ ":no_signature_change_prebuilt_generator" ] +} diff --git a/third_party/libwebrtc/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py b/third_party/libwebrtc/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py new file mode 100755 index 0000000000..c84cff0d3b --- /dev/null +++ b/third_party/libwebrtc/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +# +# Copyright 2021 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. +"""Compiles twice: With incremental_javac_test_toggle_gn=[false, true] + +The purpose of compiling the target twice is to test that builds generated by +the incremental build code path are valid. +""" + +import argparse +import os +import pathlib +import subprocess +import shutil + +_CHROMIUM_SRC = pathlib.Path(__file__).resolve().parents[4].resolve() +_NINJA_PATH = _CHROMIUM_SRC / 'third_party' / 'depot_tools' / 'ninja' + +# Relative to _CHROMIUM_SRC +_GN_SRC_REL_PATH = 'third_party/depot_tools/gn' + +_USING_PARTIAL_JAVAC_MSG = 'Using partial javac optimization' + + +def _raise_command_exception(args, returncode, output): + """Raises an exception whose message describes a command failure. + + Args: + args: shell command-line (as passed to subprocess.Popen()) + returncode: status code. + output: command output. + Raises: + a new Exception. + """ + message = ('Command failed with status {}: {}\n' + 'Output:-----------------------------------------\n{}\n' + '------------------------------------------------\n').format( + returncode, args, output) + raise Exception(message) + + +def _run_command(args, check_returncode=True, cwd=None, env=None): + """Runs shell command. Raises exception if command fails.""" + p = subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + cwd=cwd, + env=env, + universal_newlines=True) + pout, _ = p.communicate() + if check_returncode and p.returncode != 0: + _raise_command_exception(args, p.returncode, pout) + return pout + + +def _copy_and_append_gn_args(src_args_path, dest_args_path, extra_args): + """Copies args.gn. + + Args: + src_args_path: args.gn file to copy. + dest_args_path: Copy file destination. + extra_args: Text to append to args.gn after copy. + """ + with open(src_args_path) as f: + initial_args_str = f.read() + + with open(dest_args_path, 'w') as f: + f.write(initial_args_str) + f.write('\n') + + # Write |extra_args| after |initial_args_str| so that |extra_args| + # overwrites |initial_args_str| in the case of duplicate entries. + f.write('\n'.join(extra_args)) + + +def _run_gn(args, check_returncode=True): + _run_command([_GN_SRC_REL_PATH] + args, + check_returncode=check_returncode, + cwd=_CHROMIUM_SRC) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--target-name', + required=True, + help='name of target to build with and without ' + + 'incremental_javac_test_toggle_gn=true') + parser.add_argument('--gn-args-path', + required=True, + help='Path to args.gn file to copy args from.') + parser.add_argument('--out-dir', + required=True, + help='Path to output directory to use for compilation.') + parser.add_argument('--out-jar', + required=True, + help='Path where output jar should be stored.') + options = parser.parse_args() + + options.out_dir = pathlib.Path(options.out_dir).resolve() + + options.out_dir.mkdir(parents=True, exist_ok=True) + + # Clear the output directory so that first compile is not an incremental + # build. + # This will make the test fail in the scenario that: + # - The output directory contains a previous build generated by this script. + # - Incremental builds are broken and are a no-op. + _run_gn(['clean', options.out_dir.relative_to(_CHROMIUM_SRC)], + check_returncode=False) + + out_gn_args_path = options.out_dir / 'args.gn' + extra_gn_args = [ + 'treat_warnings_as_errors = true', + # GOMA does not work with non-standard output directories. + 'use_goma = false', + ] + _copy_and_append_gn_args(options.gn_args_path, out_gn_args_path, + extra_gn_args) + + _run_gn([ + '--root-target=' + options.target_name, 'gen', + options.out_dir.relative_to(_CHROMIUM_SRC) + ]) + + ninja_env = os.environ.copy() + ninja_env['JAVAC_DEBUG'] = '1' + + # Strip leading '//' + gn_path = options.target_name[2:] + ninja_args = [_NINJA_PATH, '-C', options.out_dir, gn_path] + ninja_output = _run_command(ninja_args, env=ninja_env) + if _USING_PARTIAL_JAVAC_MSG in ninja_output: + raise Exception("Incorrectly using partial javac for clean compile.") + + _copy_and_append_gn_args( + options.gn_args_path, out_gn_args_path, + extra_gn_args + ['incremental_javac_test_toggle_gn = true']) + ninja_output = _run_command(ninja_args, env=ninja_env) + if _USING_PARTIAL_JAVAC_MSG not in ninja_output: + raise Exception("Not using partial javac for incremental compile.") + + expected_output_path = "{}/lib.java/{}.jar".format(options.out_dir, + gn_path.replace(':', '/')) + if not os.path.exists(expected_output_path): + raise Exception("{} not created.".format(expected_output_path)) + + shutil.copyfile(expected_output_path, options.out_jar) + + +if __name__ == '__main__': + main() diff --git a/third_party/libwebrtc/build/android/test/missing_symbol_test.gni b/third_party/libwebrtc/build/android/test/missing_symbol_test.gni new file mode 100644 index 0000000000..a11eef3cf6 --- /dev/null +++ b/third_party/libwebrtc/build/android/test/missing_symbol_test.gni @@ -0,0 +1,57 @@ +# Copyright 2021 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. + +import("//build/config/android/android_nocompile.gni") +import("//build/config/android/rules.gni") + +missing_symbol_generated_importer_template_nocompile_source = + "//build/android/java/test/missing_symbol/Importer.template" + +template("missing_symbol_test") { + # Not named "_java" to prevent target from being considered a classpath dep. + _helper_target_name = string_replace("${target_name}__helper", "java", "") + + group(_helper_target_name) { + # Make group() depend on dependencies that |target_name| cannot find so that + # the missing symbol resolver can find and suggest the missing GN dep. + deps = invoker.deps + } + + android_library(target_name) { + sources = [ "//tools/android/errorprone_plugin/test/src/org/chromium/tools/errorprone/plugin/Empty.java" ] + not_needed(invoker, + [ + "sources", + "importer_srcjar_deps", + ]) + if (enable_android_nocompile_tests) { + if (defined(invoker.sources)) { + sources += invoker.sources + } + if (defined(invoker.importer_srcjar_deps)) { + srcjar_deps = invoker.importer_srcjar_deps + } + } + + deps = [ ":${_helper_target_name}" ] + } +} + +# missing_symbol_test() template wrapper which generates importer class. +template("missing_symbol_generated_importer_test") { + _importer_generator_target = "${target_name}__importer_javagen" + java_cpp_template(_importer_generator_target) { + sources = [ missing_symbol_generated_importer_template_nocompile_source ] + defines = [ + "_IMPORTER_PACKAGE=${invoker.importer_package}", + "_IMPORTEE_PACKAGE=${invoker.imported_package}", + "_IMPORTEE_CLASS_NAME=${invoker.imported_class_name}", + ] + } + + missing_symbol_test(target_name) { + importer_srcjar_deps = [ ":${_importer_generator_target}" ] + forward_variables_from(invoker, [ "deps" ]) + } +} diff --git a/third_party/libwebrtc/build/android/test/nocompile_gn/BUILD.gn b/third_party/libwebrtc/build/android/test/nocompile_gn/BUILD.gn new file mode 100644 index 0000000000..11feef6a4c --- /dev/null +++ b/third_party/libwebrtc/build/android/test/nocompile_gn/BUILD.gn @@ -0,0 +1,101 @@ +# Copyright 2021 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. + +import("//build/android/test/missing_symbol_test.gni") +import("//build/config/android/android_nocompile.gni") +import("//build/config/android/rules.gni") +import("nocompile_sources.gni") + +template("lint_test") { + _library_target_name = "${target_name}_test_java" + _apk_target_name = "${target_name}_apk" + + android_library(_library_target_name) { + sources = [ "//tools/android/errorprone_plugin/test/src/org/chromium/tools/errorprone/plugin/Empty.java" ] + not_needed(invoker, [ "sources" ]) + if (enable_android_nocompile_tests) { + sources += invoker.sources + } + } + + android_apk(_apk_target_name) { + # This cannot be marked testonly since lint has special ignores for testonly + # targets. We need to test linting a normal apk target. + apk_name = _apk_target_name + deps = [ ":$_library_target_name" ] + android_manifest = "//build/android/AndroidManifest.xml" + } + + android_lint(target_name) { + _apk_target = ":${_apk_target_name}" + deps = [ "${_apk_target}__java" ] + build_config_dep = "$_apk_target$build_config_target_suffix" + build_config = get_label_info(_apk_target, "target_gen_dir") + "/" + + get_label_info(_apk_target, "name") + ".build_config.json" + if (enable_android_nocompile_tests) { + skip_build_server = true + } + } +} + +lint_test("default_locale_lint_test") { + sources = default_locale_lint_test_nocompile_sources +} + +lint_test("new_api_lint_test") { + sources = new_api_lint_test_nocompile_sources +} + +missing_symbol_generated_importer_test( + "import_parent_missing_symbol_test_java") { + importer_package = "test.missing_symbol.child_missing" + imported_package = "test.missing_symbol" + imported_class_name = "B" + deps = [ ":b_java" ] +} + +missing_symbol_test("import_child_missing_symbol_test_java") { + sources = import_child_missing_symbol_test_nocompile_sources + deps = [ ":sub_b_java" ] +} + +missing_symbol_test("import_turbine_missing_symbol_test_java") { + sources = import_turbine_missing_symbol_test_nocompile_sources + deps = [ ":b_java" ] +} + +missing_symbol_generated_importer_test("prebuilt_missing_symbol_test_java") { + importer_package = "test.missing_symbol.prebuilt_missing" + imported_package = "test.missing_symbol" + imported_class_name = "C" + deps = [ ":c_prebuilt_java" ] +} + +missing_symbol_generated_importer_test( + "cpp_template_missing_symbol_test_java") { + importer_package = "test.missing_symbol.cpp_template_missing" + imported_package = "test.missing_symbol" + imported_class_name = "D" + deps = [ ":d_java" ] +} + +android_library("b_java") { + sources = [ "../../java/test/missing_symbol/B.java" ] +} + +android_library("sub_b_java") { + sources = [ "../../java/test/missing_symbol/sub/SubB.java" ] +} + +android_java_prebuilt("c_prebuilt_java") { + jar_path = "../../java/test/missing_symbol/c.jar" +} + +android_library("d_java") { + srcjar_deps = [ ":d_template_javagen" ] +} + +java_cpp_template("d_template_javagen") { + sources = [ "../../java/test/missing_symbol/D.template" ] +} diff --git a/third_party/libwebrtc/build/android/test/nocompile_gn/nocompile_sources.gni b/third_party/libwebrtc/build/android/test/nocompile_gn/nocompile_sources.gni new file mode 100644 index 0000000000..1338f19cd9 --- /dev/null +++ b/third_party/libwebrtc/build/android/test/nocompile_gn/nocompile_sources.gni @@ -0,0 +1,14 @@ +# Copyright 2021 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. + +default_locale_lint_test_nocompile_sources = + [ "../../java/test/DefaultLocaleLintTest.java" ] + +new_api_lint_test_nocompile_sources = [ "../../java/test/NewApiLintTest.java" ] + +import_child_missing_symbol_test_nocompile_sources = + [ "../../java/test/missing_symbol/ImportsSubB.java" ] + +import_turbine_missing_symbol_test_nocompile_sources = + [ "../../java/test/missing_symbol/sub/BInMethodSignature.java" ] |