xref: /linux/tools/tracing/rtla/tests/unit/cli_opt_callback.c (revision 5daa3c4fa49474fc8935722b3bbc7181aefe7169)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #define _GNU_SOURCE
4 #include <stdio.h>
5 #include <check.h>
6 
7 #define RTLA_ALLOW_CLI_P_H
8 #include "../../src/cli_p.h"
9 #include "cli_params_assert.h"
10 
11 #define TEST_CALLBACK(value, cb) OPT_CALLBACK('t', "test", value, "test value", "test help", cb)
12 
13 START_TEST(test_opt_llong_callback_simple)
14 {
15 	long long test_value = 0;
16 	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);
17 
18 	ck_assert_int_eq(opt_llong_callback(&opt, "1234567890", 0), 0);
19 	ck_assert_int_eq(test_value, 1234567890);
20 }
21 END_TEST
22 
23 START_TEST(test_opt_llong_callback_max)
24 {
25 	long long test_value = 0;
26 	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);
27 
28 	ck_assert_int_eq(opt_llong_callback(&opt, "9223372036854775807", 0), 0);
29 	ck_assert_int_eq(test_value, 9223372036854775807LL);
30 }
31 END_TEST
32 
33 START_TEST(test_opt_llong_callback_min)
34 {
35 	long long test_value = 0;
36 	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);
37 
38 	ck_assert_int_eq(opt_llong_callback(&opt, "-9223372036854775808", 0), 0);
39 	ck_assert_int_eq(test_value, ~9223372036854775807LL);
40 }
41 END_TEST
42 
43 START_TEST(test_opt_int_callback_simple)
44 {
45 	int test_value = 0;
46 	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);
47 
48 	ck_assert_int_eq(opt_int_callback(&opt, "1234567890", 0), 0);
49 	ck_assert_int_eq(test_value, 1234567890);
50 }
51 END_TEST
52 
53 START_TEST(test_opt_int_callback_max)
54 {
55 	int test_value = 0;
56 	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);
57 
58 	ck_assert_int_eq(opt_int_callback(&opt, "2147483647", 0), 0);
59 	ck_assert_int_eq(test_value, 2147483647);
60 }
61 END_TEST
62 
63 START_TEST(test_opt_int_callback_min)
64 {
65 	int test_value = 0;
66 	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);
67 
68 	ck_assert_int_eq(opt_int_callback(&opt, "-2147483648", 0), 0);
69 	ck_assert_int_eq(test_value, -2147483648);
70 }
71 END_TEST
72 
73 START_TEST(test_opt_int_callback_non_numeric)
74 {
75 	int test_value = 0;
76 	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);
77 
78 	ck_assert_int_eq(opt_int_callback(&opt, "abc", 0), -1);
79 	ck_assert_int_eq(test_value, 0);
80 }
81 END_TEST
82 
83 START_TEST(test_opt_int_callback_non_numeric_suffix)
84 {
85 	int test_value = 0;
86 	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);
87 
88 	ck_assert_int_eq(opt_int_callback(&opt, "1234567890abc", 0), -1);
89 	ck_assert_int_eq(test_value, 0);
90 }
91 END_TEST
92 
93 START_TEST(test_opt_cpus_cb)
94 {
95 	struct common_params params = {0};
96 	const struct option opt = TEST_CALLBACK(&params, opt_cpus_cb);
97 
98 	nr_cpus = 4;
99 	ck_assert_int_eq(opt_cpus_cb(&opt, "0-3", 0), 0);
100 	ck_assert_str_eq(params.cpus, "0-3");
101 }
102 END_TEST
103 
104 START_TEST(test_opt_cpus_cb_invalid)
105 {
106 	struct common_params params = {0};
107 	const struct option opt = TEST_CALLBACK(&params, opt_cpus_cb);
108 
109 	nr_cpus = 4;
110 	assert(freopen("/dev/null", "w", stderr));
111 	opt_cpus_cb(&opt, "0-3,5", 0);
112 }
113 END_TEST
114 
115 START_TEST(test_opt_cgroup_cb)
116 {
117 	struct common_params params = {0};
118 	const struct option opt = TEST_CALLBACK(&params, opt_cgroup_cb);
119 
120 	ck_assert_int_eq(opt_cgroup_cb(&opt, "cgroup", 0), 0);
121 	ck_assert_int_eq(params.cgroup, 1);
122 	ck_assert_str_eq(params.cgroup_name, "cgroup");
123 }
124 END_TEST
125 
126 START_TEST(test_opt_cgroup_cb_equals)
127 {
128 	struct common_params params = {0};
129 	const struct option opt = TEST_CALLBACK(&params, opt_cgroup_cb);
130 
131 	ck_assert_int_eq(opt_cgroup_cb(&opt, "=cgroup", 0), 0);
132 	ck_assert_int_eq(params.cgroup, 1);
133 	ck_assert_str_eq(params.cgroup_name, "cgroup");
134 }
135 END_TEST
136 
137 START_TEST(test_opt_duration_cb)
138 {
139 	struct common_params params = {0};
140 	const struct option opt = TEST_CALLBACK(&params, opt_duration_cb);
141 
142 	ck_assert_int_eq(opt_duration_cb(&opt, "1m", 0), 0);
143 	ck_assert_int_eq(params.duration, 60);
144 }
145 END_TEST
146 
147 START_TEST(test_opt_duration_cb_invalid)
148 {
149 	struct common_params params = {0};
150 	const struct option opt = TEST_CALLBACK(&params, opt_duration_cb);
151 
152 	assert(freopen("/dev/null", "w", stderr));
153 	opt_duration_cb(&opt, "abc", 0);
154 }
155 END_TEST
156 
157 START_TEST(test_opt_event_cb)
158 {
159 	struct trace_events *events = NULL;
160 	const struct option opt = TEST_CALLBACK(&events, opt_event_cb);
161 
162 	ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_switch", 0), 0);
163 	ck_assert_str_eq(events->system, "sched");
164 	ck_assert_str_eq(events->event, "sched_switch");
165 	ck_assert_ptr_eq(events->next, NULL);
166 }
167 END_TEST
168 
169 START_TEST(test_opt_event_cb_multiple)
170 {
171 	struct trace_events *events = NULL;
172 	const struct option opt = TEST_CALLBACK(&events, opt_event_cb);
173 
174 	ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_switch", 0), 0);
175 	ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_wakeup", 0), 0);
176 	ck_assert_str_eq(events->system, "sched");
177 	ck_assert_str_eq(events->event, "sched_wakeup");
178 	ck_assert_str_eq(events->next->system, "sched");
179 	ck_assert_str_eq(events->next->event, "sched_switch");
180 	ck_assert_ptr_eq(events->next->next, NULL);
181 }
182 END_TEST
183 
184 START_TEST(test_opt_housekeeping_cb)
185 {
186 	struct common_params __params = {0};
187 	struct common_params *params = &__params;
188 	const struct option opt = TEST_CALLBACK(params, opt_housekeeping_cb);
189 
190 	nr_cpus = 4;
191 	ck_assert_int_eq(opt_housekeeping_cb(&opt, "0-3", 0), 0);
192 	ck_assert_int_eq(params->hk_cpus, 1);
193 	CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 2, 3);
194 }
195 END_TEST
196 
197 START_TEST(test_opt_housekeeping_cb_invalid)
198 {
199 	struct common_params params = {0};
200 	const struct option opt = TEST_CALLBACK(&params, opt_housekeeping_cb);
201 
202 	nr_cpus = 4;
203 	assert(freopen("/dev/null", "w", stderr));
204 	opt_housekeeping_cb(&opt, "0-3,5", 0);
205 }
206 END_TEST
207 
208 START_TEST(test_opt_priority_cb)
209 {
210 	struct common_params params = {0};
211 	const struct option opt = TEST_CALLBACK(&params, opt_priority_cb);
212 
213 	ck_assert_int_eq(opt_priority_cb(&opt, "f:95", 0), 0);
214 	ck_assert_int_eq(params.sched_param.sched_policy, SCHED_FIFO);
215 	ck_assert_int_eq(params.sched_param.sched_priority, 95);
216 }
217 END_TEST
218 
219 START_TEST(test_opt_priority_cb_invalid)
220 {
221 	struct common_params params = {0};
222 	const struct option opt = TEST_CALLBACK(&params, opt_priority_cb);
223 
224 	assert(freopen("/dev/null", "w", stderr));
225 	opt_priority_cb(&opt, "abc", 0);
226 }
227 END_TEST
228 
229 START_TEST(test_opt_trigger_cb)
230 {
231 	struct trace_events *events = trace_event_alloc("sched:sched_switch");
232 	const struct option opt = TEST_CALLBACK(&events, opt_trigger_cb);
233 
234 	ck_assert_int_eq(opt_trigger_cb(&opt, "stacktrace", 0), 0);
235 	ck_assert_str_eq(events->trigger, "stacktrace");
236 }
237 END_TEST
238 
239 START_TEST(test_opt_trigger_cb_no_event)
240 {
241 	struct trace_events *events = NULL;
242 	const struct option opt = TEST_CALLBACK(&events, opt_trigger_cb);
243 
244 	assert(freopen("/dev/null", "w", stderr));
245 	opt_trigger_cb(&opt, "stacktrace", 0);
246 }
247 END_TEST
248 
249 START_TEST(test_opt_filter_cb)
250 {
251 	struct trace_events *events = trace_event_alloc("sched:sched_switch");
252 	const struct option opt = TEST_CALLBACK(&events, opt_filter_cb);
253 
254 	ck_assert_int_eq(opt_filter_cb(&opt, "comm ~ \"rtla\"", 0), 0);
255 	ck_assert_str_eq(events->filter, "comm ~ \"rtla\"");
256 }
257 END_TEST
258 
259 START_TEST(test_opt_filter_cb_no_event)
260 {
261 	struct trace_events *events = NULL;
262 	const struct option opt = TEST_CALLBACK(&events, opt_filter_cb);
263 
264 	assert(freopen("/dev/null", "w", stderr));
265 	opt_filter_cb(&opt, "comm ~ \"rtla\"", 0);
266 }
267 END_TEST
268 
269 START_TEST(test_opt_osnoise_auto_cb)
270 {
271 	struct osnoise_params params = {0};
272 	struct osnoise_cb_data cb_data = {&params};
273 	const struct option opt = TEST_CALLBACK(&cb_data, opt_osnoise_auto_cb);
274 
275 	ck_assert_int_eq(opt_osnoise_auto_cb(&opt, "10", 0), 0);
276 	ck_assert_int_eq(params.common.stop_us, 10);
277 	ck_assert_int_eq(params.threshold, 1);
278 	ck_assert_str_eq(cb_data.trace_output, "osnoise_trace.txt");
279 }
280 END_TEST
281 
282 START_TEST(test_opt_osnoise_period_cb)
283 {
284 	unsigned long long period = 0;
285 	const struct option opt = TEST_CALLBACK(&period, opt_osnoise_period_cb);
286 
287 	ck_assert_int_eq(opt_osnoise_period_cb(&opt, "1000000", 0), 0);
288 	ck_assert_int_eq(period, 1000000);
289 }
290 END_TEST
291 
292 START_TEST(test_opt_osnoise_period_cb_invalid)
293 {
294 	unsigned long long period = 0;
295 	const struct option opt = TEST_CALLBACK(&period, opt_osnoise_period_cb);
296 
297 	assert(freopen("/dev/null", "w", stderr));
298 	opt_osnoise_period_cb(&opt, "10000001", 0);
299 }
300 END_TEST
301 
302 START_TEST(test_opt_osnoise_runtime_cb)
303 {
304 	unsigned long long runtime = 0;
305 	const struct option opt = TEST_CALLBACK(&runtime, opt_osnoise_runtime_cb);
306 
307 	ck_assert_int_eq(opt_osnoise_runtime_cb(&opt, "900000", 0), 0);
308 	ck_assert_int_eq(runtime, 900000);
309 }
310 END_TEST
311 
312 START_TEST(test_opt_osnoise_runtime_cb_invalid)
313 {
314 	unsigned long long runtime = 0;
315 	const struct option opt = TEST_CALLBACK(&runtime, opt_osnoise_runtime_cb);
316 
317 	assert(freopen("/dev/null", "w", stderr));
318 	opt_osnoise_runtime_cb(&opt, "99", 0);
319 }
320 END_TEST
321 
322 START_TEST(test_opt_osnoise_trace_output_cb)
323 {
324 	const char *trace_output = NULL;
325 	const struct option opt = TEST_CALLBACK(&trace_output, opt_osnoise_trace_output_cb);
326 
327 	ck_assert_int_eq(opt_osnoise_trace_output_cb(&opt, "trace.txt", 0), 0);
328 	ck_assert_str_eq(trace_output, "trace.txt");
329 }
330 END_TEST
331 
332 START_TEST(test_opt_osnoise_trace_output_cb_noarg)
333 {
334 	const char *trace_output = NULL;
335 	const struct option opt = TEST_CALLBACK(&trace_output, opt_osnoise_trace_output_cb);
336 
337 	ck_assert_int_eq(opt_osnoise_trace_output_cb(&opt, NULL, 0), 0);
338 	ck_assert_str_eq(trace_output, "osnoise_trace.txt");
339 }
340 END_TEST
341 
342 START_TEST(test_opt_osnoise_on_threshold_cb)
343 {
344 	struct actions actions = {0};
345 	const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_threshold_cb);
346 
347 	ck_assert_int_eq(opt_osnoise_on_threshold_cb(&opt, "trace", 0), 0);
348 	ck_assert_int_eq(actions.len, 1);
349 	ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT);
350 	ck_assert_str_eq(actions.list[0].trace_output, "osnoise_trace.txt");
351 }
352 END_TEST
353 
354 START_TEST(test_opt_osnoise_on_threshold_cb_invalid)
355 {
356 	struct actions actions = {0};
357 	const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_threshold_cb);
358 
359 	assert(freopen("/dev/null", "w", stderr));
360 	opt_osnoise_on_threshold_cb(&opt, "abc", 0);
361 }
362 END_TEST
363 
364 START_TEST(test_opt_osnoise_on_end_cb)
365 {
366 	struct actions actions = {0};
367 	const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_end_cb);
368 
369 	ck_assert_int_eq(opt_osnoise_on_end_cb(&opt, "trace", 0), 0);
370 	ck_assert_int_eq(actions.len, 1);
371 	ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT);
372 	ck_assert_str_eq(actions.list[0].trace_output, "osnoise_trace.txt");
373 }
374 END_TEST
375 
376 START_TEST(test_opt_osnoise_on_end_cb_invalid)
377 {
378 	struct actions actions = {0};
379 	const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_end_cb);
380 
381 	assert(freopen("/dev/null", "w", stderr));
382 	opt_osnoise_on_end_cb(&opt, "abc", 0);
383 }
384 END_TEST
385 
386 START_TEST(test_opt_timerlat_period_cb)
387 {
388 	long long period = 0;
389 	const struct option opt = TEST_CALLBACK(&period, opt_timerlat_period_cb);
390 
391 	ck_assert_int_eq(opt_timerlat_period_cb(&opt, "1000", 0), 0);
392 	ck_assert_int_eq(period, 1000);
393 }
394 END_TEST
395 
396 START_TEST(test_opt_timerlat_period_cb_invalid)
397 {
398 	long long period = 0;
399 	const struct option opt = TEST_CALLBACK(&period, opt_timerlat_period_cb);
400 
401 	assert(freopen("/dev/null", "w", stderr));
402 	opt_timerlat_period_cb(&opt, "1000001", 0);
403 }
404 END_TEST
405 
406 START_TEST(test_opt_timerlat_auto_cb)
407 {
408 	struct timerlat_params params = {0};
409 	struct timerlat_cb_data cb_data = {&params};
410 	const struct option opt = TEST_CALLBACK(&cb_data, opt_timerlat_auto_cb);
411 
412 	ck_assert_int_eq(opt_timerlat_auto_cb(&opt, "10", 0), 0);
413 	ck_assert_int_eq(params.common.stop_us, 10);
414 	ck_assert_int_eq(params.common.stop_total_us, 10);
415 	ck_assert_int_eq(params.print_stack, 10);
416 	ck_assert_str_eq(cb_data.trace_output, "timerlat_trace.txt");
417 }
418 END_TEST
419 
420 START_TEST(test_opt_dma_latency_cb)
421 {
422 	int dma_latency = 0;
423 	const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb);
424 
425 	ck_assert_int_eq(opt_dma_latency_cb(&opt, "1000", 0), 0);
426 	ck_assert_int_eq(dma_latency, 1000);
427 }
428 END_TEST
429 
430 START_TEST(test_opt_dma_latency_cb_min)
431 {
432 	int dma_latency = 0;
433 	const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb);
434 
435 	assert(freopen("/dev/null", "w", stderr));
436 	opt_dma_latency_cb(&opt, "-1", 0);
437 }
438 END_TEST
439 
440 START_TEST(test_opt_dma_latency_cb_max)
441 {
442 	int dma_latency = 0;
443 	const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb);
444 
445 	assert(freopen("/dev/null", "w", stderr));
446 	opt_dma_latency_cb(&opt, "10001", 0);
447 }
448 END_TEST
449 
450 START_TEST(test_opt_aa_only_cb)
451 {
452 	struct timerlat_params params = {0};
453 	const struct option opt = TEST_CALLBACK(&params, opt_aa_only_cb);
454 
455 	ck_assert_int_eq(opt_aa_only_cb(&opt, "10", 0), 0);
456 	ck_assert_int_eq(params.common.stop_us, 10);
457 	ck_assert_int_eq(params.common.stop_total_us, 10);
458 	ck_assert_int_eq(params.print_stack, 10);
459 	ck_assert_int_eq(params.common.aa_only, 1);
460 }
461 END_TEST
462 
463 START_TEST(test_opt_timerlat_trace_output_cb)
464 {
465 	const char *trace_output = NULL;
466 	const struct option opt = TEST_CALLBACK(&trace_output, opt_timerlat_trace_output_cb);
467 
468 	ck_assert_int_eq(opt_timerlat_trace_output_cb(&opt, "trace.txt", 0), 0);
469 	ck_assert_str_eq(trace_output, "trace.txt");
470 }
471 END_TEST
472 
473 START_TEST(test_opt_timerlat_trace_output_cb_noarg)
474 {
475 	const char *trace_output = NULL;
476 	const struct option opt = TEST_CALLBACK(&trace_output, opt_timerlat_trace_output_cb);
477 
478 	ck_assert_int_eq(opt_timerlat_trace_output_cb(&opt, NULL, 0), 0);
479 	ck_assert_str_eq(trace_output, "timerlat_trace.txt");
480 }
481 END_TEST
482 
483 START_TEST(test_opt_timerlat_on_threshold_cb)
484 {
485 	struct actions actions = {0};
486 	const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_threshold_cb);
487 
488 	ck_assert_int_eq(opt_timerlat_on_threshold_cb(&opt, "trace", 0), 0);
489 	ck_assert_int_eq(actions.len, 1);
490 	ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT);
491 	ck_assert_str_eq(actions.list[0].trace_output, "timerlat_trace.txt");
492 }
493 END_TEST
494 
495 START_TEST(test_opt_timerlat_on_threshold_cb_invalid)
496 {
497 	struct actions actions = {0};
498 	const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_threshold_cb);
499 
500 	assert(freopen("/dev/null", "w", stderr));
501 	opt_timerlat_on_threshold_cb(&opt, "abc", 0);
502 }
503 END_TEST
504 
505 START_TEST(test_opt_timerlat_on_end_cb)
506 {
507 	struct actions actions = {0};
508 	const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_end_cb);
509 
510 	ck_assert_int_eq(opt_timerlat_on_end_cb(&opt, "trace", 0), 0);
511 	ck_assert_int_eq(actions.len, 1);
512 	ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT);
513 	ck_assert_str_eq(actions.list[0].trace_output, "timerlat_trace.txt");
514 }
515 END_TEST
516 
517 START_TEST(test_opt_timerlat_on_end_cb_invalid)
518 {
519 	struct actions actions = {0};
520 	const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_end_cb);
521 
522 	assert(freopen("/dev/null", "w", stderr));
523 	opt_timerlat_on_end_cb(&opt, "abc", 0);
524 }
525 END_TEST
526 
527 START_TEST(test_opt_user_threads_cb)
528 {
529 	struct timerlat_params params = {0};
530 	const struct option opt = TEST_CALLBACK(&params, opt_user_threads_cb);
531 
532 	ck_assert_int_eq(opt_user_threads_cb(&opt, NULL, 0), 0);
533 	ck_assert_int_eq(params.common.user_workload, 1);
534 	ck_assert_int_eq(params.common.user_data, 1);
535 }
536 END_TEST
537 
538 START_TEST(test_opt_nano_cb)
539 {
540 	struct timerlat_params params = {0};
541 	const struct option opt = TEST_CALLBACK(&params, opt_nano_cb);
542 
543 	ck_assert_int_eq(opt_nano_cb(&opt, NULL, 0), 0);
544 	ck_assert_int_eq(params.common.output_divisor, 1);
545 }
546 END_TEST
547 
548 START_TEST(test_opt_timerlat_align_cb)
549 {
550 	struct timerlat_params params = {0};
551 	const struct option opt = TEST_CALLBACK(&params, opt_timerlat_align_cb);
552 
553 	ck_assert_int_eq(opt_timerlat_align_cb(&opt, "500", 0), 0);
554 	ck_assert(params.timerlat_align);
555 	ck_assert_int_eq(params.timerlat_align_us, 500);
556 }
557 END_TEST
558 
559 START_TEST(test_opt_stack_format_cb)
560 {
561 	int stack_format = 0;
562 	const struct option opt = TEST_CALLBACK(&stack_format, opt_stack_format_cb);
563 
564 	ck_assert_int_eq(opt_stack_format_cb(&opt, "full", 0), 0);
565 	ck_assert_int_eq(stack_format, STACK_FORMAT_FULL);
566 }
567 END_TEST
568 
569 START_TEST(test_opt_stack_format_cb_invalid)
570 {
571 	int stack_format = 0;
572 	const struct option opt = TEST_CALLBACK(&stack_format, opt_stack_format_cb);
573 
574 	assert(freopen("/dev/null", "w", stderr));
575 	opt_stack_format_cb(&opt, "abc", 0);
576 }
577 END_TEST
578 
579 START_TEST(test_opt_bucket_size_cb)
580 {
581 	int bucket_size = 0;
582 	const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb);
583 
584 	ck_assert_int_eq(opt_bucket_size_cb(&opt, "100", 0), 0);
585 	ck_assert_int_eq(bucket_size, 100);
586 }
587 END_TEST
588 
589 START_TEST(test_opt_bucket_size_min)
590 {
591 	int bucket_size = 0;
592 	const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb);
593 
594 	assert(freopen("/dev/null", "w", stderr));
595 	opt_bucket_size_cb(&opt, "0", 0);
596 }
597 END_TEST
598 
599 START_TEST(test_opt_bucket_size_max)
600 {
601 	int bucket_size = 0;
602 	const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb);
603 
604 	assert(freopen("/dev/null", "w", stderr));
605 	opt_bucket_size_cb(&opt, "1000001", 0);
606 }
607 END_TEST
608 
609 START_TEST(test_opt_entries_cb)
610 {
611 	int entries = 0;
612 	const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb);
613 
614 	ck_assert_int_eq(opt_entries_cb(&opt, "100", 0), 0);
615 	ck_assert_int_eq(entries, 100);
616 }
617 END_TEST
618 
619 START_TEST(test_opt_entries_min)
620 {
621 	int entries = 0;
622 	const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb);
623 
624 	assert(freopen("/dev/null", "w", stderr));
625 	opt_entries_cb(&opt, "9", 0);
626 }
627 END_TEST
628 
629 START_TEST(test_opt_entries_max)
630 {
631 	int entries = 0;
632 	const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb);
633 
634 	assert(freopen("/dev/null", "w", stderr));
635 	opt_entries_cb(&opt, "10000000", 0);
636 }
637 END_TEST
638 
639 Suite *cli_opt_callback_suite(void)
640 {
641 	Suite *s = suite_create("cli_opt_callback");
642 	TCase *tc;
643 
644 	tc = tcase_create("common");
645 	tcase_add_test(tc, test_opt_llong_callback_simple);
646 	tcase_add_test(tc, test_opt_llong_callback_max);
647 	tcase_add_test(tc, test_opt_llong_callback_min);
648 	tcase_add_test(tc, test_opt_int_callback_simple);
649 	tcase_add_test(tc, test_opt_int_callback_max);
650 	tcase_add_test(tc, test_opt_int_callback_min);
651 	tcase_add_test(tc, test_opt_int_callback_non_numeric);
652 	tcase_add_test(tc, test_opt_int_callback_non_numeric_suffix);
653 	tcase_add_test(tc, test_opt_cpus_cb);
654 	tcase_add_exit_test(tc, test_opt_cpus_cb_invalid, EXIT_FAILURE);
655 	tcase_add_test(tc, test_opt_cgroup_cb);
656 	tcase_add_test(tc, test_opt_cgroup_cb_equals);
657 	tcase_add_test(tc, test_opt_duration_cb);
658 	tcase_add_exit_test(tc, test_opt_duration_cb_invalid, EXIT_FAILURE);
659 	tcase_add_test(tc, test_opt_event_cb);
660 	tcase_add_test(tc, test_opt_event_cb_multiple);
661 	tcase_add_test(tc, test_opt_housekeeping_cb);
662 	tcase_add_exit_test(tc, test_opt_housekeeping_cb_invalid, EXIT_FAILURE);
663 	tcase_add_test(tc, test_opt_priority_cb);
664 	tcase_add_exit_test(tc, test_opt_priority_cb_invalid, EXIT_FAILURE);
665 	tcase_add_test(tc, test_opt_trigger_cb);
666 	tcase_add_exit_test(tc, test_opt_trigger_cb_no_event, EXIT_FAILURE);
667 	tcase_add_test(tc, test_opt_filter_cb);
668 	tcase_add_exit_test(tc, test_opt_filter_cb_no_event, EXIT_FAILURE);
669 	suite_add_tcase(s, tc);
670 
671 	tc = tcase_create("osnoise");
672 	tcase_add_test(tc, test_opt_osnoise_auto_cb);
673 	tcase_add_test(tc, test_opt_osnoise_period_cb);
674 	tcase_add_exit_test(tc, test_opt_osnoise_period_cb_invalid, EXIT_FAILURE);
675 	tcase_add_test(tc, test_opt_osnoise_runtime_cb);
676 	tcase_add_exit_test(tc, test_opt_osnoise_runtime_cb_invalid, EXIT_FAILURE);
677 	tcase_add_test(tc, test_opt_osnoise_trace_output_cb);
678 	tcase_add_test(tc, test_opt_osnoise_trace_output_cb_noarg);
679 	tcase_add_test(tc, test_opt_osnoise_on_threshold_cb);
680 	tcase_add_exit_test(tc, test_opt_osnoise_on_threshold_cb_invalid, EXIT_FAILURE);
681 	tcase_add_test(tc, test_opt_osnoise_on_end_cb);
682 	tcase_add_exit_test(tc, test_opt_osnoise_on_end_cb_invalid, EXIT_FAILURE);
683 	suite_add_tcase(s, tc);
684 
685 	tc = tcase_create("timerlat");
686 	tcase_add_test(tc, test_opt_timerlat_period_cb);
687 	tcase_add_exit_test(tc, test_opt_timerlat_period_cb_invalid, EXIT_FAILURE);
688 	tcase_add_test(tc, test_opt_timerlat_auto_cb);
689 	tcase_add_test(tc, test_opt_dma_latency_cb);
690 	tcase_add_exit_test(tc, test_opt_dma_latency_cb_min, EXIT_FAILURE);
691 	tcase_add_exit_test(tc, test_opt_dma_latency_cb_max, EXIT_FAILURE);
692 	tcase_add_test(tc, test_opt_aa_only_cb);
693 	tcase_add_test(tc, test_opt_timerlat_trace_output_cb);
694 	tcase_add_test(tc, test_opt_timerlat_trace_output_cb_noarg);
695 	tcase_add_test(tc, test_opt_timerlat_on_threshold_cb);
696 	tcase_add_exit_test(tc, test_opt_timerlat_on_threshold_cb_invalid, EXIT_FAILURE);
697 	tcase_add_test(tc, test_opt_timerlat_on_end_cb);
698 	tcase_add_exit_test(tc, test_opt_timerlat_on_end_cb_invalid, EXIT_FAILURE);
699 	tcase_add_test(tc, test_opt_user_threads_cb);
700 	tcase_add_test(tc, test_opt_nano_cb);
701 	tcase_add_test(tc, test_opt_stack_format_cb);
702 	tcase_add_exit_test(tc, test_opt_stack_format_cb_invalid, EXIT_FAILURE);
703 	tcase_add_test(tc, test_opt_timerlat_align_cb);
704 	suite_add_tcase(s, tc);
705 
706 	tc = tcase_create("histogram");
707 	tcase_add_test(tc, test_opt_bucket_size_cb);
708 	tcase_add_exit_test(tc, test_opt_bucket_size_min, EXIT_FAILURE);
709 	tcase_add_exit_test(tc, test_opt_bucket_size_max, EXIT_FAILURE);
710 	tcase_add_test(tc, test_opt_entries_cb);
711 	tcase_add_exit_test(tc, test_opt_entries_min, EXIT_FAILURE);
712 	tcase_add_exit_test(tc, test_opt_entries_max, EXIT_FAILURE);
713 	suite_add_tcase(s, tc);
714 
715 	return s;
716 }
717