From 6ee7a647bf25bfc720f8d2bcf74294f8320d919c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 6 Sep 2022 12:16:54 -0700 Subject: [PATCH] [experiments] Add support for testing disabling already enabled experiments (#30831) --- bazel/experiments.bzl | 3 +++ bazel/grpc_build_system.bzl | 29 ++++++++++++++++++++++++++- tools/codegen/core/gen_experiments.py | 17 ++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/bazel/experiments.bzl b/bazel/experiments.bzl index 9f116cefd15..5acd6f60a59 100644 --- a/bazel/experiments.bzl +++ b/bazel/experiments.bzl @@ -28,3 +28,6 @@ EXPERIMENTS = { "tcp_read_chunks", ], } + +NEGATED_EXPERIMENTS = { +} diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 4c59d5aa4f1..fc388e9f0c6 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -29,7 +29,7 @@ Contains macros used throughout the repo. load("//bazel:cc_grpc_library.bzl", "cc_grpc_library") load("//bazel:copts.bzl", "GRPC_DEFAULT_COPTS") -load("//bazel:experiments.bzl", "EXPERIMENTS") +load("//bazel:experiments.bzl", "EXPERIMENTS", "NEGATED_EXPERIMENTS") load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library", "upb_proto_reflection_library") load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") load("@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", "ios_test_runner") @@ -336,6 +336,14 @@ def expand_tests(name, srcs, deps, tags, args, exclude_pollers, uses_event_engin experiments[experiment] = 1 experiments = list(experiments.keys()) + negated_experiments = {} + for tag in tags: + if tag not in NEGATED_EXPERIMENTS: + continue + for experiment in NEGATED_EXPERIMENTS[tag]: + negated_experiments[experiment] = 1 + negated_experiments = list(negated_experiments.keys()) + experiment_config = list(poller_config) for experiment in experiments: for config in poller_config: @@ -356,6 +364,25 @@ def expand_tests(name, srcs, deps, tags, args, exclude_pollers, uses_event_engin tags = tags + [tag] config["tags"] = tags experiment_config.append(config) + for experiment in negated_experiments: + for config in poller_config: + config = dict(config) + config["name"] = config["name"] + "@experiment=no_" + experiment + config["args"] = config["args"] + ["--experiment=-" + experiment] + tags = config["tags"] + must_have_tags = [ + # We don't run experiments on cmake builds + "bazel_only", + # Nor on windows + "no_windows", + # Nor on mac + "no_mac", + ] + for tag in must_have_tags: + if tag not in tags: + tags = tags + [tag] + config["tags"] = tags + experiment_config.append(config) return experiment_config diff --git a/tools/codegen/core/gen_experiments.py b/tools/codegen/core/gen_experiments.py index 0cbe5d14745..8b131ce758a 100755 --- a/tools/codegen/core/gen_experiments.py +++ b/tools/codegen/core/gen_experiments.py @@ -187,9 +187,14 @@ with open('src/core/lib/experiments/experiments.cc', 'w') as C: print("} // namespace grpc_core", file=C) tags_to_experiments = collections.defaultdict(list) +tags_to_negated_experiments = collections.defaultdict(list) for attr in attrs: - for tag in attr['test_tags']: - tags_to_experiments[tag].append(attr['name']) + if attr['default']: + for tag in attr['test_tags']: + tags_to_negated_experiments[tag].append(attr['name']) + else: + for tag in attr['test_tags']: + tags_to_experiments[tag].append(attr['name']) with open('bazel/experiments.bzl', 'w') as B: put_copyright(B, "#") @@ -211,3 +216,11 @@ with open('bazel/experiments.bzl', 'w') as B: print(" \"%s\"," % experiment, file=B) print(" ],", file=B) print("}", file=B) + print(file=B) + print("NEGATED_EXPERIMENTS = {", file=B) + for tag, experiments in sorted(tags_to_negated_experiments.items()): + print(" \"%s\": [" % tag, file=B) + for experiment in sorted(experiments): + print(" \"%s\"," % experiment, file=B) + print(" ],", file=B) + print("}", file=B)