diff mbox

[v7] cunit: add queue test

Message ID 1415711160-5060-1-git-send-email-yan.songming@linaro.org
State New
Headers show

Commit Message

yan.songming Nov. 11, 2014, 1:06 p.m. UTC
Add the cunit test for none syne queue. Test the base queue function

Signed-off-by: yan.songming <yan.songming@linaro.org>
---
Fix spelling problem and commend problem. Add term_local and term_global.
Move cunit queue test to test_odp_queue_base for none syn queue.
---
 test/cunit/Makefile.am |   8 ++-
 test/cunit/odp_queue.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+), 3 deletions(-)
 create mode 100644 test/cunit/odp_queue.c

Comments

Anders Roxell Nov. 11, 2014, 2:33 p.m. UTC | #1
On 2014-11-11 21:06, Yan Songming wrote:
> Add the cunit test for none syne queue. Test the base queue function
> 
> Signed-off-by: yan.songming <yan.songming@linaro.org>

Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>

Minor nit that maybe Maxim can fixup before applying the patch?

See inline

> ---
> Fix spelling problem and commend problem. Add term_local and term_global.
> Move cunit queue test to test_odp_queue_base for none syn queue.
> ---
>  test/cunit/Makefile.am |   8 ++-
>  test/cunit/odp_queue.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 162 insertions(+), 3 deletions(-)
>  create mode 100644 test/cunit/odp_queue.c
> 
> diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
> index 4014bed..439e134 100644
> --- a/test/cunit/Makefile.am
> +++ b/test/cunit/Makefile.am
> @@ -1,13 +1,15 @@
>  include $(top_srcdir)/test/Makefile.inc
>  
>  AM_CFLAGS += -I$(CUNIT_PATH)/include
> -AM_LDFLAGS += -L$(CUNIT_PATH)/lib
> +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
>  
>  if ODP_CUNIT_ENABLED
>  TESTS = ${bin_PROGRAMS}
>  check_PROGRAMS = ${bin_PROGRAMS}
> -bin_PROGRAMS = odp_init
> -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
> +bin_PROGRAMS = odp_init odp_queue
> +odp_init_LDFLAGS = $(AM_LDFLAGS)
> +odp_queue_LDFLAGS = $(AM_LDFLAGS)
>  endif
>  
>  dist_odp_init_SOURCES = odp_init.c
> +dist_odp_queue_SOURCES = odp_queue.c
> diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
> new file mode 100644
> index 0000000..001b544
> --- /dev/null
> +++ b/test/cunit/odp_queue.c
> @@ -0,0 +1,157 @@
> +/* Copyright (c) 2014, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include "odp.h"
> +#include "CUnit/Basic.h"
> +
> +#define MAX_BUFFER_QUEUE        (8)
> +#define MSG_POOL_SIZE           (4*1024*1024)
> +#define CONFIG_MAX_ITERATION    (100)
> +
> +static int queue_contest = 0xff;
> +
> +static int test_odp_buffer_pool_init(void)
> +{
> +	odp_buffer_pool_t pool;
> +	void *pool_base;
> +	odp_shm_t shm;
> +
> +	shm = odp_shm_reserve("msg_pool",
> +			      MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
> +
> +	pool_base = odp_shm_addr(shm);
> +
> +	if (NULL == pool_base) {
> +		printf("Shared memory reserve failed.\n");
> +		return -1;
> +	}
> +
> +	pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, 0,
> +				      ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
> +
> +	if (ODP_BUFFER_POOL_INVALID == pool) {
> +		printf("Pool create failed.\n");
> +		return -1;
> +	}
> +	return 0;
> +}
> +
> +static void test_odp_queue_sunnyday(void)
> +{
> +	odp_queue_t queue_creat_id, queue_id;
> +	odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
> +	odp_buffer_t buf;
> +	odp_buffer_pool_t msg_pool;
> +	odp_queue_param_t param;
> +	odp_buffer_t *pbuf_tmp;
> +	int i, deq_ret;
> +	int nr_deq_entries = 0;
> +	int max_iteration = CONFIG_MAX_ITERATION;
> +	void *prtn = NULL;
> +
> +	memset(&param, 0, sizeof(param));
> +	param.sched.sync  = ODP_SCHED_SYNC_NONE;
> +
> +	queue_creat_id = odp_queue_create("test_queue",
> +					  ODP_QUEUE_TYPE_POLL, &param);
> +	CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
> +
> +	CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
> +			odp_queue_type(queue_creat_id));
> +	CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
> +			odp_queue_sched_type(queue_creat_id));
> +
> +	queue_id = odp_queue_lookup("test_queue");
> +	CU_ASSERT_EQUAL(queue_creat_id, queue_id);
> +
> +	CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));
> +
> +	prtn = odp_queue_get_context(queue_id);
> +	CU_ASSERT(&queue_contest == (int *)prtn);
> +
> +	msg_pool = odp_buffer_pool_lookup("msg_pool");
> +	buf = odp_buffer_alloc(msg_pool);
> +
> +	odp_queue_enq(queue_id, buf);
> +	CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
> +	odp_buffer_free(buf);
> +
> +	for (i = 0; i < MAX_BUFFER_QUEUE; i++)
> +		enbuf[i] = odp_buffer_alloc(msg_pool);
> +
> +	/*
> +	 * odp_queue_enq_multi may return 0..n buffers due to the resource
> +	 * constraints in the implementation at that given point of time.
> +	 */
> +	odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
> +	pbuf_tmp = debuf;
> +	do {
> +		deq_ret  = odp_queue_deq_multi(queue_id, pbuf_tmp,
> +					       MAX_BUFFER_QUEUE);
> +		nr_deq_entries += deq_ret;
> +		max_iteration--;
> +		pbuf_tmp += deq_ret;
> +		CU_ASSERT(max_iteration >= 0);
> +	} while (nr_deq_entries < MAX_BUFFER_QUEUE);
> +
> +	for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
> +		CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
> +		odp_buffer_free(enbuf[i]);
> +	}
> +
> +	return;
> +}
> +
> +static int init(void)
> +{
> +	if (0 != odp_init_global(NULL, NULL)) {
> +		printf("odp_init_global fail.\n");
> +		return -1;
> +	}
> +	if (0 != odp_init_local()) {
> +		printf("odp_init_local fail.\n");
> +		return -1;
> +	}
> +	if (0 != test_odp_buffer_pool_init()) {
> +		printf("test_odp_buffer_pool_init fail.\n");
> +		return -1;
> +	}
> +	return 0;
> +}
> +
> +static int finalize(void)
> +{
> +	odp_term_local();
> +	odp_term_global();
> +	return 0;
> +}
> +
> +int main(void)
> +{
> +	CU_pSuite ptr_suite = NULL;
> +
> +	/* initialize the CUnit test registry */
> +	if (CUE_SUCCESS != CU_initialize_registry())
> +		return CU_get_error();
> +
> +	/* add the tests to the queue suite */
> +	ptr_suite = CU_add_suite("odp queue", init, finalize);

change "odp queue" to __FILE__

> +	if (NULL == ptr_suite) {
> +		CU_cleanup_registry();
> +		return CU_get_error();
> +	}
> +
> +	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
> +		CU_cleanup_registry();
> +		return CU_get_error();
> +	}
> +
> +	/* Run all tests using the CUnit Basic interface */
> +	CU_basic_set_mode(CU_BRM_VERBOSE);
> +	CU_basic_run_tests();
> +	CU_cleanup_registry();
> +	return CU_get_error();
> +}
> -- 
> 1.8.3.1
> 
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
yan.songming Nov. 11, 2014, 2:58 p.m. UTC | #2
Anders,
I think you mean that the name of suit should be the same as file name .
I just see the change you made at odp_init.c today.
I will fix it and send to Maxim 
Thanks.





yan.songming@linaro.org
 
From: Anders Roxell

Date: 2014-11-11 22:33
To: Yan Songming
CC: lng-odp
Subject: Re: [lng-odp] [PATCH v7] cunit: add queue test
On 2014-11-11 21:06, Yan Songming wrote:
> Add the cunit test for none syne queue. Test the base queue function

> 

> Signed-off-by: yan.songming <yan.songming@linaro.org>

 
Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>
 
Minor nit that maybe Maxim can fixup before applying the patch?
 
See inline
 
> ---

> Fix spelling problem and commend problem. Add term_local and term_global.

> Move cunit queue test to test_odp_queue_base for none syn queue.

> ---

>  test/cunit/Makefile.am |   8 ++-

>  test/cunit/odp_queue.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++

>  2 files changed, 162 insertions(+), 3 deletions(-)

>  create mode 100644 test/cunit/odp_queue.c

> 

> diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am

> index 4014bed..439e134 100644

> --- a/test/cunit/Makefile.am

> +++ b/test/cunit/Makefile.am

> @@ -1,13 +1,15 @@

>  include $(top_srcdir)/test/Makefile.inc

>  

>  AM_CFLAGS += -I$(CUNIT_PATH)/include

> -AM_LDFLAGS += -L$(CUNIT_PATH)/lib

> +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit

>  

>  if ODP_CUNIT_ENABLED

>  TESTS = ${bin_PROGRAMS}

>  check_PROGRAMS = ${bin_PROGRAMS}

> -bin_PROGRAMS = odp_init

> -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit

> +bin_PROGRAMS = odp_init odp_queue

> +odp_init_LDFLAGS = $(AM_LDFLAGS)

> +odp_queue_LDFLAGS = $(AM_LDFLAGS)

>  endif

>  

>  dist_odp_init_SOURCES = odp_init.c

> +dist_odp_queue_SOURCES = odp_queue.c

> diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c

> new file mode 100644

> index 0000000..001b544

> --- /dev/null

> +++ b/test/cunit/odp_queue.c

> @@ -0,0 +1,157 @@

> +/* Copyright (c) 2014, Linaro Limited

> + * All rights reserved.

> + *

> + * SPDX-License-Identifier:     BSD-3-Clause

> + */

> +

> +#include "odp.h"

> +#include "CUnit/Basic.h"

> +

> +#define MAX_BUFFER_QUEUE        (8)

> +#define MSG_POOL_SIZE           (4*1024*1024)

> +#define CONFIG_MAX_ITERATION    (100)

> +

> +static int queue_contest = 0xff;

> +

> +static int test_odp_buffer_pool_init(void)

> +{

> + odp_buffer_pool_t pool;

> + void *pool_base;

> + odp_shm_t shm;

> +

> + shm = odp_shm_reserve("msg_pool",

> +       MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);

> +

> + pool_base = odp_shm_addr(shm);

> +

> + if (NULL == pool_base) {

> + printf("Shared memory reserve failed.\n");

> + return -1;

> + }

> +

> + pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, 0,

> +       ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);

> +

> + if (ODP_BUFFER_POOL_INVALID == pool) {

> + printf("Pool create failed.\n");

> + return -1;

> + }

> + return 0;

> +}

> +

> +static void test_odp_queue_sunnyday(void)

> +{

> + odp_queue_t queue_creat_id, queue_id;

> + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];

> + odp_buffer_t buf;

> + odp_buffer_pool_t msg_pool;

> + odp_queue_param_t param;

> + odp_buffer_t *pbuf_tmp;

> + int i, deq_ret;

> + int nr_deq_entries = 0;

> + int max_iteration = CONFIG_MAX_ITERATION;

> + void *prtn = NULL;

> +

> + memset(&param, 0, sizeof(param));

> + param.sched.sync  = ODP_SCHED_SYNC_NONE;

> +

> + queue_creat_id = odp_queue_create("test_queue",

> +   ODP_QUEUE_TYPE_POLL, &param);

> + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);

> +

> + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,

> + odp_queue_type(queue_creat_id));

> + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,

> + odp_queue_sched_type(queue_creat_id));

> +

> + queue_id = odp_queue_lookup("test_queue");

> + CU_ASSERT_EQUAL(queue_creat_id, queue_id);

> +

> + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));

> +

> + prtn = odp_queue_get_context(queue_id);

> + CU_ASSERT(&queue_contest == (int *)prtn);

> +

> + msg_pool = odp_buffer_pool_lookup("msg_pool");

> + buf = odp_buffer_alloc(msg_pool);

> +

> + odp_queue_enq(queue_id, buf);

> + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));

> + odp_buffer_free(buf);

> +

> + for (i = 0; i < MAX_BUFFER_QUEUE; i++)

> + enbuf[i] = odp_buffer_alloc(msg_pool);

> +

> + /*

> + * odp_queue_enq_multi may return 0..n buffers due to the resource

> + * constraints in the implementation at that given point of time.

> + */

> + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);

> + pbuf_tmp = debuf;

> + do {

> + deq_ret  = odp_queue_deq_multi(queue_id, pbuf_tmp,

> +        MAX_BUFFER_QUEUE);

> + nr_deq_entries += deq_ret;

> + max_iteration--;

> + pbuf_tmp += deq_ret;

> + CU_ASSERT(max_iteration >= 0);

> + } while (nr_deq_entries < MAX_BUFFER_QUEUE);

> +

> + for (i = 0; i < MAX_BUFFER_QUEUE; i++) {

> + CU_ASSERT_EQUAL(enbuf[i], debuf[i]);

> + odp_buffer_free(enbuf[i]);

> + }

> +

> + return;

> +}

> +

> +static int init(void)

> +{

> + if (0 != odp_init_global(NULL, NULL)) {

> + printf("odp_init_global fail.\n");

> + return -1;

> + }

> + if (0 != odp_init_local()) {

> + printf("odp_init_local fail.\n");

> + return -1;

> + }

> + if (0 != test_odp_buffer_pool_init()) {

> + printf("test_odp_buffer_pool_init fail.\n");

> + return -1;

> + }

> + return 0;

> +}

> +

> +static int finalize(void)

> +{

> + odp_term_local();

> + odp_term_global();

> + return 0;

> +}

> +

> +int main(void)

> +{

> + CU_pSuite ptr_suite = NULL;

> +

> + /* initialize the CUnit test registry */

> + if (CUE_SUCCESS != CU_initialize_registry())

> + return CU_get_error();

> +

> + /* add the tests to the queue suite */

> + ptr_suite = CU_add_suite("odp queue", init, finalize);

 
change "odp queue" to __FILE__
 
> + if (NULL == ptr_suite) {

> + CU_cleanup_registry();

> + return CU_get_error();

> + }

> +

> + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {

> + CU_cleanup_registry();

> + return CU_get_error();

> + }

> +

> + /* Run all tests using the CUnit Basic interface */

> + CU_basic_set_mode(CU_BRM_VERBOSE);

> + CU_basic_run_tests();

> + CU_cleanup_registry();

> + return CU_get_error();

> +}

> -- 

> 1.8.3.1

> 

> 

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

> http://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov Nov. 11, 2014, 3:09 p.m. UTC | #3
I can fix that on applying.

Maxim.

On 11/11/2014 05:58 PM, yan.songming@linaro.org wrote:
> Anders,
> I think you mean that the name of suit should be the same as file name .
> I just see the change you made at odp_init.c today.
> I will fix it and send to Maxim
> Thanks.
>
>
>
> ------------------------------------------------------------------------
> yan.songming@linaro.org
>
>     *From:* Anders Roxell <mailto:anders.roxell@linaro.org>
>     *Date:* 2014-11-11 22:33
>     *To:* Yan Songming <mailto:yan.songming@linaro.org>
>     *CC:* lng-odp <mailto:lng-odp@lists.linaro.org>
>     *Subject:* Re: [lng-odp] [PATCH v7] cunit: add queue test
>     On 2014-11-11 21:06, Yan Songming wrote:
>     > Add the cunit test for none syne queue. Test the base queue function
>     >
>     > Signed-off-by: yan.songming <yan.songming@linaro.org>
>     Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>
>     Minor nit that maybe Maxim can fixup before applying the patch?
>     See inline
>     > ---
>     > Fix spelling problem and commend problem. Add term_local and
>     term_global.
>     > Move cunit queue test to test_odp_queue_base for none syn queue.
>     > ---
>     > test/cunit/Makefile.am | 8 ++-
>     > test/cunit/odp_queue.c | 157
>     +++++++++++++++++++++++++++++++++++++++++++++++++
>     > 2 files changed, 162 insertions(+), 3 deletions(-)
>     > create mode 100644 test/cunit/odp_queue.c
>     >
>     > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
>     > index 4014bed..439e134 100644
>     > --- a/test/cunit/Makefile.am
>     > +++ b/test/cunit/Makefile.am
>     > @@ -1,13 +1,15 @@
>     > include $(top_srcdir)/test/Makefile.inc
>     >
>     > AM_CFLAGS += -I$(CUNIT_PATH)/include
>     > -AM_LDFLAGS += -L$(CUNIT_PATH)/lib
>     > +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
>     >
>     > if ODP_CUNIT_ENABLED
>     > TESTS = ${bin_PROGRAMS}
>     > check_PROGRAMS = ${bin_PROGRAMS}
>     > -bin_PROGRAMS = odp_init
>     > -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
>     > +bin_PROGRAMS = odp_init odp_queue
>     > +odp_init_LDFLAGS = $(AM_LDFLAGS)
>     > +odp_queue_LDFLAGS = $(AM_LDFLAGS)
>     > endif
>     >
>     > dist_odp_init_SOURCES = odp_init.c
>     > +dist_odp_queue_SOURCES = odp_queue.c
>     > diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
>     > new file mode 100644
>     > index 0000000..001b544
>     > --- /dev/null
>     > +++ b/test/cunit/odp_queue.c
>     > @@ -0,0 +1,157 @@
>     > +/* Copyright (c) 2014, Linaro Limited
>     > + * All rights reserved.
>     > + *
>     > + * SPDX-License-Identifier: BSD-3-Clause
>     > + */
>     > +
>     > +#include "odp.h"
>     > +#include "CUnit/Basic.h"
>     > +
>     > +#define MAX_BUFFER_QUEUE (8)
>     > +#define MSG_POOL_SIZE (4*1024*1024)
>     > +#define CONFIG_MAX_ITERATION (100)
>     > +
>     > +static int queue_contest = 0xff;
>     > +
>     > +static int test_odp_buffer_pool_init(void)
>     > +{
>     > + odp_buffer_pool_t pool;
>     > + void *pool_base;
>     > + odp_shm_t shm;
>     > +
>     > + shm = odp_shm_reserve("msg_pool",
>     > + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
>     > +
>     > + pool_base = odp_shm_addr(shm);
>     > +
>     > + if (NULL == pool_base) {
>     > + printf("Shared memory reserve failed.\n");
>     > + return -1;
>     > + }
>     > +
>     > + pool = odp_buffer_pool_create("msg_pool", pool_base,
>     MSG_POOL_SIZE, 0,
>     > + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
>     > +
>     > + if (ODP_BUFFER_POOL_INVALID == pool) {
>     > + printf("Pool create failed.\n");
>     > + return -1;
>     > + }
>     > + return 0;
>     > +}
>     > +
>     > +static void test_odp_queue_sunnyday(void)
>     > +{
>     > + odp_queue_t queue_creat_id, queue_id;
>     > + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
>     > + odp_buffer_t buf;
>     > + odp_buffer_pool_t msg_pool;
>     > + odp_queue_param_t param;
>     > + odp_buffer_t *pbuf_tmp;
>     > + int i, deq_ret;
>     > + int nr_deq_entries = 0;
>     > + int max_iteration = CONFIG_MAX_ITERATION;
>     > + void *prtn = NULL;
>     > +
>     > + memset(&param, 0, sizeof(param));
>     > + param.sched.sync = ODP_SCHED_SYNC_NONE;
>     > +
>     > + queue_creat_id = odp_queue_create("test_queue",
>     > + ODP_QUEUE_TYPE_POLL, &param);
>     > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
>     > +
>     > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
>     > + odp_queue_type(queue_creat_id));
>     > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
>     > + odp_queue_sched_type(queue_creat_id));
>     > +
>     > + queue_id = odp_queue_lookup("test_queue");
>     > + CU_ASSERT_EQUAL(queue_creat_id, queue_id);
>     > +
>     > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));
>     > +
>     > + prtn = odp_queue_get_context(queue_id);
>     > + CU_ASSERT(&queue_contest == (int *)prtn);
>     > +
>     > + msg_pool = odp_buffer_pool_lookup("msg_pool");
>     > + buf = odp_buffer_alloc(msg_pool);
>     > +
>     > + odp_queue_enq(queue_id, buf);
>     > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
>     > + odp_buffer_free(buf);
>     > +
>     > + for (i = 0; i < MAX_BUFFER_QUEUE; i++)
>     > + enbuf[i] = odp_buffer_alloc(msg_pool);
>     > +
>     > + /*
>     > + * odp_queue_enq_multi may return 0..n buffers due to the resource
>     > + * constraints in the implementation at that given point of time.
>     > + */
>     > + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
>     > + pbuf_tmp = debuf;
>     > + do {
>     > + deq_ret = odp_queue_deq_multi(queue_id, pbuf_tmp,
>     > + MAX_BUFFER_QUEUE);
>     > + nr_deq_entries += deq_ret;
>     > + max_iteration--;
>     > + pbuf_tmp += deq_ret;
>     > + CU_ASSERT(max_iteration >= 0);
>     > + } while (nr_deq_entries < MAX_BUFFER_QUEUE);
>     > +
>     > + for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
>     > + CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
>     > + odp_buffer_free(enbuf[i]);
>     > + }
>     > +
>     > + return;
>     > +}
>     > +
>     > +static int init(void)
>     > +{
>     > + if (0 != odp_init_global(NULL, NULL)) {
>     > + printf("odp_init_global fail.\n");
>     > + return -1;
>     > + }
>     > + if (0 != odp_init_local()) {
>     > + printf("odp_init_local fail.\n");
>     > + return -1;
>     > + }
>     > + if (0 != test_odp_buffer_pool_init()) {
>     > + printf("test_odp_buffer_pool_init fail.\n");
>     > + return -1;
>     > + }
>     > + return 0;
>     > +}
>     > +
>     > +static int finalize(void)
>     > +{
>     > + odp_term_local();
>     > + odp_term_global();
>     > + return 0;
>     > +}
>     > +
>     > +int main(void)
>     > +{
>     > + CU_pSuite ptr_suite = NULL;
>     > +
>     > + /* initialize the CUnit test registry */
>     > + if (CUE_SUCCESS != CU_initialize_registry())
>     > + return CU_get_error();
>     > +
>     > + /* add the tests to the queue suite */
>     > + ptr_suite = CU_add_suite("odp queue", init, finalize);
>     change "odp queue" to __FILE__
>     > + if (NULL == ptr_suite) {
>     > + CU_cleanup_registry();
>     > + return CU_get_error();
>     > + }
>     > +
>     > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
>     > + CU_cleanup_registry();
>     > + return CU_get_error();
>     > + }
>     > +
>     > + /* Run all tests using the CUnit Basic interface */
>     > + CU_basic_set_mode(CU_BRM_VERBOSE);
>     > + CU_basic_run_tests();
>     > + CU_cleanup_registry();
>     > + return CU_get_error();
>     > +}
>     > --
>     > 1.8.3.1
>     >
>     >
>     > _______________________________________________
>     > lng-odp mailing list
>     > lng-odp@lists.linaro.org
>     > http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Anders Roxell Nov. 11, 2014, 3:10 p.m. UTC | #4
On 11 November 2014 16:09, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> I can fix that on applying.

Thanks Maxim.

Yan, then you don't need to resend the patch!

Cheers,
Anders

>
> Maxim.
>
> On 11/11/2014 05:58 PM, yan.songming@linaro.org wrote:
>>
>> Anders,
>> I think you mean that the name of suit should be the same as file name .
>> I just see the change you made at odp_init.c today.
>> I will fix it and send to Maxim
>> Thanks.
>>
>>
>>
>> ------------------------------------------------------------------------
>> yan.songming@linaro.org
>>
>>     *From:* Anders Roxell <mailto:anders.roxell@linaro.org>
>>     *Date:* 2014-11-11 22:33
>>     *To:* Yan Songming <mailto:yan.songming@linaro.org>
>>     *CC:* lng-odp <mailto:lng-odp@lists.linaro.org>
>>     *Subject:* Re: [lng-odp] [PATCH v7] cunit: add queue test
>>
>>     On 2014-11-11 21:06, Yan Songming wrote:
>>     > Add the cunit test for none syne queue. Test the base queue function
>>     >
>>     > Signed-off-by: yan.songming <yan.songming@linaro.org>
>>     Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>
>>     Minor nit that maybe Maxim can fixup before applying the patch?
>>     See inline
>>     > ---
>>     > Fix spelling problem and commend problem. Add term_local and
>>     term_global.
>>     > Move cunit queue test to test_odp_queue_base for none syn queue.
>>     > ---
>>     > test/cunit/Makefile.am | 8 ++-
>>     > test/cunit/odp_queue.c | 157
>>     +++++++++++++++++++++++++++++++++++++++++++++++++
>>     > 2 files changed, 162 insertions(+), 3 deletions(-)
>>     > create mode 100644 test/cunit/odp_queue.c
>>     >
>>     > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
>>     > index 4014bed..439e134 100644
>>     > --- a/test/cunit/Makefile.am
>>     > +++ b/test/cunit/Makefile.am
>>     > @@ -1,13 +1,15 @@
>>     > include $(top_srcdir)/test/Makefile.inc
>>     >
>>     > AM_CFLAGS += -I$(CUNIT_PATH)/include
>>     > -AM_LDFLAGS += -L$(CUNIT_PATH)/lib
>>     > +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
>>     >
>>     > if ODP_CUNIT_ENABLED
>>     > TESTS = ${bin_PROGRAMS}
>>     > check_PROGRAMS = ${bin_PROGRAMS}
>>     > -bin_PROGRAMS = odp_init
>>     > -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
>>     > +bin_PROGRAMS = odp_init odp_queue
>>     > +odp_init_LDFLAGS = $(AM_LDFLAGS)
>>     > +odp_queue_LDFLAGS = $(AM_LDFLAGS)
>>     > endif
>>     >
>>     > dist_odp_init_SOURCES = odp_init.c
>>     > +dist_odp_queue_SOURCES = odp_queue.c
>>     > diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
>>     > new file mode 100644
>>     > index 0000000..001b544
>>     > --- /dev/null
>>     > +++ b/test/cunit/odp_queue.c
>>     > @@ -0,0 +1,157 @@
>>     > +/* Copyright (c) 2014, Linaro Limited
>>     > + * All rights reserved.
>>     > + *
>>     > + * SPDX-License-Identifier: BSD-3-Clause
>>     > + */
>>     > +
>>     > +#include "odp.h"
>>     > +#include "CUnit/Basic.h"
>>     > +
>>     > +#define MAX_BUFFER_QUEUE (8)
>>     > +#define MSG_POOL_SIZE (4*1024*1024)
>>     > +#define CONFIG_MAX_ITERATION (100)
>>     > +
>>     > +static int queue_contest = 0xff;
>>     > +
>>     > +static int test_odp_buffer_pool_init(void)
>>     > +{
>>     > + odp_buffer_pool_t pool;
>>     > + void *pool_base;
>>     > + odp_shm_t shm;
>>     > +
>>     > + shm = odp_shm_reserve("msg_pool",
>>     > + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
>>     > +
>>     > + pool_base = odp_shm_addr(shm);
>>     > +
>>     > + if (NULL == pool_base) {
>>     > + printf("Shared memory reserve failed.\n");
>>     > + return -1;
>>     > + }
>>     > +
>>     > + pool = odp_buffer_pool_create("msg_pool", pool_base,
>>     MSG_POOL_SIZE, 0,
>>     > + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
>>     > +
>>     > + if (ODP_BUFFER_POOL_INVALID == pool) {
>>     > + printf("Pool create failed.\n");
>>     > + return -1;
>>     > + }
>>     > + return 0;
>>     > +}
>>     > +
>>     > +static void test_odp_queue_sunnyday(void)
>>     > +{
>>     > + odp_queue_t queue_creat_id, queue_id;
>>     > + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
>>     > + odp_buffer_t buf;
>>     > + odp_buffer_pool_t msg_pool;
>>     > + odp_queue_param_t param;
>>     > + odp_buffer_t *pbuf_tmp;
>>     > + int i, deq_ret;
>>     > + int nr_deq_entries = 0;
>>     > + int max_iteration = CONFIG_MAX_ITERATION;
>>     > + void *prtn = NULL;
>>     > +
>>     > + memset(&param, 0, sizeof(param));
>>     > + param.sched.sync = ODP_SCHED_SYNC_NONE;
>>     > +
>>     > + queue_creat_id = odp_queue_create("test_queue",
>>     > + ODP_QUEUE_TYPE_POLL, &param);
>>     > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
>>     > +
>>     > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
>>     > + odp_queue_type(queue_creat_id));
>>     > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
>>     > + odp_queue_sched_type(queue_creat_id));
>>     > +
>>     > + queue_id = odp_queue_lookup("test_queue");
>>     > + CU_ASSERT_EQUAL(queue_creat_id, queue_id);
>>     > +
>>     > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));
>>     > +
>>     > + prtn = odp_queue_get_context(queue_id);
>>     > + CU_ASSERT(&queue_contest == (int *)prtn);
>>     > +
>>     > + msg_pool = odp_buffer_pool_lookup("msg_pool");
>>     > + buf = odp_buffer_alloc(msg_pool);
>>     > +
>>     > + odp_queue_enq(queue_id, buf);
>>     > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
>>     > + odp_buffer_free(buf);
>>     > +
>>     > + for (i = 0; i < MAX_BUFFER_QUEUE; i++)
>>     > + enbuf[i] = odp_buffer_alloc(msg_pool);
>>     > +
>>     > + /*
>>     > + * odp_queue_enq_multi may return 0..n buffers due to the resource
>>     > + * constraints in the implementation at that given point of time.
>>     > + */
>>     > + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
>>     > + pbuf_tmp = debuf;
>>     > + do {
>>     > + deq_ret = odp_queue_deq_multi(queue_id, pbuf_tmp,
>>     > + MAX_BUFFER_QUEUE);
>>     > + nr_deq_entries += deq_ret;
>>     > + max_iteration--;
>>     > + pbuf_tmp += deq_ret;
>>     > + CU_ASSERT(max_iteration >= 0);
>>     > + } while (nr_deq_entries < MAX_BUFFER_QUEUE);
>>     > +
>>     > + for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
>>     > + CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
>>     > + odp_buffer_free(enbuf[i]);
>>     > + }
>>     > +
>>     > + return;
>>     > +}
>>     > +
>>     > +static int init(void)
>>     > +{
>>     > + if (0 != odp_init_global(NULL, NULL)) {
>>     > + printf("odp_init_global fail.\n");
>>     > + return -1;
>>     > + }
>>     > + if (0 != odp_init_local()) {
>>     > + printf("odp_init_local fail.\n");
>>     > + return -1;
>>     > + }
>>     > + if (0 != test_odp_buffer_pool_init()) {
>>     > + printf("test_odp_buffer_pool_init fail.\n");
>>     > + return -1;
>>     > + }
>>     > + return 0;
>>     > +}
>>     > +
>>     > +static int finalize(void)
>>     > +{
>>     > + odp_term_local();
>>     > + odp_term_global();
>>     > + return 0;
>>     > +}
>>     > +
>>     > +int main(void)
>>     > +{
>>     > + CU_pSuite ptr_suite = NULL;
>>     > +
>>     > + /* initialize the CUnit test registry */
>>     > + if (CUE_SUCCESS != CU_initialize_registry())
>>     > + return CU_get_error();
>>     > +
>>     > + /* add the tests to the queue suite */
>>     > + ptr_suite = CU_add_suite("odp queue", init, finalize);
>>     change "odp queue" to __FILE__
>>     > + if (NULL == ptr_suite) {
>>     > + CU_cleanup_registry();
>>     > + return CU_get_error();
>>     > + }
>>     > +
>>     > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
>>     > + CU_cleanup_registry();
>>     > + return CU_get_error();
>>     > + }
>>     > +
>>     > + /* Run all tests using the CUnit Basic interface */
>>     > + CU_basic_set_mode(CU_BRM_VERBOSE);
>>     > + CU_basic_run_tests();
>>     > + CU_cleanup_registry();
>>     > + return CU_get_error();
>>     > +}
>>     > --
>>     > 1.8.3.1
>>     >
>>     >
>>     > _______________________________________________
>>     > lng-odp mailing list
>>     > lng-odp@lists.linaro.org
>>     > http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov Nov. 11, 2014, 3:16 p.m. UTC | #5
Merged, please check!

Maxim.

On 11/11/2014 06:10 PM, Anders Roxell wrote:
> On 11 November 2014 16:09, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>> I can fix that on applying.
> Thanks Maxim.
>
> Yan, then you don't need to resend the patch!
>
> Cheers,
> Anders
>
>> Maxim.
>>
>> On 11/11/2014 05:58 PM, yan.songming@linaro.org wrote:
>>> Anders,
>>> I think you mean that the name of suit should be the same as file name .
>>> I just see the change you made at odp_init.c today.
>>> I will fix it and send to Maxim
>>> Thanks.
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>> yan.songming@linaro.org
>>>
>>>      *From:* Anders Roxell <mailto:anders.roxell@linaro.org>
>>>      *Date:* 2014-11-11 22:33
>>>      *To:* Yan Songming <mailto:yan.songming@linaro.org>
>>>      *CC:* lng-odp <mailto:lng-odp@lists.linaro.org>
>>>      *Subject:* Re: [lng-odp] [PATCH v7] cunit: add queue test
>>>
>>>      On 2014-11-11 21:06, Yan Songming wrote:
>>>      > Add the cunit test for none syne queue. Test the base queue function
>>>      >
>>>      > Signed-off-by: yan.songming <yan.songming@linaro.org>
>>>      Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>
>>>      Minor nit that maybe Maxim can fixup before applying the patch?
>>>      See inline
>>>      > ---
>>>      > Fix spelling problem and commend problem. Add term_local and
>>>      term_global.
>>>      > Move cunit queue test to test_odp_queue_base for none syn queue.
>>>      > ---
>>>      > test/cunit/Makefile.am | 8 ++-
>>>      > test/cunit/odp_queue.c | 157
>>>      +++++++++++++++++++++++++++++++++++++++++++++++++
>>>      > 2 files changed, 162 insertions(+), 3 deletions(-)
>>>      > create mode 100644 test/cunit/odp_queue.c
>>>      >
>>>      > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
>>>      > index 4014bed..439e134 100644
>>>      > --- a/test/cunit/Makefile.am
>>>      > +++ b/test/cunit/Makefile.am
>>>      > @@ -1,13 +1,15 @@
>>>      > include $(top_srcdir)/test/Makefile.inc
>>>      >
>>>      > AM_CFLAGS += -I$(CUNIT_PATH)/include
>>>      > -AM_LDFLAGS += -L$(CUNIT_PATH)/lib
>>>      > +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
>>>      >
>>>      > if ODP_CUNIT_ENABLED
>>>      > TESTS = ${bin_PROGRAMS}
>>>      > check_PROGRAMS = ${bin_PROGRAMS}
>>>      > -bin_PROGRAMS = odp_init
>>>      > -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
>>>      > +bin_PROGRAMS = odp_init odp_queue
>>>      > +odp_init_LDFLAGS = $(AM_LDFLAGS)
>>>      > +odp_queue_LDFLAGS = $(AM_LDFLAGS)
>>>      > endif
>>>      >
>>>      > dist_odp_init_SOURCES = odp_init.c
>>>      > +dist_odp_queue_SOURCES = odp_queue.c
>>>      > diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
>>>      > new file mode 100644
>>>      > index 0000000..001b544
>>>      > --- /dev/null
>>>      > +++ b/test/cunit/odp_queue.c
>>>      > @@ -0,0 +1,157 @@
>>>      > +/* Copyright (c) 2014, Linaro Limited
>>>      > + * All rights reserved.
>>>      > + *
>>>      > + * SPDX-License-Identifier: BSD-3-Clause
>>>      > + */
>>>      > +
>>>      > +#include "odp.h"
>>>      > +#include "CUnit/Basic.h"
>>>      > +
>>>      > +#define MAX_BUFFER_QUEUE (8)
>>>      > +#define MSG_POOL_SIZE (4*1024*1024)
>>>      > +#define CONFIG_MAX_ITERATION (100)
>>>      > +
>>>      > +static int queue_contest = 0xff;
>>>      > +
>>>      > +static int test_odp_buffer_pool_init(void)
>>>      > +{
>>>      > + odp_buffer_pool_t pool;
>>>      > + void *pool_base;
>>>      > + odp_shm_t shm;
>>>      > +
>>>      > + shm = odp_shm_reserve("msg_pool",
>>>      > + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
>>>      > +
>>>      > + pool_base = odp_shm_addr(shm);
>>>      > +
>>>      > + if (NULL == pool_base) {
>>>      > + printf("Shared memory reserve failed.\n");
>>>      > + return -1;
>>>      > + }
>>>      > +
>>>      > + pool = odp_buffer_pool_create("msg_pool", pool_base,
>>>      MSG_POOL_SIZE, 0,
>>>      > + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
>>>      > +
>>>      > + if (ODP_BUFFER_POOL_INVALID == pool) {
>>>      > + printf("Pool create failed.\n");
>>>      > + return -1;
>>>      > + }
>>>      > + return 0;
>>>      > +}
>>>      > +
>>>      > +static void test_odp_queue_sunnyday(void)
>>>      > +{
>>>      > + odp_queue_t queue_creat_id, queue_id;
>>>      > + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
>>>      > + odp_buffer_t buf;
>>>      > + odp_buffer_pool_t msg_pool;
>>>      > + odp_queue_param_t param;
>>>      > + odp_buffer_t *pbuf_tmp;
>>>      > + int i, deq_ret;
>>>      > + int nr_deq_entries = 0;
>>>      > + int max_iteration = CONFIG_MAX_ITERATION;
>>>      > + void *prtn = NULL;
>>>      > +
>>>      > + memset(&param, 0, sizeof(param));
>>>      > + param.sched.sync = ODP_SCHED_SYNC_NONE;
>>>      > +
>>>      > + queue_creat_id = odp_queue_create("test_queue",
>>>      > + ODP_QUEUE_TYPE_POLL, &param);
>>>      > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
>>>      > +
>>>      > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
>>>      > + odp_queue_type(queue_creat_id));
>>>      > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
>>>      > + odp_queue_sched_type(queue_creat_id));
>>>      > +
>>>      > + queue_id = odp_queue_lookup("test_queue");
>>>      > + CU_ASSERT_EQUAL(queue_creat_id, queue_id);
>>>      > +
>>>      > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));
>>>      > +
>>>      > + prtn = odp_queue_get_context(queue_id);
>>>      > + CU_ASSERT(&queue_contest == (int *)prtn);
>>>      > +
>>>      > + msg_pool = odp_buffer_pool_lookup("msg_pool");
>>>      > + buf = odp_buffer_alloc(msg_pool);
>>>      > +
>>>      > + odp_queue_enq(queue_id, buf);
>>>      > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
>>>      > + odp_buffer_free(buf);
>>>      > +
>>>      > + for (i = 0; i < MAX_BUFFER_QUEUE; i++)
>>>      > + enbuf[i] = odp_buffer_alloc(msg_pool);
>>>      > +
>>>      > + /*
>>>      > + * odp_queue_enq_multi may return 0..n buffers due to the resource
>>>      > + * constraints in the implementation at that given point of time.
>>>      > + */
>>>      > + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
>>>      > + pbuf_tmp = debuf;
>>>      > + do {
>>>      > + deq_ret = odp_queue_deq_multi(queue_id, pbuf_tmp,
>>>      > + MAX_BUFFER_QUEUE);
>>>      > + nr_deq_entries += deq_ret;
>>>      > + max_iteration--;
>>>      > + pbuf_tmp += deq_ret;
>>>      > + CU_ASSERT(max_iteration >= 0);
>>>      > + } while (nr_deq_entries < MAX_BUFFER_QUEUE);
>>>      > +
>>>      > + for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
>>>      > + CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
>>>      > + odp_buffer_free(enbuf[i]);
>>>      > + }
>>>      > +
>>>      > + return;
>>>      > +}
>>>      > +
>>>      > +static int init(void)
>>>      > +{
>>>      > + if (0 != odp_init_global(NULL, NULL)) {
>>>      > + printf("odp_init_global fail.\n");
>>>      > + return -1;
>>>      > + }
>>>      > + if (0 != odp_init_local()) {
>>>      > + printf("odp_init_local fail.\n");
>>>      > + return -1;
>>>      > + }
>>>      > + if (0 != test_odp_buffer_pool_init()) {
>>>      > + printf("test_odp_buffer_pool_init fail.\n");
>>>      > + return -1;
>>>      > + }
>>>      > + return 0;
>>>      > +}
>>>      > +
>>>      > +static int finalize(void)
>>>      > +{
>>>      > + odp_term_local();
>>>      > + odp_term_global();
>>>      > + return 0;
>>>      > +}
>>>      > +
>>>      > +int main(void)
>>>      > +{
>>>      > + CU_pSuite ptr_suite = NULL;
>>>      > +
>>>      > + /* initialize the CUnit test registry */
>>>      > + if (CUE_SUCCESS != CU_initialize_registry())
>>>      > + return CU_get_error();
>>>      > +
>>>      > + /* add the tests to the queue suite */
>>>      > + ptr_suite = CU_add_suite("odp queue", init, finalize);
>>>      change "odp queue" to __FILE__
>>>      > + if (NULL == ptr_suite) {
>>>      > + CU_cleanup_registry();
>>>      > + return CU_get_error();
>>>      > + }
>>>      > +
>>>      > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
>>>      > + CU_cleanup_registry();
>>>      > + return CU_get_error();
>>>      > + }
>>>      > +
>>>      > + /* Run all tests using the CUnit Basic interface */
>>>      > + CU_basic_set_mode(CU_BRM_VERBOSE);
>>>      > + CU_basic_run_tests();
>>>      > + CU_cleanup_registry();
>>>      > + return CU_get_error();
>>>      > +}
>>>      > --
>>>      > 1.8.3.1
>>>      >
>>>      >
>>>      > _______________________________________________
>>>      > lng-odp mailing list
>>>      > lng-odp@lists.linaro.org
>>>      > http://lists.linaro.org/mailman/listinfo/lng-odp
>>>
>>>
>>>
>>> _______________________________________________
>>> lng-odp mailing list
>>> lng-odp@lists.linaro.org
>>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
Mike Holmes Nov. 11, 2014, 3:33 p.m. UTC | #6
http://docs.opendataplane.org/linux-generic-gcov-html/linux-generic/index.html

It works, but there are still holes in the linux-generic implementation of
the API

ODP_QUEUE_TYPE_PKTIN: needs testing in this unit test possibly, but it may
fall with APIs that are going to be tested by other code we believe.

   - odp_buffer_t queue_sched_buf(odp_queue_t handle) - > in scheduler
   - int queue_sched_atomic(odp_queue_t handle)  - > in scheduler



On 11 November 2014 10:16, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> Merged, please check!
>
> Maxim.
>
>
> On 11/11/2014 06:10 PM, Anders Roxell wrote:
>
>> On 11 November 2014 16:09, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>>
>>> I can fix that on applying.
>>>
>> Thanks Maxim.
>>
>> Yan, then you don't need to resend the patch!
>>
>> Cheers,
>> Anders
>>
>>  Maxim.
>>>
>>> On 11/11/2014 05:58 PM, yan.songming@linaro.org wrote:
>>>
>>>> Anders,
>>>> I think you mean that the name of suit should be the same as file name .
>>>> I just see the change you made at odp_init.c today.
>>>> I will fix it and send to Maxim
>>>> Thanks.
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------
>>>> yan.songming@linaro.org
>>>>
>>>>      *From:* Anders Roxell <mailto:anders.roxell@linaro.org>
>>>>      *Date:* 2014-11-11 22:33
>>>>      *To:* Yan Songming <mailto:yan.songming@linaro.org>
>>>>      *CC:* lng-odp <mailto:lng-odp@lists.linaro.org>
>>>>      *Subject:* Re: [lng-odp] [PATCH v7] cunit: add queue test
>>>>
>>>>      On 2014-11-11 21:06, Yan Songming wrote:
>>>>      > Add the cunit test for none syne queue. Test the base queue
>>>> function
>>>>      >
>>>>      > Signed-off-by: yan.songming <yan.songming@linaro.org>
>>>>      Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org>
>>>>      Minor nit that maybe Maxim can fixup before applying the patch?
>>>>      See inline
>>>>      > ---
>>>>      > Fix spelling problem and commend problem. Add term_local and
>>>>      term_global.
>>>>      > Move cunit queue test to test_odp_queue_base for none syn queue.
>>>>      > ---
>>>>      > test/cunit/Makefile.am | 8 ++-
>>>>      > test/cunit/odp_queue.c | 157
>>>>      +++++++++++++++++++++++++++++++++++++++++++++++++
>>>>      > 2 files changed, 162 insertions(+), 3 deletions(-)
>>>>      > create mode 100644 test/cunit/odp_queue.c
>>>>      >
>>>>      > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
>>>>      > index 4014bed..439e134 100644
>>>>      > --- a/test/cunit/Makefile.am
>>>>      > +++ b/test/cunit/Makefile.am
>>>>      > @@ -1,13 +1,15 @@
>>>>      > include $(top_srcdir)/test/Makefile.inc
>>>>      >
>>>>      > AM_CFLAGS += -I$(CUNIT_PATH)/include
>>>>      > -AM_LDFLAGS += -L$(CUNIT_PATH)/lib
>>>>      > +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
>>>>      >
>>>>      > if ODP_CUNIT_ENABLED
>>>>      > TESTS = ${bin_PROGRAMS}
>>>>      > check_PROGRAMS = ${bin_PROGRAMS}
>>>>      > -bin_PROGRAMS = odp_init
>>>>      > -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
>>>>      > +bin_PROGRAMS = odp_init odp_queue
>>>>      > +odp_init_LDFLAGS = $(AM_LDFLAGS)
>>>>      > +odp_queue_LDFLAGS = $(AM_LDFLAGS)
>>>>      > endif
>>>>      >
>>>>      > dist_odp_init_SOURCES = odp_init.c
>>>>      > +dist_odp_queue_SOURCES = odp_queue.c
>>>>      > diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
>>>>      > new file mode 100644
>>>>      > index 0000000..001b544
>>>>      > --- /dev/null
>>>>      > +++ b/test/cunit/odp_queue.c
>>>>      > @@ -0,0 +1,157 @@
>>>>      > +/* Copyright (c) 2014, Linaro Limited
>>>>      > + * All rights reserved.
>>>>      > + *
>>>>      > + * SPDX-License-Identifier: BSD-3-Clause
>>>>      > + */
>>>>      > +
>>>>      > +#include "odp.h"
>>>>      > +#include "CUnit/Basic.h"
>>>>      > +
>>>>      > +#define MAX_BUFFER_QUEUE (8)
>>>>      > +#define MSG_POOL_SIZE (4*1024*1024)
>>>>      > +#define CONFIG_MAX_ITERATION (100)
>>>>      > +
>>>>      > +static int queue_contest = 0xff;
>>>>      > +
>>>>      > +static int test_odp_buffer_pool_init(void)
>>>>      > +{
>>>>      > + odp_buffer_pool_t pool;
>>>>      > + void *pool_base;
>>>>      > + odp_shm_t shm;
>>>>      > +
>>>>      > + shm = odp_shm_reserve("msg_pool",
>>>>      > + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
>>>>      > +
>>>>      > + pool_base = odp_shm_addr(shm);
>>>>      > +
>>>>      > + if (NULL == pool_base) {
>>>>      > + printf("Shared memory reserve failed.\n");
>>>>      > + return -1;
>>>>      > + }
>>>>      > +
>>>>      > + pool = odp_buffer_pool_create("msg_pool", pool_base,
>>>>      MSG_POOL_SIZE, 0,
>>>>      > + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
>>>>      > +
>>>>      > + if (ODP_BUFFER_POOL_INVALID == pool) {
>>>>      > + printf("Pool create failed.\n");
>>>>      > + return -1;
>>>>      > + }
>>>>      > + return 0;
>>>>      > +}
>>>>      > +
>>>>      > +static void test_odp_queue_sunnyday(void)
>>>>      > +{
>>>>      > + odp_queue_t queue_creat_id, queue_id;
>>>>      > + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
>>>>      > + odp_buffer_t buf;
>>>>      > + odp_buffer_pool_t msg_pool;
>>>>      > + odp_queue_param_t param;
>>>>      > + odp_buffer_t *pbuf_tmp;
>>>>      > + int i, deq_ret;
>>>>      > + int nr_deq_entries = 0;
>>>>      > + int max_iteration = CONFIG_MAX_ITERATION;
>>>>      > + void *prtn = NULL;
>>>>      > +
>>>>      > + memset(&param, 0, sizeof(param));
>>>>      > + param.sched.sync = ODP_SCHED_SYNC_NONE;
>>>>      > +
>>>>      > + queue_creat_id = odp_queue_create("test_queue",
>>>>      > + ODP_QUEUE_TYPE_POLL, &param);
>>>>      > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
>>>>      > +
>>>>      > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
>>>>      > + odp_queue_type(queue_creat_id));
>>>>      > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
>>>>      > + odp_queue_sched_type(queue_creat_id));
>>>>      > +
>>>>      > + queue_id = odp_queue_lookup("test_queue");
>>>>      > + CU_ASSERT_EQUAL(queue_creat_id, queue_id);
>>>>      > +
>>>>      > + CU_ASSERT(0 == odp_queue_set_context(queue_id,
>>>> &queue_contest));
>>>>      > +
>>>>      > + prtn = odp_queue_get_context(queue_id);
>>>>      > + CU_ASSERT(&queue_contest == (int *)prtn);
>>>>      > +
>>>>      > + msg_pool = odp_buffer_pool_lookup("msg_pool");
>>>>      > + buf = odp_buffer_alloc(msg_pool);
>>>>      > +
>>>>      > + odp_queue_enq(queue_id, buf);
>>>>      > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
>>>>      > + odp_buffer_free(buf);
>>>>      > +
>>>>      > + for (i = 0; i < MAX_BUFFER_QUEUE; i++)
>>>>      > + enbuf[i] = odp_buffer_alloc(msg_pool);
>>>>      > +
>>>>      > + /*
>>>>      > + * odp_queue_enq_multi may return 0..n buffers due to the
>>>> resource
>>>>      > + * constraints in the implementation at that given point of
>>>> time.
>>>>      > + */
>>>>      > + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
>>>>      > + pbuf_tmp = debuf;
>>>>      > + do {
>>>>      > + deq_ret = odp_queue_deq_multi(queue_id, pbuf_tmp,
>>>>      > + MAX_BUFFER_QUEUE);
>>>>      > + nr_deq_entries += deq_ret;
>>>>      > + max_iteration--;
>>>>      > + pbuf_tmp += deq_ret;
>>>>      > + CU_ASSERT(max_iteration >= 0);
>>>>      > + } while (nr_deq_entries < MAX_BUFFER_QUEUE);
>>>>      > +
>>>>      > + for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
>>>>      > + CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
>>>>      > + odp_buffer_free(enbuf[i]);
>>>>      > + }
>>>>      > +
>>>>      > + return;
>>>>      > +}
>>>>      > +
>>>>      > +static int init(void)
>>>>      > +{
>>>>      > + if (0 != odp_init_global(NULL, NULL)) {
>>>>      > + printf("odp_init_global fail.\n");
>>>>      > + return -1;
>>>>      > + }
>>>>      > + if (0 != odp_init_local()) {
>>>>      > + printf("odp_init_local fail.\n");
>>>>      > + return -1;
>>>>      > + }
>>>>      > + if (0 != test_odp_buffer_pool_init()) {
>>>>      > + printf("test_odp_buffer_pool_init fail.\n");
>>>>      > + return -1;
>>>>      > + }
>>>>      > + return 0;
>>>>      > +}
>>>>      > +
>>>>      > +static int finalize(void)
>>>>      > +{
>>>>      > + odp_term_local();
>>>>      > + odp_term_global();
>>>>      > + return 0;
>>>>      > +}
>>>>      > +
>>>>      > +int main(void)
>>>>      > +{
>>>>      > + CU_pSuite ptr_suite = NULL;
>>>>      > +
>>>>      > + /* initialize the CUnit test registry */
>>>>      > + if (CUE_SUCCESS != CU_initialize_registry())
>>>>      > + return CU_get_error();
>>>>      > +
>>>>      > + /* add the tests to the queue suite */
>>>>      > + ptr_suite = CU_add_suite("odp queue", init, finalize);
>>>>      change "odp queue" to __FILE__
>>>>      > + if (NULL == ptr_suite) {
>>>>      > + CU_cleanup_registry();
>>>>      > + return CU_get_error();
>>>>      > + }
>>>>      > +
>>>>      > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
>>>>      > + CU_cleanup_registry();
>>>>      > + return CU_get_error();
>>>>      > + }
>>>>      > +
>>>>      > + /* Run all tests using the CUnit Basic interface */
>>>>      > + CU_basic_set_mode(CU_BRM_VERBOSE);
>>>>      > + CU_basic_run_tests();
>>>>      > + CU_cleanup_registry();
>>>>      > + return CU_get_error();
>>>>      > +}
>>>>      > --
>>>>      > 1.8.3.1
>>>>      >
>>>>      >
>>>>      > _______________________________________________
>>>>      > lng-odp mailing list
>>>>      > lng-odp@lists.linaro.org
>>>>      > http://lists.linaro.org/mailman/listinfo/lng-odp
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> lng-odp mailing list
>>>> lng-odp@lists.linaro.org
>>>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>>>
>>>
>>>
>>> _______________________________________________
>>> lng-odp mailing list
>>> lng-odp@lists.linaro.org
>>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>>
>>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
index 4014bed..439e134 100644
--- a/test/cunit/Makefile.am
+++ b/test/cunit/Makefile.am
@@ -1,13 +1,15 @@ 
 include $(top_srcdir)/test/Makefile.inc
 
 AM_CFLAGS += -I$(CUNIT_PATH)/include
-AM_LDFLAGS += -L$(CUNIT_PATH)/lib
+AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
 
 if ODP_CUNIT_ENABLED
 TESTS = ${bin_PROGRAMS}
 check_PROGRAMS = ${bin_PROGRAMS}
-bin_PROGRAMS = odp_init
-odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit
+bin_PROGRAMS = odp_init odp_queue
+odp_init_LDFLAGS = $(AM_LDFLAGS)
+odp_queue_LDFLAGS = $(AM_LDFLAGS)
 endif
 
 dist_odp_init_SOURCES = odp_init.c
+dist_odp_queue_SOURCES = odp_queue.c
diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
new file mode 100644
index 0000000..001b544
--- /dev/null
+++ b/test/cunit/odp_queue.c
@@ -0,0 +1,157 @@ 
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include "odp.h"
+#include "CUnit/Basic.h"
+
+#define MAX_BUFFER_QUEUE        (8)
+#define MSG_POOL_SIZE           (4*1024*1024)
+#define CONFIG_MAX_ITERATION    (100)
+
+static int queue_contest = 0xff;
+
+static int test_odp_buffer_pool_init(void)
+{
+	odp_buffer_pool_t pool;
+	void *pool_base;
+	odp_shm_t shm;
+
+	shm = odp_shm_reserve("msg_pool",
+			      MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0);
+
+	pool_base = odp_shm_addr(shm);
+
+	if (NULL == pool_base) {
+		printf("Shared memory reserve failed.\n");
+		return -1;
+	}
+
+	pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, 0,
+				      ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW);
+
+	if (ODP_BUFFER_POOL_INVALID == pool) {
+		printf("Pool create failed.\n");
+		return -1;
+	}
+	return 0;
+}
+
+static void test_odp_queue_sunnyday(void)
+{
+	odp_queue_t queue_creat_id, queue_id;
+	odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE];
+	odp_buffer_t buf;
+	odp_buffer_pool_t msg_pool;
+	odp_queue_param_t param;
+	odp_buffer_t *pbuf_tmp;
+	int i, deq_ret;
+	int nr_deq_entries = 0;
+	int max_iteration = CONFIG_MAX_ITERATION;
+	void *prtn = NULL;
+
+	memset(&param, 0, sizeof(param));
+	param.sched.sync  = ODP_SCHED_SYNC_NONE;
+
+	queue_creat_id = odp_queue_create("test_queue",
+					  ODP_QUEUE_TYPE_POLL, &param);
+	CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id);
+
+	CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL,
+			odp_queue_type(queue_creat_id));
+	CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE,
+			odp_queue_sched_type(queue_creat_id));
+
+	queue_id = odp_queue_lookup("test_queue");
+	CU_ASSERT_EQUAL(queue_creat_id, queue_id);
+
+	CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest));
+
+	prtn = odp_queue_get_context(queue_id);
+	CU_ASSERT(&queue_contest == (int *)prtn);
+
+	msg_pool = odp_buffer_pool_lookup("msg_pool");
+	buf = odp_buffer_alloc(msg_pool);
+
+	odp_queue_enq(queue_id, buf);
+	CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id));
+	odp_buffer_free(buf);
+
+	for (i = 0; i < MAX_BUFFER_QUEUE; i++)
+		enbuf[i] = odp_buffer_alloc(msg_pool);
+
+	/*
+	 * odp_queue_enq_multi may return 0..n buffers due to the resource
+	 * constraints in the implementation at that given point of time.
+	 */
+	odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE);
+	pbuf_tmp = debuf;
+	do {
+		deq_ret  = odp_queue_deq_multi(queue_id, pbuf_tmp,
+					       MAX_BUFFER_QUEUE);
+		nr_deq_entries += deq_ret;
+		max_iteration--;
+		pbuf_tmp += deq_ret;
+		CU_ASSERT(max_iteration >= 0);
+	} while (nr_deq_entries < MAX_BUFFER_QUEUE);
+
+	for (i = 0; i < MAX_BUFFER_QUEUE; i++) {
+		CU_ASSERT_EQUAL(enbuf[i], debuf[i]);
+		odp_buffer_free(enbuf[i]);
+	}
+
+	return;
+}
+
+static int init(void)
+{
+	if (0 != odp_init_global(NULL, NULL)) {
+		printf("odp_init_global fail.\n");
+		return -1;
+	}
+	if (0 != odp_init_local()) {
+		printf("odp_init_local fail.\n");
+		return -1;
+	}
+	if (0 != test_odp_buffer_pool_init()) {
+		printf("test_odp_buffer_pool_init fail.\n");
+		return -1;
+	}
+	return 0;
+}
+
+static int finalize(void)
+{
+	odp_term_local();
+	odp_term_global();
+	return 0;
+}
+
+int main(void)
+{
+	CU_pSuite ptr_suite = NULL;
+
+	/* initialize the CUnit test registry */
+	if (CUE_SUCCESS != CU_initialize_registry())
+		return CU_get_error();
+
+	/* add the tests to the queue suite */
+	ptr_suite = CU_add_suite("odp queue", init, finalize);
+	if (NULL == ptr_suite) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
+	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
+	/* Run all tests using the CUnit Basic interface */
+	CU_basic_set_mode(CU_BRM_VERBOSE);
+	CU_basic_run_tests();
+	CU_cleanup_registry();
+	return CU_get_error();
+}