diff mbox

test: helper: add process and thread tests

Message ID 1431466331-16931-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit ee48c657b52d0f8dd8a11c18c62bce8920935c3e
Headers show

Commit Message

Mike Holmes May 12, 2015, 9:32 p.m. UTC
The helpers need to be tested independently from the ODP API, create a
folder to contain helper tests, adding tests for process and thread
creation.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 Makefile.am               |  2 +-
 configure.ac              | 16 +++++++++
 helper/Makefile.am        |  1 +
 helper/test/.gitignore    |  4 +++
 helper/test/Makefile.am   | 25 ++++++++++++++
 helper/test/odp_process.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++
 helper/test/odp_thread.c  | 79 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 211 insertions(+), 1 deletion(-)
 create mode 100644 helper/Makefile.am
 create mode 100644 helper/test/.gitignore
 create mode 100644 helper/test/Makefile.am
 create mode 100644 helper/test/odp_process.c
 create mode 100644 helper/test/odp_thread.c

Comments

Maxim Uvarov May 13, 2015, 9:08 a.m. UTC | #1
On 05/13/2015 00:32, Mike Holmes wrote:
> The helpers need to be tested independently from the ODP API, create a
> folder to contain helper tests, adding tests for process and thread
> creation.
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>   Makefile.am               |  2 +-
>   configure.ac              | 16 +++++++++
>   helper/Makefile.am        |  1 +
>   helper/test/.gitignore    |  4 +++
>   helper/test/Makefile.am   | 25 ++++++++++++++
>   helper/test/odp_process.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++
>   helper/test/odp_thread.c  | 79 +++++++++++++++++++++++++++++++++++++++++++
>   7 files changed, 211 insertions(+), 1 deletion(-)
>   create mode 100644 helper/Makefile.am
>   create mode 100644 helper/test/.gitignore
>   create mode 100644 helper/test/Makefile.am
>   create mode 100644 helper/test/odp_process.c
>   create mode 100644 helper/test/odp_thread.c
>
> diff --git a/Makefile.am b/Makefile.am
> index 3f80a2a..cff83f7 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -1,7 +1,7 @@
>   ACLOCAL_AMFLAGS=-I m4
>   AUTOMAKE_OPTIONS = foreign
>   
> -SUBDIRS = doc platform example test
> +SUBDIRS = doc platform example test helper
>   
>   include $(top_srcdir)/aminclude.am
>   
> diff --git a/configure.ac b/configure.ac
> index d20bad2..4146b20 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -138,6 +138,20 @@ AC_ARG_ENABLE([test-perf],
>   AM_CONDITIONAL([test_perf], [test x$test_perf = xyes ])
>   
>   ##########################################################################
> +# Enable/disable test-helper
> +##########################################################################
> +test_helper=no

I think default has to be yes. We need as match as possible test to be 
run under make check.

Maxim.


> +AC_ARG_ENABLE([test-helper],
> +    [  --enable-test-helper      run test in helper/test],
> +    [if test "x$enableval" = "xyes"; then
> +        test_helper=yes
> +    fi])
> +
> +AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ])
> +
> +##########################################################################
> +
> +##########################################################################
>   # Enable/disable test-cpp
>   ##########################################################################
>   test_cpp=no
> @@ -277,6 +291,8 @@ AC_CONFIG_FILES([Makefile
>   		 example/ipsec/Makefile
>   		 example/packet/Makefile
>   		 example/timer/Makefile
> +		 helper/Makefile
> +		 helper/test/Makefile
>   		 pkgconfig/libodp.pc
>   		 platform/Makefile
>   		 platform/linux-generic/Makefile
> diff --git a/helper/Makefile.am b/helper/Makefile.am
> new file mode 100644
> index 0000000..02af5b3
> --- /dev/null
> +++ b/helper/Makefile.am
> @@ -0,0 +1 @@
> +SUBDIRS = test
> diff --git a/helper/test/.gitignore b/helper/test/.gitignore
> new file mode 100644
> index 0000000..fe65f30
> --- /dev/null
> +++ b/helper/test/.gitignore
> @@ -0,0 +1,4 @@
> +*.trs
> +*.log
> +odp_process
> +odp_thread
> diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am
> new file mode 100644
> index 0000000..f330533
> --- /dev/null
> +++ b/helper/test/Makefile.am
> @@ -0,0 +1,25 @@
> +include $(top_srcdir)/test/Makefile.inc
> +
> +AM_CFLAGS += -I$(srcdir)/common
> +AM_LDFLAGS += -static
> +
> +TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir}
> +
> +EXECUTABLES = odp_thread \
> +              odp_process
> +
> +COMPILE_ONLY =
> +
> +TESTSCRIPTS =
> +
> +if test_helper
> +TESTS = $(EXECUTABLES) $(TESTSCRIPTS)
> +endif
> +
> +dist_bin_SCRIPTS =
> +
> +bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY)
> +
> +
> +dist_odp_thread_SOURCES = odp_thread.c
> +dist_odp_process_SOURCES = odp_process.c
> diff --git a/helper/test/odp_process.c b/helper/test/odp_process.c
> new file mode 100644
> index 0000000..3483549
> --- /dev/null
> +++ b/helper/test/odp_process.c
> @@ -0,0 +1,85 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <test_debug.h>
> +#include <odp.h>
> +#include <odp/helper/linux.h>
> +
> +#define NUMBER_WORKERS 16 /* 0 = max */
> +
> +static void *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());
> +
> +	return 0;
> +}
> +
> +/* Create additional dataplane processes */
> +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> +{
> +	odp_cpumask_t cpu_mask;
> +	int num_workers;
> +	int cpu;
> +	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> +	int ret;
> +	odph_linux_process_t proc[NUMBER_WORKERS];
> +
> +	if (odp_init_global(NULL, NULL)) {
> +		LOG_ERR("Error: ODP global init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_init_local()) {
> +		LOG_ERR("Error: ODP local init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* discover how many processes this system can support */
> +	num_workers = odph_linux_cpumask_default(&cpu_mask, NUMBER_WORKERS);
> +	if (num_workers < NUMBER_WORKERS) {
> +		printf("System can only support %d processes 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 processes: %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 processes:     %i\n\n", num_workers);
> +
> +	/* Fork worker processes */
> +	ret = odph_linux_process_fork_n(proc, &cpu_mask);
> +
> +	if (ret < 0) {
> +		LOG_ERR("Fork workers failed %i\n", ret);
> +		return -1;
> +	}
> +
> +	if (ret == 0) {
> +		/* Child process */
> +		worker_fn(NULL);
> +	} else {
> +		/* Parent process */
> +		odph_linux_process_wait_n(proc, num_workers);
> +
> +		if (odp_term_global()) {
> +			LOG_ERR("Error: ODP global term failed.\n");
> +			exit(EXIT_FAILURE);
> +		}
> +	}
> +
> +	return 0;
> +}
> diff --git a/helper/test/odp_thread.c b/helper/test/odp_thread.c
> new file mode 100644
> index 0000000..04c6b1e
> --- /dev/null
> +++ b/helper/test/odp_thread.c
> @@ -0,0 +1,79 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <test_debug.h>
> +#include <odp.h>
> +#include <odp/helper/linux.h>
> +
> +#define NUMBER_WORKERS 16
> +static void *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 threads */
> +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> +{
> +	odph_linux_pthread_t thread_tbl[NUMBER_WORKERS];
> +	odp_cpumask_t cpu_mask;
> +	int num_workers;
> +	int cpu;
> +	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> +
> +	if (odp_init_global(NULL, NULL)) {
> +		LOG_ERR("Error: ODP global init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_init_local()) {
> +		LOG_ERR("Error: ODP local init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* discover how many threads this system can support */
> +	num_workers = odph_linux_cpumask_default(&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);
> +
> +	odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, worker_fn, NULL);
> +
> +	odph_linux_pthread_join(thread_tbl, num_workers);
> +
> +	if (odp_term_local()) {
> +		LOG_ERR("Error: ODP local term failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_term_global()) {
> +		LOG_ERR("Error: ODP global term failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	return 0;
> +}
Christophe Milard May 13, 2015, 12:45 p.m. UTC | #2
On 2015-05-12 17:32, Mike Holmes wrote:
> The helpers need to be tested independently from the ODP API, create a
> folder to contain helper tests, adding tests for process and thread
> creation.
> 
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>

Reviewed-by: Christophe Milard <christophe.milard@linaro.org>

> ---
>  Makefile.am               |  2 +-
>  configure.ac              | 16 +++++++++
>  helper/Makefile.am        |  1 +
>  helper/test/.gitignore    |  4 +++
>  helper/test/Makefile.am   | 25 ++++++++++++++
>  helper/test/odp_process.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++
>  helper/test/odp_thread.c  | 79 +++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 211 insertions(+), 1 deletion(-)
>  create mode 100644 helper/Makefile.am
>  create mode 100644 helper/test/.gitignore
>  create mode 100644 helper/test/Makefile.am
>  create mode 100644 helper/test/odp_process.c
>  create mode 100644 helper/test/odp_thread.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index 3f80a2a..cff83f7 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -1,7 +1,7 @@
>  ACLOCAL_AMFLAGS=-I m4
>  AUTOMAKE_OPTIONS = foreign
>  
> -SUBDIRS = doc platform example test
> +SUBDIRS = doc platform example test helper
>  
>  include $(top_srcdir)/aminclude.am
>  
> diff --git a/configure.ac b/configure.ac
> index d20bad2..4146b20 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -138,6 +138,20 @@ AC_ARG_ENABLE([test-perf],
>  AM_CONDITIONAL([test_perf], [test x$test_perf = xyes ])
>  
>  ##########################################################################
> +# Enable/disable test-helper
> +##########################################################################
> +test_helper=no
> +AC_ARG_ENABLE([test-helper],
> +    [  --enable-test-helper      run test in helper/test],
> +    [if test "x$enableval" = "xyes"; then
> +        test_helper=yes
> +    fi])
> +
> +AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ])
> +
> +##########################################################################
> +
> +##########################################################################
>  # Enable/disable test-cpp
>  ##########################################################################
>  test_cpp=no
> @@ -277,6 +291,8 @@ AC_CONFIG_FILES([Makefile
>  		 example/ipsec/Makefile
>  		 example/packet/Makefile
>  		 example/timer/Makefile
> +		 helper/Makefile
> +		 helper/test/Makefile
>  		 pkgconfig/libodp.pc
>  		 platform/Makefile
>  		 platform/linux-generic/Makefile
> diff --git a/helper/Makefile.am b/helper/Makefile.am
> new file mode 100644
> index 0000000..02af5b3
> --- /dev/null
> +++ b/helper/Makefile.am
> @@ -0,0 +1 @@
> +SUBDIRS = test
> diff --git a/helper/test/.gitignore b/helper/test/.gitignore
> new file mode 100644
> index 0000000..fe65f30
> --- /dev/null
> +++ b/helper/test/.gitignore
> @@ -0,0 +1,4 @@
> +*.trs
> +*.log
> +odp_process
> +odp_thread
> diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am
> new file mode 100644
> index 0000000..f330533
> --- /dev/null
> +++ b/helper/test/Makefile.am
> @@ -0,0 +1,25 @@
> +include $(top_srcdir)/test/Makefile.inc
> +
> +AM_CFLAGS += -I$(srcdir)/common
> +AM_LDFLAGS += -static
> +
> +TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir}
> +
> +EXECUTABLES = odp_thread \
> +              odp_process
> +
> +COMPILE_ONLY =
> +
> +TESTSCRIPTS =
> +
> +if test_helper
> +TESTS = $(EXECUTABLES) $(TESTSCRIPTS)
> +endif
> +
> +dist_bin_SCRIPTS =
> +
> +bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY)
> +
> +
> +dist_odp_thread_SOURCES = odp_thread.c
> +dist_odp_process_SOURCES = odp_process.c
> diff --git a/helper/test/odp_process.c b/helper/test/odp_process.c
> new file mode 100644
> index 0000000..3483549
> --- /dev/null
> +++ b/helper/test/odp_process.c
> @@ -0,0 +1,85 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <test_debug.h>
> +#include <odp.h>
> +#include <odp/helper/linux.h>
> +
> +#define NUMBER_WORKERS 16 /* 0 = max */
> +
> +static void *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());
> +
> +	return 0;
> +}
> +
> +/* Create additional dataplane processes */
> +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> +{
> +	odp_cpumask_t cpu_mask;
> +	int num_workers;
> +	int cpu;
> +	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> +	int ret;
> +	odph_linux_process_t proc[NUMBER_WORKERS];
> +
> +	if (odp_init_global(NULL, NULL)) {
> +		LOG_ERR("Error: ODP global init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_init_local()) {
> +		LOG_ERR("Error: ODP local init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* discover how many processes this system can support */
> +	num_workers = odph_linux_cpumask_default(&cpu_mask, NUMBER_WORKERS);
> +	if (num_workers < NUMBER_WORKERS) {
> +		printf("System can only support %d processes 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 processes: %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 processes:     %i\n\n", num_workers);
> +
> +	/* Fork worker processes */
> +	ret = odph_linux_process_fork_n(proc, &cpu_mask);
> +
> +	if (ret < 0) {
> +		LOG_ERR("Fork workers failed %i\n", ret);
> +		return -1;
> +	}
> +
> +	if (ret == 0) {
> +		/* Child process */
> +		worker_fn(NULL);
> +	} else {
> +		/* Parent process */
> +		odph_linux_process_wait_n(proc, num_workers);
> +
> +		if (odp_term_global()) {
> +			LOG_ERR("Error: ODP global term failed.\n");
> +			exit(EXIT_FAILURE);
> +		}
> +	}
> +
> +	return 0;
> +}
> diff --git a/helper/test/odp_thread.c b/helper/test/odp_thread.c
> new file mode 100644
> index 0000000..04c6b1e
> --- /dev/null
> +++ b/helper/test/odp_thread.c
> @@ -0,0 +1,79 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <test_debug.h>
> +#include <odp.h>
> +#include <odp/helper/linux.h>
> +
> +#define NUMBER_WORKERS 16
> +static void *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 threads */
> +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> +{
> +	odph_linux_pthread_t thread_tbl[NUMBER_WORKERS];
> +	odp_cpumask_t cpu_mask;
> +	int num_workers;
> +	int cpu;
> +	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> +
> +	if (odp_init_global(NULL, NULL)) {
> +		LOG_ERR("Error: ODP global init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_init_local()) {
> +		LOG_ERR("Error: ODP local init failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* discover how many threads this system can support */
> +	num_workers = odph_linux_cpumask_default(&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);
> +
> +	odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, worker_fn, NULL);
> +
> +	odph_linux_pthread_join(thread_tbl, num_workers);
> +
> +	if (odp_term_local()) {
> +		LOG_ERR("Error: ODP local term failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (odp_term_global()) {
> +		LOG_ERR("Error: ODP global term failed.\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	return 0;
> +}
> -- 
> 2.1.4
>
Mike Holmes May 27, 2015, 12:49 p.m. UTC | #3
Merged

I made the test cases on by default as per Maxims suggestion and added the
debug print for test_helper to the information displayed when you run
configure.

On 13 May 2015 at 08:45, Christophe Milard <christophe.milard@linaro.org>
wrote:

> On 2015-05-12 17:32, Mike Holmes wrote:
> > The helpers need to be tested independently from the ODP API, create a
> > folder to contain helper tests, adding tests for process and thread
> > creation.
> >
> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
>
> Reviewed-by: Christophe Milard <christophe.milard@linaro.org>
>
> > ---
> >  Makefile.am               |  2 +-
> >  configure.ac              | 16 +++++++++
> >  helper/Makefile.am        |  1 +
> >  helper/test/.gitignore    |  4 +++
> >  helper/test/Makefile.am   | 25 ++++++++++++++
> >  helper/test/odp_process.c | 85
> +++++++++++++++++++++++++++++++++++++++++++++++
> >  helper/test/odp_thread.c  | 79
> +++++++++++++++++++++++++++++++++++++++++++
> >  7 files changed, 211 insertions(+), 1 deletion(-)
> >  create mode 100644 helper/Makefile.am
> >  create mode 100644 helper/test/.gitignore
> >  create mode 100644 helper/test/Makefile.am
> >  create mode 100644 helper/test/odp_process.c
> >  create mode 100644 helper/test/odp_thread.c
> >
> > diff --git a/Makefile.am b/Makefile.am
> > index 3f80a2a..cff83f7 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -1,7 +1,7 @@
> >  ACLOCAL_AMFLAGS=-I m4
> >  AUTOMAKE_OPTIONS = foreign
> >
> > -SUBDIRS = doc platform example test
> > +SUBDIRS = doc platform example test helper
> >
> >  include $(top_srcdir)/aminclude.am
> >
> > diff --git a/configure.ac b/configure.ac
> > index d20bad2..4146b20 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -138,6 +138,20 @@ AC_ARG_ENABLE([test-perf],
> >  AM_CONDITIONAL([test_perf], [test x$test_perf = xyes ])
> >
> >
> ##########################################################################
> > +# Enable/disable test-helper
> >
> +##########################################################################
> > +test_helper=no
> > +AC_ARG_ENABLE([test-helper],
> > +    [  --enable-test-helper      run test in helper/test],
> > +    [if test "x$enableval" = "xyes"; then
> > +        test_helper=yes
> > +    fi])
> > +
> > +AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ])
> > +
> >
> +##########################################################################
> > +
> >
> +##########################################################################
> >  # Enable/disable test-cpp
> >
> ##########################################################################
> >  test_cpp=no
> > @@ -277,6 +291,8 @@ AC_CONFIG_FILES([Makefile
> >                example/ipsec/Makefile
> >                example/packet/Makefile
> >                example/timer/Makefile
> > +              helper/Makefile
> > +              helper/test/Makefile
> >                pkgconfig/libodp.pc
> >                platform/Makefile
> >                platform/linux-generic/Makefile
> > diff --git a/helper/Makefile.am b/helper/Makefile.am
> > new file mode 100644
> > index 0000000..02af5b3
> > --- /dev/null
> > +++ b/helper/Makefile.am
> > @@ -0,0 +1 @@
> > +SUBDIRS = test
> > diff --git a/helper/test/.gitignore b/helper/test/.gitignore
> > new file mode 100644
> > index 0000000..fe65f30
> > --- /dev/null
> > +++ b/helper/test/.gitignore
> > @@ -0,0 +1,4 @@
> > +*.trs
> > +*.log
> > +odp_process
> > +odp_thread
> > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am
> > new file mode 100644
> > index 0000000..f330533
> > --- /dev/null
> > +++ b/helper/test/Makefile.am
> > @@ -0,0 +1,25 @@
> > +include $(top_srcdir)/test/Makefile.inc
> > +
> > +AM_CFLAGS += -I$(srcdir)/common
> > +AM_LDFLAGS += -static
> > +
> > +TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir}
> > +
> > +EXECUTABLES = odp_thread \
> > +              odp_process
> > +
> > +COMPILE_ONLY =
> > +
> > +TESTSCRIPTS =
> > +
> > +if test_helper
> > +TESTS = $(EXECUTABLES) $(TESTSCRIPTS)
> > +endif
> > +
> > +dist_bin_SCRIPTS =
> > +
> > +bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY)
> > +
> > +
> > +dist_odp_thread_SOURCES = odp_thread.c
> > +dist_odp_process_SOURCES = odp_process.c
> > diff --git a/helper/test/odp_process.c b/helper/test/odp_process.c
> > new file mode 100644
> > index 0000000..3483549
> > --- /dev/null
> > +++ b/helper/test/odp_process.c
> > @@ -0,0 +1,85 @@
> > +/* Copyright (c) 2015, Linaro Limited
> > + * All rights reserved.
> > + *
> > + * SPDX-License-Identifier:     BSD-3-Clause
> > + */
> > +
> > +#include <test_debug.h>
> > +#include <odp.h>
> > +#include <odp/helper/linux.h>
> > +
> > +#define NUMBER_WORKERS 16 /* 0 = max */
> > +
> > +static void *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());
> > +
> > +     return 0;
> > +}
> > +
> > +/* Create additional dataplane processes */
> > +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> > +{
> > +     odp_cpumask_t cpu_mask;
> > +     int num_workers;
> > +     int cpu;
> > +     char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> > +     int ret;
> > +     odph_linux_process_t proc[NUMBER_WORKERS];
> > +
> > +     if (odp_init_global(NULL, NULL)) {
> > +             LOG_ERR("Error: ODP global init failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     if (odp_init_local()) {
> > +             LOG_ERR("Error: ODP local init failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     /* discover how many processes this system can support */
> > +     num_workers = odph_linux_cpumask_default(&cpu_mask,
> NUMBER_WORKERS);
> > +     if (num_workers < NUMBER_WORKERS) {
> > +             printf("System can only support %d processes 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 processes: %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 processes:     %i\n\n", num_workers);
> > +
> > +     /* Fork worker processes */
> > +     ret = odph_linux_process_fork_n(proc, &cpu_mask);
> > +
> > +     if (ret < 0) {
> > +             LOG_ERR("Fork workers failed %i\n", ret);
> > +             return -1;
> > +     }
> > +
> > +     if (ret == 0) {
> > +             /* Child process */
> > +             worker_fn(NULL);
> > +     } else {
> > +             /* Parent process */
> > +             odph_linux_process_wait_n(proc, num_workers);
> > +
> > +             if (odp_term_global()) {
> > +                     LOG_ERR("Error: ODP global term failed.\n");
> > +                     exit(EXIT_FAILURE);
> > +             }
> > +     }
> > +
> > +     return 0;
> > +}
> > diff --git a/helper/test/odp_thread.c b/helper/test/odp_thread.c
> > new file mode 100644
> > index 0000000..04c6b1e
> > --- /dev/null
> > +++ b/helper/test/odp_thread.c
> > @@ -0,0 +1,79 @@
> > +/* Copyright (c) 2015, Linaro Limited
> > + * All rights reserved.
> > + *
> > + * SPDX-License-Identifier:     BSD-3-Clause
> > + */
> > +
> > +#include <test_debug.h>
> > +#include <odp.h>
> > +#include <odp/helper/linux.h>
> > +
> > +#define NUMBER_WORKERS 16
> > +static void *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 threads */
> > +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
> > +{
> > +     odph_linux_pthread_t thread_tbl[NUMBER_WORKERS];
> > +     odp_cpumask_t cpu_mask;
> > +     int num_workers;
> > +     int cpu;
> > +     char cpumaskstr[ODP_CPUMASK_STR_SIZE];
> > +
> > +     if (odp_init_global(NULL, NULL)) {
> > +             LOG_ERR("Error: ODP global init failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     if (odp_init_local()) {
> > +             LOG_ERR("Error: ODP local init failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     /* discover how many threads this system can support */
> > +     num_workers = odph_linux_cpumask_default(&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);
> > +
> > +     odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, worker_fn,
> NULL);
> > +
> > +     odph_linux_pthread_join(thread_tbl, num_workers);
> > +
> > +     if (odp_term_local()) {
> > +             LOG_ERR("Error: ODP local term failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     if (odp_term_global()) {
> > +             LOG_ERR("Error: ODP global term failed.\n");
> > +             exit(EXIT_FAILURE);
> > +     }
> > +
> > +     return 0;
> > +}
> > --
> > 2.1.4
> >
>
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 3f80a2a..cff83f7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@ 
 ACLOCAL_AMFLAGS=-I m4
 AUTOMAKE_OPTIONS = foreign
 
-SUBDIRS = doc platform example test
+SUBDIRS = doc platform example test helper
 
 include $(top_srcdir)/aminclude.am
 
diff --git a/configure.ac b/configure.ac
index d20bad2..4146b20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,20 @@  AC_ARG_ENABLE([test-perf],
 AM_CONDITIONAL([test_perf], [test x$test_perf = xyes ])
 
 ##########################################################################
+# Enable/disable test-helper
+##########################################################################
+test_helper=no
+AC_ARG_ENABLE([test-helper],
+    [  --enable-test-helper      run test in helper/test],
+    [if test "x$enableval" = "xyes"; then
+        test_helper=yes
+    fi])
+
+AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ])
+
+##########################################################################
+
+##########################################################################
 # Enable/disable test-cpp
 ##########################################################################
 test_cpp=no
@@ -277,6 +291,8 @@  AC_CONFIG_FILES([Makefile
 		 example/ipsec/Makefile
 		 example/packet/Makefile
 		 example/timer/Makefile
+		 helper/Makefile
+		 helper/test/Makefile
 		 pkgconfig/libodp.pc
 		 platform/Makefile
 		 platform/linux-generic/Makefile
diff --git a/helper/Makefile.am b/helper/Makefile.am
new file mode 100644
index 0000000..02af5b3
--- /dev/null
+++ b/helper/Makefile.am
@@ -0,0 +1 @@ 
+SUBDIRS = test
diff --git a/helper/test/.gitignore b/helper/test/.gitignore
new file mode 100644
index 0000000..fe65f30
--- /dev/null
+++ b/helper/test/.gitignore
@@ -0,0 +1,4 @@ 
+*.trs
+*.log
+odp_process
+odp_thread
diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am
new file mode 100644
index 0000000..f330533
--- /dev/null
+++ b/helper/test/Makefile.am
@@ -0,0 +1,25 @@ 
+include $(top_srcdir)/test/Makefile.inc
+
+AM_CFLAGS += -I$(srcdir)/common
+AM_LDFLAGS += -static
+
+TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir}
+
+EXECUTABLES = odp_thread \
+              odp_process
+
+COMPILE_ONLY =
+
+TESTSCRIPTS =
+
+if test_helper
+TESTS = $(EXECUTABLES) $(TESTSCRIPTS)
+endif
+
+dist_bin_SCRIPTS =
+
+bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY)
+
+
+dist_odp_thread_SOURCES = odp_thread.c
+dist_odp_process_SOURCES = odp_process.c
diff --git a/helper/test/odp_process.c b/helper/test/odp_process.c
new file mode 100644
index 0000000..3483549
--- /dev/null
+++ b/helper/test/odp_process.c
@@ -0,0 +1,85 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <test_debug.h>
+#include <odp.h>
+#include <odp/helper/linux.h>
+
+#define NUMBER_WORKERS 16 /* 0 = max */
+
+static void *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());
+
+	return 0;
+}
+
+/* Create additional dataplane processes */
+int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
+{
+	odp_cpumask_t cpu_mask;
+	int num_workers;
+	int cpu;
+	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
+	int ret;
+	odph_linux_process_t proc[NUMBER_WORKERS];
+
+	if (odp_init_global(NULL, NULL)) {
+		LOG_ERR("Error: ODP global init failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (odp_init_local()) {
+		LOG_ERR("Error: ODP local init failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	/* discover how many processes this system can support */
+	num_workers = odph_linux_cpumask_default(&cpu_mask, NUMBER_WORKERS);
+	if (num_workers < NUMBER_WORKERS) {
+		printf("System can only support %d processes 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 processes: %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 processes:     %i\n\n", num_workers);
+
+	/* Fork worker processes */
+	ret = odph_linux_process_fork_n(proc, &cpu_mask);
+
+	if (ret < 0) {
+		LOG_ERR("Fork workers failed %i\n", ret);
+		return -1;
+	}
+
+	if (ret == 0) {
+		/* Child process */
+		worker_fn(NULL);
+	} else {
+		/* Parent process */
+		odph_linux_process_wait_n(proc, num_workers);
+
+		if (odp_term_global()) {
+			LOG_ERR("Error: ODP global term failed.\n");
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	return 0;
+}
diff --git a/helper/test/odp_thread.c b/helper/test/odp_thread.c
new file mode 100644
index 0000000..04c6b1e
--- /dev/null
+++ b/helper/test/odp_thread.c
@@ -0,0 +1,79 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <test_debug.h>
+#include <odp.h>
+#include <odp/helper/linux.h>
+
+#define NUMBER_WORKERS 16
+static void *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 threads */
+int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
+{
+	odph_linux_pthread_t thread_tbl[NUMBER_WORKERS];
+	odp_cpumask_t cpu_mask;
+	int num_workers;
+	int cpu;
+	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
+
+	if (odp_init_global(NULL, NULL)) {
+		LOG_ERR("Error: ODP global init failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (odp_init_local()) {
+		LOG_ERR("Error: ODP local init failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	/* discover how many threads this system can support */
+	num_workers = odph_linux_cpumask_default(&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);
+
+	odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, worker_fn, NULL);
+
+	odph_linux_pthread_join(thread_tbl, num_workers);
+
+	if (odp_term_local()) {
+		LOG_ERR("Error: ODP local term failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (odp_term_global()) {
+		LOG_ERR("Error: ODP global term failed.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	return 0;
+}