diff options
author | Christophe Milard <christophe.milard@linaro.org> | 2016-04-15 10:38:13 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2016-05-23 15:06:58 +0300 |
commit | ff0f5ec4d5cb871890e8a3dadabb4fe748f6c419 (patch) | |
tree | fdf553ee981fee6ede13f97d9879d8311d00dc8f | |
parent | 03a915e00c04ac53a63dc42c9206d82926f5ad4f (diff) |
helper: test: adding odpthread functions tests
Simple tests testing odph_odpthreads_create() and
odph_odpthreads_join() are added.
A single test binary, odpthreads, is added. This program creates
odp threads as pthreads or linux processes, dependng on its calling args.
Two calling scripts are added to create ODP threads as either processes,
or threads.
Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Reviewed-by: Brian Brooks <brian.brooks@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | helper/test/.gitignore | 1 | ||||
-rw-r--r-- | helper/test/Makefile.am | 7 | ||||
-rw-r--r-- | helper/test/odpthreads.c | 100 | ||||
-rwxr-xr-x | helper/test/odpthreads_as_processes | 14 | ||||
-rwxr-xr-x | helper/test/odpthreads_as_pthreads | 14 |
5 files changed, 134 insertions, 2 deletions
diff --git a/helper/test/.gitignore b/helper/test/.gitignore index e2327530e..5ce3c3baf 100644 --- a/helper/test/.gitignore +++ b/helper/test/.gitignore @@ -1,6 +1,7 @@ *.trs *.log chksum +odpthreads parse process table diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am index 7f0b67d58..8e6594865 100644 --- a/helper/test/Makefile.am +++ b/helper/test/Makefile.am @@ -11,9 +11,10 @@ EXECUTABLES = chksum$(EXEEXT) \ process$(EXEEXT)\ table$(EXEEXT) -COMPILE_ONLY = +COMPILE_ONLY = odpthreads -TESTSCRIPTS = +TESTSCRIPTS = odpthreads_as_processes \ + odpthreads_as_pthreads if test_helper TESTS = $(EXECUTABLES) $(TESTSCRIPTS) @@ -25,6 +26,8 @@ bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) dist_chksum_SOURCES = chksum.c +dist_odpthreads_SOURCES = odpthreads.c +odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la dist_thread_SOURCES = thread.c thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la dist_process_SOURCES = process.c diff --git a/helper/test/odpthreads.c b/helper/test/odpthreads.c new file mode 100644 index 000000000..bba4fa5e3 --- /dev/null +++ b/helper/test/odpthreads.c @@ -0,0 +1,100 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * This program tests the ability of the linux helper to create ODP threads, + * either implemented as linux pthreads or as linux processes, depending on + * the option passed to the program (--odph_proc, --odph_thread or both) + */ + +#include <test_debug.h> +#include <odp_api.h> +#include <odp/helper/linux.h> + +#define NUMBER_WORKERS 16 +static int worker_fn(void *arg TEST_UNUSED) +{ + /* depend on the odp helper to call odp_init_local */ + + printf("Worker thread on CPU %d\n", odp_cpu_id()); + + /* depend on the odp helper to call odp_term_local */ + + return 0; +} + +/* Create additional dataplane opdthreads */ +int main(int argc, char *argv[]) +{ + odp_instance_t instance; + odph_odpthread_params_t thr_params; + odph_odpthread_t thread_tbl[NUMBER_WORKERS]; + odp_cpumask_t cpu_mask; + int num_workers; + int cpu; + int ret; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + + /* let helper collect its own arguments (e.g. --odph_proc) */ + odph_parse_options(argc, argv, NULL, NULL); + + if (odp_init_global(&instance, NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local(instance, ODP_THREAD_CONTROL)) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* discover how many opdthreads this system can support */ + num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); + if (num_workers < NUMBER_WORKERS) { + printf("System can only support %d threads and not the %d requested\n", + num_workers, NUMBER_WORKERS); + } + + /* generate a summary for the user */ + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("default cpu mask: %s\n", cpumaskstr); + printf("default num worker threads: %i\n", num_workers); + + cpu = odp_cpumask_first(&cpu_mask); + printf("the first CPU: %i\n", cpu); + + /* reserve cpu 0 for the control plane so remove it from + * the default mask */ + odp_cpumask_clr(&cpu_mask, 0); + num_workers = odp_cpumask_count(&cpu_mask); + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("new cpu mask: %s\n", cpumaskstr); + printf("new num worker threads: %i\n\n", num_workers); + + memset(&thr_params, 0, sizeof(thr_params)); + thr_params.start = worker_fn; + thr_params.arg = NULL; + thr_params.thr_type = ODP_THREAD_WORKER; + thr_params.instance = instance; + + odph_odpthreads_create(&thread_tbl[0], &cpu_mask, &thr_params); + + ret = odph_odpthreads_join(thread_tbl); + if (ret < 0) + exit(EXIT_FAILURE); + + if (odp_term_local()) { + LOG_ERR("Error: ODP local term failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_term_global(instance)) { + LOG_ERR("Error: ODP global term failed.\n"); + exit(EXIT_FAILURE); + } + + return 0; +} diff --git a/helper/test/odpthreads_as_processes b/helper/test/odpthreads_as_processes new file mode 100755 index 000000000..89405f363 --- /dev/null +++ b/helper/test/odpthreads_as_processes @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Copyright (c) 2016, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +PATH=$(dirname $0):$PATH +PATH=.:$PATH + +# The odpthreads test recognise the "--odph_proc" option to create +# odp threads as linux processes: +odpthreads --odph_proc diff --git a/helper/test/odpthreads_as_pthreads b/helper/test/odpthreads_as_pthreads new file mode 100755 index 000000000..ef569c3d4 --- /dev/null +++ b/helper/test/odpthreads_as_pthreads @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Copyright (c) 2016, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +PATH=$(dirname $0):$PATH +PATH=.:$PATH + +# The odpthreads test without the "--odph_proc" option defaults to create +# odp threads as linux pthreads: +odpthreads |