| 103 | } |
| 104 | |
| 105 | void BM_SymbolicPolicy(benchmark::State& state) { |
| 106 | auto param = static_cast<BenchmarkParam>(state.range(0)); |
| 107 | state.SetLabel(LabelForParam(param)); |
| 108 | |
| 109 | ASSERT_OK_AND_ASSIGN(ParsedExpr expr, parser::Parse(R"cel( |
| 110 | !(request.ip in ["10.0.1.4", "10.0.1.5", "10.0.1.6"]) && |
| 111 | ((request.path.startsWith("v1") && request.token in ["v1", "v2", "admin"]) || |
| 112 | (request.path.startsWith("v2") && request.token in ["v2", "admin"]) || |
| 113 | (request.path.startsWith("/admin") && request.token == "admin" && |
| 114 | request.ip in ["10.0.1.1", "10.0.1.2", "10.0.1.3"]) |
| 115 | ))cel")); |
| 116 | |
| 117 | google::protobuf::Arena arena; |
| 118 | InterpreterOptions options = OptionsForParam(param, arena); |
| 119 | |
| 120 | auto builder = CreateCelExpressionBuilder(options); |
| 121 | auto reg_status = RegisterBuiltinFunctions(builder->GetRegistry()); |
| 122 | ASSERT_OK(reg_status); |
| 123 | |
| 124 | for (auto _ : state) { |
| 125 | ASSERT_OK_AND_ASSIGN( |
| 126 | auto expression, |
| 127 | builder->CreateExpression(&expr.expr(), &expr.source_info())); |
| 128 | arena.Reset(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | BENCHMARK(BM_SymbolicPolicy) |
| 133 | ->Arg(BenchmarkParam::kDefault) |
| 134 | ->Arg(BenchmarkParam::kFoldConstants) |
| 135 | ->Arg(BenchmarkParam::kRecursivePlanning) |
| 136 | ->Arg(BenchmarkParam::kRecursivePlanningWithConstantFolding); |
| 137 | |
| 138 | absl::StatusOr<std::unique_ptr<CelExpressionBuilder>> MakeBuilderForEnums( |
| 139 | absl::string_view container, absl::string_view enum_type, |
| 140 | int num_enum_values) { |
| 141 | auto builder = |
| 142 | CreateCelExpressionBuilder(cel::GetMinimalDescriptorPool(), nullptr, {}); |
| 143 | builder->set_container(std::string(container)); |
| 144 | CelTypeRegistry* type_registry = builder->GetTypeRegistry(); |
| 145 | std::vector<CelTypeRegistry::Enumerator> enumerators; |
| 146 | enumerators.reserve(num_enum_values); |
| 147 | for (int i = 0; i < num_enum_values; ++i) { |
| 148 | enumerators.push_back( |
| 149 | CelTypeRegistry::Enumerator{absl::StrCat("ENUM_VALUE_", i), i}); |
| 150 | } |
| 151 | type_registry->RegisterEnum(enum_type, std::move(enumerators)); |
| 152 | |
| 153 | CEL_RETURN_IF_ERROR(RegisterBuiltinFunctions(builder->GetRegistry())); |
| 154 | return builder; |
| 155 | } |
| 156 | |
| 157 | void BM_EnumResolutionSimple(benchmark::State& state) { |
| 158 | static const CelExpressionBuilder* builder = []() { |
| 159 | auto builder = MakeBuilderForEnums("", "com.example.TestEnum", 4); |
| 160 | ABSL_CHECK_OK(builder.status()); |
| 161 | return builder->release(); |
| 162 | }(); |
nothing calls this directly
no test coverage detected