Migrate batch 8 of CcBinaryThinLtoTest to Starlark Migrate Cache Prefetch and Error tests: - testFdoCachePrefetchLLVMOptionsToBackendFromLabel - testFdoCachePrefetchAndFdoLLVMOptionsToBackendFromLabel - testThinLtoWithoutSupportsStartEndLibError PiperOrigin-RevId: 963363830 Change-Id: I1403452b645f3734944c787b7e95bce7470a7743
diff --git a/tests/cc/common/cc_binary_thin_lto_tests.bzl b/tests/cc/common/cc_binary_thin_lto_tests.bzl index 88df76c..9c907b5 100644 --- a/tests/cc/common/cc_binary_thin_lto_tests.bzl +++ b/tests/cc/common/cc_binary_thin_lto_tests.bzl
@@ -7,6 +7,7 @@ load("//cc:cc_binary.bzl", _actual_cc_binary = "cc_binary") load("//cc:cc_library.bzl", "cc_library") load("//cc:cc_test.bzl", _actual_cc_test = "cc_test") +load("//cc/toolchains:fdo_prefetch_hints.bzl", "fdo_prefetch_hints") load("//cc/toolchains:fdo_profile.bzl", "fdo_profile") load("//cc/toolchains:propeller_optimize.bzl", "propeller_optimize") load("//tests/cc/testutil:cc_analysis_test.bzl", "cc_analysis_test") @@ -2103,6 +2104,117 @@ backend_action.inputs().contains_predicate(matching.file_basename_equals("cc_profile.txt")) backend_action.inputs().contains_predicate(matching.file_basename_equals("ld_profile.txt")) +def _test_no_use_lto_indexing_bitcode_file(name, **kwargs): + _create_thin_lto_basic_targets(name) + cc_analysis_test( + name = name, + impl = _test_no_use_lto_indexing_bitcode_file_impl, + target = name + "/bin", + test_features = [ + "thin_lto", + "supports_pic", + "supports_start_end_lib", + "no_use_lto_indexing_bitcode_file", + ], + **kwargs + ) + +def _test_no_use_lto_indexing_bitcode_file_impl(env, target): + test_name = target.label.name.split("/")[0] + lib_name = test_name + "/lib" + + binary_obj_path = "{package}/{name}.lto/{bindir}/{package}/_objs/{name}/binfile.pic.o".format( + package = target.label.package, + name = target.label.name, + bindir = target[TestingAspectInfo].bin_path, + ) + + backend_action = env.expect.that_target(target).action_generating(binary_obj_path) + backend_action.mnemonic().equals("CcLtoBackendCompile") + + index_action = env.expect.that_target(target).action_generating(binary_obj_path + ".thinlto.bc") + index_action.mnemonic().equals("CppLTOIndexing") + + index_action.argv().not_contains("object_suffix_replace") + + binary_normal_obj = "{package}/_objs/{name}/binfile.pic.o".format( + package = target.label.package, + name = target.label.name, + ) + lib_normal_obj = "{package}/_objs/{lib_name}/libfile.pic.o".format( + package = target.label.package, + lib_name = lib_name, + ) + index_action.inputs().contains(binary_normal_obj) + index_action.inputs().contains(lib_normal_obj) + + bitcode_action = env.expect.that_target(target).action_generating(binary_normal_obj) + bitcode_action.mnemonic().equals("CppCompile") + bitcode_action.argv().not_contains("lto_indexing_bitcode=") + +def _test_fdo_cache_prefetch_llvm_options_to_backend_base(name, extra_config_settings, **kwargs): + util.helper_target( + fdo_prefetch_hints, + name = name + "/test_profile", + profile = "prefetch.afdo", + ) + _create_thin_lto_basic_targets(name) + config_settings = { + "//command_line_option:fdo_prefetch_hints": Label(":" + name + "/test_profile"), + "//command_line_option:compilation_mode": "opt", + } + config_settings.update(extra_config_settings) + cc_analysis_test( + name = name, + impl = _test_fdo_cache_prefetch_llvm_options_to_backend_impl, + target = name + "/bin", + with_features = ["thin_lto", "autofdo", "supports_start_end_lib", "fdo_prefetch_hints"], + test_features = ["thin_lto", "supports_start_end_lib", "fdo_prefetch_hints"], + config_settings = config_settings, + **kwargs + ) + +def _test_fdo_cache_prefetch_llvm_options_to_backend_impl(env, target): + obj_path = "{package}/{name}.lto/{bindir}/{package}/_objs/{name}/binfile.o".format( + package = target.label.package, + name = target.label.name, + bindir = target[TestingAspectInfo].bin_path, + ) + + backend_action = env.expect.that_target(target).action_generating(obj_path) + backend_action.mnemonic().equals("CcLtoBackendCompile") + + backend_action.argv().contains("-mllvm") + backend_action.argv().contains_predicate(matching.str_matches("*-prefetch-hints-file=*/prefetch.afdo")) + backend_action.inputs().contains_predicate(matching.file_basename_equals("prefetch.afdo")) + +def _test_fdo_cache_prefetch_llvm_options_to_backend_from_label(name, **kwargs): + _test_fdo_cache_prefetch_llvm_options_to_backend_base(name, [], **kwargs) + +def _test_fdo_cache_prefetch_and_fdo_llvm_options_to_backend_from_label(name, **kwargs): + _test_fdo_cache_prefetch_llvm_options_to_backend_base( + name, + [("//command_line_option:fdo_optimize", "/profile.zip")], + **kwargs + ) + +def _test_thin_lto_without_supports_start_end_lib_error(name, **kwargs): + _create_thin_lto_basic_targets(name) + cc_analysis_test( + name = name, + impl = _test_thin_lto_without_supports_start_end_lib_error_impl, + target = name + "/bin", + with_features = ["thin_lto"], + test_features = ["thin_lto"], + expect_failure = True, + **kwargs + ) + +def _test_thin_lto_without_supports_start_end_lib_error_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.contains("The feature supports_start_end_lib must be enabled."), + ) + def cc_binary_thin_lto_tests(name): """TestSuite for cc_binary with ThinLTO. @@ -2148,6 +2260,10 @@ tests.append(_test_propeller_cc_compile_with_propeller_optimize_thin_lto_compile_actions) tests.append(_test_propeller_cc_compile_with_thin_lto_disabled) tests.append(_test_propeller_host_builds) + tests.append(_test_no_use_lto_indexing_bitcode_file) + tests.append(_test_fdo_cache_prefetch_llvm_options_to_backend_from_label) + tests.append(_test_fdo_cache_prefetch_and_fdo_llvm_options_to_backend_from_label) + tests.append(_test_thin_lto_without_supports_start_end_lib_error) # These tests fail on Bazel 7 and 8, run only for Bazel 9+. if bazel_features.cc.cc_common_is_in_rules_cc:
diff --git a/tests/cc/testutil/toolchains/cc_toolchain_config.bzl b/tests/cc/testutil/toolchains/cc_toolchain_config.bzl index 9719058..79e5da2 100644 --- a/tests/cc/testutil/toolchains/cc_toolchain_config.bzl +++ b/tests/cc/testutil/toolchains/cc_toolchain_config.bzl
@@ -1701,9 +1701,31 @@ _propeller_optimize_thinlto_compile_actions_feature = feature( name = FEATURE_NAMES.propeller_optimize_thinlto_compile_actions, ) +_fdo_prefetch_hints_feature = feature( + name = FEATURE_NAMES.fdo_prefetch_hints, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.lto_backend, + ], + flag_groups = [ + flag_group( + flags = [ + "-mllvm", + "-prefetch-hints-file=%{fdo_prefetch_hints_path}", + ], + expand_if_available = "fdo_prefetch_hints_path", + ), + ], + ), + ], +) _feature_name_to_feature = { FEATURE_NAMES.force_pic_flags: _force_pic_flags_feature, FEATURE_NAMES.libraries_to_link: _libraries_to_link_feature, + FEATURE_NAMES.fdo_prefetch_hints: _fdo_prefetch_hints_feature, FEATURE_NAMES.propeller_optimize: _propeller_optimize_feature, FEATURE_NAMES.propeller_optimize_thinlto_compile_actions: _propeller_optimize_thinlto_compile_actions_feature, FEATURE_NAMES.cpp_modules: _cpp_modules_feature,
diff --git a/tests/cc/testutil/toolchains/features.bzl b/tests/cc/testutil/toolchains/features.bzl index 91f476f..6ded051 100644 --- a/tests/cc/testutil/toolchains/features.bzl +++ b/tests/cc/testutil/toolchains/features.bzl
@@ -103,6 +103,7 @@ libraries_to_link = "libraries_to_link", propeller_optimize = "propeller_optimize", propeller_optimize_thinlto_compile_actions = "propeller_optimize_thinlto_compile_actions", + fdo_prefetch_hints = "fdo_prefetch_hints", uses_output_execpath = "uses_output_execpath", uses_is_cc_test = "uses_is_cc_test", uses_strip_debug_symbols = "uses_strip_debug_symbols",