Lines Matching refs:ctx

60 static int test(struct expr_parse_ctx *ctx, const char *e, double val2)  in test()  argument
64 if (expr__parse(&val, ctx, e)) in test()
76 struct expr_parse_ctx *ctx; in test__expr() local
88 ctx = expr__ctx_new(); in test__expr()
89 TEST_ASSERT_VAL("expr__ctx_new", ctx); in test__expr()
90 expr__add_id_val(ctx, strdup("FOO"), 1); in test__expr()
91 expr__add_id_val(ctx, strdup("BAR"), 2); in test__expr()
93 ret = test(ctx, "1+1", 2); in test__expr()
94 ret |= test(ctx, "FOO+BAR", 3); in test__expr()
95 ret |= test(ctx, "(BAR/2)%2", 1); in test__expr()
96 ret |= test(ctx, "1 - -4", 5); in test__expr()
97 ret |= test(ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5); in test__expr()
98 ret |= test(ctx, "1-1 | 1", 1); in test__expr()
99 ret |= test(ctx, "1-1 & 1", 0); in test__expr()
100 ret |= test(ctx, "min(1,2) + 1", 2); in test__expr()
101 ret |= test(ctx, "max(1,2) + 1", 3); in test__expr()
102 ret |= test(ctx, "1+1 if 3*4 else 0", 2); in test__expr()
103 ret |= test(ctx, "100 if 1 else 200 if 1 else 300", 100); in test__expr()
104 ret |= test(ctx, "100 if 0 else 200 if 1 else 300", 200); in test__expr()
105 ret |= test(ctx, "100 if 1 else 200 if 0 else 300", 100); in test__expr()
106 ret |= test(ctx, "100 if 0 else 200 if 0 else 300", 300); in test__expr()
107 ret |= test(ctx, "1.1 + 2.1", 3.2); in test__expr()
108 ret |= test(ctx, ".1 + 2.", 2.1); in test__expr()
109 ret |= test(ctx, "d_ratio(1, 2)", 0.5); in test__expr()
110 ret |= test(ctx, "d_ratio(2.5, 0)", 0); in test__expr()
111 ret |= test(ctx, "1.1 < 2.2", 1); in test__expr()
112 ret |= test(ctx, "2.2 > 1.1", 1); in test__expr()
113 ret |= test(ctx, "1.1 < 1.1", 0); in test__expr()
114 ret |= test(ctx, "2.2 > 2.2", 0); in test__expr()
115 ret |= test(ctx, "2.2 < 1.1", 0); in test__expr()
116 ret |= test(ctx, "1.1 > 2.2", 0); in test__expr()
117 ret |= test(ctx, "1.1e10 < 1.1e100", 1); in test__expr()
118 ret |= test(ctx, "1.1e2 > 1.1e-2", 1); in test__expr()
121 expr__ctx_free(ctx); in test__expr()
126 ret = expr__parse(&val, ctx, p); in test__expr()
131 ret = expr__parse(&val, ctx, p); in test__expr()
134 expr__ctx_clear(ctx); in test__expr()
137 ctx) == 0); in test__expr()
138 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 3); in test__expr()
139 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAR", &val_ptr)); in test__expr()
140 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAZ", &val_ptr)); in test__expr()
141 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BOZO", &val_ptr)); in test__expr()
143 expr__ctx_clear(ctx); in test__expr()
144 ctx->sctx.runtime = 3; in test__expr()
147 NULL, ctx) == 0); in test__expr()
148 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
149 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1,param=3@", &val_ptr)); in test__expr()
150 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT2,param=3@", &val_ptr)); in test__expr()
152 expr__ctx_clear(ctx); in test__expr()
155 NULL, ctx) == 0); in test__expr()
156 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
157 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event1", &val_ptr)); in test__expr()
158 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event2", &val_ptr)); in test__expr()
166 expr__ctx_clear(ctx); in test__expr()
169 NULL, ctx) == 0); in test__expr()
170 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
171 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
175 expr__ctx_clear(ctx); in test__expr()
178 NULL, ctx) == 0); in test__expr()
179 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
180 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
186 expr__ctx_clear(ctx); in test__expr()
189 NULL, ctx) == 0); in test__expr()
190 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
193 expr__ctx_clear(ctx); in test__expr()
195 expr__find_ids("0 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
196 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
197 expr__ctx_clear(ctx); in test__expr()
199 expr__find_ids("EVENT1 > 0 & 0", NULL, ctx) == 0); in test__expr()
200 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
201 expr__ctx_clear(ctx); in test__expr()
203 expr__find_ids("1 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
204 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
205 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
206 expr__ctx_clear(ctx); in test__expr()
208 expr__find_ids("EVENT1 > 0 & 1", NULL, ctx) == 0); in test__expr()
209 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
210 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
213 expr__ctx_clear(ctx); in test__expr()
215 expr__find_ids("1 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
216 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
217 expr__ctx_clear(ctx); in test__expr()
219 expr__find_ids("EVENT1 > 0 | 1", NULL, ctx) == 0); in test__expr()
220 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
221 expr__ctx_clear(ctx); in test__expr()
223 expr__find_ids("0 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
224 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
225 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
226 expr__ctx_clear(ctx); in test__expr()
228 expr__find_ids("EVENT1 > 0 | 0", NULL, ctx) == 0); in test__expr()
229 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
230 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
233 expr__ctx_clear(ctx); in test__expr()
235 expr__parse(&num_cpus_online, ctx, "#num_cpus_online") == 0); in test__expr()
236 TEST_ASSERT_VAL("#num_cpus", expr__parse(&num_cpus, ctx, "#num_cpus") == 0); in test__expr()
238 TEST_ASSERT_VAL("#num_cores", expr__parse(&num_cores, ctx, "#num_cores") == 0); in test__expr()
240 TEST_ASSERT_VAL("#num_dies", expr__parse(&num_dies, ctx, "#num_dies") == 0); in test__expr()
242 TEST_ASSERT_VAL("#num_packages", expr__parse(&num_packages, ctx, "#num_packages") == 0); in test__expr()
247 TEST_ASSERT_VAL("#system_tsc_freq", expr__parse(&val, ctx, "#system_tsc_freq") == 0); in test__expr()
257 expr__ctx_clear(ctx); in test__expr()
260 NULL, ctx) == 0); in test__expr()
261 TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1); in test__expr()
262 TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
266 ret = test(ctx, "strcmp_cpuid_str(0x0)", 0); in test__expr()
281 ret |= test(ctx, strcmp_cpuid_buf, 1); in test__expr()
284 expr__add_id_val(ctx, strdup("cycles"), 2); in test__expr()
285 ret |= test(ctx, "has_event(cycles)", 1); in test__expr()
287 expr__ctx_free(ctx); in test__expr()