Lines Matching refs:ctx
59 static int test(struct expr_parse_ctx *ctx, const char *e, double val2) in test() argument
63 if (expr__parse(&val, ctx, e)) in test()
75 struct expr_parse_ctx *ctx; in test__expr() local
84 ctx = expr__ctx_new(); in test__expr()
85 TEST_ASSERT_VAL("expr__ctx_new", ctx); in test__expr()
86 expr__add_id_val(ctx, strdup("FOO"), 1); in test__expr()
87 expr__add_id_val(ctx, strdup("BAR"), 2); in test__expr()
89 ret = test(ctx, "1+1", 2); in test__expr()
90 ret |= test(ctx, "FOO+BAR", 3); in test__expr()
91 ret |= test(ctx, "(BAR/2)%2", 1); in test__expr()
92 ret |= test(ctx, "1 - -4", 5); in test__expr()
93 ret |= test(ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5); in test__expr()
94 ret |= test(ctx, "1-1 | 1", 1); in test__expr()
95 ret |= test(ctx, "1-1 & 1", 0); in test__expr()
96 ret |= test(ctx, "min(1,2) + 1", 2); in test__expr()
97 ret |= test(ctx, "max(1,2) + 1", 3); in test__expr()
98 ret |= test(ctx, "1+1 if 3*4 else 0", 2); in test__expr()
99 ret |= test(ctx, "100 if 1 else 200 if 1 else 300", 100); in test__expr()
100 ret |= test(ctx, "100 if 0 else 200 if 1 else 300", 200); in test__expr()
101 ret |= test(ctx, "100 if 1 else 200 if 0 else 300", 100); in test__expr()
102 ret |= test(ctx, "100 if 0 else 200 if 0 else 300", 300); in test__expr()
103 ret |= test(ctx, "1.1 + 2.1", 3.2); in test__expr()
104 ret |= test(ctx, ".1 + 2.", 2.1); in test__expr()
105 ret |= test(ctx, "d_ratio(1, 2)", 0.5); in test__expr()
106 ret |= test(ctx, "d_ratio(2.5, 0)", 0); in test__expr()
107 ret |= test(ctx, "1.1 < 2.2", 1); in test__expr()
108 ret |= test(ctx, "2.2 > 1.1", 1); in test__expr()
109 ret |= test(ctx, "1.1 < 1.1", 0); in test__expr()
110 ret |= test(ctx, "2.2 > 2.2", 0); in test__expr()
111 ret |= test(ctx, "2.2 < 1.1", 0); in test__expr()
112 ret |= test(ctx, "1.1 > 2.2", 0); in test__expr()
113 ret |= test(ctx, "1.1e10 < 1.1e100", 1); in test__expr()
114 ret |= test(ctx, "1.1e2 > 1.1e-2", 1); in test__expr()
117 expr__ctx_free(ctx); in test__expr()
122 ret = expr__parse(&val, ctx, p); in test__expr()
127 ret = expr__parse(&val, ctx, p); in test__expr()
130 expr__ctx_clear(ctx); in test__expr()
133 ctx) == 0); in test__expr()
134 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 3); in test__expr()
135 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAR", &val_ptr)); in test__expr()
136 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAZ", &val_ptr)); in test__expr()
137 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BOZO", &val_ptr)); in test__expr()
139 expr__ctx_clear(ctx); in test__expr()
140 ctx->sctx.runtime = 3; in test__expr()
143 NULL, ctx) == 0); in test__expr()
144 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
145 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1,param=3@", &val_ptr)); in test__expr()
146 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT2,param=3@", &val_ptr)); in test__expr()
148 expr__ctx_clear(ctx); in test__expr()
151 NULL, ctx) == 0); in test__expr()
152 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 2); in test__expr()
153 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event1", &val_ptr)); in test__expr()
154 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event2", &val_ptr)); in test__expr()
162 expr__ctx_clear(ctx); in test__expr()
165 NULL, ctx) == 0); in test__expr()
166 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
167 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
171 expr__ctx_clear(ctx); in test__expr()
174 NULL, ctx) == 0); in test__expr()
175 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
176 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, in test__expr()
182 expr__ctx_clear(ctx); in test__expr()
185 NULL, ctx) == 0); in test__expr()
186 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
189 expr__ctx_clear(ctx); in test__expr()
191 expr__find_ids("0 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
192 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("EVENT1 > 0 & 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("1 & EVENT1 > 0", NULL, ctx) == 0); in test__expr()
200 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
201 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
202 expr__ctx_clear(ctx); in test__expr()
204 expr__find_ids("EVENT1 > 0 & 1", NULL, ctx) == 0); in test__expr()
205 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
206 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
209 expr__ctx_clear(ctx); in test__expr()
211 expr__find_ids("1 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
212 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); in test__expr()
213 expr__ctx_clear(ctx); in test__expr()
215 expr__find_ids("EVENT1 > 0 | 1", 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("0 | EVENT1 > 0", NULL, ctx) == 0); in test__expr()
220 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
221 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
222 expr__ctx_clear(ctx); in test__expr()
224 expr__find_ids("EVENT1 > 0 | 0", NULL, ctx) == 0); in test__expr()
225 TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 1); in test__expr()
226 TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
229 expr__ctx_clear(ctx); in test__expr()
231 expr__parse(&num_cpus_online, ctx, "#num_cpus_online") == 0); in test__expr()
232 TEST_ASSERT_VAL("#num_cpus", expr__parse(&num_cpus, ctx, "#num_cpus") == 0); in test__expr()
234 TEST_ASSERT_VAL("#num_cores", expr__parse(&num_cores, ctx, "#num_cores") == 0); in test__expr()
236 TEST_ASSERT_VAL("#num_dies", expr__parse(&num_dies, ctx, "#num_dies") == 0); in test__expr()
238 TEST_ASSERT_VAL("#num_packages", expr__parse(&num_packages, ctx, "#num_packages") == 0); in test__expr()
243 TEST_ASSERT_VAL("#system_tsc_freq", expr__parse(&val, ctx, "#system_tsc_freq") == 0); in test__expr()
253 expr__ctx_clear(ctx); in test__expr()
256 NULL, ctx) == 0); in test__expr()
257 TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1); in test__expr()
258 TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); in test__expr()
261 expr__add_id_val(ctx, strdup("cycles"), 2); in test__expr()
262 ret = test(ctx, "has_event(cycles)", 1); in test__expr()
264 expr__ctx_free(ctx); in test__expr()