diff options
Diffstat (limited to 'tools/tracing/rtla/tests/unit')
| -rw-r--r-- | tools/tracing/rtla/tests/unit/Build | 8 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/Makefile.unit | 6 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/actions.c | 393 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/cli_opt_callback.c | 716 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/cli_params_assert.h | 68 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/osnoise_hist_cli.c | 557 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/osnoise_top_cli.c | 503 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/timerlat_hist_cli.c | 722 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/timerlat_top_cli.c | 654 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/unit_tests.c | 120 | ||||
| -rw-r--r-- | tools/tracing/rtla/tests/unit/utils.c | 106 |
11 files changed, 3749 insertions, 104 deletions
diff --git a/tools/tracing/rtla/tests/unit/Build b/tools/tracing/rtla/tests/unit/Build index 5f1e531ea8c9..d5a0f13922be 100644 --- a/tools/tracing/rtla/tests/unit/Build +++ b/tools/tracing/rtla/tests/unit/Build @@ -1,2 +1,8 @@ +unit_tests-y += utils.o +unit_tests-y += actions.o unit_tests-y += unit_tests.o -unit_tests-y +=../../src/utils.o +unit_tests-y += osnoise_top_cli.o +unit_tests-y += osnoise_hist_cli.o +unit_tests-y += timerlat_top_cli.o +unit_tests-y += timerlat_hist_cli.o +unit_tests-y += cli_opt_callback.o diff --git a/tools/tracing/rtla/tests/unit/Makefile.unit b/tools/tracing/rtla/tests/unit/Makefile.unit index 2088c9cc3571..839abda64b76 100644 --- a/tools/tracing/rtla/tests/unit/Makefile.unit +++ b/tools/tracing/rtla/tests/unit/Makefile.unit @@ -3,10 +3,10 @@ UNIT_TESTS := $(OUTPUT)unit_tests UNIT_TESTS_IN := $(UNIT_TESTS)-in.o -$(UNIT_TESTS): $(UNIT_TESTS_IN) - $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ -lcheck +$(UNIT_TESTS): $(UNIT_TESTS_IN) $(RTLA_IN) $(LIBSUBCMD) $(LIB_STRING) $(LIB_STR_ERROR_R) + $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $(EXTLIBS) -lcheck -$(UNIT_TESTS_IN): +$(UNIT_TESTS_IN): fixdep $(LIBSUBCMD_INCLUDES) make $(build)=unit_tests unit-tests: FORCE diff --git a/tools/tracing/rtla/tests/unit/actions.c b/tools/tracing/rtla/tests/unit/actions.c new file mode 100644 index 000000000000..94ad5ad42774 --- /dev/null +++ b/tools/tracing/rtla/tests/unit/actions.c @@ -0,0 +1,393 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <signal.h> + +#include "../../src/actions.h" + +static struct actions actions_fixture; + +static void actions_fixture_setup(void) +{ + actions_init(&actions_fixture); +} + +static void actions_fixture_teardown(void) +{ + actions_destroy(&actions_fixture); +} + +START_TEST(test_actions_init) +{ + struct actions actions; + + actions_init(&actions); + + ck_assert_int_eq(actions.len, 0); + ck_assert_int_eq(actions.size, action_default_size); + ck_assert(!actions.continue_flag); + ck_assert_ptr_eq(actions.trace_output_inst, NULL); +} +END_TEST + +START_TEST(test_actions_destroy) +{ + struct actions actions; + + actions_init(&actions); + actions_destroy(&actions); +} +END_TEST + +START_TEST(test_actions_reallocate) +{ + struct actions actions; + int i; + + actions_init(&actions); + + ck_assert_int_eq(actions.len, 0); + ck_assert_int_eq(actions.size, action_default_size); + + /* Fill size of actions array */ + for (i = 0; i < action_default_size; i++) + actions_add_continue(&actions); + + ck_assert_int_eq(actions.len, action_default_size); + ck_assert_int_eq(actions.size, action_default_size); + + /* Add one more action to trigger reallocation */ + actions_add_continue(&actions); + + ck_assert_int_eq(actions.len, action_default_size + 1); + ck_assert_int_eq(actions.size, action_default_size * 2); + + actions_destroy(&actions); +} +END_TEST + +START_TEST(test_actions_add_trace_output) +{ + actions_add_trace_output(&actions_fixture, "trace_output.txt"); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[0].trace_output, "trace_output.txt"); + ck_assert(actions_fixture.present[ACTION_TRACE_OUTPUT]); +} +END_TEST + +START_TEST(test_actions_add_signal) +{ + actions_add_signal(&actions_fixture, SIGINT, 1234); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SIGNAL); + ck_assert_int_eq(actions_fixture.list[0].signal, SIGINT); + ck_assert_int_eq(actions_fixture.list[0].pid, 1234); + ck_assert(actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_add_shell) +{ + actions_add_shell(&actions_fixture, "echo Hello"); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SHELL); + ck_assert_str_eq(actions_fixture.list[0].command, "echo Hello"); + ck_assert(actions_fixture.present[ACTION_SHELL]); +} +END_TEST + +START_TEST(test_actions_add_continue) +{ + actions_add_continue(&actions_fixture); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_CONTINUE); + ck_assert(actions_fixture.present[ACTION_CONTINUE]); +} +END_TEST + +START_TEST(test_actions_add_multiple_same_action) +{ + actions_add_trace_output(&actions_fixture, "trace1.txt"); + actions_add_trace_output(&actions_fixture, "trace2.txt"); + + ck_assert_int_eq(actions_fixture.len, 2); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[0].trace_output, "trace1.txt"); + ck_assert_int_eq(actions_fixture.list[1].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[1].trace_output, "trace2.txt"); + ck_assert(actions_fixture.present[ACTION_TRACE_OUTPUT]); +} +END_TEST + +START_TEST(test_actions_add_multiple_different_action) +{ + actions_add_trace_output(&actions_fixture, "trace_output.txt"); + actions_add_signal(&actions_fixture, SIGINT, 1234); + + ck_assert_int_eq(actions_fixture.len, 2); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[0].trace_output, "trace_output.txt"); + ck_assert(actions_fixture.present[ACTION_TRACE_OUTPUT]); + ck_assert_int_eq(actions_fixture.list[1].type, ACTION_SIGNAL); + ck_assert_int_eq(actions_fixture.list[1].signal, SIGINT); + ck_assert_int_eq(actions_fixture.list[1].pid, 1234); + ck_assert(actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_trace_output) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "trace", "trace.txt"), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[0].trace_output, "trace.txt"); + ck_assert(actions_fixture.present[ACTION_TRACE_OUTPUT]); +} +END_TEST + +START_TEST(test_actions_parse_trace_output_arg) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "trace,file=trace2.txt", "trace1.txt"), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions_fixture.list[0].trace_output, "trace2.txt"); + ck_assert(actions_fixture.present[ACTION_TRACE_OUTPUT]); +} +END_TEST + +START_TEST(test_actions_parse_trace_output_arg_bad) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "trace,foo=bar", "trace_output.txt"), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_TRACE_OUTPUT]); +} +END_TEST + +START_TEST(test_actions_parse_signal) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,num=1,pid=1234", NULL), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SIGNAL); + ck_assert_int_eq(actions_fixture.list[0].signal, 1); + ck_assert_int_eq(actions_fixture.list[0].pid, 1234); + ck_assert(actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_swapped) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,pid=1234,num=1", NULL), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SIGNAL); + ck_assert_int_eq(actions_fixture.list[0].signal, 1); + ck_assert_int_eq(actions_fixture.list[0].pid, 1234); + ck_assert(actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_parent) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,pid=parent,num=1", NULL), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SIGNAL); + ck_assert_int_eq(actions_fixture.list[0].signal, 1); + ck_assert_int_eq(actions_fixture.list[0].pid, -1); + ck_assert(actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_no_arg) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_no_pid) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,num=1", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_no_num) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,pid=1234", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_signal_arg_bad) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "signal,foo=bar", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SIGNAL]); +} +END_TEST + +START_TEST(test_actions_parse_shell) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "shell,command=echo Hello", NULL), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_SHELL); + ck_assert_str_eq(actions_fixture.list[0].command, "echo Hello"); + ck_assert(actions_fixture.present[ACTION_SHELL]); +} +END_TEST + +START_TEST(test_actions_parse_shell_no_arg) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "shell", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SHELL]); +} +END_TEST + +START_TEST(test_actions_parse_shell_arg_bad) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "shell,foo=bar", NULL), -1); + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_SHELL]); +} +END_TEST + +START_TEST(test_actions_parse_continue) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "continue", NULL), 0); + + ck_assert_int_eq(actions_fixture.len, 1); + ck_assert_int_eq(actions_fixture.list[0].type, ACTION_CONTINUE); + ck_assert(actions_fixture.present[ACTION_CONTINUE]); +} +END_TEST + +START_TEST(test_actions_parse_continue_arg_bad) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "continue,foo=bar", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); + ck_assert(!actions_fixture.present[ACTION_CONTINUE]); +} +END_TEST + +START_TEST(test_actions_parse_invalid) +{ + ck_assert_int_eq(actions_parse(&actions_fixture, "foobar", NULL), -1); + + ck_assert_int_eq(actions_fixture.len, 0); +} +END_TEST + +START_TEST(test_actions_perform_continue) +{ + actions_add_continue(&actions_fixture); + ck_assert_int_eq(actions_perform(&actions_fixture), 0); + + ck_assert(actions_fixture.continue_flag); +} +END_TEST + +START_TEST(test_actions_perform_continue_after_successful_shell_command) +{ + actions_add_shell(&actions_fixture, "exit 0"); + actions_add_continue(&actions_fixture); + ck_assert_int_eq(actions_perform(&actions_fixture), 0 << 8); + + ck_assert(actions_fixture.continue_flag); +} +END_TEST + +START_TEST(test_actions_perform_continue_after_failed_shell_command) +{ + actions_add_shell(&actions_fixture, "exit 1"); + actions_add_continue(&actions_fixture); + ck_assert_int_eq(actions_perform(&actions_fixture), 1 << 8); + + ck_assert(!actions_fixture.continue_flag); +} +END_TEST + +START_TEST(test_actions_perform_continue_unset_flag) +{ + actions_fixture.continue_flag = true; + + actions_add_shell(&actions_fixture, "exit 1"); + actions_add_continue(&actions_fixture); + ck_assert_int_eq(actions_perform(&actions_fixture), 1 << 8); + + ck_assert(!actions_fixture.continue_flag); +} +END_TEST + +Suite *actions_suite(void) +{ + Suite *s = suite_create("actions"); + TCase *tc; + + tc = tcase_create("alloc"); + tcase_add_test(tc, test_actions_init); + tcase_add_test(tc, test_actions_destroy); + tcase_add_test(tc, test_actions_reallocate); + suite_add_tcase(s, tc); + + tc = tcase_create("add"); + tcase_add_checked_fixture(tc, actions_fixture_setup, actions_fixture_teardown); + tcase_add_test(tc, test_actions_add_trace_output); + tcase_add_test(tc, test_actions_add_signal); + tcase_add_test(tc, test_actions_add_shell); + tcase_add_test(tc, test_actions_add_continue); + tcase_add_test(tc, test_actions_add_multiple_same_action); + tcase_add_test(tc, test_actions_add_multiple_different_action); + suite_add_tcase(s, tc); + + tc = tcase_create("parse"); + tcase_add_checked_fixture(tc, actions_fixture_setup, actions_fixture_teardown); + tcase_add_test(tc, test_actions_parse_trace_output); + tcase_add_test(tc, test_actions_parse_trace_output_arg); + tcase_add_test(tc, test_actions_parse_trace_output_arg_bad); + tcase_add_test(tc, test_actions_parse_signal); + tcase_add_test(tc, test_actions_parse_signal_swapped); + tcase_add_test(tc, test_actions_parse_signal_parent); + tcase_add_test(tc, test_actions_parse_signal_no_arg); + tcase_add_test(tc, test_actions_parse_signal_no_pid); + tcase_add_test(tc, test_actions_parse_signal_no_num); + tcase_add_test(tc, test_actions_parse_signal_arg_bad); + tcase_add_test(tc, test_actions_parse_shell); + tcase_add_test(tc, test_actions_parse_shell_no_arg); + tcase_add_test(tc, test_actions_parse_shell_arg_bad); + tcase_add_test(tc, test_actions_parse_continue); + tcase_add_test(tc, test_actions_parse_continue_arg_bad); + tcase_add_test(tc, test_actions_parse_invalid); + suite_add_tcase(s, tc); + + tc = tcase_create("perform"); + tcase_add_checked_fixture(tc, actions_fixture_setup, actions_fixture_teardown); + tcase_add_test(tc, test_actions_perform_continue); + tcase_add_test(tc, test_actions_perform_continue_after_successful_shell_command); + tcase_add_test(tc, test_actions_perform_continue_after_failed_shell_command); + tcase_add_test(tc, test_actions_perform_continue_unset_flag); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/cli_opt_callback.c b/tools/tracing/rtla/tests/unit/cli_opt_callback.c new file mode 100644 index 000000000000..4a406af42821 --- /dev/null +++ b/tools/tracing/rtla/tests/unit/cli_opt_callback.c @@ -0,0 +1,716 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <stdio.h> +#include <check.h> + +#define RTLA_ALLOW_CLI_P_H +#include "../../src/cli_p.h" +#include "cli_params_assert.h" + +#define TEST_CALLBACK(value, cb) OPT_CALLBACK('t', "test", value, "test value", "test help", cb) + +START_TEST(test_opt_llong_callback_simple) +{ + long long test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback); + + ck_assert_int_eq(opt_llong_callback(&opt, "1234567890", 0), 0); + ck_assert_int_eq(test_value, 1234567890); +} +END_TEST + +START_TEST(test_opt_llong_callback_max) +{ + long long test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback); + + ck_assert_int_eq(opt_llong_callback(&opt, "9223372036854775807", 0), 0); + ck_assert_int_eq(test_value, 9223372036854775807LL); +} +END_TEST + +START_TEST(test_opt_llong_callback_min) +{ + long long test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback); + + ck_assert_int_eq(opt_llong_callback(&opt, "-9223372036854775808", 0), 0); + ck_assert_int_eq(test_value, ~9223372036854775807LL); +} +END_TEST + +START_TEST(test_opt_int_callback_simple) +{ + int test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback); + + ck_assert_int_eq(opt_int_callback(&opt, "1234567890", 0), 0); + ck_assert_int_eq(test_value, 1234567890); +} +END_TEST + +START_TEST(test_opt_int_callback_max) +{ + int test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback); + + ck_assert_int_eq(opt_int_callback(&opt, "2147483647", 0), 0); + ck_assert_int_eq(test_value, 2147483647); +} +END_TEST + +START_TEST(test_opt_int_callback_min) +{ + int test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback); + + ck_assert_int_eq(opt_int_callback(&opt, "-2147483648", 0), 0); + ck_assert_int_eq(test_value, -2147483648); +} +END_TEST + +START_TEST(test_opt_int_callback_non_numeric) +{ + int test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback); + + ck_assert_int_eq(opt_int_callback(&opt, "abc", 0), -1); + ck_assert_int_eq(test_value, 0); +} +END_TEST + +START_TEST(test_opt_int_callback_non_numeric_suffix) +{ + int test_value = 0; + const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback); + + ck_assert_int_eq(opt_int_callback(&opt, "1234567890abc", 0), -1); + ck_assert_int_eq(test_value, 0); +} +END_TEST + +START_TEST(test_opt_cpus_cb) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_cpus_cb); + + nr_cpus = 4; + ck_assert_int_eq(opt_cpus_cb(&opt, "0-3", 0), 0); + ck_assert_str_eq(params.cpus, "0-3"); +} +END_TEST + +START_TEST(test_opt_cpus_cb_invalid) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_cpus_cb); + + nr_cpus = 4; + assert(freopen("/dev/null", "w", stderr)); + opt_cpus_cb(&opt, "0-3,5", 0); +} +END_TEST + +START_TEST(test_opt_cgroup_cb) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_cgroup_cb); + + ck_assert_int_eq(opt_cgroup_cb(&opt, "cgroup", 0), 0); + ck_assert_int_eq(params.cgroup, 1); + ck_assert_str_eq(params.cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_opt_cgroup_cb_equals) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_cgroup_cb); + + ck_assert_int_eq(opt_cgroup_cb(&opt, "=cgroup", 0), 0); + ck_assert_int_eq(params.cgroup, 1); + ck_assert_str_eq(params.cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_opt_duration_cb) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_duration_cb); + + ck_assert_int_eq(opt_duration_cb(&opt, "1m", 0), 0); + ck_assert_int_eq(params.duration, 60); +} +END_TEST + +START_TEST(test_opt_duration_cb_invalid) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_duration_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_duration_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_event_cb) +{ + struct trace_events *events = NULL; + const struct option opt = TEST_CALLBACK(&events, opt_event_cb); + + ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_switch", 0), 0); + ck_assert_str_eq(events->system, "sched"); + ck_assert_str_eq(events->event, "sched_switch"); + ck_assert_ptr_eq(events->next, NULL); +} +END_TEST + +START_TEST(test_opt_event_cb_multiple) +{ + struct trace_events *events = NULL; + const struct option opt = TEST_CALLBACK(&events, opt_event_cb); + + ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_switch", 0), 0); + ck_assert_int_eq(opt_event_cb(&opt, "sched:sched_wakeup", 0), 0); + ck_assert_str_eq(events->system, "sched"); + ck_assert_str_eq(events->event, "sched_wakeup"); + ck_assert_str_eq(events->next->system, "sched"); + ck_assert_str_eq(events->next->event, "sched_switch"); + ck_assert_ptr_eq(events->next->next, NULL); +} +END_TEST + +START_TEST(test_opt_housekeeping_cb) +{ + struct common_params __params = {0}; + struct common_params *params = &__params; + const struct option opt = TEST_CALLBACK(params, opt_housekeeping_cb); + + nr_cpus = 4; + ck_assert_int_eq(opt_housekeeping_cb(&opt, "0-3", 0), 0); + ck_assert_int_eq(params->hk_cpus, 1); + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 2, 3); +} +END_TEST + +START_TEST(test_opt_housekeeping_cb_invalid) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_housekeeping_cb); + + nr_cpus = 4; + assert(freopen("/dev/null", "w", stderr)); + opt_housekeeping_cb(&opt, "0-3,5", 0); +} +END_TEST + +START_TEST(test_opt_priority_cb) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_priority_cb); + + ck_assert_int_eq(opt_priority_cb(&opt, "f:95", 0), 0); + ck_assert_int_eq(params.sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params.sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_opt_priority_cb_invalid) +{ + struct common_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_priority_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_priority_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_trigger_cb) +{ + struct trace_events *events = trace_event_alloc("sched:sched_switch"); + const struct option opt = TEST_CALLBACK(&events, opt_trigger_cb); + + ck_assert_int_eq(opt_trigger_cb(&opt, "stacktrace", 0), 0); + ck_assert_str_eq(events->trigger, "stacktrace"); +} +END_TEST + +START_TEST(test_opt_trigger_cb_no_event) +{ + struct trace_events *events = NULL; + const struct option opt = TEST_CALLBACK(&events, opt_trigger_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_trigger_cb(&opt, "stacktrace", 0); +} +END_TEST + +START_TEST(test_opt_filter_cb) +{ + struct trace_events *events = trace_event_alloc("sched:sched_switch"); + const struct option opt = TEST_CALLBACK(&events, opt_filter_cb); + + ck_assert_int_eq(opt_filter_cb(&opt, "comm ~ \"rtla\"", 0), 0); + ck_assert_str_eq(events->filter, "comm ~ \"rtla\""); +} +END_TEST + +START_TEST(test_opt_filter_cb_no_event) +{ + struct trace_events *events = NULL; + const struct option opt = TEST_CALLBACK(&events, opt_filter_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_filter_cb(&opt, "comm ~ \"rtla\"", 0); +} +END_TEST + +START_TEST(test_opt_osnoise_auto_cb) +{ + struct osnoise_params params = {0}; + struct osnoise_cb_data cb_data = {¶ms}; + const struct option opt = TEST_CALLBACK(&cb_data, opt_osnoise_auto_cb); + + ck_assert_int_eq(opt_osnoise_auto_cb(&opt, "10", 0), 0); + ck_assert_int_eq(params.common.stop_us, 10); + ck_assert_int_eq(params.threshold, 1); + ck_assert_str_eq(cb_data.trace_output, "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_opt_osnoise_period_cb) +{ + unsigned long long period = 0; + const struct option opt = TEST_CALLBACK(&period, opt_osnoise_period_cb); + + ck_assert_int_eq(opt_osnoise_period_cb(&opt, "1000000", 0), 0); + ck_assert_int_eq(period, 1000000); +} +END_TEST + +START_TEST(test_opt_osnoise_period_cb_invalid) +{ + unsigned long long period = 0; + const struct option opt = TEST_CALLBACK(&period, opt_osnoise_period_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_osnoise_period_cb(&opt, "10000001", 0); +} +END_TEST + +START_TEST(test_opt_osnoise_runtime_cb) +{ + unsigned long long runtime = 0; + const struct option opt = TEST_CALLBACK(&runtime, opt_osnoise_runtime_cb); + + ck_assert_int_eq(opt_osnoise_runtime_cb(&opt, "900000", 0), 0); + ck_assert_int_eq(runtime, 900000); +} +END_TEST + +START_TEST(test_opt_osnoise_runtime_cb_invalid) +{ + unsigned long long runtime = 0; + const struct option opt = TEST_CALLBACK(&runtime, opt_osnoise_runtime_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_osnoise_runtime_cb(&opt, "99", 0); +} +END_TEST + +START_TEST(test_opt_osnoise_trace_output_cb) +{ + const char *trace_output = NULL; + const struct option opt = TEST_CALLBACK(&trace_output, opt_osnoise_trace_output_cb); + + ck_assert_int_eq(opt_osnoise_trace_output_cb(&opt, "trace.txt", 0), 0); + ck_assert_str_eq(trace_output, "trace.txt"); +} +END_TEST + +START_TEST(test_opt_osnoise_trace_output_cb_noarg) +{ + const char *trace_output = NULL; + const struct option opt = TEST_CALLBACK(&trace_output, opt_osnoise_trace_output_cb); + + ck_assert_int_eq(opt_osnoise_trace_output_cb(&opt, NULL, 0), 0); + ck_assert_str_eq(trace_output, "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_opt_osnoise_on_threshold_cb) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_threshold_cb); + + ck_assert_int_eq(opt_osnoise_on_threshold_cb(&opt, "trace", 0), 0); + ck_assert_int_eq(actions.len, 1); + ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions.list[0].trace_output, "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_opt_osnoise_on_threshold_cb_invalid) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_threshold_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_osnoise_on_threshold_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_osnoise_on_end_cb) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_end_cb); + + ck_assert_int_eq(opt_osnoise_on_end_cb(&opt, "trace", 0), 0); + ck_assert_int_eq(actions.len, 1); + ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions.list[0].trace_output, "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_opt_osnoise_on_end_cb_invalid) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_osnoise_on_end_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_osnoise_on_end_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_timerlat_period_cb) +{ + long long period = 0; + const struct option opt = TEST_CALLBACK(&period, opt_timerlat_period_cb); + + ck_assert_int_eq(opt_timerlat_period_cb(&opt, "1000", 0), 0); + ck_assert_int_eq(period, 1000); +} +END_TEST + +START_TEST(test_opt_timerlat_period_cb_invalid) +{ + long long period = 0; + const struct option opt = TEST_CALLBACK(&period, opt_timerlat_period_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_timerlat_period_cb(&opt, "1000001", 0); +} +END_TEST + +START_TEST(test_opt_timerlat_auto_cb) +{ + struct timerlat_params params = {0}; + struct timerlat_cb_data cb_data = {¶ms}; + const struct option opt = TEST_CALLBACK(&cb_data, opt_timerlat_auto_cb); + + ck_assert_int_eq(opt_timerlat_auto_cb(&opt, "10", 0), 0); + ck_assert_int_eq(params.common.stop_us, 10); + ck_assert_int_eq(params.common.stop_total_us, 10); + ck_assert_int_eq(params.print_stack, 10); + ck_assert_str_eq(cb_data.trace_output, "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_opt_dma_latency_cb) +{ + int dma_latency = 0; + const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb); + + ck_assert_int_eq(opt_dma_latency_cb(&opt, "1000", 0), 0); + ck_assert_int_eq(dma_latency, 1000); +} +END_TEST + +START_TEST(test_opt_dma_latency_cb_min) +{ + int dma_latency = 0; + const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_dma_latency_cb(&opt, "-1", 0); +} +END_TEST + +START_TEST(test_opt_dma_latency_cb_max) +{ + int dma_latency = 0; + const struct option opt = TEST_CALLBACK(&dma_latency, opt_dma_latency_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_dma_latency_cb(&opt, "10001", 0); +} +END_TEST + +START_TEST(test_opt_aa_only_cb) +{ + struct timerlat_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_aa_only_cb); + + ck_assert_int_eq(opt_aa_only_cb(&opt, "10", 0), 0); + ck_assert_int_eq(params.common.stop_us, 10); + ck_assert_int_eq(params.common.stop_total_us, 10); + ck_assert_int_eq(params.print_stack, 10); + ck_assert_int_eq(params.common.aa_only, 1); +} +END_TEST + +START_TEST(test_opt_timerlat_trace_output_cb) +{ + const char *trace_output = NULL; + const struct option opt = TEST_CALLBACK(&trace_output, opt_timerlat_trace_output_cb); + + ck_assert_int_eq(opt_timerlat_trace_output_cb(&opt, "trace.txt", 0), 0); + ck_assert_str_eq(trace_output, "trace.txt"); +} +END_TEST + +START_TEST(test_opt_timerlat_trace_output_cb_noarg) +{ + const char *trace_output = NULL; + const struct option opt = TEST_CALLBACK(&trace_output, opt_timerlat_trace_output_cb); + + ck_assert_int_eq(opt_timerlat_trace_output_cb(&opt, NULL, 0), 0); + ck_assert_str_eq(trace_output, "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_opt_timerlat_on_threshold_cb) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_threshold_cb); + + ck_assert_int_eq(opt_timerlat_on_threshold_cb(&opt, "trace", 0), 0); + ck_assert_int_eq(actions.len, 1); + ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions.list[0].trace_output, "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_opt_timerlat_on_threshold_cb_invalid) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_threshold_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_timerlat_on_threshold_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_timerlat_on_end_cb) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_end_cb); + + ck_assert_int_eq(opt_timerlat_on_end_cb(&opt, "trace", 0), 0); + ck_assert_int_eq(actions.len, 1); + ck_assert_int_eq(actions.list[0].type, ACTION_TRACE_OUTPUT); + ck_assert_str_eq(actions.list[0].trace_output, "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_opt_timerlat_on_end_cb_invalid) +{ + struct actions actions = {0}; + const struct option opt = TEST_CALLBACK(&actions, opt_timerlat_on_end_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_timerlat_on_end_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_user_threads_cb) +{ + struct timerlat_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_user_threads_cb); + + ck_assert_int_eq(opt_user_threads_cb(&opt, NULL, 0), 0); + ck_assert_int_eq(params.common.user_workload, 1); + ck_assert_int_eq(params.common.user_data, 1); +} +END_TEST + +START_TEST(test_opt_nano_cb) +{ + struct timerlat_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_nano_cb); + + ck_assert_int_eq(opt_nano_cb(&opt, NULL, 0), 0); + ck_assert_int_eq(params.common.output_divisor, 1); +} +END_TEST + +START_TEST(test_opt_timerlat_align_cb) +{ + struct timerlat_params params = {0}; + const struct option opt = TEST_CALLBACK(¶ms, opt_timerlat_align_cb); + + ck_assert_int_eq(opt_timerlat_align_cb(&opt, "500", 0), 0); + ck_assert(params.timerlat_align); + ck_assert_int_eq(params.timerlat_align_us, 500); +} +END_TEST + +START_TEST(test_opt_stack_format_cb) +{ + int stack_format = 0; + const struct option opt = TEST_CALLBACK(&stack_format, opt_stack_format_cb); + + ck_assert_int_eq(opt_stack_format_cb(&opt, "full", 0), 0); + ck_assert_int_eq(stack_format, STACK_FORMAT_FULL); +} +END_TEST + +START_TEST(test_opt_stack_format_cb_invalid) +{ + int stack_format = 0; + const struct option opt = TEST_CALLBACK(&stack_format, opt_stack_format_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_stack_format_cb(&opt, "abc", 0); +} +END_TEST + +START_TEST(test_opt_bucket_size_cb) +{ + int bucket_size = 0; + const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb); + + ck_assert_int_eq(opt_bucket_size_cb(&opt, "100", 0), 0); + ck_assert_int_eq(bucket_size, 100); +} +END_TEST + +START_TEST(test_opt_bucket_size_min) +{ + int bucket_size = 0; + const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_bucket_size_cb(&opt, "0", 0); +} +END_TEST + +START_TEST(test_opt_bucket_size_max) +{ + int bucket_size = 0; + const struct option opt = TEST_CALLBACK(&bucket_size, opt_bucket_size_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_bucket_size_cb(&opt, "1000001", 0); +} +END_TEST + +START_TEST(test_opt_entries_cb) +{ + int entries = 0; + const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb); + + ck_assert_int_eq(opt_entries_cb(&opt, "100", 0), 0); + ck_assert_int_eq(entries, 100); +} +END_TEST + +START_TEST(test_opt_entries_min) +{ + int entries = 0; + const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_entries_cb(&opt, "9", 0); +} +END_TEST + +START_TEST(test_opt_entries_max) +{ + int entries = 0; + const struct option opt = TEST_CALLBACK(&entries, opt_entries_cb); + + assert(freopen("/dev/null", "w", stderr)); + opt_entries_cb(&opt, "10000000", 0); +} +END_TEST + +Suite *cli_opt_callback_suite(void) +{ + Suite *s = suite_create("cli_opt_callback"); + TCase *tc; + + tc = tcase_create("common"); + tcase_add_test(tc, test_opt_llong_callback_simple); + tcase_add_test(tc, test_opt_llong_callback_max); + tcase_add_test(tc, test_opt_llong_callback_min); + tcase_add_test(tc, test_opt_int_callback_simple); + tcase_add_test(tc, test_opt_int_callback_max); + tcase_add_test(tc, test_opt_int_callback_min); + tcase_add_test(tc, test_opt_int_callback_non_numeric); + tcase_add_test(tc, test_opt_int_callback_non_numeric_suffix); + tcase_add_test(tc, test_opt_cpus_cb); + tcase_add_exit_test(tc, test_opt_cpus_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_cgroup_cb); + tcase_add_test(tc, test_opt_cgroup_cb_equals); + tcase_add_test(tc, test_opt_duration_cb); + tcase_add_exit_test(tc, test_opt_duration_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_event_cb); + tcase_add_test(tc, test_opt_event_cb_multiple); + tcase_add_test(tc, test_opt_housekeeping_cb); + tcase_add_exit_test(tc, test_opt_housekeeping_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_priority_cb); + tcase_add_exit_test(tc, test_opt_priority_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_trigger_cb); + tcase_add_exit_test(tc, test_opt_trigger_cb_no_event, EXIT_FAILURE); + tcase_add_test(tc, test_opt_filter_cb); + tcase_add_exit_test(tc, test_opt_filter_cb_no_event, EXIT_FAILURE); + suite_add_tcase(s, tc); + + tc = tcase_create("osnoise"); + tcase_add_test(tc, test_opt_osnoise_auto_cb); + tcase_add_test(tc, test_opt_osnoise_period_cb); + tcase_add_exit_test(tc, test_opt_osnoise_period_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_osnoise_runtime_cb); + tcase_add_exit_test(tc, test_opt_osnoise_runtime_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_osnoise_trace_output_cb); + tcase_add_test(tc, test_opt_osnoise_trace_output_cb_noarg); + tcase_add_test(tc, test_opt_osnoise_on_threshold_cb); + tcase_add_exit_test(tc, test_opt_osnoise_on_threshold_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_osnoise_on_end_cb); + tcase_add_exit_test(tc, test_opt_osnoise_on_end_cb_invalid, EXIT_FAILURE); + suite_add_tcase(s, tc); + + tc = tcase_create("timerlat"); + tcase_add_test(tc, test_opt_timerlat_period_cb); + tcase_add_exit_test(tc, test_opt_timerlat_period_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_timerlat_auto_cb); + tcase_add_test(tc, test_opt_dma_latency_cb); + tcase_add_exit_test(tc, test_opt_dma_latency_cb_min, EXIT_FAILURE); + tcase_add_exit_test(tc, test_opt_dma_latency_cb_max, EXIT_FAILURE); + tcase_add_test(tc, test_opt_aa_only_cb); + tcase_add_test(tc, test_opt_timerlat_trace_output_cb); + tcase_add_test(tc, test_opt_timerlat_trace_output_cb_noarg); + tcase_add_test(tc, test_opt_timerlat_on_threshold_cb); + tcase_add_exit_test(tc, test_opt_timerlat_on_threshold_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_timerlat_on_end_cb); + tcase_add_exit_test(tc, test_opt_timerlat_on_end_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_user_threads_cb); + tcase_add_test(tc, test_opt_nano_cb); + tcase_add_test(tc, test_opt_stack_format_cb); + tcase_add_exit_test(tc, test_opt_stack_format_cb_invalid, EXIT_FAILURE); + tcase_add_test(tc, test_opt_timerlat_align_cb); + suite_add_tcase(s, tc); + + tc = tcase_create("histogram"); + tcase_add_test(tc, test_opt_bucket_size_cb); + tcase_add_exit_test(tc, test_opt_bucket_size_min, EXIT_FAILURE); + tcase_add_exit_test(tc, test_opt_bucket_size_max, EXIT_FAILURE); + tcase_add_test(tc, test_opt_entries_cb); + tcase_add_exit_test(tc, test_opt_entries_min, EXIT_FAILURE); + tcase_add_exit_test(tc, test_opt_entries_max, EXIT_FAILURE); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/cli_params_assert.h b/tools/tracing/rtla/tests/unit/cli_params_assert.h new file mode 100644 index 000000000000..4bc7d582fcf4 --- /dev/null +++ b/tools/tracing/rtla/tests/unit/cli_params_assert.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#pragma once + +#include "../../src/timerlat.h" + +/* Tracing Options */ + +#define CLI_ASSERT_SINGLE_EVENT(_system, _event) do {\ + ck_assert_ptr_nonnull(params->events);\ + ck_assert_str_eq(params->events->system, _system);\ + ck_assert_str_eq(params->events->event, _event);\ + ck_assert_ptr_null(params->events->next);\ +} while (0) + +#define CLI_ASSERT_SINGLE_FILTER(_filter) do {\ + ck_assert_ptr_nonnull(params->events);\ + ck_assert_str_eq(params->events->filter, _filter);\ + ck_assert_ptr_null(params->events->next);\ +} while (0) + +#define CLI_ASSERT_SINGLE_TRIGGER(_trigger) do {\ + ck_assert_ptr_nonnull(params->events);\ + ck_assert_str_eq(params->events->trigger, _trigger);\ + ck_assert_ptr_null(params->events->next);\ +} while (0) + +/* CPU Configuration */ + +#define CLI_ASSERT_CPUSET(_field, ...) do {\ + int n;\ + int cpus[] = { __VA_ARGS__ };\ + for (n = 0; n < sizeof(cpus) / sizeof(int); n++)\ + ck_assert(CPU_ISSET(cpus[n], ¶ms->_field));\ + ck_assert_int_eq(CPU_COUNT(¶ms->_field), n);\ +} while (0) + +/* Auto Analysis and Actions */ + +#define CLI_OSNOISE_ASSERT_AUTO(_stop) do {\ + ck_assert_int_eq(params->stop_us, _stop);\ + ck_assert_int_eq(osn_params->threshold, 1);\ + ck_assert_int_eq(params->threshold_actions.len, 1);\ + ck_assert_int_eq(params->threshold_actions.list[0].type, ACTION_TRACE_OUTPUT);\ + ck_assert_str_eq(params->threshold_actions.list[0].trace_output, "osnoise_trace.txt");\ +} while (0) + +#define CLI_TIMERLAT_ASSERT_AUTO(_threshold) do {\ + ck_assert_int_eq(params->stop_us, _threshold);\ + ck_assert_int_eq(params->stop_total_us, _threshold);\ + ck_assert_int_eq(tlat_params->print_stack, _threshold);\ + ck_assert_int_eq(params->threshold_actions.len, 1);\ + ck_assert_int_eq(params->threshold_actions.list[0].type, ACTION_TRACE_OUTPUT);\ + ck_assert_str_eq(params->threshold_actions.list[0].trace_output, "timerlat_trace.txt");\ +} while (0) + +#define CLI_TIMERLAT_ASSERT_AA_ONLY(_threshold) do {\ + ck_assert_int_eq(params->stop_us, _threshold);\ + ck_assert_int_eq(params->stop_total_us, _threshold);\ + ck_assert_int_eq(tlat_params->print_stack, _threshold);\ + ck_assert_int_eq(params->threshold_actions.len, 0);\ + ck_assert(params->aa_only);\ +} while (0) + +#define CLI_ASSERT_SINGLE_ACTION(_actions, _type, _arg, _valtype, _value) do {\ + ck_assert_int_eq(params->_actions.len, 1);\ + ck_assert_int_eq(params->_actions.list[0].type, _type);\ + ck_assert_##_valtype##_eq(params->_actions.list[0]._arg, _value);\ +} while (0) diff --git a/tools/tracing/rtla/tests/unit/osnoise_hist_cli.c b/tools/tracing/rtla/tests/unit/osnoise_hist_cli.c new file mode 100644 index 000000000000..3661529f93dc --- /dev/null +++ b/tools/tracing/rtla/tests/unit/osnoise_hist_cli.c @@ -0,0 +1,557 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <limits.h> +#include <unistd.h> +#include <sys/sysinfo.h> + +#include "cli_params_assert.h" +#include "../../src/cli.h" + +#define PARSE_ARGS(...) char *argv[] = { __VA_ARGS__, NULL };\ + int argc = sizeof(argv) / sizeof(char *) - 1;\ + struct common_params *params =\ + osnoise_hist_parse_args(argc, argv);\ + struct osnoise_params *osn_params __maybe_unused =\ + to_osnoise_params(params) + +/* Tracing Options */ + +START_TEST(test_period_short) +{ + PARSE_ARGS("osnoise", "hist", "-p", "100000"); + + ck_assert_int_eq(osn_params->period, 100000); +} +END_TEST + +START_TEST(test_period_long) +{ + PARSE_ARGS("osnoise", "hist", "--period", "100000"); + + ck_assert_int_eq(osn_params->period, 100000); +} +END_TEST + +START_TEST(test_runtime_short) +{ + PARSE_ARGS("osnoise", "hist", "-r", "95000"); + + ck_assert_int_eq(osn_params->runtime, 95000); +} +END_TEST + +START_TEST(test_runtime_long) +{ + PARSE_ARGS("osnoise", "hist", "--runtime", "95000"); + + ck_assert_int_eq(osn_params->runtime, 95000); +} +END_TEST + +START_TEST(test_stop_short) +{ + PARSE_ARGS("osnoise", "hist", "-s", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_stop_long) +{ + PARSE_ARGS("osnoise", "hist", "--stop", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_stop_total_short) +{ + PARSE_ARGS("osnoise", "hist", "-S", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_stop_total_long) +{ + PARSE_ARGS("osnoise", "hist", "--stop-total", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_threshold_short) +{ + PARSE_ARGS("osnoise", "hist", "-T", "5"); + + ck_assert_int_eq(osn_params->threshold, 5); +} +END_TEST + +START_TEST(test_threshold_long) +{ + PARSE_ARGS("osnoise", "hist", "--threshold", "5"); + + ck_assert_int_eq(osn_params->threshold, 5); +} +END_TEST + +START_TEST(test_trace_short_noarg) +{ + PARSE_ARGS("osnoise", "hist", "-t"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_trace_short_followarg) +{ + PARSE_ARGS("osnoise", "hist", "-t", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_short_space) +{ + PARSE_ARGS("osnoise", "hist", "-t", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_short_equals) +{ + PARSE_ARGS("osnoise", "hist", "-t=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_noarg) +{ + PARSE_ARGS("osnoise", "hist", "--trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_trace_long_followarg) +{ + PARSE_ARGS("osnoise", "hist", "--trace", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_long_space) +{ + PARSE_ARGS("osnoise", "hist", "--trace", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_equals) +{ + PARSE_ARGS("osnoise", "hist", "--trace=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +/* Event Configuration */ + +START_TEST(test_event_short) +{ + PARSE_ARGS("osnoise", "hist", "-e", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_event_long) +{ + PARSE_ARGS("osnoise", "hist", "--event", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_filter) +{ + PARSE_ARGS("osnoise", "hist", "-e", "system:event", "--filter", "filter"); + + CLI_ASSERT_SINGLE_FILTER("filter"); +} +END_TEST + +START_TEST(test_trigger) +{ + PARSE_ARGS("osnoise", "hist", "-e", "system:event", "--trigger", "trigger"); + + CLI_ASSERT_SINGLE_TRIGGER("trigger"); +} +END_TEST + +/* CPU Configuration */ + +START_TEST(test_cpus_short) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "hist", "-c", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_cpus_long) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "hist", "--cpus", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_short) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "hist", "-H", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_long) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "hist", "--house-keeping", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +/* Thread Configuration */ + +START_TEST(test_cgroup_short_noarg) +{ + PARSE_ARGS("osnoise", "hist", "-C"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_short_space) +{ + PARSE_ARGS("osnoise", "hist", "-C", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_short_equals) +{ + PARSE_ARGS("osnoise", "hist", "-C=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_noarg) +{ + PARSE_ARGS("osnoise", "hist", "--cgroup"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_long_space) +{ + PARSE_ARGS("osnoise", "hist", "--cgroup", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_equals) +{ + PARSE_ARGS("osnoise", "hist", "--cgroup=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_priority_short) +{ + PARSE_ARGS("osnoise", "hist", "-P", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_priority_long) +{ + PARSE_ARGS("osnoise", "hist", "--priority", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +/* Histogram Options */ + +START_TEST(test_bucket_size_short) +{ + PARSE_ARGS("osnoise", "hist", "-b", "2"); + + ck_assert_int_eq(params->hist.bucket_size, 2); +} +END_TEST + +START_TEST(test_bucket_size_long) +{ + PARSE_ARGS("osnoise", "hist", "--bucket-size", "2"); + + ck_assert_int_eq(params->hist.bucket_size, 2); +} +END_TEST + +START_TEST(test_entries_short) +{ + PARSE_ARGS("osnoise", "hist", "-E", "512"); + + ck_assert_int_eq(params->hist.entries, 512); +} +END_TEST + +START_TEST(test_entries_long) +{ + PARSE_ARGS("osnoise", "hist", "--entries", "512"); + + ck_assert_int_eq(params->hist.entries, 512); +} +END_TEST + +START_TEST(test_no_header) +{ + PARSE_ARGS("osnoise", "hist", "--no-header"); + + ck_assert(params->hist.no_header); +} +END_TEST + +START_TEST(test_no_index) +{ + PARSE_ARGS("osnoise", "hist", "--with-zeros", "--no-index"); + + ck_assert(params->hist.no_index); +} +END_TEST + +START_TEST(test_no_summary) +{ + PARSE_ARGS("osnoise", "hist", "--no-summary"); + + ck_assert(params->hist.no_summary); +} +END_TEST + +START_TEST(test_with_zeros) +{ + PARSE_ARGS("osnoise", "hist", "--with-zeros"); + + ck_assert(params->hist.with_zeros); +} +END_TEST + +/* System Tuning */ + +START_TEST(test_trace_buffer_size) +{ + PARSE_ARGS("osnoise", "hist", "--trace-buffer-size", "200"); + + ck_assert_int_eq(params->buffer_size, 200); +} +END_TEST + +START_TEST(test_warm_up) +{ + PARSE_ARGS("osnoise", "hist", "--warm-up", "5"); + + ck_assert_int_eq(params->warmup, 5); +} +END_TEST + +/* Auto Analysis and Actions */ + +START_TEST(test_auto) +{ + PARSE_ARGS("osnoise", "hist", "-a", "20"); + + CLI_OSNOISE_ASSERT_AUTO(20); +} +END_TEST + +START_TEST(test_on_end) +{ + PARSE_ARGS("osnoise", "hist", "--on-end", "trace"); + + CLI_ASSERT_SINGLE_ACTION(end_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_on_threshold) +{ + PARSE_ARGS("osnoise", "hist", "--on-threshold", "trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +/* General */ + +START_TEST(test_debug_short) +{ + PARSE_ARGS("osnoise", "hist", "-D"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_debug_long) +{ + PARSE_ARGS("osnoise", "hist", "--debug"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_duration_short) +{ + PARSE_ARGS("osnoise", "hist", "-d", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +START_TEST(test_duration_long) +{ + PARSE_ARGS("osnoise", "hist", "--duration", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +Suite *osnoise_hist_cli_suite(void) +{ + Suite *s = suite_create("osnoise_hist_cli"); + TCase *tc; + + tc = tcase_create("tracing_options"); + tcase_add_test(tc, test_period_short); + tcase_add_test(tc, test_period_long); + tcase_add_test(tc, test_runtime_short); + tcase_add_test(tc, test_runtime_long); + tcase_add_test(tc, test_stop_short); + tcase_add_test(tc, test_stop_long); + tcase_add_test(tc, test_stop_total_short); + tcase_add_test(tc, test_stop_total_long); + tcase_add_test(tc, test_threshold_short); + tcase_add_test(tc, test_threshold_long); + tcase_add_test(tc, test_trace_short_noarg); + tcase_add_test(tc, test_trace_short_followarg); + tcase_add_test(tc, test_trace_short_space); + tcase_add_test(tc, test_trace_short_equals); + tcase_add_test(tc, test_trace_long_noarg); + tcase_add_test(tc, test_trace_long_followarg); + tcase_add_test(tc, test_trace_long_space); + tcase_add_test(tc, test_trace_long_equals); + suite_add_tcase(s, tc); + + tc = tcase_create("event_configuration"); + tcase_add_test(tc, test_event_short); + tcase_add_test(tc, test_event_long); + tcase_add_test(tc, test_filter); + tcase_add_test(tc, test_trigger); + suite_add_tcase(s, tc); + + tc = tcase_create("cpu_configuration"); + tcase_add_test(tc, test_cpus_short); + tcase_add_test(tc, test_cpus_long); + tcase_add_test(tc, test_housekeeping_short); + tcase_add_test(tc, test_housekeeping_long); + suite_add_tcase(s, tc); + + tc = tcase_create("thread_configuration"); + tcase_add_test(tc, test_cgroup_short_noarg); + tcase_add_test(tc, test_cgroup_short_space); + tcase_add_test(tc, test_cgroup_short_equals); + tcase_add_test(tc, test_cgroup_long_noarg); + tcase_add_test(tc, test_cgroup_long_space); + tcase_add_test(tc, test_cgroup_long_equals); + tcase_add_test(tc, test_priority_short); + tcase_add_test(tc, test_priority_long); + suite_add_tcase(s, tc); + + tc = tcase_create("histogram_options"); + tcase_add_test(tc, test_bucket_size_short); + tcase_add_test(tc, test_bucket_size_long); + tcase_add_test(tc, test_entries_short); + tcase_add_test(tc, test_entries_long); + tcase_add_test(tc, test_no_header); + tcase_add_test(tc, test_no_index); + tcase_add_test(tc, test_no_summary); + tcase_add_test(tc, test_with_zeros); + suite_add_tcase(s, tc); + + tc = tcase_create("system_tuning"); + tcase_add_test(tc, test_trace_buffer_size); + tcase_add_test(tc, test_warm_up); + suite_add_tcase(s, tc); + + tc = tcase_create("aa_actions"); + tcase_add_test(tc, test_auto); + tcase_add_test(tc, test_on_end); + tcase_add_test(tc, test_on_threshold); + suite_add_tcase(s, tc); + + tc = tcase_create("general"); + tcase_add_test(tc, test_debug_short); + tcase_add_test(tc, test_debug_long); + tcase_add_test(tc, test_duration_short); + tcase_add_test(tc, test_duration_long); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/osnoise_top_cli.c b/tools/tracing/rtla/tests/unit/osnoise_top_cli.c new file mode 100644 index 000000000000..f3a8633cc84e --- /dev/null +++ b/tools/tracing/rtla/tests/unit/osnoise_top_cli.c @@ -0,0 +1,503 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <limits.h> +#include <unistd.h> +#include <sys/sysinfo.h> + +#include "cli_params_assert.h" +#include "../../src/cli.h" + +#define PARSE_ARGS(...) char *argv[] = { __VA_ARGS__, NULL };\ + int argc = sizeof(argv) / sizeof(char *) - 1;\ + struct common_params *params =\ + osnoise_top_parse_args(argc, argv);\ + struct osnoise_params *osn_params __maybe_unused =\ + to_osnoise_params(params) + +/* Tracing Options */ + +START_TEST(test_period_short) +{ + PARSE_ARGS("osnoise", "top", "-p", "100000"); + + ck_assert_int_eq(osn_params->period, 100000); +} +END_TEST + +START_TEST(test_period_long) +{ + PARSE_ARGS("osnoise", "top", "--period", "100000"); + + ck_assert_int_eq(osn_params->period, 100000); +} +END_TEST + +START_TEST(test_runtime_short) +{ + PARSE_ARGS("osnoise", "top", "-r", "95000"); + + ck_assert_int_eq(osn_params->runtime, 95000); +} +END_TEST + +START_TEST(test_runtime_long) +{ + PARSE_ARGS("osnoise", "top", "--runtime", "95000"); + + ck_assert_int_eq(osn_params->runtime, 95000); +} +END_TEST + +START_TEST(test_stop_short) +{ + PARSE_ARGS("osnoise", "top", "-s", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_stop_long) +{ + PARSE_ARGS("osnoise", "top", "--stop", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_stop_total_short) +{ + PARSE_ARGS("osnoise", "top", "-S", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_stop_total_long) +{ + PARSE_ARGS("osnoise", "top", "--stop-total", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_threshold_short) +{ + PARSE_ARGS("osnoise", "top", "-T", "5"); + + ck_assert_int_eq(osn_params->threshold, 5); +} +END_TEST + +START_TEST(test_threshold_long) +{ + PARSE_ARGS("osnoise", "top", "--threshold", "5"); + + ck_assert_int_eq(osn_params->threshold, 5); +} +END_TEST + +START_TEST(test_trace_short_noarg) +{ + PARSE_ARGS("osnoise", "top", "-t"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_trace_short_followarg) +{ + PARSE_ARGS("osnoise", "top", "-t", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_short_space) +{ + PARSE_ARGS("osnoise", "top", "-t", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_short_equals) +{ + PARSE_ARGS("osnoise", "top", "-t=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_noarg) +{ + PARSE_ARGS("osnoise", "top", "--trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_trace_long_followarg) +{ + PARSE_ARGS("osnoise", "top", "--trace", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_long_space) +{ + PARSE_ARGS("osnoise", "top", "--trace", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_equals) +{ + PARSE_ARGS("osnoise", "top", "--trace=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +/* Event Configuration */ + +START_TEST(test_event_short) +{ + PARSE_ARGS("osnoise", "top", "-e", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_event_long) +{ + PARSE_ARGS("osnoise", "top", "--event", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_filter) +{ + PARSE_ARGS("osnoise", "top", "-e", "system:event", "--filter", "filter"); + + CLI_ASSERT_SINGLE_FILTER("filter"); +} +END_TEST + +START_TEST(test_trigger) +{ + PARSE_ARGS("osnoise", "top", "-e", "system:event", "--trigger", "trigger"); + + CLI_ASSERT_SINGLE_TRIGGER("trigger"); +} +END_TEST + +/* CPU Configuration */ + +START_TEST(test_cpus_short) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "top", "-c", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_cpus_long) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "top", "--cpus", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_short) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "top", "-H", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_long) +{ + nr_cpus = 4; + + PARSE_ARGS("osnoise", "top", "--house-keeping", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +/* Thread Configuration */ + +START_TEST(test_cgroup_short_noarg) +{ + PARSE_ARGS("osnoise", "top", "-C"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_short_space) +{ + PARSE_ARGS("osnoise", "top", "-C", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_short_equals) +{ + PARSE_ARGS("osnoise", "top", "-C=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_noarg) +{ + PARSE_ARGS("osnoise", "top", "--cgroup"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_long_space) +{ + PARSE_ARGS("osnoise", "top", "--cgroup", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_equals) +{ + PARSE_ARGS("osnoise", "top", "--cgroup=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_priority_short) +{ + PARSE_ARGS("osnoise", "top", "-P", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_priority_long) +{ + PARSE_ARGS("osnoise", "top", "--priority", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +/* Output */ + +START_TEST(test_quiet_short) +{ + PARSE_ARGS("osnoise", "top", "-q"); + + ck_assert(params->quiet); +} +END_TEST + +START_TEST(test_quiet_long) +{ + PARSE_ARGS("osnoise", "top", "--quiet"); + + ck_assert(params->quiet); +} +END_TEST + +/* Auto Analysis and Actions */ + +START_TEST(test_auto) +{ + PARSE_ARGS("osnoise", "top", "-a", "20"); + + CLI_OSNOISE_ASSERT_AUTO(20); +} +END_TEST + +START_TEST(test_on_end) +{ + PARSE_ARGS("osnoise", "top", "--on-end", "trace"); + + CLI_ASSERT_SINGLE_ACTION(end_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +START_TEST(test_on_threshold) +{ + PARSE_ARGS("osnoise", "top", "--on-threshold", "trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "osnoise_trace.txt"); +} +END_TEST + +/* System Tuning */ + +START_TEST(test_trace_buffer_size) +{ + PARSE_ARGS("osnoise", "top", "--trace-buffer-size", "200"); + + ck_assert_int_eq(params->buffer_size, 200); +} +END_TEST + +START_TEST(test_warm_up) +{ + PARSE_ARGS("osnoise", "top", "--warm-up", "5"); + + ck_assert_int_eq(params->warmup, 5); +} +END_TEST + +/* General */ + +START_TEST(test_debug_short) +{ + PARSE_ARGS("osnoise", "top", "-D"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_debug_long) +{ + PARSE_ARGS("osnoise", "top", "--debug"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_duration_short) +{ + PARSE_ARGS("osnoise", "top", "-d", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +START_TEST(test_duration_long) +{ + PARSE_ARGS("osnoise", "top", "--duration", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +Suite *osnoise_top_cli_suite(void) +{ + Suite *s = suite_create("osnoise_top_cli"); + TCase *tc; + + tc = tcase_create("tracing_options"); + tcase_add_test(tc, test_period_short); + tcase_add_test(tc, test_period_long); + tcase_add_test(tc, test_runtime_short); + tcase_add_test(tc, test_runtime_long); + tcase_add_test(tc, test_stop_short); + tcase_add_test(tc, test_stop_long); + tcase_add_test(tc, test_stop_total_short); + tcase_add_test(tc, test_stop_total_long); + tcase_add_test(tc, test_threshold_short); + tcase_add_test(tc, test_threshold_long); + tcase_add_test(tc, test_trace_short_noarg); + tcase_add_test(tc, test_trace_short_followarg); + tcase_add_test(tc, test_trace_short_space); + tcase_add_test(tc, test_trace_short_equals); + tcase_add_test(tc, test_trace_long_noarg); + tcase_add_test(tc, test_trace_long_followarg); + tcase_add_test(tc, test_trace_long_space); + tcase_add_test(tc, test_trace_long_equals); + suite_add_tcase(s, tc); + + tc = tcase_create("event_configuration"); + tcase_add_test(tc, test_event_short); + tcase_add_test(tc, test_event_long); + tcase_add_test(tc, test_filter); + tcase_add_test(tc, test_trigger); + suite_add_tcase(s, tc); + + tc = tcase_create("cpu_configuration"); + tcase_add_test(tc, test_cpus_short); + tcase_add_test(tc, test_cpus_long); + tcase_add_test(tc, test_housekeeping_short); + tcase_add_test(tc, test_housekeeping_long); + suite_add_tcase(s, tc); + + tc = tcase_create("thread_configuration"); + tcase_add_test(tc, test_cgroup_short_noarg); + tcase_add_test(tc, test_cgroup_short_space); + tcase_add_test(tc, test_cgroup_short_equals); + tcase_add_test(tc, test_cgroup_long_noarg); + tcase_add_test(tc, test_cgroup_long_space); + tcase_add_test(tc, test_cgroup_long_equals); + tcase_add_test(tc, test_priority_short); + tcase_add_test(tc, test_priority_long); + suite_add_tcase(s, tc); + + tc = tcase_create("output"); + tcase_add_test(tc, test_quiet_short); + tcase_add_test(tc, test_quiet_long); + suite_add_tcase(s, tc); + + tc = tcase_create("system_tuning"); + tcase_add_test(tc, test_trace_buffer_size); + tcase_add_test(tc, test_warm_up); + suite_add_tcase(s, tc); + + tc = tcase_create("aa_actions"); + tcase_add_test(tc, test_auto); + tcase_add_test(tc, test_on_end); + tcase_add_test(tc, test_on_threshold); + suite_add_tcase(s, tc); + + tc = tcase_create("general"); + tcase_add_test(tc, test_debug_short); + tcase_add_test(tc, test_debug_long); + tcase_add_test(tc, test_duration_short); + tcase_add_test(tc, test_duration_long); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/timerlat_hist_cli.c b/tools/tracing/rtla/tests/unit/timerlat_hist_cli.c new file mode 100644 index 000000000000..968bf962f53f --- /dev/null +++ b/tools/tracing/rtla/tests/unit/timerlat_hist_cli.c @@ -0,0 +1,722 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <limits.h> +#include <unistd.h> +#include <sys/sysinfo.h> + +#include <linux/container_of.h> + +#include "cli_params_assert.h" +#include "../../src/cli.h" + +#define PARSE_ARGS(...) char *argv[] = { __VA_ARGS__, NULL };\ + int argc = sizeof(argv) / sizeof(char *) - 1;\ + struct common_params *params =\ + timerlat_hist_parse_args(argc, argv);\ + struct timerlat_params *tlat_params __maybe_unused =\ + to_timerlat_params(params) + +/* Tracing Options */ + +START_TEST(test_irq_short) +{ + PARSE_ARGS("timerlat", "hist", "-i", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_irq_long) +{ + PARSE_ARGS("timerlat", "hist", "--irq", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_period_short) +{ + PARSE_ARGS("timerlat", "hist", "-p", "200"); + + ck_assert_int_eq(tlat_params->timerlat_period_us, 200); +} +END_TEST + +START_TEST(test_period_long) +{ + PARSE_ARGS("timerlat", "hist", "--period", "200"); + + ck_assert_int_eq(tlat_params->timerlat_period_us, 200); +} +END_TEST + +START_TEST(test_stack_short) +{ + PARSE_ARGS("timerlat", "hist", "-s", "20"); + + ck_assert_int_eq(tlat_params->print_stack, 20); +} +END_TEST + +START_TEST(test_stack_long) +{ + PARSE_ARGS("timerlat", "hist", "--stack", "20"); + + ck_assert_int_eq(tlat_params->print_stack, 20); +} +END_TEST + +START_TEST(test_thread_short) +{ + PARSE_ARGS("timerlat", "hist", "-T", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_thread_long) +{ + PARSE_ARGS("timerlat", "hist", "--thread", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_trace_short_noarg) +{ + PARSE_ARGS("timerlat", "hist", "-t"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_trace_short_followarg) +{ + PARSE_ARGS("timerlat", "hist", "-t", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_short_space) +{ + PARSE_ARGS("timerlat", "hist", "-t", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_short_equals) +{ + PARSE_ARGS("timerlat", "hist", "-t=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_noarg) +{ + PARSE_ARGS("timerlat", "hist", "--trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_trace_long_followarg) +{ + PARSE_ARGS("timerlat", "hist", "--trace", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_long_space) +{ + PARSE_ARGS("timerlat", "hist", "--trace", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_equals) +{ + PARSE_ARGS("timerlat", "hist", "--trace=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +/* Event Configuration */ + +START_TEST(test_event_short) +{ + PARSE_ARGS("timerlat", "hist", "-e", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_event_long) +{ + PARSE_ARGS("timerlat", "hist", "--event", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_filter) +{ + PARSE_ARGS("timerlat", "hist", "-e", "system:event", "--filter", "filter"); + + CLI_ASSERT_SINGLE_FILTER("filter"); +} +END_TEST + +START_TEST(test_trigger) +{ + PARSE_ARGS("timerlat", "hist", "-e", "system:event", "--trigger", "trigger"); + + CLI_ASSERT_SINGLE_TRIGGER("trigger"); +} +END_TEST + +/* CPU Configuration */ + +START_TEST(test_cpus_short) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "hist", "-c", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_cpus_long) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "hist", "--cpus", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_short) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "hist", "-H", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_long) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "hist", "--house-keeping", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +/* Thread Configuration */ + +START_TEST(test_cgroup_short_noarg) +{ + PARSE_ARGS("timerlat", "hist", "-C"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_short_space) +{ + PARSE_ARGS("timerlat", "hist", "-C", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_short_equals) +{ + PARSE_ARGS("timerlat", "hist", "-C=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_noarg) +{ + PARSE_ARGS("timerlat", "hist", "--cgroup"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_long_space) +{ + PARSE_ARGS("timerlat", "hist", "--cgroup", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_equals) +{ + PARSE_ARGS("timerlat", "hist", "--cgroup=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_kernel_threads_short) +{ + PARSE_ARGS("timerlat", "hist", "-k"); + + ck_assert(params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(!params->user_data); +} +END_TEST + +START_TEST(test_kernel_threads_long) +{ + PARSE_ARGS("timerlat", "hist", "--kernel-threads"); + + ck_assert(params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(!params->user_data); +} +END_TEST + +START_TEST(test_priority_short) +{ + PARSE_ARGS("timerlat", "hist", "-P", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_priority_long) +{ + PARSE_ARGS("timerlat", "hist", "--priority", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_user_load_short) +{ + PARSE_ARGS("timerlat", "hist", "-U"); + + ck_assert(!params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_load_long) +{ + PARSE_ARGS("timerlat", "hist", "--user-load"); + + ck_assert(!params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_threads_short) +{ + PARSE_ARGS("timerlat", "hist", "-u"); + + ck_assert(!params->kernel_workload); + ck_assert(params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_threads_long) +{ + PARSE_ARGS("timerlat", "hist", "--user-threads"); + + ck_assert(!params->kernel_workload); + ck_assert(params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_aligned_short) +{ + PARSE_ARGS("timerlat", "hist", "-A", "500"); + + ck_assert(tlat_params->timerlat_align); + ck_assert_int_eq(tlat_params->timerlat_align_us, 500); +} +END_TEST + +START_TEST(test_aligned_long) +{ + PARSE_ARGS("timerlat", "hist", "--aligned", "500"); + + ck_assert(tlat_params->timerlat_align); + ck_assert_int_eq(tlat_params->timerlat_align_us, 500); +} +END_TEST + +/* Histogram Options */ + +START_TEST(test_bucket_size_short) +{ + PARSE_ARGS("timerlat", "hist", "-b", "2"); + + ck_assert_int_eq(params->hist.bucket_size, 2); +} +END_TEST + +START_TEST(test_bucket_size_long) +{ + PARSE_ARGS("timerlat", "hist", "--bucket-size", "2"); + + ck_assert_int_eq(params->hist.bucket_size, 2); +} +END_TEST + +START_TEST(test_entries_short) +{ + PARSE_ARGS("timerlat", "hist", "-E", "512"); + + ck_assert_int_eq(params->hist.entries, 512); +} +END_TEST + +START_TEST(test_entries_long) +{ + PARSE_ARGS("timerlat", "hist", "--entries", "512"); + + ck_assert_int_eq(params->hist.entries, 512); +} +END_TEST + +START_TEST(test_no_header) +{ + PARSE_ARGS("timerlat", "hist", "--no-header"); + + ck_assert(params->hist.no_header); +} +END_TEST + +START_TEST(test_no_index) +{ + PARSE_ARGS("timerlat", "hist", "--with-zeros", "--no-index"); + + ck_assert(params->hist.no_index); +} +END_TEST + +START_TEST(test_no_irq) +{ + PARSE_ARGS("timerlat", "hist", "--no-irq"); + + ck_assert(params->hist.no_irq); +} +END_TEST + +START_TEST(test_no_summary) +{ + PARSE_ARGS("timerlat", "hist", "--no-summary"); + + ck_assert(params->hist.no_summary); +} +END_TEST + +START_TEST(test_no_thread) +{ + PARSE_ARGS("timerlat", "hist", "--no-thread"); + + ck_assert(params->hist.no_thread); +} +END_TEST + +START_TEST(test_with_zeros) +{ + PARSE_ARGS("timerlat", "hist", "--with-zeros"); + + ck_assert(params->hist.with_zeros); +} +END_TEST + +/* Output */ + +START_TEST(test_nano_short) +{ + PARSE_ARGS("timerlat", "hist", "-n"); + + ck_assert_int_eq(params->output_divisor, 1); +} +END_TEST + +START_TEST(test_nano_long) +{ + PARSE_ARGS("timerlat", "hist", "--nano"); + + ck_assert_int_eq(params->output_divisor, 1); +} +END_TEST + +/* System Tuning */ + +START_TEST(test_deepest_idle_state) +{ + PARSE_ARGS("timerlat", "hist", "--deepest-idle-state", "1"); + + ck_assert_int_eq(tlat_params->deepest_idle_state, 1); +} +END_TEST + +START_TEST(test_dma_latency) +{ + PARSE_ARGS("timerlat", "hist", "--dma-latency", "10"); + + ck_assert_int_eq(tlat_params->dma_latency, 10); +} +END_TEST + +START_TEST(test_trace_buffer_size) +{ + PARSE_ARGS("timerlat", "hist", "--trace-buffer-size", "200"); + + ck_assert_int_eq(params->buffer_size, 200); +} +END_TEST + +START_TEST(test_warm_up) +{ + PARSE_ARGS("timerlat", "hist", "--warm-up", "5"); + + ck_assert_int_eq(params->warmup, 5); +} +END_TEST + +/* Auto Analysis and Actions */ + +START_TEST(test_auto) +{ + PARSE_ARGS("timerlat", "hist", "-a", "20"); + + CLI_TIMERLAT_ASSERT_AUTO(20); +} +END_TEST + +START_TEST(test_bpf_action) +{ + PARSE_ARGS("timerlat", "hist", "--bpf-action", "program"); + + ck_assert_str_eq(tlat_params->bpf_action_program, "program"); +} +END_TEST + +START_TEST(test_dump_tasks) +{ + PARSE_ARGS("timerlat", "hist", "--dump-tasks"); + + ck_assert(tlat_params->dump_tasks); +} +END_TEST + +START_TEST(test_no_aa) +{ + PARSE_ARGS("timerlat", "hist", "--no-aa"); + + ck_assert(tlat_params->no_aa); +} +END_TEST + +START_TEST(test_on_end) +{ + PARSE_ARGS("timerlat", "hist", "--on-end", "trace"); + + CLI_ASSERT_SINGLE_ACTION(end_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_on_threshold) +{ + PARSE_ARGS("timerlat", "hist", "--on-threshold", "trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_stack_format) +{ + PARSE_ARGS("timerlat", "hist", "--stack-format", "truncate"); + + ck_assert_int_eq(tlat_params->stack_format, STACK_FORMAT_TRUNCATE); +} +END_TEST + +/* General */ + +START_TEST(test_debug_short) +{ + PARSE_ARGS("timerlat", "hist", "-D"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_debug_long) +{ + PARSE_ARGS("timerlat", "hist", "--debug"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_duration_short) +{ + PARSE_ARGS("timerlat", "hist", "-d", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +START_TEST(test_duration_long) +{ + PARSE_ARGS("timerlat", "hist", "--duration", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +Suite *timerlat_hist_cli_suite(void) +{ + Suite *s = suite_create("timerlat_hist_cli"); + TCase *tc; + + tc = tcase_create("tracing_options"); + tcase_add_test(tc, test_irq_short); + tcase_add_test(tc, test_irq_long); + tcase_add_test(tc, test_period_short); + tcase_add_test(tc, test_period_long); + tcase_add_test(tc, test_stack_short); + tcase_add_test(tc, test_stack_long); + tcase_add_test(tc, test_thread_short); + tcase_add_test(tc, test_thread_long); + tcase_add_test(tc, test_trace_short_noarg); + tcase_add_test(tc, test_trace_short_followarg); + tcase_add_test(tc, test_trace_short_space); + tcase_add_test(tc, test_trace_short_equals); + tcase_add_test(tc, test_trace_long_noarg); + tcase_add_test(tc, test_trace_long_followarg); + tcase_add_test(tc, test_trace_long_space); + tcase_add_test(tc, test_trace_long_equals); + suite_add_tcase(s, tc); + + tc = tcase_create("event_configuration"); + tcase_add_test(tc, test_event_short); + tcase_add_test(tc, test_event_long); + tcase_add_test(tc, test_filter); + tcase_add_test(tc, test_trigger); + suite_add_tcase(s, tc); + + tc = tcase_create("cpu_configuration"); + tcase_add_test(tc, test_cpus_short); + tcase_add_test(tc, test_cpus_long); + tcase_add_test(tc, test_housekeeping_short); + tcase_add_test(tc, test_housekeeping_long); + suite_add_tcase(s, tc); + + tc = tcase_create("thread_configuration"); + tcase_add_test(tc, test_cgroup_short_noarg); + tcase_add_test(tc, test_cgroup_short_space); + tcase_add_test(tc, test_cgroup_short_equals); + tcase_add_test(tc, test_cgroup_long_noarg); + tcase_add_test(tc, test_cgroup_long_space); + tcase_add_test(tc, test_cgroup_long_equals); + tcase_add_test(tc, test_kernel_threads_short); + tcase_add_test(tc, test_kernel_threads_long); + tcase_add_test(tc, test_priority_short); + tcase_add_test(tc, test_priority_long); + tcase_add_test(tc, test_user_load_short); + tcase_add_test(tc, test_user_load_long); + tcase_add_test(tc, test_user_threads_short); + tcase_add_test(tc, test_user_threads_long); + tcase_add_test(tc, test_aligned_short); + tcase_add_test(tc, test_aligned_long); + suite_add_tcase(s, tc); + + tc = tcase_create("histogram_options"); + tcase_add_test(tc, test_bucket_size_short); + tcase_add_test(tc, test_bucket_size_long); + tcase_add_test(tc, test_entries_short); + tcase_add_test(tc, test_entries_long); + tcase_add_test(tc, test_no_header); + tcase_add_test(tc, test_no_index); + tcase_add_test(tc, test_no_irq); + tcase_add_test(tc, test_no_summary); + tcase_add_test(tc, test_no_thread); + tcase_add_test(tc, test_with_zeros); + suite_add_tcase(s, tc); + + tc = tcase_create("output"); + tcase_add_test(tc, test_nano_short); + tcase_add_test(tc, test_nano_long); + suite_add_tcase(s, tc); + + tc = tcase_create("system_tuning"); + tcase_add_test(tc, test_deepest_idle_state); + tcase_add_test(tc, test_dma_latency); + tcase_add_test(tc, test_trace_buffer_size); + tcase_add_test(tc, test_warm_up); + suite_add_tcase(s, tc); + + tc = tcase_create("aa_actions"); + tcase_add_test(tc, test_auto); + tcase_add_test(tc, test_bpf_action); + tcase_add_test(tc, test_dump_tasks); + tcase_add_test(tc, test_no_aa); + tcase_add_test(tc, test_on_end); + tcase_add_test(tc, test_on_threshold); + tcase_add_test(tc, test_stack_format); + suite_add_tcase(s, tc); + + tc = tcase_create("general"); + tcase_add_test(tc, test_debug_short); + tcase_add_test(tc, test_debug_long); + tcase_add_test(tc, test_duration_short); + tcase_add_test(tc, test_duration_long); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/timerlat_top_cli.c b/tools/tracing/rtla/tests/unit/timerlat_top_cli.c new file mode 100644 index 000000000000..33aa6588d503 --- /dev/null +++ b/tools/tracing/rtla/tests/unit/timerlat_top_cli.c @@ -0,0 +1,654 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <limits.h> +#include <unistd.h> +#include <sys/sysinfo.h> + +#include <linux/container_of.h> + +#include "cli_params_assert.h" +#include "../../src/cli.h" + +#define PARSE_ARGS(...) char *argv[] = { __VA_ARGS__, NULL };\ + int argc = sizeof(argv) / sizeof(char *) - 1;\ + struct common_params *params =\ + timerlat_top_parse_args(argc, argv);\ + struct timerlat_params *tlat_params __maybe_unused =\ + to_timerlat_params(params) + +/* Tracing Options */ + +START_TEST(test_irq_short) +{ + PARSE_ARGS("timerlat", "top", "-i", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_irq_long) +{ + PARSE_ARGS("timerlat", "top", "--irq", "20"); + + ck_assert_int_eq(params->stop_us, 20); +} +END_TEST + +START_TEST(test_period_short) +{ + PARSE_ARGS("timerlat", "top", "-p", "200"); + + ck_assert_int_eq(tlat_params->timerlat_period_us, 200); +} +END_TEST + +START_TEST(test_period_long) +{ + PARSE_ARGS("timerlat", "top", "--period", "200"); + + ck_assert_int_eq(tlat_params->timerlat_period_us, 200); +} +END_TEST + +START_TEST(test_stack_short) +{ + PARSE_ARGS("timerlat", "top", "-s", "20"); + + ck_assert_int_eq(tlat_params->print_stack, 20); +} +END_TEST + +START_TEST(test_stack_long) +{ + PARSE_ARGS("timerlat", "top", "--stack", "20"); + + ck_assert_int_eq(tlat_params->print_stack, 20); +} +END_TEST + +START_TEST(test_thread_short) +{ + PARSE_ARGS("timerlat", "top", "-T", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +START_TEST(test_thread_long) +{ + PARSE_ARGS("timerlat", "top", "--thread", "20"); + + ck_assert_int_eq(params->stop_total_us, 20); +} +END_TEST + +/* Event Configuration */ + +START_TEST(test_event_short) +{ + PARSE_ARGS("timerlat", "top", "-e", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_event_long) +{ + PARSE_ARGS("timerlat", "top", "--event", "system:event"); + + CLI_ASSERT_SINGLE_EVENT("system", "event"); +} +END_TEST + +START_TEST(test_filter) +{ + PARSE_ARGS("timerlat", "top", "-e", "system:event", "--filter", "filter"); + + CLI_ASSERT_SINGLE_FILTER("filter"); +} +END_TEST + +START_TEST(test_trigger) +{ + PARSE_ARGS("timerlat", "top", "-e", "system:event", "--trigger", "trigger"); + + CLI_ASSERT_SINGLE_TRIGGER("trigger"); +} +END_TEST + +START_TEST(test_trace_short_noarg) +{ + PARSE_ARGS("timerlat", "top", "-t"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_trace_short_followarg) +{ + PARSE_ARGS("timerlat", "top", "-t", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_short_space) +{ + PARSE_ARGS("timerlat", "top", "-t", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_short_equals) +{ + PARSE_ARGS("timerlat", "top", "-t=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_noarg) +{ + PARSE_ARGS("timerlat", "top", "--trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_trace_long_followarg) +{ + PARSE_ARGS("timerlat", "top", "--trace", "-d", "20"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); + ck_assert_int_eq(params->duration, 20); /* check if next argument is read correctly */ +} +END_TEST + +START_TEST(test_trace_long_space) +{ + PARSE_ARGS("timerlat", "top", "--trace", "tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +START_TEST(test_trace_long_equals) +{ + PARSE_ARGS("timerlat", "top", "--trace=tracefile"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "tracefile"); +} +END_TEST + +/* CPU Configuration */ + +START_TEST(test_cpus_short) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "top", "-c", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_cpus_long) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "top", "--cpus", "0-1,3"); + + ck_assert_str_eq(params->cpus, "0-1,3"); + CLI_ASSERT_CPUSET(monitored_cpus, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_short) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "top", "-H", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +START_TEST(test_housekeeping_long) +{ + nr_cpus = 4; + + PARSE_ARGS("timerlat", "top", "--house-keeping", "0-1,3"); + + CLI_ASSERT_CPUSET(hk_cpu_set, 0, 1, 3); +} +END_TEST + +/* Thread Configuration */ + +START_TEST(test_cgroup_short_noarg) +{ + PARSE_ARGS("timerlat", "top", "-C"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_short_space) +{ + PARSE_ARGS("timerlat", "top", "-C", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_short_equals) +{ + PARSE_ARGS("timerlat", "top", "-C=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_noarg) +{ + PARSE_ARGS("timerlat", "top", "--cgroup"); + + ck_assert(params->cgroup); + ck_assert_ptr_null(params->cgroup_name); +} +END_TEST + +START_TEST(test_cgroup_long_space) +{ + PARSE_ARGS("timerlat", "top", "--cgroup", "cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_cgroup_long_equals) +{ + PARSE_ARGS("timerlat", "top", "--cgroup=cgroup"); + + ck_assert(params->cgroup); + ck_assert_str_eq(params->cgroup_name, "cgroup"); +} +END_TEST + +START_TEST(test_kernel_threads_short) +{ + PARSE_ARGS("timerlat", "top", "-k"); + + ck_assert(params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(!params->user_data); +} +END_TEST + +START_TEST(test_kernel_threads_long) +{ + PARSE_ARGS("timerlat", "top", "--kernel-threads"); + + ck_assert(params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(!params->user_data); +} +END_TEST + +START_TEST(test_priority_short) +{ + PARSE_ARGS("timerlat", "top", "-P", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_priority_long) +{ + PARSE_ARGS("timerlat", "top", "--priority", "f:95"); + + ck_assert_int_eq(params->sched_param.sched_policy, SCHED_FIFO); + ck_assert_int_eq(params->sched_param.sched_priority, 95); +} +END_TEST + +START_TEST(test_user_load_short) +{ + PARSE_ARGS("timerlat", "top", "-U"); + + ck_assert(!params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_load_long) +{ + PARSE_ARGS("timerlat", "top", "--user-load"); + + ck_assert(!params->kernel_workload); + ck_assert(!params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_threads_short) +{ + PARSE_ARGS("timerlat", "top", "-u"); + + ck_assert(!params->kernel_workload); + ck_assert(params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_user_threads_long) +{ + PARSE_ARGS("timerlat", "top", "--user-threads"); + + ck_assert(!params->kernel_workload); + ck_assert(params->user_workload); + ck_assert(params->user_data); +} +END_TEST + +START_TEST(test_aligned_short) +{ + PARSE_ARGS("timerlat", "top", "-A", "500"); + + ck_assert(tlat_params->timerlat_align); + ck_assert_int_eq(tlat_params->timerlat_align_us, 500); +} +END_TEST + +START_TEST(test_aligned_long) +{ + PARSE_ARGS("timerlat", "top", "--aligned", "500"); + + ck_assert(tlat_params->timerlat_align); + ck_assert_int_eq(tlat_params->timerlat_align_us, 500); +} +END_TEST + +/* Output */ + +START_TEST(test_nano_short) +{ + PARSE_ARGS("timerlat", "top", "-n"); + + ck_assert_int_eq(params->output_divisor, 1); +} +END_TEST + +START_TEST(test_nano_long) +{ + PARSE_ARGS("timerlat", "top", "--nano"); + + ck_assert_int_eq(params->output_divisor, 1); +} +END_TEST + +START_TEST(test_quiet_short) +{ + PARSE_ARGS("timerlat", "top", "-q"); + + ck_assert(params->quiet); +} +END_TEST + +START_TEST(test_quiet_long) +{ + PARSE_ARGS("timerlat", "top", "--quiet"); + + ck_assert(params->quiet); +} +END_TEST + +/* System Tuning */ + +START_TEST(test_deepest_idle_state) +{ + PARSE_ARGS("timerlat", "top", "--deepest-idle-state", "1"); + + ck_assert_int_eq(tlat_params->deepest_idle_state, 1); +} +END_TEST + +START_TEST(test_dma_latency) +{ + PARSE_ARGS("timerlat", "top", "--dma-latency", "10"); + + ck_assert_int_eq(tlat_params->dma_latency, 10); +} +END_TEST + +START_TEST(test_trace_buffer_size) +{ + PARSE_ARGS("timerlat", "top", "--trace-buffer-size", "200"); + + ck_assert_int_eq(params->buffer_size, 200); +} +END_TEST + +START_TEST(test_warm_up) +{ + PARSE_ARGS("timerlat", "top", "--warm-up", "5"); + + ck_assert_int_eq(params->warmup, 5); +} +END_TEST + +/* Auto Analysis and Actions */ + +START_TEST(test_auto) +{ + PARSE_ARGS("timerlat", "top", "-a", "20"); + + CLI_TIMERLAT_ASSERT_AUTO(20); +} +END_TEST + +START_TEST(test_aa_only) +{ + PARSE_ARGS("timerlat", "top", "--aa-only", "20"); + + CLI_TIMERLAT_ASSERT_AA_ONLY(20); +} +END_TEST + +START_TEST(test_bpf_action) +{ + PARSE_ARGS("timerlat", "top", "--bpf-action", "program"); + + ck_assert_str_eq(tlat_params->bpf_action_program, "program"); +} +END_TEST + +START_TEST(test_dump_tasks) +{ + PARSE_ARGS("timerlat", "top", "--dump-tasks"); + + ck_assert(tlat_params->dump_tasks); +} +END_TEST + +START_TEST(test_no_aa) +{ + PARSE_ARGS("timerlat", "top", "--no-aa"); + + ck_assert(tlat_params->no_aa); +} +END_TEST + +START_TEST(test_on_end) +{ + PARSE_ARGS("timerlat", "top", "--on-end", "trace"); + + CLI_ASSERT_SINGLE_ACTION(end_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_on_threshold) +{ + PARSE_ARGS("timerlat", "top", "--on-threshold", "trace"); + + CLI_ASSERT_SINGLE_ACTION(threshold_actions, ACTION_TRACE_OUTPUT, trace_output, str, + "timerlat_trace.txt"); +} +END_TEST + +START_TEST(test_stack_format) +{ + PARSE_ARGS("timerlat", "top", "--stack-format", "truncate"); + + ck_assert_int_eq(tlat_params->stack_format, STACK_FORMAT_TRUNCATE); +} +END_TEST + +/* General */ + +START_TEST(test_debug_short) +{ + PARSE_ARGS("timerlat", "top", "-D"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_debug_long) +{ + PARSE_ARGS("timerlat", "top", "--debug"); + + ck_assert(config_debug); +} +END_TEST + +START_TEST(test_duration_short) +{ + PARSE_ARGS("timerlat", "top", "-d", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +START_TEST(test_duration_long) +{ + PARSE_ARGS("timerlat", "top", "--duration", "1m"); + + ck_assert_int_eq(params->duration, 60); +} +END_TEST + +Suite *timerlat_top_cli_suite(void) +{ + Suite *s = suite_create("timerlat_top_cli"); + TCase *tc; + + tc = tcase_create("tracing_options"); + tcase_add_test(tc, test_irq_short); + tcase_add_test(tc, test_irq_long); + tcase_add_test(tc, test_period_short); + tcase_add_test(tc, test_period_long); + tcase_add_test(tc, test_stack_short); + tcase_add_test(tc, test_stack_long); + tcase_add_test(tc, test_thread_short); + tcase_add_test(tc, test_thread_long); + tcase_add_test(tc, test_trace_short_noarg); + tcase_add_test(tc, test_trace_short_followarg); + tcase_add_test(tc, test_trace_short_space); + tcase_add_test(tc, test_trace_short_equals); + tcase_add_test(tc, test_trace_long_noarg); + tcase_add_test(tc, test_trace_long_followarg); + tcase_add_test(tc, test_trace_long_space); + tcase_add_test(tc, test_trace_long_equals); + suite_add_tcase(s, tc); + + tc = tcase_create("event_configuration"); + tcase_add_test(tc, test_event_short); + tcase_add_test(tc, test_event_long); + tcase_add_test(tc, test_filter); + tcase_add_test(tc, test_trigger); + suite_add_tcase(s, tc); + + tc = tcase_create("cpu_configuration"); + tcase_add_test(tc, test_cpus_short); + tcase_add_test(tc, test_cpus_long); + tcase_add_test(tc, test_housekeeping_short); + tcase_add_test(tc, test_housekeeping_long); + suite_add_tcase(s, tc); + + tc = tcase_create("thread_configuration"); + tcase_add_test(tc, test_cgroup_short_noarg); + tcase_add_test(tc, test_cgroup_short_space); + tcase_add_test(tc, test_cgroup_short_equals); + tcase_add_test(tc, test_cgroup_long_noarg); + tcase_add_test(tc, test_cgroup_long_space); + tcase_add_test(tc, test_cgroup_long_equals); + tcase_add_test(tc, test_kernel_threads_short); + tcase_add_test(tc, test_kernel_threads_long); + tcase_add_test(tc, test_priority_short); + tcase_add_test(tc, test_priority_long); + tcase_add_test(tc, test_user_load_short); + tcase_add_test(tc, test_user_load_long); + tcase_add_test(tc, test_user_threads_short); + tcase_add_test(tc, test_user_threads_long); + tcase_add_test(tc, test_aligned_short); + tcase_add_test(tc, test_aligned_long); + suite_add_tcase(s, tc); + + tc = tcase_create("output"); + tcase_add_test(tc, test_nano_short); + tcase_add_test(tc, test_nano_long); + tcase_add_test(tc, test_quiet_short); + tcase_add_test(tc, test_quiet_long); + suite_add_tcase(s, tc); + + tc = tcase_create("system_tuning"); + tcase_add_test(tc, test_deepest_idle_state); + tcase_add_test(tc, test_dma_latency); + tcase_add_test(tc, test_trace_buffer_size); + tcase_add_test(tc, test_warm_up); + suite_add_tcase(s, tc); + + tc = tcase_create("aa_actions"); + tcase_add_test(tc, test_auto); + tcase_add_test(tc, test_aa_only); + tcase_add_test(tc, test_bpf_action); + tcase_add_test(tc, test_dump_tasks); + tcase_add_test(tc, test_no_aa); + tcase_add_test(tc, test_on_end); + tcase_add_test(tc, test_on_threshold); + tcase_add_test(tc, test_stack_format); + suite_add_tcase(s, tc); + + tc = tcase_create("general"); + tcase_add_test(tc, test_debug_short); + tcase_add_test(tc, test_debug_long); + tcase_add_test(tc, test_duration_short); + tcase_add_test(tc, test_duration_long); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tools/tracing/rtla/tests/unit/unit_tests.c b/tools/tracing/rtla/tests/unit/unit_tests.c index f3c6d89e3300..75ca813f81ca 100644 --- a/tools/tracing/rtla/tests/unit/unit_tests.c +++ b/tools/tracing/rtla/tests/unit/unit_tests.c @@ -2,115 +2,35 @@ #define _GNU_SOURCE #include <check.h> -#include <stdio.h> -#include <stdlib.h> -#include <sched.h> -#include <limits.h> -#include <unistd.h> -#include <sys/sysinfo.h> +#include <stdbool.h> #include "../../src/utils.h" -int nr_cpus; +#include "../../src/cli.h" -START_TEST(test_strtoi) -{ - int result; - char buf[64]; - - ck_assert_int_eq(strtoi("123", &result), 0); - ck_assert_int_eq(result, 123); - ck_assert_int_eq(strtoi(" -456", &result), 0); - ck_assert_int_eq(result, -456); - - snprintf(buf, sizeof(buf), "%d", INT_MAX); - ck_assert_int_eq(strtoi(buf, &result), 0); - snprintf(buf, sizeof(buf), "%ld", (long)INT_MAX + 1); - ck_assert_int_eq(strtoi(buf, &result), -1); - - ck_assert_int_eq(strtoi("", &result), -1); - ck_assert_int_eq(strtoi("123abc", &result), -1); - ck_assert_int_eq(strtoi("123 ", &result), -1); -} -END_TEST - -START_TEST(test_parse_cpu_set) -{ - cpu_set_t set; +Suite *utils_suite(void); +Suite *actions_suite(void); +Suite *osnoise_top_cli_suite(void); +Suite *osnoise_hist_cli_suite(void); +Suite *timerlat_top_cli_suite(void); +Suite *timerlat_hist_cli_suite(void); +Suite *cli_opt_callback_suite(void); - nr_cpus = 8; - ck_assert_int_eq(parse_cpu_set("0", &set), 0); - ck_assert(CPU_ISSET(0, &set)); - ck_assert(!CPU_ISSET(1, &set)); - - ck_assert_int_eq(parse_cpu_set("0,2", &set), 0); - ck_assert(CPU_ISSET(0, &set)); - ck_assert(CPU_ISSET(2, &set)); - - ck_assert_int_eq(parse_cpu_set("0-3", &set), 0); - ck_assert(CPU_ISSET(0, &set)); - ck_assert(CPU_ISSET(1, &set)); - ck_assert(CPU_ISSET(2, &set)); - ck_assert(CPU_ISSET(3, &set)); - - ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0); - ck_assert(!CPU_ISSET(0, &set)); - ck_assert(CPU_ISSET(1, &set)); - ck_assert(CPU_ISSET(2, &set)); - ck_assert(CPU_ISSET(3, &set)); - ck_assert(!CPU_ISSET(4, &set)); - ck_assert(CPU_ISSET(5, &set)); - - ck_assert_int_eq(parse_cpu_set("-1", &set), 1); - ck_assert_int_eq(parse_cpu_set("abc", &set), 1); - ck_assert_int_eq(parse_cpu_set("9999", &set), 1); -} -END_TEST - -START_TEST(test_parse_prio) -{ - struct sched_attr attr; - - ck_assert_int_eq(parse_prio("f:50", &attr), 0); - ck_assert_uint_eq(attr.sched_policy, SCHED_FIFO); - ck_assert_uint_eq(attr.sched_priority, 50U); - - ck_assert_int_eq(parse_prio("r:30", &attr), 0); - ck_assert_uint_eq(attr.sched_policy, SCHED_RR); - - ck_assert_int_eq(parse_prio("o:0", &attr), 0); - ck_assert_uint_eq(attr.sched_policy, SCHED_OTHER); - ck_assert_int_eq(attr.sched_nice, 0); - - ck_assert_int_eq(parse_prio("d:10ms:100ms", &attr), 0); - ck_assert_uint_eq(attr.sched_policy, 6U); - - ck_assert_int_eq(parse_prio("f:999", &attr), -1); - ck_assert_int_eq(parse_prio("o:-20", &attr), -1); - ck_assert_int_eq(parse_prio("d:100ms:10ms", &attr), -1); - ck_assert_int_eq(parse_prio("x:50", &attr), -1); -} -END_TEST - -Suite *utils_suite(void) -{ - Suite *s = suite_create("utils"); - TCase *tc = tcase_create("core"); - - tcase_add_test(tc, test_strtoi); - tcase_add_test(tc, test_parse_cpu_set); - tcase_add_test(tc, test_parse_prio); - - suite_add_tcase(s, tc); - return s; -} - -int main(void) +int main(int argc, char *argv[]) { int num_failed; SRunner *sr; + in_unit_test = true; + sr = srunner_create(utils_suite()); - srunner_run_all(sr, CK_NORMAL); + srunner_add_suite(sr, cli_opt_callback_suite()); + srunner_add_suite(sr, actions_suite()); + srunner_add_suite(sr, osnoise_top_cli_suite()); + srunner_add_suite(sr, osnoise_hist_cli_suite()); + srunner_add_suite(sr, timerlat_top_cli_suite()); + srunner_add_suite(sr, timerlat_hist_cli_suite()); + + srunner_run_all(sr, CK_VERBOSE); num_failed = srunner_ntests_failed(sr); srunner_free(sr); diff --git a/tools/tracing/rtla/tests/unit/utils.c b/tools/tracing/rtla/tests/unit/utils.c new file mode 100644 index 000000000000..ce53cab49457 --- /dev/null +++ b/tools/tracing/rtla/tests/unit/utils.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <check.h> +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <limits.h> +#include <unistd.h> +#include <sys/sysinfo.h> + +#include "../../src/utils.h" + +extern int nr_cpus; + +START_TEST(test_strtoi) +{ + int result; + char buf[64]; + + ck_assert_int_eq(strtoi("123", &result), 0); + ck_assert_int_eq(result, 123); + ck_assert_int_eq(strtoi(" -456", &result), 0); + ck_assert_int_eq(result, -456); + + snprintf(buf, sizeof(buf), "%d", INT_MAX); + ck_assert_int_eq(strtoi(buf, &result), 0); + snprintf(buf, sizeof(buf), "%ld", (long)INT_MAX + 1); + ck_assert_int_eq(strtoi(buf, &result), -1); + + ck_assert_int_eq(strtoi("", &result), -1); + ck_assert_int_eq(strtoi("123abc", &result), -1); + ck_assert_int_eq(strtoi("123 ", &result), -1); +} +END_TEST + +START_TEST(test_parse_cpu_set) +{ + cpu_set_t set; + + nr_cpus = 8; + ck_assert_int_eq(parse_cpu_set("0", &set), 0); + ck_assert(CPU_ISSET(0, &set)); + ck_assert(!CPU_ISSET(1, &set)); + + ck_assert_int_eq(parse_cpu_set("0,2", &set), 0); + ck_assert(CPU_ISSET(0, &set)); + ck_assert(CPU_ISSET(2, &set)); + + ck_assert_int_eq(parse_cpu_set("0-3", &set), 0); + ck_assert(CPU_ISSET(0, &set)); + ck_assert(CPU_ISSET(1, &set)); + ck_assert(CPU_ISSET(2, &set)); + ck_assert(CPU_ISSET(3, &set)); + + ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0); + ck_assert(!CPU_ISSET(0, &set)); + ck_assert(CPU_ISSET(1, &set)); + ck_assert(CPU_ISSET(2, &set)); + ck_assert(CPU_ISSET(3, &set)); + ck_assert(!CPU_ISSET(4, &set)); + ck_assert(CPU_ISSET(5, &set)); + + ck_assert_int_eq(parse_cpu_set("-1", &set), 1); + ck_assert_int_eq(parse_cpu_set("abc", &set), 1); + ck_assert_int_eq(parse_cpu_set("9999", &set), 1); +} +END_TEST + +START_TEST(test_parse_prio) +{ + struct sched_attr attr; + + ck_assert_int_eq(parse_prio("f:50", &attr), 0); + ck_assert_uint_eq(attr.sched_policy, SCHED_FIFO); + ck_assert_uint_eq(attr.sched_priority, 50U); + + ck_assert_int_eq(parse_prio("r:30", &attr), 0); + ck_assert_uint_eq(attr.sched_policy, SCHED_RR); + + ck_assert_int_eq(parse_prio("o:0", &attr), 0); + ck_assert_uint_eq(attr.sched_policy, SCHED_OTHER); + ck_assert_int_eq(attr.sched_nice, 0); + + ck_assert_int_eq(parse_prio("d:10ms:100ms", &attr), 0); + ck_assert_uint_eq(attr.sched_policy, 6U); + + ck_assert_int_eq(parse_prio("f:999", &attr), -1); + ck_assert_int_eq(parse_prio("o:-20", &attr), -1); + ck_assert_int_eq(parse_prio("d:100ms:10ms", &attr), -1); + ck_assert_int_eq(parse_prio("x:50", &attr), -1); +} +END_TEST + +Suite *utils_suite(void) +{ + Suite *s = suite_create("utils"); + TCase *tc = tcase_create("core"); + + tcase_add_test(tc, test_strtoi); + tcase_add_test(tc, test_parse_cpu_set); + tcase_add_test(tc, test_parse_prio); + + suite_add_tcase(s, tc); + return s; +} |
