diff options
author | Jere Leppänen <jere.leppanen@nokia.com> | 2021-09-08 18:08:42 +0300 |
---|---|---|
committer | Matias Elo <matias.elo@nokia.com> | 2021-09-30 13:10:07 +0300 |
commit | ad67a7c251c8f6fc4630666dfd705f45ba56e6bc (patch) | |
tree | 7819028e997a5a5ad4657baeb823dd8390a750ee /helper/test | |
parent | 7f88e6a0777aa41d8175ecbc257e37df5714daff (diff) |
helper: cli: don't create the server thread
Add odph_cli_run() and remove odph_cli_start().
Don't create a thread in the CLI helper. Instead, the caller may
create a thread and call odph_cli_run() to run the CLI.
Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
Cc: Lifang Zhang <lifang.zhang@nokia.com>
Diffstat (limited to 'helper/test')
-rw-r--r-- | helper/test/cli.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/helper/test/cli.c b/helper/test/cli.c index e7ed0e06f..475a99b90 100644 --- a/helper/test/cli.c +++ b/helper/test/cli.c @@ -7,6 +7,16 @@ #include <odp_api.h> #include <odp/helper/odph_api.h> +static int cli_server(void *arg ODP_UNUSED) +{ + if (odph_cli_run()) { + ODPH_ERR("odph_cli_run() failed.\n"); + exit(EXIT_FAILURE); + } + + return 0; +} + int main(int argc, char *argv[]) { odp_instance_t instance; @@ -43,16 +53,46 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if (odph_cli_start()) { - ODPH_ERR("Error: odph_cli_start() failed.\n"); + odp_cpumask_t cpumask; + odph_thread_common_param_t thr_common; + odph_thread_param_t thr_param; + odph_thread_t thr_server; + + if (odp_cpumask_default_control(&cpumask, 1) != 1) { + ODPH_ERR("Failed to get default CPU mask.\n"); exit(EXIT_FAILURE); } + odph_thread_common_param_init(&thr_common); + thr_common.instance = instance; + thr_common.cpumask = &cpumask; + + odph_thread_param_init(&thr_param); + thr_param.thr_type = ODP_THREAD_CONTROL; + thr_param.start = cli_server; + + memset(&thr_server, 0, sizeof(thr_server)); + + if (odph_thread_create(&thr_server, &thr_common, &thr_param, 1) != 1) { + ODPH_ERR("Failed to create server thread.\n"); + exit(EXIT_FAILURE); + } + + /* + * Wait for a bit to ensure that the server thread has time to start. + */ + odp_time_wait_ns(ODP_TIME_SEC_IN_NS / 10); + if (odph_cli_stop()) { ODPH_ERR("Error: odph_cli_stop() failed.\n"); exit(EXIT_FAILURE); } + if (odph_thread_join(&thr_server, 1) != 1) { + ODPH_ERR("Failed to join server thread.\n"); + exit(EXIT_FAILURE); + } + if (odph_cli_term()) { ODPH_ERR("Error: odph_cli_term() failed.\n"); exit(EXIT_FAILURE); |