Lines Matching refs:ctx
61 static int test(struct expr_parse_ctx *ctx, const char *e, double val2) in test() argument
65 if (expr__parse(&val, ctx, e)) in test()
77 struct expr_parse_ctx *ctx; in test__expr() local
87 ctx = expr__ctx_new(); in test__expr()
88 TEST_ASSERT_VAL("expr__ctx_new", ctx); in test__expr()
89 expr__add_id_val(ctx, strdup("FOO"), 1); in test__expr()
90 expr__add_id_val(ctx, strdup("BAR"), 2); in test__expr()
92 ret = test(ctx, "1+1", 2); in test__expr()
93 ret |= test(ctx, "FOO+BAR", 3); in test__expr()
94 ret |= test(ctx, "(BAR/2)%2", 1); in test__expr()
95 ret |= test(ctx, "1 - -4", 5); in test__expr()
96 ret |= test(ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5); in test__expr()
97 ret |= test(ctx, "1-1 | 1", 1); in test__expr()
98 ret |= test(ctx, "1-1 & 1", 0); in test__expr()
99 ret |= test(ctx, "min(1,2) + 1", 2); in test__expr()
100 ret |= test(ctx, "max(1,2) + 1", 3); in test__expr()
101 ret |= test(ctx, "1+1 if 3*4 else 0", 2); in test__expr()
102 ret |= test(ctx, "100 if 1 else 200 if 1 else 300", 100); in test__expr()
103 ret |= test(ctx, "100 if 0 else 200 if 1 else 300", 200); in test__expr()
104 ret |= test(ctx, "100 if 1 else 200 if 0 else 300", 100); in test__expr()
105 ret |= test(ctx, "100 if 0 else 200 if 0 else 300", 300); in test__expr()
106 ret |= test(ctx, "1.1 + 2.1", 3.2); in test__expr()
107 ret |= test(ctx, ".1 + 2.", 2.1); in test__expr()
108 ret |= test(ctx, "d_ratio(1, 2)", 0.5); in test__expr()
109 ret |= test(ctx, "d_ratio(2.5, 0)", 0); in test__expr()
110 ret |= test(ctx, "1.1 < 2.2", 1); in test__expr()
111 ret |= test(ctx, "2.2 > 1.1", 1); in test__expr()
112 ret |= test(ctx, "1.1 < 1.1", 0); in test__expr()
113 ret |= test(ctx, "2.2 > 2.2", 0); in test__expr()
114 ret |= test(ctx, "2.2 < 1.1", 0); in test__expr()
115 ret |= test(ctx, "1.1 > 2.2", 0); in test__expr()
116 ret |= test(ctx, "1.1e10 < 1.1e100", 1); in test__expr()
117 ret |= test(ctx, "1.1e2 > 1.1e-2", 1); in test__expr()
120 expr__ctx_free(ctx); in test__expr()
125 ret = expr__parse(&val, ctx, p); in test__expr()
130 ret = expr__parse(&val, ctx, p); in test__expr()
133 expr__ctx_clear(ctx); in test__expr()
136 ctx) == 0); in test__expr()
137 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 3); in test__expr()
138 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAR", &val_ptr)); in test__expr()
139 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAZ", &val_ptr)); in test__expr()
140 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BOZO", &val_ptr)); in test__expr()
142 expr__ctx_clear(ctx); in test__expr()
143 ctx->sctx.runtime = 3; in test__expr()
146 NULL, ctx) == 0); in test__expr()
147 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
148 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1,param=3@", &val_ptr)); in test__expr()
149 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT2,param=3@", &val_ptr)); in test__expr()
151 expr__ctx_clear(ctx); in test__expr()
154 NULL, ctx) == 0); in test__expr()
155 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
156 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event1", &val_ptr)); in test__expr()
157 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event2", &val_ptr)); in test__expr()
165 expr__ctx_clear(ctx); in test__expr()
168 NULL, ctx) == 0); in test__expr()
169 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
170 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
174 expr__ctx_clear(ctx); in test__expr()
177 NULL, ctx) == 0); in test__expr()
178 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
179 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
185 expr__ctx_clear(ctx); in test__expr()
188 NULL, ctx) == 0); in test__expr()
189 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
192 expr__ctx_clear(ctx); in test__expr()
194 expr__find_ids("0 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
195 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
196 expr__ctx_clear(ctx); in test__expr()
198 expr__find_ids("EVENT1 > 0 & 0", NULL, ctx) == 0); in test__expr()
199 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
200 expr__ctx_clear(ctx); in test__expr()
202 expr__find_ids("1 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
203 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
204 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
205 expr__ctx_clear(ctx); in test__expr()
207 expr__find_ids("EVENT1 > 0 & 1", NULL, ctx) == 0); in test__expr()
208 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
209 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
212 expr__ctx_clear(ctx); in test__expr()
214 expr__find_ids("1 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
215 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
216 expr__ctx_clear(ctx); in test__expr()
218 expr__find_ids("EVENT1 > 0 | 1", NULL, ctx) == 0); in test__expr()
219 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
220 expr__ctx_clear(ctx); in test__expr()
222 expr__find_ids("0 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
223 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
224 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
225 expr__ctx_clear(ctx); in test__expr()
227 expr__find_ids("EVENT1 > 0 | 0", NULL, ctx) == 0); in test__expr()
228 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
229 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
232 expr__ctx_clear(ctx); in test__expr()
234 expr__parse(&num_cpus_online, ctx, "#num_cpus_online") == 0); in test__expr()
235 TEST_ASSERT_VAL("#num_cpus", expr__parse(&num_cpus, ctx, "#num_cpus") == 0); in test__expr()
237 TEST_ASSERT_VAL("#num_cores", expr__parse(&num_cores, ctx, "#num_cores") == 0); in test__expr()
239 TEST_ASSERT_VAL("#num_dies", expr__parse(&num_dies, ctx, "#num_dies") == 0); in test__expr()
241 TEST_ASSERT_VAL("#num_packages", expr__parse(&num_packages, ctx, "#num_packages") == 0); in test__expr()
247 if (expr__parse(&val, ctx, "#system_tsc_freq") == 0) { in test__expr()
263 expr__ctx_clear(ctx); in test__expr()
266 NULL, ctx) == 0); in test__expr()
267 TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1); in test__expr()
268 TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
272 ret = test(ctx, "strcmp_cpuid_str(0x0)", 0); in test__expr()
287 ret |= test(ctx, strcmp_cpuid_buf, 1); in test__expr()
290 expr__add_id_val(ctx, strdup("cycles"), 2); in test__expr()
291 ret |= test(ctx, "has_event(cycles)", 1); in test__expr()
293 expr__ctx_free(ctx); in test__expr()