mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-26 11:54:30 -04:00
Add a test suite for the _parse_args() function of each tool that checks the params structures (struct common_params, struct osnoise_params, struct timerlat_params) returned by them for correctness. One test case is added per option, as well as a few special cases for tricky combinations of options. Test cases are ordered the same as the option arrays and help message to allow easy checking of whether all options are covered. This should help clarify what the proper command line behavior of RTLA is in case there are holes in the documentation and verify that the intended behavior is implemented correctly. A few necessary changes to the unit tests were done as part of this commit: - Unit tests now also link to libsubcmd and its dependencies. - A new global variable in_unit_test is added to RTLA's CLI interface, causing it to skip check for root if running in unit tests. This allows the CLI unit tests to run as non-root, like existing unit tests. There is quite a lot of duplication, some of it is mitigated with macros, but partially it is intentional so that future changes in behavior are tracked across tools. Link: https://lore.kernel.org/r/20260528103254.2990068-6-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
69 lines
2.4 KiB
C
69 lines
2.4 KiB
C
/* 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)
|