diff mbox

[API-NEXT,PATCHv4,06/10] validation: split out cpumask tests into separate file

Message ID 1437579989-1241-7-git-send-email-stuart.haslam@linaro.org
State Accepted
Commit 8bfd55383ea91742b279dd031d968f25ad499382
Headers show

Commit Message

Stuart Haslam July 22, 2015, 3:46 p.m. UTC
Split the majority of the test cases out into a separate file in
preparation for them being reused to perform thrmask tests.

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 test/validation/Makefile.inc         |   3 +-
 test/validation/common/Makefile.am   |   4 +-
 test/validation/common/mask_common.c | 472 +++++++++++++++++++++++++++++++++++
 test/validation/common/mask_common.h |  28 +++
 test/validation/cpumask/Makefile.am  |   1 +
 test/validation/cpumask/cpumask.c    | 465 +---------------------------------
 6 files changed, 508 insertions(+), 465 deletions(-)
 create mode 100644 test/validation/common/mask_common.c
 create mode 100644 test/validation/common/mask_common.h

Comments

Christophe Milard July 23, 2015, 8:50 a.m. UTC | #1
On 2015-07-22 16:46, Stuart Haslam wrote:
> Split the majority of the test cases out into a separate file in
> preparation for them being reused to perform thrmask tests.
> 
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>

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

> ---
>  test/validation/Makefile.inc         |   3 +-
>  test/validation/common/Makefile.am   |   4 +-
>  test/validation/common/mask_common.c | 472 +++++++++++++++++++++++++++++++++++
>  test/validation/common/mask_common.h |  28 +++
>  test/validation/cpumask/Makefile.am  |   1 +
>  test/validation/cpumask/cpumask.c    | 465 +---------------------------------
>  6 files changed, 508 insertions(+), 465 deletions(-)
>  create mode 100644 test/validation/common/mask_common.c
>  create mode 100644 test/validation/common/mask_common.h
> 
> diff --git a/test/validation/Makefile.inc b/test/validation/Makefile.inc
> index cacdfe1..fb07d0a 100644
> --- a/test/validation/Makefile.inc
> +++ b/test/validation/Makefile.inc
> @@ -2,8 +2,9 @@ include $(top_srcdir)/test/Makefile.inc
>  
>  COMMON_DIR = $(top_srcdir)/test/validation/common
>  
> -AM_CFLAGS += -I$(top_srcdir)/test/validation/common
> +AM_CFLAGS += -I$(COMMON_DIR)
>  AM_LDFLAGS += -static
>  
>  LIBCUNIT_COMMON = $(COMMON_DIR)/libcunit_common.la
> +LIBCPUMASK_COMMON = $(COMMON_DIR)/libcpumask_common.la
>  LIBODP = $(LIB)/libodphelper.la $(LIB)/libodp.la
> diff --git a/test/validation/common/Makefile.am b/test/validation/common/Makefile.am
> index c6d019c..12fdb08 100644
> --- a/test/validation/common/Makefile.am
> +++ b/test/validation/common/Makefile.am
> @@ -1,6 +1,8 @@
>  AUTOMAKE_OPTIONS = foreign
>  include $(top_srcdir)/test/Makefile.inc
>  
> -noinst_LTLIBRARIES = libcunit_common.la
> +noinst_LTLIBRARIES = libcunit_common.la libcpumask_common.la
>  
>  libcunit_common_la_SOURCES = odp_cunit_common.c
> +
> +libcpumask_common_la_SOURCES = mask_common.c
> diff --git a/test/validation/common/mask_common.c b/test/validation/common/mask_common.c
> new file mode 100644
> index 0000000..e10b2fe
> --- /dev/null
> +++ b/test/validation/common/mask_common.c
> @@ -0,0 +1,472 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <odp.h>
> +#include "odp_cunit_common.h"
> +#include "mask_common.h"
> +
> +/*
> + * The following string are used to build cpu masks with
> + * odp_cpumask_from_str(). Both 0x prefixed and non prefixed
> + * hex values are supported by odp_cpumask_from_str()
> + */
> +#define TEST_MASK_NO_CPU      "0x0"
> +#define TEST_MASK_CPU_0       "0x1"
> +#define TEST_MASK_CPU_1       "0x2"
> +#define TEST_MASK_CPU_2       "0x4"
> +#define TEST_MASK_CPU_0_2     "0x5"
> +#define TEST_MASK_CPU_0_3     "0x9"
> +#define TEST_MASK_CPU_1_2     "0x6"
> +#define TEST_MASK_CPU_1_3     "0xA"
> +#define TEST_MASK_CPU_0_1_2   "0x7"
> +#define TEST_MASK_CPU_0_2_4_6 "0x55"
> +#define TEST_MASK_CPU_1_2_4_6 "0x56"
> +
> +#define TEST_MASK_CPU_0_NO_PREFIX       "1"
> +
> +/* padding pattern used to check buffer overflow: */
> +#define FILLING_PATTERN 0x55
> +
> +/*
> + * returns the length of a string, excluding terminating NULL.
> + * As its C lib strlen equivalent. Just rewritten here to avoid C lib
> + * dependency in ODP tests (for platform independent / bare metal testing)
> + */
> +static unsigned int stringlen(const char *str)
> +{
> +	unsigned int i = 0;
> +
> +	while (str[i] != 0)
> +		i++;
> +	return i;
> +}
> +
> +/*
> + * builds a string containing a 0x prefixed hex number
> + * where a single bit (corresponding to cpu) is set.
> + * The string is null terminated.
> + * cpu_to_str(0) returns "0x1".
> + * cpu_to_str(10) returns "0x400".
> + * The buffer should be at least ceil(cpu/4)+3 bytes long,
> + * to accommodate with 4 cpus per nibble + "0x" prefix + null.
> + */
> +#define CPUS_PER_NIBBLE 4
> +static void cpu_to_str(char *buff, int cpu)
> +{
> +	const char *hex_nibble = "1248";
> +	int i = 0;
> +
> +	buff[i++] = '0';
> +	buff[i++] = 'x';
> +	buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE];
> +	while (cpu > 3) {
> +		buff[i++] = '0';
> +		cpu -= CPUS_PER_NIBBLE;
> +	}
> +	buff[i++] = 0; /* null */
> +}
> +
> +/*
> + * Returns the maximum number of CPUs that a mask can contain.
> + */
> +unsigned mask_capacity(void)
> +{
> +	odp_cpumask_t mask;
> +
> +	odp_cpumask_setall(&mask);
> +
> +	return odp_cpumask_count(&mask);
> +}
> +
> +void cpumask_test_odp_cpumask_to_from_str(void)
> +{
> +	odp_cpumask_t mask;
> +	int32_t str_sz;
> +	unsigned int buf_sz; /* buf size for the 2 following bufs */
> +	char *buf_in;
> +	char *buf_out;
> +	unsigned int cpu;
> +	unsigned int i;
> +
> +	/* makes sure the mask has room for at least 1 CPU...: */
> +	CU_ASSERT_FATAL(mask_capacity() > 0);
> +
> +	/* allocate memory for the buffers containing the mask strings:
> +	   1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/
> +	buf_sz = (mask_capacity() >> 2) + 20;
> +	buf_in  = malloc(buf_sz);
> +	buf_out = malloc(buf_sz);
> +	CU_ASSERT_FATAL(buf_in && buf_out);
> +
> +	/* test 1 CPU at a time for all possible cpu positions in the mask */
> +	for (cpu = 0; cpu < mask_capacity(); cpu++) {
> +		/* init buffer for overwrite check: */
> +		for (i = 0; i < buf_sz; i++)
> +			buf_out[i] = FILLING_PATTERN;
> +
> +		/* generate a hex string with that cpu set: */
> +		cpu_to_str(buf_in, cpu);
> +
> +		/* generate mask: */
> +		odp_cpumask_from_str(&mask, buf_in);
> +
> +		/* reverse cpu mask computation to get string back: */
> +		str_sz = odp_cpumask_to_str(&mask, buf_out,
> +					    stringlen(buf_in) + 1);
> +
> +		/* check that returned size matches original (with NULL): */
> +		CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1);
> +
> +		/* check that returned string matches original (with NULL): */
> +		CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1);
> +
> +		/* check that no extra buffer writes occurred: */
> +		CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN);
> +	}
> +
> +	/* re-init buffer for overwrite check: */
> +	for (i = 0; i < buf_sz; i++)
> +		buf_out[i] = FILLING_PATTERN;
> +
> +	/* check for buffer overflow when too small buffer given: */
> +	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0);
> +	str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0));
> +
> +	CU_ASSERT(str_sz == -1);
> +
> +	for (i = 0; i < buf_sz; i++)
> +		CU_ASSERT(buf_out[i] == FILLING_PATTERN);
> +
> +	/* check for handling of missing "0x" prefix: */
> +	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX);
> +
> +	str_sz = odp_cpumask_to_str(&mask, buf_out,
> +				    stringlen(TEST_MASK_CPU_0) + 1);
> +
> +	CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0,
> +				stringlen(TEST_MASK_CPU_0) + 1);
> +
> +	free(buf_out);
> +	free(buf_in);
> +}
> +
> +void cpumask_test_odp_cpumask_equal(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +	odp_cpumask_t mask3;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2);
> +	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> +
> +	if (mask_capacity() < 8)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6);
> +	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> +}
> +
> +void cpumask_test_odp_cpumask_zero(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_zero(&mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +}
> +
> +void cpumask_test_odp_cpumask_set(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_set(&mask1, 0);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3);
> +	odp_cpumask_set(&mask1, 3);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +
> +	/* make sure that re-asserting a cpu has no impact: */
> +	odp_cpumask_set(&mask1, 3);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +}
> +
> +void cpumask_test_odp_cpumask_clr(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> +	odp_cpumask_clr(&mask1, 0);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_clr(&mask1, 2);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +
> +	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> +	odp_cpumask_clr(&mask1, 0);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +
> +	/* make sure that re-clearing a cpu has no impact: */
> +	odp_cpumask_clr(&mask1, 0);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +}
> +
> +void cpumask_test_odp_cpumask_isset(void)
> +{
> +	odp_cpumask_t mask1;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
> +	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1));
> +	CU_ASSERT(odp_cpumask_isset(&mask1, 2));
> +	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3));
> +}
> +
> +void cpumask_test_odp_cpumask_count(void)
> +{
> +	odp_cpumask_t mask1;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	CU_ASSERT(odp_cpumask_count(&mask1) == 1);
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	CU_ASSERT(odp_cpumask_count(&mask1) == 0);
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	CU_ASSERT(odp_cpumask_count(&mask1) == 2);
> +}
> +
> +void cpumask_test_odp_cpumask_and(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +	odp_cpumask_t mask3;
> +	odp_cpumask_t mask4;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> +	odp_cpumask_and(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> +	odp_cpumask_and(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> +	odp_cpumask_and(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2);
> +	odp_cpumask_and(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +}
> +
> +void cpumask_test_odp_cpumask_or(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +	odp_cpumask_t mask3;
> +	odp_cpumask_t mask4;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> +	odp_cpumask_or(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> +	odp_cpumask_or(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> +	odp_cpumask_or(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2);
> +	odp_cpumask_or(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +}
> +
> +void cpumask_test_odp_cpumask_xor(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +	odp_cpumask_t mask3;
> +	odp_cpumask_t mask4;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> +	odp_cpumask_xor(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> +	odp_cpumask_xor(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> +	odp_cpumask_xor(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2);
> +	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
> +	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1);
> +	odp_cpumask_xor(&mask3, &mask1, &mask2);
> +	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> +}
> +
> +void cpumask_test_odp_cpumask_copy(void)
> +{
> +	odp_cpumask_t mask1;
> +	odp_cpumask_t mask2;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	odp_cpumask_copy(&mask2, &mask1);
> +	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> +}
> +
> +void cpumask_test_odp_cpumask_first(void)
> +{
> +	odp_cpumask_t mask1;
> +
> +	/* check when there is no first */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	CU_ASSERT(odp_cpumask_first(&mask1) == -1);
> +
> +	/* single CPU case: */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	CU_ASSERT(odp_cpumask_first(&mask1) == 0);
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> +	CU_ASSERT(odp_cpumask_first(&mask1) == 1);
> +}
> +
> +void cpumask_test_odp_cpumask_last(void)
> +{
> +	odp_cpumask_t mask1;
> +
> +	/* check when there is no last: */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	CU_ASSERT(odp_cpumask_last(&mask1) == -1);
> +
> +	/* single CPU case: */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	CU_ASSERT(odp_cpumask_last(&mask1) == 0);
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> +	CU_ASSERT(odp_cpumask_last(&mask1) == 3);
> +}
> +
> +void cpumask_test_odp_cpumask_next(void)
> +{
> +	unsigned int i;
> +	int expected[] = {1, 3, 3, -1};
> +	odp_cpumask_t mask1;
> +
> +	/* case when the mask does not contain any CPU: */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> +	CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1);
> +
> +	/* case when the mask just contain CPU 0: */
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> +	CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0);
> +	CU_ASSERT(odp_cpumask_next(&mask1, 0)  == -1);
> +
> +	if (mask_capacity() < 4)
> +		return;
> +
> +	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> +
> +	for (i = 0; i < sizeof(expected) / sizeof(int); i++)
> +		CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]);
> +}
> +
> +void cpumask_test_odp_cpumask_setall(void)
> +{
> +	int num_cpus;
> +	int max_cpus = mask_capacity();
> +	odp_cpumask_t mask;
> +
> +	odp_cpumask_setall(&mask);
> +	num_cpus = odp_cpumask_count(&mask);
> +
> +	CU_ASSERT(num_cpus > 0);
> +	CU_ASSERT(num_cpus >= max_cpus);
> +}
> diff --git a/test/validation/common/mask_common.h b/test/validation/common/mask_common.h
> new file mode 100644
> index 0000000..17cae45
> --- /dev/null
> +++ b/test/validation/common/mask_common.h
> @@ -0,0 +1,28 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#ifndef ODP_MASK_COMMON_H_
> +#define ODP_MASK_COMMON_H_
> +
> +unsigned mask_capacity(void);
> +
> +void cpumask_test_odp_cpumask_to_from_str(void);
> +void cpumask_test_odp_cpumask_equal(void);
> +void cpumask_test_odp_cpumask_zero(void);
> +void cpumask_test_odp_cpumask_set(void);
> +void cpumask_test_odp_cpumask_clr(void);
> +void cpumask_test_odp_cpumask_isset(void);
> +void cpumask_test_odp_cpumask_count(void);
> +void cpumask_test_odp_cpumask_and(void);
> +void cpumask_test_odp_cpumask_or(void);
> +void cpumask_test_odp_cpumask_xor(void);
> +void cpumask_test_odp_cpumask_copy(void);
> +void cpumask_test_odp_cpumask_first(void);
> +void cpumask_test_odp_cpumask_last(void);
> +void cpumask_test_odp_cpumask_next(void);
> +void cpumask_test_odp_cpumask_setall(void);
> +
> +#endif
> diff --git a/test/validation/cpumask/Makefile.am b/test/validation/cpumask/Makefile.am
> index fa44f8d..795d9ff 100644
> --- a/test/validation/cpumask/Makefile.am
> +++ b/test/validation/cpumask/Makefile.am
> @@ -2,6 +2,7 @@ include ../Makefile.inc
>  
>  noinst_LTLIBRARIES = libcpumask.la
>  libcpumask_la_SOURCES = cpumask.c
> +libcpumask_la_LIBADD = $(LIBCPUMASK_COMMON)
>  
>  bin_PROGRAMS = cpumask_main$(EXEEXT)
>  dist_cpumask_main_SOURCES = cpumask_main.c
> diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c
> index d72569e..76b7648 100644
> --- a/test/validation/cpumask/cpumask.c
> +++ b/test/validation/cpumask/cpumask.c
> @@ -5,475 +5,14 @@
>   */
>  
>  #include <odp.h>
> +
>  #include "odp_cunit_common.h"
>  #include "cpumask.h"
> -
> -/*
> - * The following string are used to build cpu masks with
> - * odp_cpumask_from_str(). Both 0x prefixed and non prefixed
> - * hex values are supported by odp_cpumask_from_str()
> - */
> -#define TEST_MASK_NO_CPU      "0x0"
> -#define TEST_MASK_CPU_0       "0x1"
> -#define TEST_MASK_CPU_1       "0x2"
> -#define TEST_MASK_CPU_2       "0x4"
> -#define TEST_MASK_CPU_0_2     "0x5"
> -#define TEST_MASK_CPU_0_3     "0x9"
> -#define TEST_MASK_CPU_1_2     "0x6"
> -#define TEST_MASK_CPU_1_3     "0xA"
> -#define TEST_MASK_CPU_0_1_2   "0x7"
> -#define TEST_MASK_CPU_0_2_4_6 "0x55"
> -#define TEST_MASK_CPU_1_2_4_6 "0x56"
> -
> -#define TEST_MASK_CPU_0_NO_PREFIX       "1"
> -
> -/* padding pattern used to check buffer overflow: */
> -#define FILLING_PATTERN 0x55
> +#include "mask_common.h"
>  
>  /* default worker paramiter to get all that may be available */
>  #define ALL_AVAILABLE 0
>  
> -/*
> - * returns the length of a string, excluding terminating NULL.
> - * As its C lib strlen equivalent. Just rewritten here to avoid C lib
> - * dependency in ODP tests (for platform independent / bare metal testing)
> - */
> -static unsigned int stringlen(const char *str)
> -{
> -	unsigned int i = 0;
> -
> -	while (str[i] != 0)
> -		i++;
> -	return i;
> -}
> -
> -/*
> - * builds a string containing a 0x prefixed hex number
> - * where a single bit (corresponding to cpu) is set.
> - * The string is null terminated.
> - * cpu_to_str(0) returns "0x1".
> - * cpu_to_str(10) returns "0x400".
> - * The buffer should be at least ceil(cpu/4)+3 bytes long,
> - * to accommodate with 4 cpus per nibble + "0x" prefix + null.
> - */
> -#define CPUS_PER_NIBBLE 4
> -static void cpu_to_str(char *buff, int cpu)
> -{
> -	const char *hex_nibble = "1248";
> -	int i = 0;
> -
> -	buff[i++] = '0';
> -	buff[i++] = 'x';
> -	buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE];
> -	while (cpu > 3) {
> -		buff[i++] = '0';
> -		cpu -= CPUS_PER_NIBBLE;
> -	}
> -	buff[i++] = 0; /* null */
> -}
> -
> -/*
> - * Returns the maximum number of CPUs that a mask can contain.
> - */
> -static unsigned mask_capacity(void)
> -{
> -	odp_cpumask_t mask;
> -
> -	odp_cpumask_setall(&mask);
> -
> -	return odp_cpumask_count(&mask);
> -}
> -
> -static void cpumask_test_odp_cpumask_to_from_str(void)
> -{
> -	odp_cpumask_t mask;
> -	int32_t str_sz;
> -	unsigned int buf_sz; /* buf size for the 2 following bufs */
> -	char *buf_in;
> -	char *buf_out;
> -	unsigned int cpu;
> -	unsigned int i;
> -
> -	/* makes sure the mask has room for at least 1 CPU...: */
> -	CU_ASSERT_FATAL(mask_capacity() > 0);
> -
> -	/* allocate memory for the buffers containing the mask strings:
> -	   1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/
> -	buf_sz = (mask_capacity() >> 2) + 20;
> -	buf_in  = malloc(buf_sz);
> -	buf_out = malloc(buf_sz);
> -	CU_ASSERT_FATAL(buf_in && buf_out);
> -
> -	/* test 1 CPU at a time for all possible cpu positions in the mask */
> -	for (cpu = 0; cpu < mask_capacity(); cpu++) {
> -		/* init buffer for overwrite check: */
> -		for (i = 0; i < buf_sz; i++)
> -			buf_out[i] = FILLING_PATTERN;
> -
> -		/* generate a hex string with that cpu set: */
> -		cpu_to_str(buf_in, cpu);
> -
> -		/* generate mask: */
> -		odp_cpumask_from_str(&mask, buf_in);
> -
> -		/* reverse cpu mask computation to get string back: */
> -		str_sz = odp_cpumask_to_str(&mask, buf_out,
> -					    stringlen(buf_in) + 1);
> -
> -		/* check that returned size matches original (with NULL): */
> -		CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1);
> -
> -		/* check that returned string matches original (with NULL): */
> -		CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1);
> -
> -		/* check that no extra buffer writes occurred: */
> -		CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN);
> -	}
> -
> -	/* re-init buffer for overwrite check: */
> -	for (i = 0; i < buf_sz; i++)
> -		buf_out[i] = FILLING_PATTERN;
> -
> -	/* check for buffer overflow when too small buffer given: */
> -	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0);
> -	str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0));
> -
> -	CU_ASSERT(str_sz == -1);
> -
> -	for (i = 0; i < buf_sz; i++)
> -		CU_ASSERT(buf_out[i] == FILLING_PATTERN);
> -
> -	/* check for handling of missing "0x" prefix: */
> -	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX);
> -
> -	str_sz = odp_cpumask_to_str(&mask, buf_out,
> -				    stringlen(TEST_MASK_CPU_0) + 1);
> -
> -	CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0,
> -				stringlen(TEST_MASK_CPU_0) + 1);
> -
> -	free(buf_out);
> -	free(buf_in);
> -}
> -
> -static void cpumask_test_odp_cpumask_equal(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -	odp_cpumask_t mask3;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2);
> -	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> -
> -	if (mask_capacity() < 8)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6);
> -	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
> -}
> -
> -static void cpumask_test_odp_cpumask_zero(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_zero(&mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -}
> -
> -static void cpumask_test_odp_cpumask_set(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_set(&mask1, 0);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3);
> -	odp_cpumask_set(&mask1, 3);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -
> -	/* make sure that re-asserting a cpu has no impact: */
> -	odp_cpumask_set(&mask1, 3);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -}
> -
> -static void cpumask_test_odp_cpumask_clr(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> -	odp_cpumask_clr(&mask1, 0);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_clr(&mask1, 2);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -
> -	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> -	odp_cpumask_clr(&mask1, 0);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -
> -	/* make sure that re-clearing a cpu has no impact: */
> -	odp_cpumask_clr(&mask1, 0);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -}
> -
> -static void cpumask_test_odp_cpumask_isset(void)
> -{
> -	odp_cpumask_t mask1;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
> -	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1));
> -	CU_ASSERT(odp_cpumask_isset(&mask1, 2));
> -	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3));
> -}
> -
> -static void cpumask_test_odp_cpumask_count(void)
> -{
> -	odp_cpumask_t mask1;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	CU_ASSERT(odp_cpumask_count(&mask1) == 1);
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	CU_ASSERT(odp_cpumask_count(&mask1) == 0);
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	CU_ASSERT(odp_cpumask_count(&mask1) == 2);
> -}
> -
> -static void cpumask_test_odp_cpumask_and(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -	odp_cpumask_t mask3;
> -	odp_cpumask_t mask4;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> -	odp_cpumask_and(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> -	odp_cpumask_and(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> -	odp_cpumask_and(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2);
> -	odp_cpumask_and(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -}
> -
> -static void cpumask_test_odp_cpumask_or(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -	odp_cpumask_t mask3;
> -	odp_cpumask_t mask4;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> -	odp_cpumask_or(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> -	odp_cpumask_or(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> -	odp_cpumask_or(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2);
> -	odp_cpumask_or(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -}
> -
> -static void cpumask_test_odp_cpumask_xor(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -	odp_cpumask_t mask3;
> -	odp_cpumask_t mask4;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> -	odp_cpumask_xor(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
> -	odp_cpumask_xor(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
> -	odp_cpumask_xor(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2);
> -	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
> -	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1);
> -	odp_cpumask_xor(&mask3, &mask1, &mask2);
> -	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
> -}
> -
> -static void cpumask_test_odp_cpumask_copy(void)
> -{
> -	odp_cpumask_t mask1;
> -	odp_cpumask_t mask2;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	odp_cpumask_copy(&mask2, &mask1);
> -	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
> -}
> -
> -static void cpumask_test_odp_cpumask_first(void)
> -{
> -	odp_cpumask_t mask1;
> -
> -	/* check when there is no first */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	CU_ASSERT(odp_cpumask_first(&mask1) == -1);
> -
> -	/* single CPU case: */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	CU_ASSERT(odp_cpumask_first(&mask1) == 0);
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> -	CU_ASSERT(odp_cpumask_first(&mask1) == 1);
> -}
> -
> -static void cpumask_test_odp_cpumask_last(void)
> -{
> -	odp_cpumask_t mask1;
> -
> -	/* check when there is no last: */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	CU_ASSERT(odp_cpumask_last(&mask1) == -1);
> -
> -	/* single CPU case: */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	CU_ASSERT(odp_cpumask_last(&mask1) == 0);
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> -	CU_ASSERT(odp_cpumask_last(&mask1) == 3);
> -}
> -
> -static void cpumask_test_odp_cpumask_next(void)
> -{
> -	unsigned int i;
> -	int expected[] = {1, 3, 3, -1};
> -	odp_cpumask_t mask1;
> -
> -	/* case when the mask does not contain any CPU: */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
> -	CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1);
> -
> -	/* case when the mask just contain CPU 0: */
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
> -	CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0);
> -	CU_ASSERT(odp_cpumask_next(&mask1, 0)  == -1);
> -
> -	if (mask_capacity() < 4)
> -		return;
> -
> -	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
> -
> -	for (i = 0; i < sizeof(expected) / sizeof(int); i++)
> -		CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]);
> -}
> -
> -static void cpumask_test_odp_cpumask_setall(void)
> -{
> -	int num_cpus;
> -	int max_cpus = mask_capacity();
> -	odp_cpumask_t mask;
> -
> -	odp_cpumask_setall(&mask);
> -	num_cpus = odp_cpumask_count(&mask);
> -
> -	CU_ASSERT(num_cpus > 0);
> -	CU_ASSERT(num_cpus >= max_cpus);
> -}
> -
>  static void cpumask_test_odp_cpumask_def_control(void)
>  {
>  	unsigned num;
> -- 
> 2.1.1
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/test/validation/Makefile.inc b/test/validation/Makefile.inc
index cacdfe1..fb07d0a 100644
--- a/test/validation/Makefile.inc
+++ b/test/validation/Makefile.inc
@@ -2,8 +2,9 @@  include $(top_srcdir)/test/Makefile.inc
 
 COMMON_DIR = $(top_srcdir)/test/validation/common
 
-AM_CFLAGS += -I$(top_srcdir)/test/validation/common
+AM_CFLAGS += -I$(COMMON_DIR)
 AM_LDFLAGS += -static
 
 LIBCUNIT_COMMON = $(COMMON_DIR)/libcunit_common.la
+LIBCPUMASK_COMMON = $(COMMON_DIR)/libcpumask_common.la
 LIBODP = $(LIB)/libodphelper.la $(LIB)/libodp.la
diff --git a/test/validation/common/Makefile.am b/test/validation/common/Makefile.am
index c6d019c..12fdb08 100644
--- a/test/validation/common/Makefile.am
+++ b/test/validation/common/Makefile.am
@@ -1,6 +1,8 @@ 
 AUTOMAKE_OPTIONS = foreign
 include $(top_srcdir)/test/Makefile.inc
 
-noinst_LTLIBRARIES = libcunit_common.la
+noinst_LTLIBRARIES = libcunit_common.la libcpumask_common.la
 
 libcunit_common_la_SOURCES = odp_cunit_common.c
+
+libcpumask_common_la_SOURCES = mask_common.c
diff --git a/test/validation/common/mask_common.c b/test/validation/common/mask_common.c
new file mode 100644
index 0000000..e10b2fe
--- /dev/null
+++ b/test/validation/common/mask_common.c
@@ -0,0 +1,472 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp.h>
+#include "odp_cunit_common.h"
+#include "mask_common.h"
+
+/*
+ * The following string are used to build cpu masks with
+ * odp_cpumask_from_str(). Both 0x prefixed and non prefixed
+ * hex values are supported by odp_cpumask_from_str()
+ */
+#define TEST_MASK_NO_CPU      "0x0"
+#define TEST_MASK_CPU_0       "0x1"
+#define TEST_MASK_CPU_1       "0x2"
+#define TEST_MASK_CPU_2       "0x4"
+#define TEST_MASK_CPU_0_2     "0x5"
+#define TEST_MASK_CPU_0_3     "0x9"
+#define TEST_MASK_CPU_1_2     "0x6"
+#define TEST_MASK_CPU_1_3     "0xA"
+#define TEST_MASK_CPU_0_1_2   "0x7"
+#define TEST_MASK_CPU_0_2_4_6 "0x55"
+#define TEST_MASK_CPU_1_2_4_6 "0x56"
+
+#define TEST_MASK_CPU_0_NO_PREFIX       "1"
+
+/* padding pattern used to check buffer overflow: */
+#define FILLING_PATTERN 0x55
+
+/*
+ * returns the length of a string, excluding terminating NULL.
+ * As its C lib strlen equivalent. Just rewritten here to avoid C lib
+ * dependency in ODP tests (for platform independent / bare metal testing)
+ */
+static unsigned int stringlen(const char *str)
+{
+	unsigned int i = 0;
+
+	while (str[i] != 0)
+		i++;
+	return i;
+}
+
+/*
+ * builds a string containing a 0x prefixed hex number
+ * where a single bit (corresponding to cpu) is set.
+ * The string is null terminated.
+ * cpu_to_str(0) returns "0x1".
+ * cpu_to_str(10) returns "0x400".
+ * The buffer should be at least ceil(cpu/4)+3 bytes long,
+ * to accommodate with 4 cpus per nibble + "0x" prefix + null.
+ */
+#define CPUS_PER_NIBBLE 4
+static void cpu_to_str(char *buff, int cpu)
+{
+	const char *hex_nibble = "1248";
+	int i = 0;
+
+	buff[i++] = '0';
+	buff[i++] = 'x';
+	buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE];
+	while (cpu > 3) {
+		buff[i++] = '0';
+		cpu -= CPUS_PER_NIBBLE;
+	}
+	buff[i++] = 0; /* null */
+}
+
+/*
+ * Returns the maximum number of CPUs that a mask can contain.
+ */
+unsigned mask_capacity(void)
+{
+	odp_cpumask_t mask;
+
+	odp_cpumask_setall(&mask);
+
+	return odp_cpumask_count(&mask);
+}
+
+void cpumask_test_odp_cpumask_to_from_str(void)
+{
+	odp_cpumask_t mask;
+	int32_t str_sz;
+	unsigned int buf_sz; /* buf size for the 2 following bufs */
+	char *buf_in;
+	char *buf_out;
+	unsigned int cpu;
+	unsigned int i;
+
+	/* makes sure the mask has room for at least 1 CPU...: */
+	CU_ASSERT_FATAL(mask_capacity() > 0);
+
+	/* allocate memory for the buffers containing the mask strings:
+	   1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/
+	buf_sz = (mask_capacity() >> 2) + 20;
+	buf_in  = malloc(buf_sz);
+	buf_out = malloc(buf_sz);
+	CU_ASSERT_FATAL(buf_in && buf_out);
+
+	/* test 1 CPU at a time for all possible cpu positions in the mask */
+	for (cpu = 0; cpu < mask_capacity(); cpu++) {
+		/* init buffer for overwrite check: */
+		for (i = 0; i < buf_sz; i++)
+			buf_out[i] = FILLING_PATTERN;
+
+		/* generate a hex string with that cpu set: */
+		cpu_to_str(buf_in, cpu);
+
+		/* generate mask: */
+		odp_cpumask_from_str(&mask, buf_in);
+
+		/* reverse cpu mask computation to get string back: */
+		str_sz = odp_cpumask_to_str(&mask, buf_out,
+					    stringlen(buf_in) + 1);
+
+		/* check that returned size matches original (with NULL): */
+		CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1);
+
+		/* check that returned string matches original (with NULL): */
+		CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1);
+
+		/* check that no extra buffer writes occurred: */
+		CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN);
+	}
+
+	/* re-init buffer for overwrite check: */
+	for (i = 0; i < buf_sz; i++)
+		buf_out[i] = FILLING_PATTERN;
+
+	/* check for buffer overflow when too small buffer given: */
+	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0);
+	str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0));
+
+	CU_ASSERT(str_sz == -1);
+
+	for (i = 0; i < buf_sz; i++)
+		CU_ASSERT(buf_out[i] == FILLING_PATTERN);
+
+	/* check for handling of missing "0x" prefix: */
+	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX);
+
+	str_sz = odp_cpumask_to_str(&mask, buf_out,
+				    stringlen(TEST_MASK_CPU_0) + 1);
+
+	CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0,
+				stringlen(TEST_MASK_CPU_0) + 1);
+
+	free(buf_out);
+	free(buf_in);
+}
+
+void cpumask_test_odp_cpumask_equal(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+	odp_cpumask_t mask3;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2);
+	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
+
+	if (mask_capacity() < 8)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6);
+	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
+}
+
+void cpumask_test_odp_cpumask_zero(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_zero(&mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+}
+
+void cpumask_test_odp_cpumask_set(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_set(&mask1, 0);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3);
+	odp_cpumask_set(&mask1, 3);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+
+	/* make sure that re-asserting a cpu has no impact: */
+	odp_cpumask_set(&mask1, 3);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+}
+
+void cpumask_test_odp_cpumask_clr(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
+	odp_cpumask_clr(&mask1, 0);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_clr(&mask1, 2);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+
+	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
+	odp_cpumask_clr(&mask1, 0);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+
+	/* make sure that re-clearing a cpu has no impact: */
+	odp_cpumask_clr(&mask1, 0);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+}
+
+void cpumask_test_odp_cpumask_isset(void)
+{
+	odp_cpumask_t mask1;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
+	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1));
+	CU_ASSERT(odp_cpumask_isset(&mask1, 2));
+	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3));
+}
+
+void cpumask_test_odp_cpumask_count(void)
+{
+	odp_cpumask_t mask1;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	CU_ASSERT(odp_cpumask_count(&mask1) == 1);
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	CU_ASSERT(odp_cpumask_count(&mask1) == 0);
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	CU_ASSERT(odp_cpumask_count(&mask1) == 2);
+}
+
+void cpumask_test_odp_cpumask_and(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+	odp_cpumask_t mask3;
+	odp_cpumask_t mask4;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
+	odp_cpumask_and(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
+	odp_cpumask_and(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
+	odp_cpumask_and(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2);
+	odp_cpumask_and(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+}
+
+void cpumask_test_odp_cpumask_or(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+	odp_cpumask_t mask3;
+	odp_cpumask_t mask4;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
+	odp_cpumask_or(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
+	odp_cpumask_or(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
+	odp_cpumask_or(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2);
+	odp_cpumask_or(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+}
+
+void cpumask_test_odp_cpumask_xor(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+	odp_cpumask_t mask3;
+	odp_cpumask_t mask4;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
+	odp_cpumask_xor(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
+	odp_cpumask_xor(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
+	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
+	odp_cpumask_xor(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2);
+	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
+	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1);
+	odp_cpumask_xor(&mask3, &mask1, &mask2);
+	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
+}
+
+void cpumask_test_odp_cpumask_copy(void)
+{
+	odp_cpumask_t mask1;
+	odp_cpumask_t mask2;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	odp_cpumask_copy(&mask2, &mask1);
+	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
+}
+
+void cpumask_test_odp_cpumask_first(void)
+{
+	odp_cpumask_t mask1;
+
+	/* check when there is no first */
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	CU_ASSERT(odp_cpumask_first(&mask1) == -1);
+
+	/* single CPU case: */
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	CU_ASSERT(odp_cpumask_first(&mask1) == 0);
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
+	CU_ASSERT(odp_cpumask_first(&mask1) == 1);
+}
+
+void cpumask_test_odp_cpumask_last(void)
+{
+	odp_cpumask_t mask1;
+
+	/* check when there is no last: */
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	CU_ASSERT(odp_cpumask_last(&mask1) == -1);
+
+	/* single CPU case: */
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	CU_ASSERT(odp_cpumask_last(&mask1) == 0);
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
+	CU_ASSERT(odp_cpumask_last(&mask1) == 3);
+}
+
+void cpumask_test_odp_cpumask_next(void)
+{
+	unsigned int i;
+	int expected[] = {1, 3, 3, -1};
+	odp_cpumask_t mask1;
+
+	/* case when the mask does not contain any CPU: */
+	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
+	CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1);
+
+	/* case when the mask just contain CPU 0: */
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
+	CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0);
+	CU_ASSERT(odp_cpumask_next(&mask1, 0)  == -1);
+
+	if (mask_capacity() < 4)
+		return;
+
+	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
+
+	for (i = 0; i < sizeof(expected) / sizeof(int); i++)
+		CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]);
+}
+
+void cpumask_test_odp_cpumask_setall(void)
+{
+	int num_cpus;
+	int max_cpus = mask_capacity();
+	odp_cpumask_t mask;
+
+	odp_cpumask_setall(&mask);
+	num_cpus = odp_cpumask_count(&mask);
+
+	CU_ASSERT(num_cpus > 0);
+	CU_ASSERT(num_cpus >= max_cpus);
+}
diff --git a/test/validation/common/mask_common.h b/test/validation/common/mask_common.h
new file mode 100644
index 0000000..17cae45
--- /dev/null
+++ b/test/validation/common/mask_common.h
@@ -0,0 +1,28 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#ifndef ODP_MASK_COMMON_H_
+#define ODP_MASK_COMMON_H_
+
+unsigned mask_capacity(void);
+
+void cpumask_test_odp_cpumask_to_from_str(void);
+void cpumask_test_odp_cpumask_equal(void);
+void cpumask_test_odp_cpumask_zero(void);
+void cpumask_test_odp_cpumask_set(void);
+void cpumask_test_odp_cpumask_clr(void);
+void cpumask_test_odp_cpumask_isset(void);
+void cpumask_test_odp_cpumask_count(void);
+void cpumask_test_odp_cpumask_and(void);
+void cpumask_test_odp_cpumask_or(void);
+void cpumask_test_odp_cpumask_xor(void);
+void cpumask_test_odp_cpumask_copy(void);
+void cpumask_test_odp_cpumask_first(void);
+void cpumask_test_odp_cpumask_last(void);
+void cpumask_test_odp_cpumask_next(void);
+void cpumask_test_odp_cpumask_setall(void);
+
+#endif
diff --git a/test/validation/cpumask/Makefile.am b/test/validation/cpumask/Makefile.am
index fa44f8d..795d9ff 100644
--- a/test/validation/cpumask/Makefile.am
+++ b/test/validation/cpumask/Makefile.am
@@ -2,6 +2,7 @@  include ../Makefile.inc
 
 noinst_LTLIBRARIES = libcpumask.la
 libcpumask_la_SOURCES = cpumask.c
+libcpumask_la_LIBADD = $(LIBCPUMASK_COMMON)
 
 bin_PROGRAMS = cpumask_main$(EXEEXT)
 dist_cpumask_main_SOURCES = cpumask_main.c
diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c
index d72569e..76b7648 100644
--- a/test/validation/cpumask/cpumask.c
+++ b/test/validation/cpumask/cpumask.c
@@ -5,475 +5,14 @@ 
  */
 
 #include <odp.h>
+
 #include "odp_cunit_common.h"
 #include "cpumask.h"
-
-/*
- * The following string are used to build cpu masks with
- * odp_cpumask_from_str(). Both 0x prefixed and non prefixed
- * hex values are supported by odp_cpumask_from_str()
- */
-#define TEST_MASK_NO_CPU      "0x0"
-#define TEST_MASK_CPU_0       "0x1"
-#define TEST_MASK_CPU_1       "0x2"
-#define TEST_MASK_CPU_2       "0x4"
-#define TEST_MASK_CPU_0_2     "0x5"
-#define TEST_MASK_CPU_0_3     "0x9"
-#define TEST_MASK_CPU_1_2     "0x6"
-#define TEST_MASK_CPU_1_3     "0xA"
-#define TEST_MASK_CPU_0_1_2   "0x7"
-#define TEST_MASK_CPU_0_2_4_6 "0x55"
-#define TEST_MASK_CPU_1_2_4_6 "0x56"
-
-#define TEST_MASK_CPU_0_NO_PREFIX       "1"
-
-/* padding pattern used to check buffer overflow: */
-#define FILLING_PATTERN 0x55
+#include "mask_common.h"
 
 /* default worker paramiter to get all that may be available */
 #define ALL_AVAILABLE 0
 
-/*
- * returns the length of a string, excluding terminating NULL.
- * As its C lib strlen equivalent. Just rewritten here to avoid C lib
- * dependency in ODP tests (for platform independent / bare metal testing)
- */
-static unsigned int stringlen(const char *str)
-{
-	unsigned int i = 0;
-
-	while (str[i] != 0)
-		i++;
-	return i;
-}
-
-/*
- * builds a string containing a 0x prefixed hex number
- * where a single bit (corresponding to cpu) is set.
- * The string is null terminated.
- * cpu_to_str(0) returns "0x1".
- * cpu_to_str(10) returns "0x400".
- * The buffer should be at least ceil(cpu/4)+3 bytes long,
- * to accommodate with 4 cpus per nibble + "0x" prefix + null.
- */
-#define CPUS_PER_NIBBLE 4
-static void cpu_to_str(char *buff, int cpu)
-{
-	const char *hex_nibble = "1248";
-	int i = 0;
-
-	buff[i++] = '0';
-	buff[i++] = 'x';
-	buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE];
-	while (cpu > 3) {
-		buff[i++] = '0';
-		cpu -= CPUS_PER_NIBBLE;
-	}
-	buff[i++] = 0; /* null */
-}
-
-/*
- * Returns the maximum number of CPUs that a mask can contain.
- */
-static unsigned mask_capacity(void)
-{
-	odp_cpumask_t mask;
-
-	odp_cpumask_setall(&mask);
-
-	return odp_cpumask_count(&mask);
-}
-
-static void cpumask_test_odp_cpumask_to_from_str(void)
-{
-	odp_cpumask_t mask;
-	int32_t str_sz;
-	unsigned int buf_sz; /* buf size for the 2 following bufs */
-	char *buf_in;
-	char *buf_out;
-	unsigned int cpu;
-	unsigned int i;
-
-	/* makes sure the mask has room for at least 1 CPU...: */
-	CU_ASSERT_FATAL(mask_capacity() > 0);
-
-	/* allocate memory for the buffers containing the mask strings:
-	   1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/
-	buf_sz = (mask_capacity() >> 2) + 20;
-	buf_in  = malloc(buf_sz);
-	buf_out = malloc(buf_sz);
-	CU_ASSERT_FATAL(buf_in && buf_out);
-
-	/* test 1 CPU at a time for all possible cpu positions in the mask */
-	for (cpu = 0; cpu < mask_capacity(); cpu++) {
-		/* init buffer for overwrite check: */
-		for (i = 0; i < buf_sz; i++)
-			buf_out[i] = FILLING_PATTERN;
-
-		/* generate a hex string with that cpu set: */
-		cpu_to_str(buf_in, cpu);
-
-		/* generate mask: */
-		odp_cpumask_from_str(&mask, buf_in);
-
-		/* reverse cpu mask computation to get string back: */
-		str_sz = odp_cpumask_to_str(&mask, buf_out,
-					    stringlen(buf_in) + 1);
-
-		/* check that returned size matches original (with NULL): */
-		CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1);
-
-		/* check that returned string matches original (with NULL): */
-		CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1);
-
-		/* check that no extra buffer writes occurred: */
-		CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN);
-	}
-
-	/* re-init buffer for overwrite check: */
-	for (i = 0; i < buf_sz; i++)
-		buf_out[i] = FILLING_PATTERN;
-
-	/* check for buffer overflow when too small buffer given: */
-	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0);
-	str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0));
-
-	CU_ASSERT(str_sz == -1);
-
-	for (i = 0; i < buf_sz; i++)
-		CU_ASSERT(buf_out[i] == FILLING_PATTERN);
-
-	/* check for handling of missing "0x" prefix: */
-	odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX);
-
-	str_sz = odp_cpumask_to_str(&mask, buf_out,
-				    stringlen(TEST_MASK_CPU_0) + 1);
-
-	CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0,
-				stringlen(TEST_MASK_CPU_0) + 1);
-
-	free(buf_out);
-	free(buf_in);
-}
-
-static void cpumask_test_odp_cpumask_equal(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-	odp_cpumask_t mask3;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2);
-	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
-
-	if (mask_capacity() < 8)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6);
-	odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-	CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3));
-}
-
-static void cpumask_test_odp_cpumask_zero(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_zero(&mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-}
-
-static void cpumask_test_odp_cpumask_set(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_set(&mask1, 0);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3);
-	odp_cpumask_set(&mask1, 3);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-
-	/* make sure that re-asserting a cpu has no impact: */
-	odp_cpumask_set(&mask1, 3);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-}
-
-static void cpumask_test_odp_cpumask_clr(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
-	odp_cpumask_clr(&mask1, 0);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_clr(&mask1, 2);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-
-	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
-	odp_cpumask_clr(&mask1, 0);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-
-	/* make sure that re-clearing a cpu has no impact: */
-	odp_cpumask_clr(&mask1, 0);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-}
-
-static void cpumask_test_odp_cpumask_isset(void)
-{
-	odp_cpumask_t mask1;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	CU_ASSERT(odp_cpumask_isset(&mask1, 0));
-	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1));
-	CU_ASSERT(odp_cpumask_isset(&mask1, 2));
-	CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3));
-}
-
-static void cpumask_test_odp_cpumask_count(void)
-{
-	odp_cpumask_t mask1;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	CU_ASSERT(odp_cpumask_count(&mask1) == 1);
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	CU_ASSERT(odp_cpumask_count(&mask1) == 0);
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	CU_ASSERT(odp_cpumask_count(&mask1) == 2);
-}
-
-static void cpumask_test_odp_cpumask_and(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-	odp_cpumask_t mask3;
-	odp_cpumask_t mask4;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
-	odp_cpumask_and(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
-	odp_cpumask_and(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
-	odp_cpumask_and(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2);
-	odp_cpumask_and(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-}
-
-static void cpumask_test_odp_cpumask_or(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-	odp_cpumask_t mask3;
-	odp_cpumask_t mask4;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
-	odp_cpumask_or(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
-	odp_cpumask_or(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
-	odp_cpumask_or(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2);
-	odp_cpumask_or(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-}
-
-static void cpumask_test_odp_cpumask_xor(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-	odp_cpumask_t mask3;
-	odp_cpumask_t mask4;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
-	odp_cpumask_xor(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0);
-	odp_cpumask_xor(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU);
-	odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU);
-	odp_cpumask_xor(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2);
-	odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2);
-	odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1);
-	odp_cpumask_xor(&mask3, &mask1, &mask2);
-	CU_ASSERT(odp_cpumask_equal(&mask3, &mask4));
-}
-
-static void cpumask_test_odp_cpumask_copy(void)
-{
-	odp_cpumask_t mask1;
-	odp_cpumask_t mask2;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	odp_cpumask_copy(&mask2, &mask1);
-	CU_ASSERT(odp_cpumask_equal(&mask1, &mask2));
-}
-
-static void cpumask_test_odp_cpumask_first(void)
-{
-	odp_cpumask_t mask1;
-
-	/* check when there is no first */
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	CU_ASSERT(odp_cpumask_first(&mask1) == -1);
-
-	/* single CPU case: */
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	CU_ASSERT(odp_cpumask_first(&mask1) == 0);
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
-	CU_ASSERT(odp_cpumask_first(&mask1) == 1);
-}
-
-static void cpumask_test_odp_cpumask_last(void)
-{
-	odp_cpumask_t mask1;
-
-	/* check when there is no last: */
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	CU_ASSERT(odp_cpumask_last(&mask1) == -1);
-
-	/* single CPU case: */
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	CU_ASSERT(odp_cpumask_last(&mask1) == 0);
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
-	CU_ASSERT(odp_cpumask_last(&mask1) == 3);
-}
-
-static void cpumask_test_odp_cpumask_next(void)
-{
-	unsigned int i;
-	int expected[] = {1, 3, 3, -1};
-	odp_cpumask_t mask1;
-
-	/* case when the mask does not contain any CPU: */
-	odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU);
-	CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1);
-
-	/* case when the mask just contain CPU 0: */
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0);
-	CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0);
-	CU_ASSERT(odp_cpumask_next(&mask1, 0)  == -1);
-
-	if (mask_capacity() < 4)
-		return;
-
-	odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3);
-
-	for (i = 0; i < sizeof(expected) / sizeof(int); i++)
-		CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]);
-}
-
-static void cpumask_test_odp_cpumask_setall(void)
-{
-	int num_cpus;
-	int max_cpus = mask_capacity();
-	odp_cpumask_t mask;
-
-	odp_cpumask_setall(&mask);
-	num_cpus = odp_cpumask_count(&mask);
-
-	CU_ASSERT(num_cpus > 0);
-	CU_ASSERT(num_cpus >= max_cpus);
-}
-
 static void cpumask_test_odp_cpumask_def_control(void)
 {
 	unsigned num;