[PATCH v12 3/3] app/testpmd: add sleep command

Bruce Richardson bruce.richardson at intel.com
Thu Feb 26 19:19:30 CET 2026


On Thu, Feb 26, 2026 at 04:44:50PM +0000, Anatoly Burakov wrote:
> 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 seconds has
> passed, using the newly added cmdline library floating point support.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
> ---
> 
Acked-by: Bruce Richardson <bruce.richardson at intel.com>

One little suggestion below. 
> Notes:
>     v1 -> v2:
>     - Add floating point support to cmdline
>     - Use floating point format for pause command
> 
>  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 c33c66f327..766c83c944 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -152,6 +152,9 @@ static void cmd_help_long_parsed(void *parsed_result,
>  
>  			"quit\n"
>  			"    Quit to prompt.\n\n"
> +
> +			"sleep secs\n"
> +			"    Sleep for secs seconds (can be fractional).\n\n"

I would add an example to the bracket to clarify "fractional", perhaps:
	(can be fractional e.g. 0.1)
or even:
	(can be fractional e.g. 0.1, for 100 millisec sleep)

>  		);
>  	}
>  
> @@ -8044,6 +8047,37 @@ static cmdline_parse_inst_t cmd_quit = {
>  	},
>  };
>  
> +/* *** SLEEP *** */
> +struct cmd_sleep_result {
> +	cmdline_fixed_string_t sleep;
> +	double secs;
> +};
> +
> +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->secs * 1E6);
> +}
> +
> +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, secs, RTE_FLOAT_DOUBLE);
> +
> +static cmdline_parse_inst_t cmd_sleep = {
> +	.f = cmd_sleep_parsed,
> +	.data = NULL,
> +	.help_str = "sleep <secs>: sleep for a specified number of seconds",
> +	.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;
> @@ -14088,6 +14122,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
>  	&cmd_showdevice,
>  	&cmd_showcfg,
>  	&cmd_showfwdall,
> +	&cmd_sleep,
>  	&cmd_start,
>  	&cmd_start_tx_first,
>  	&cmd_start_tx_first_n,
> -- 
> 2.47.3
> 


More information about the dev mailing list