MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ASSERT_OK_AND_ASSIGN

Function ASSERT_OK_AND_ASSIGN

eval/tests/benchmark_test.cc:284–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282void BM_PolicySymbolic(benchmark::State& state) {
283 google::protobuf::Arena arena;
284 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, parser::Parse(R"cel(
285 !(ip in ["10.0.1.4", "10.0.1.5", "10.0.1.6"]) &&
286 ((path.startsWith("v1") && token in ["v1", "v2", "admin"]) ||
287 (path.startsWith("v2") && token in ["v2", "admin"]) ||
288 (path.startsWith("/admin") && token == "admin" && ip in [
289 "10.0.1.1", "10.0.1.2", "10.0.1.3"
290 ])
291 ))cel"));
292
293 InterpreterOptions options = GetOptions(arena);
294 options.constant_folding = true;
295 options.constant_arena = &arena;
296
297 auto builder = CreateCelExpressionBuilder(options);
298 ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry(), options));
299
300 SourceInfo source_info;
301 ASSERT_OK_AND_ASSIGN(auto cel_expr, builder->CreateExpression(
302 &parsed_expr.expr(), &source_info));
303
304 Activation activation;
305 activation.InsertValue("ip", CelValue::CreateStringView(kIP));
306 activation.InsertValue("path", CelValue::CreateStringView(kPath));
307 activation.InsertValue("token", CelValue::CreateStringView(kToken));
308
309 for (auto _ : state) {
310 ASSERT_OK_AND_ASSIGN(CelValue result,
311 cel_expr->Evaluate(activation, &arena));
312 ASSERT_TRUE(result.BoolOrDie());
313 }
314}
315
316BENCHMARK(BM_PolicySymbolic);
317
318class RequestMap : public CelMap {
319 public:
320 absl::optional<CelValue> operator[](CelValue key) const override {
321 if (!key.IsString()) {
322 return {};
323 }
324 auto value = key.StringOrDie().value();
325 if (value == "ip") {
326 return CelValue::CreateStringView(kIP);
327 } else if (value == "path") {
328 return CelValue::CreateStringView(kPath);
329 } else if (value == "token") {
330 return CelValue::CreateStringView(kToken);
331 }
332 return {};
333 }
334 int size() const override { return 3; }
335 absl::StatusOr<const CelList*> ListKeys() const override {
336 return absl::UnimplementedError("CelMap::ListKeys is not implemented");
337 }
338};
339
340// Uses a lazily constructed map container for "ip", "path", and "token".
341void BM_PolicySymbolicMap(benchmark::State& state) {

Callers 13

TEST_PFunction · 0.70
ABSL_FLAGFunction · 0.70
TESTFunction · 0.50
TESTFunction · 0.50
TESTFunction · 0.50
TEST_FFunction · 0.50
TESTFunction · 0.50
TESTFunction · 0.50
TEST_FFunction · 0.50
TEST_PFunction · 0.50
TEST_FFunction · 0.50
TESTFunction · 0.50

Calls 15

GetOptionsFunction · 0.85
RegisterBuiltinFunctionsFunction · 0.85
ListKeysFunction · 0.85
BM_PolicySymbolicMapFunction · 0.85
GetRegistryMethod · 0.80
InsertValueMethod · 0.80
BoolOrDieMethod · 0.80
StringOrDieMethod · 0.80
IsInt64Method · 0.80
Int64OrDieMethod · 0.80
ParseFunction · 0.50

Tested by

no test coverage detected