Test-pmd already has a way to run a list of commands from file, but there is no way to pause execution for a specified amount of time between two commands. This may be necessary for simple automation, particularly for waiting on some asynchronous operation such as link status update.
Add a simple sleep command to wait until certain number of milliseconds has passed. Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com> --- app/test-pmd/cmdline.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index d4bb3ec998..1e429e6d0a 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -151,6 +151,9 @@ static void cmd_help_long_parsed(void *parsed_result, "quit\n" " Quit to prompt.\n\n" + + "sleep ms\n" + " Sleep for ms milliseconds.\n\n" ); } @@ -7768,6 +7771,37 @@ static cmdline_parse_inst_t cmd_quit = { }, }; +/* *** SLEEP *** */ +struct cmd_sleep_result { + cmdline_fixed_string_t sleep; + uint32_t ms; +}; + +static void cmd_sleep_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_sleep_result *res = parsed_result; + + rte_delay_us_sleep(res->ms * 1000); +} + +static cmdline_parse_token_string_t cmd_sleep_sleep = + TOKEN_STRING_INITIALIZER(struct cmd_sleep_result, sleep, "sleep"); +static cmdline_parse_token_num_t cmd_sleep_seconds = + TOKEN_NUM_INITIALIZER(struct cmd_sleep_result, ms, RTE_UINT32); + +static cmdline_parse_inst_t cmd_sleep = { + .f = cmd_sleep_parsed, + .data = NULL, + .help_str = "sleep <ms>: Sleep for a specified number of milliseconds", + .tokens = { + (void *)&cmd_sleep_sleep, + (void *)&cmd_sleep_seconds, + NULL, + }, +}; + /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ struct cmd_mac_addr_result { cmdline_fixed_string_t mac_addr_cmd; @@ -13701,6 +13735,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = { &cmd_help_brief, &cmd_help_long, &cmd_quit, + &cmd_sleep, &cmd_load_from_file, &cmd_showport, &cmd_showqueue, -- 2.47.1