summaryrefslogtreecommitdiff
path: root/tools/tracing/rtla/tests/unit/cli_opt_callback.c
AgeCommit message (Collapse)Author
2026-08-05rtla/cli: Unify and improve handling of invalid option argumentsTomas Glozar
The current handling of invalid command line option arguments is inconsistent: - opt_llong_callback() treats non-numerical input the same as "-1", which might or might not be rejected later. - opt_int_callback() returns -1 on non-numerical input without an error message, which makes parsing fail silently (libsubcmd will automatically print the usage of the option only, no error message). - custom callbacks abort command line parsing using fatal(), which displays an error message and exits, without libsubcmd printing the usage. Unify this such that all invalid options, regardless of the format, print an error message similar to the out of range case: Error: --opt: 'value' is not a valid XY followed by the usage of the option, e.g.: $ rtla timerlat hist --period=1us Error: --period: '1us' is not a valid number Usage: rtla timerlat hist [<options>] [-h|--help] -p, --period <us> timerlat period in us As this is a libsubcmd help path, all option parsing failures now return the exit code of 129 (help). The unified handling is implemented using a new error message helper, opt_err(), which is called from two new CLI-specific parsing functions, strtoll_safe() and strtoi_safe(), as well as from custom helpers. Option callback tests are updated to cover the new behavior. Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Wander Lairson Costa <wander@redhat.com> Link: https://lore.kernel.org/r/20260716144901.1187474-1-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2026-08-05rtla/cli: Unify and improve range validation logicTomas Glozar
Several RTLA options do range validation inside the CLI parser layer (e.g. -p/--period). When RTLA migrated CLI parsing to libsubcmd, this logic was moved unchanged inside opt_*() callbacks. Unify range validation so that all options use two newly added functions, check_llong_range() and check_int_range(), to validate the range. The new range validation returns -1 from opt_*() callbacks rather than hard-exit with fatal(), allowing the help message for the specific option to be automatically displayed by libsubcmd logic. Many options no longer need a custom callback, as they use the unified range validation of opt_llong_callback() and opt_int_callback(). Validation for several other options is improved: - timerlat -p/--period: lower bound raised from 1 to 100 us to match the kernel's timerlat_min_period in trace_osnoise.c. - timerlat -A/--aligned: reject negative values. - timerlat --deepest-idle-state: add range [-1, INT_MAX]; previously, values <= -2 were read as "option not set". - timerlat -p/--period, -A/--aligned, -b/--bucket-size: properly reject negative values instead of passing them to the tracer. Remove unit tests for removed callbacks and test the new range validation functionality of opt_llong_callback() and opt_int_callback(). Update runtime tests for histogram options to account for the new error messages and exit value. Assisted-by: Claude:claude-opus-4-6 Link: https://lore.kernel.org/r/20260710131554.338335-1-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2026-08-05rtla: Add unit tests for unset in opt callbacksTomas Glozar
Test for each opt callback that implements the unset option whether the option sets the specified default value back correctly. Reviewed-by: Wander Lairson Costa <wander@redhat.com> Link: https://lore.kernel.org/r/20260629083654.1548925-2-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2026-05-28rtla/tests: Add unit tests for -A/--aligned optionTomas Glozar
Add both parse_args() and opt_* tests for the newly added -A/--aligned option. Assisted-by: Claude:claude-4.5-opus-high-thinking Link: https://lore.kernel.org/r/20260527144928.2944472-2-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2026-05-28rtla/tests: Add unit tests for CLI option callbacksTomas Glozar
In addition to testing all tool_parse_args() functions, test also all callbacks used for parsing custom option formats. The callbacks represent a middle layer between the parsing functions and utility functions dedicated to checking specific argument formats, for example, scheduling class and duration. Callback tests are run before parsing functions to make sure any issue in the former is reported before it is encountered through the latter. Tests verify both successful parsing and proper rejection of invalid inputs (via exit tests). To enable testing static callbacks, a pragma once guard is added to timerlat.h for safe inclusion by cli_p.h. Add dependency of UNIT_TESTS_IN on LIBSUBCMD_INCLUDES, as the new test file tests/unit/cli_opt_callback.c includes cli_p.h which includes subcmd/parse-options.h. Link: https://lore.kernel.org/r/20260528103254.2990068-7-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>