Message ID | 1415032263-9819-1-git-send-email-yan.songming@linaro.org |
---|---|
State | New |
Headers | show |
mike@fedora1:~/git/odp$ git am ~/incoming/lng-odp_PATCH_v3_add_tests_for_queue.mbox Applying: add tests for queue /home/mike/git/odp/.git/rebase-apply/patch:81: trailing whitespace. /home/mike/git/odp/.git/rebase-apply/patch:85: trailing whitespace. /home/mike/git/odp/.git/rebase-apply/patch:101: trailing whitespace. CU_ASSERT_EQUAL(queue_creat_id, queue_id); /home/mike/git/odp/.git/rebase-apply/patch:152: trailing whitespace. /home/mike/git/odp/.git/rebase-apply/patch:155: trailing whitespace. warning: squelched 1 whitespace error warning: 6 lines add whitespace errors. If scripts/checkpatch did not see these problems you need to make a branch or new repo and apply the patch so that git am can show you the issues. On 3 November 2014 11:31, Yan Songming <yan.songming@linaro.org> wrote: > From: "yan.songming" <yan.songming@linaro.org> > > Add the cunit test for none sync 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 | 4 +- > test/cunit/odp_queue_test.c | 168 > ++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 171 insertions(+), 1 deletion(-) > create mode 100644 test/cunit/odp_queue_test.c > > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am > index 927a5a5..46f46c9 100644 > --- a/test/cunit/Makefile.am > +++ b/test/cunit/Makefile.am > @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init > +bin_PROGRAMS = odp_init odp_queue > odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > endif > > +dist_odp_queue_SOURCES = odp_queue_test.c > dist_odp_init_SOURCES = odp_init_test.c > diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c > new file mode 100644 > index 0000000..04342a6 > --- /dev/null > +++ b/test/cunit/odp_queue_test.c > @@ -0,0 +1,168 @@ > +/* 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) /**< Max enqueue buf num > */ > +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ > + > +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 (pool_base == NULL) { > + 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 (pool == ODP_BUFFER_POOL_INVALID) { > + printf("Pool create failed.\n"); > + return -1; > + } > + return 0; > +} > + > +static void test_odp_queue_base(void) > +{ > + odp_queue_t queue_creat_id; > + odp_queue_t queue_id; > + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; > + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; > + odp_buffer_pool_t msg_pool; > + odp_queue_param_t param; > + > + int i; > + odp_buffer_t buf; > + void *pRtn = NULL; > + > + /* test odp_queue_create */ > + memset(¶m, 0, sizeof(param)); > + param.sched.sync = ODP_SCHED_SYNC_NONE; > + > + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, > ¶m); > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, > odp_queue_sched_type(queue_creat_id)); > + > + /* test odp_queue_lookup */ > + queue_id = odp_queue_lookup("test_queue"); > + CU_ASSERT_EQUAL(queue_creat_id, queue_id); > + > + /* test odp_queue_set_context */ > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); > + > + /* test odp_queue_get_context*/ > + pRtn = odp_queue_get_context(queue_id); > + CU_ASSERT(&Queue_Contest == (int *)pRtn); > + > + /* apply for buffer */ > + msg_pool = odp_buffer_pool_lookup("msg_pool"); > + buf = odp_buffer_alloc(msg_pool); > + > + /* test odp_queue_enq and odp_queue_deq */ > + odp_queue_enq(queue_id, buf); > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); > + odp_buffer_free(buf); > + > + /* apply for mutili buffer */ > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + Enbuf[i] = odp_buffer_alloc(msg_pool); > + } > + > + /* test odp_queue_enq_multi and odp_queue_enq_multi */ > + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); > + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); > + > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + /* test odp_queue_deq_multi */ > + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); > + /* buffer free */ > + odp_buffer_free(Enbuf[i]); > + } > + return; > + > +} > + > +static void test_odp_queue(void) > +{ > + > + int status; > + status = odp_init_global(NULL, NULL); > + CU_ASSERT_FATAL(0 == status); > + > + CU_ASSERT(0 == odp_init_local()) > + > + /* initialize buffer pool */ > + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); > + > + /* test odp none syne queue */ > + test_odp_queue_base(); > + > + status = odp_term_local(); > + CU_ASSERT(0 == status); > + > + status = odp_term_global(); > + CU_ASSERT(0 == status); > + return; > +} > + > + > + > +static int init(void) > +{ > + printf("\tODP version: %s\n", odp_version_api_str()); > + return 0; > +} > + > +static int finalize(void) > +{ > + 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(); > + > + ptr_suite = CU_add_suite("odp queue", init, finalize); > + if (NULL == ptr_suite) { > + CU_cleanup_registry(); > + return CU_get_error(); > + } > + > + /* add the tests to the queue suite */ > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { > + 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 >
http://people.linaro.org/~mike.holmes/linux-generic-gcov-html/linux-generic/index.html Yan it looks like there odp_buffer_t queue_sched_buf(odp_queue_t handle) was not called in the test suite. Also the internal void queue_lock(queue_entry_t *queue) was not called but maybe odp_packet_io tests may cover that, I believe it is used there. Mike On 3 November 2014 11:45, Mike Holmes <mike.holmes@linaro.org> wrote: > mike@fedora1:~/git/odp$ git am > ~/incoming/lng-odp_PATCH_v3_add_tests_for_queue.mbox > Applying: add tests for queue > /home/mike/git/odp/.git/rebase-apply/patch:81: trailing whitespace. > > /home/mike/git/odp/.git/rebase-apply/patch:85: trailing whitespace. > > /home/mike/git/odp/.git/rebase-apply/patch:101: trailing whitespace. > CU_ASSERT_EQUAL(queue_creat_id, queue_id); > /home/mike/git/odp/.git/rebase-apply/patch:152: trailing whitespace. > > /home/mike/git/odp/.git/rebase-apply/patch:155: trailing whitespace. > > warning: squelched 1 whitespace error > warning: 6 lines add whitespace errors. > > If scripts/checkpatch did not see these problems you need to make a > branch or new repo and apply the patch so that git am can show you the > issues. > > On 3 November 2014 11:31, Yan Songming <yan.songming@linaro.org> wrote: > >> From: "yan.songming" <yan.songming@linaro.org> >> >> Add the cunit test for none sync 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 | 4 +- >> test/cunit/odp_queue_test.c | 168 >> ++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 171 insertions(+), 1 deletion(-) >> create mode 100644 test/cunit/odp_queue_test.c >> >> diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am >> index 927a5a5..46f46c9 100644 >> --- a/test/cunit/Makefile.am >> +++ b/test/cunit/Makefile.am >> @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib >> if ODP_CUNIT_ENABLED >> TESTS = ${bin_PROGRAMS} >> check_PROGRAMS = ${bin_PROGRAMS} >> -bin_PROGRAMS = odp_init >> +bin_PROGRAMS = odp_init odp_queue >> odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit >> +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit >> endif >> >> +dist_odp_queue_SOURCES = odp_queue_test.c >> dist_odp_init_SOURCES = odp_init_test.c >> diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c >> new file mode 100644 >> index 0000000..04342a6 >> --- /dev/null >> +++ b/test/cunit/odp_queue_test.c >> @@ -0,0 +1,168 @@ >> +/* 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) /**< Max enqueue buf num >> */ >> +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ >> + >> +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 (pool_base == NULL) { >> + 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 (pool == ODP_BUFFER_POOL_INVALID) { >> + printf("Pool create failed.\n"); >> + return -1; >> + } >> + return 0; >> +} >> + >> +static void test_odp_queue_base(void) >> +{ >> + odp_queue_t queue_creat_id; >> + odp_queue_t queue_id; >> + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; >> + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; >> + odp_buffer_pool_t msg_pool; >> + odp_queue_param_t param; >> + >> + int i; >> + odp_buffer_t buf; >> + void *pRtn = NULL; >> + >> + /* test odp_queue_create */ >> + memset(¶m, 0, sizeof(param)); >> + param.sched.sync = ODP_SCHED_SYNC_NONE; >> + >> + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, >> ¶m); >> + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); >> + >> + /* test odp_queue_type */ >> + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); >> + >> + /* test odp_queue_type */ >> + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, >> odp_queue_sched_type(queue_creat_id)); >> + >> + /* test odp_queue_lookup */ >> + queue_id = odp_queue_lookup("test_queue"); >> + CU_ASSERT_EQUAL(queue_creat_id, queue_id); >> + >> + /* test odp_queue_set_context */ >> + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); >> + >> + /* test odp_queue_get_context*/ >> + pRtn = odp_queue_get_context(queue_id); >> + CU_ASSERT(&Queue_Contest == (int *)pRtn); >> + >> + /* apply for buffer */ >> + msg_pool = odp_buffer_pool_lookup("msg_pool"); >> + buf = odp_buffer_alloc(msg_pool); >> + >> + /* test odp_queue_enq and odp_queue_deq */ >> + odp_queue_enq(queue_id, buf); >> + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); >> + odp_buffer_free(buf); >> + >> + /* apply for mutili buffer */ >> + for(i=0; i<MAX_BUFFER_QUEUE; i++) { >> + Enbuf[i] = odp_buffer_alloc(msg_pool); >> + } >> + >> + /* test odp_queue_enq_multi and odp_queue_enq_multi */ >> + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); >> + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); >> + >> + for(i=0; i<MAX_BUFFER_QUEUE; i++) { >> + /* test odp_queue_deq_multi */ >> + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); >> + /* buffer free */ >> + odp_buffer_free(Enbuf[i]); >> + } >> + return; >> + >> +} >> + >> +static void test_odp_queue(void) >> +{ >> + >> + int status; >> + status = odp_init_global(NULL, NULL); >> + CU_ASSERT_FATAL(0 == status); >> + >> + CU_ASSERT(0 == odp_init_local()) >> + >> + /* initialize buffer pool */ >> + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); >> + >> + /* test odp none syne queue */ >> + test_odp_queue_base(); >> + >> + status = odp_term_local(); >> + CU_ASSERT(0 == status); >> + >> + status = odp_term_global(); >> + CU_ASSERT(0 == status); >> + return; >> +} >> + >> + >> + >> +static int init(void) >> +{ >> + printf("\tODP version: %s\n", odp_version_api_str()); >> + return 0; >> +} >> + >> +static int finalize(void) >> +{ >> + 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(); >> + >> + ptr_suite = CU_add_suite("odp queue", init, finalize); >> + if (NULL == ptr_suite) { >> + CU_cleanup_registry(); >> + return CU_get_error(); >> + } >> + >> + /* add the tests to the queue suite */ >> + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { >> + 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 >> > > > > -- > *Mike Holmes* > Linaro Sr Technical Manager > LNG - ODP >
On 2014-11-04 00:31, Yan Songming wrote: > From: "yan.songming" <yan.songming@linaro.org> > Say in subject something like this: cunit/odp_queue: add queue test Run checkpatch and fix the problems I will point out some of them and other review comments. In the C file change 4 space to 1 tab. Be consistent either line varables up or don't do not mix. Example: odp_buffer_pool_t pool; void *pool_base; odp_shm_t shm; or odp_buffer_pool_t pool; void *pool_base; odp_shm_t shm; Be consistent with you if-statements don't mix: Example: if (NULL == pool_base) { or if (pool_base == NULL) { See more comments inline. > Add the cunit test for none sync 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 | 4 +- > test/cunit/odp_queue_test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 171 insertions(+), 1 deletion(-) > create mode 100644 test/cunit/odp_queue_test.c > > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am > index 927a5a5..46f46c9 100644 > --- a/test/cunit/Makefile.am > +++ b/test/cunit/Makefile.am > @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init > +bin_PROGRAMS = odp_init odp_queue > odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit From both of the above *_LDFLAGS remove: "-static -lcunit" and add that to line 6 AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit > endif > > +dist_odp_queue_SOURCES = odp_queue_test.c This should be below odp_init_test.c for alphabetic order > dist_odp_init_SOURCES = odp_init_test.c > diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c > new file mode 100644 > index 0000000..04342a6 > --- /dev/null > +++ b/test/cunit/odp_queue_test.c > @@ -0,0 +1,168 @@ > +/* 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) /**< Max enqueue buf num */ > +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ > + > +static int Queue_Contest = 0xff; Remove CamelCase and I think you mean queue_context > + > +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 (pool_base == NULL) { > + 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); Squash to two lines > + > + if (pool == ODP_BUFFER_POOL_INVALID) { > + printf("Pool create failed.\n"); > + return -1; > + } > + return 0; > +} > + > +static void test_odp_queue_base(void) > +{ > + odp_queue_t queue_creat_id; > + odp_queue_t queue_id; > + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; Remove CamelCase > + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; Remove CamelCase > + odp_buffer_pool_t msg_pool; > + odp_queue_param_t param; > + Trailing whitespace > + int i; > + odp_buffer_t buf; > + void *pRtn = NULL; Remove CamelCase and should you remove a space before * to get the variables to line up? =) > + Trailing whitespace > + /* test odp_queue_create */ > + memset(¶m, 0, sizeof(param)); > + param.sched.sync = ODP_SCHED_SYNC_NONE; > + > + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, ¶m); > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, odp_queue_sched_type(queue_creat_id)); > + > + /* test odp_queue_lookup */ > + queue_id = odp_queue_lookup("test_queue"); > + CU_ASSERT_EQUAL(queue_creat_id, queue_id); Trailing whitespace Cheers, Anders > + > + /* test odp_queue_set_context */ > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); > + > + /* test odp_queue_get_context*/ > + pRtn = odp_queue_get_context(queue_id); > + CU_ASSERT(&Queue_Contest == (int *)pRtn); > + > + /* apply for buffer */ > + msg_pool = odp_buffer_pool_lookup("msg_pool"); > + buf = odp_buffer_alloc(msg_pool); > + > + /* test odp_queue_enq and odp_queue_deq */ > + odp_queue_enq(queue_id, buf); > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); > + odp_buffer_free(buf); > + > + /* apply for mutili buffer */ > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + Enbuf[i] = odp_buffer_alloc(msg_pool); > + } > + > + /* test odp_queue_enq_multi and odp_queue_enq_multi */ > + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); > + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); > + > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + /* test odp_queue_deq_multi */ > + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); > + /* buffer free */ > + odp_buffer_free(Enbuf[i]); > + } > + return; > + > +} > + > +static void test_odp_queue(void) > +{ > + > + int status; > + status = odp_init_global(NULL, NULL); > + CU_ASSERT_FATAL(0 == status); > + > + CU_ASSERT(0 == odp_init_local()) > + > + /* initialize buffer pool */ > + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); > + > + /* test odp none syne queue */ > + test_odp_queue_base(); > + > + status = odp_term_local(); > + CU_ASSERT(0 == status); > + > + status = odp_term_global(); > + CU_ASSERT(0 == status); > + return; > +} > + > + > + > +static int init(void) > +{ > + printf("\tODP version: %s\n", odp_version_api_str()); > + return 0; > +} > + > +static int finalize(void) > +{ > + 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(); > + > + ptr_suite = CU_add_suite("odp queue", init, finalize); > + if (NULL == ptr_suite) { > + CU_cleanup_registry(); > + return CU_get_error(); > + } > + > + /* add the tests to the queue suite */ > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { > + 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
On Tue, Nov 04, 2014 at 12:31:03AM +0800, Yan Songming wrote: > From: "yan.songming" <yan.songming@linaro.org> > > Add the cunit test for none sync 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 | 4 +- > test/cunit/odp_queue_test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 171 insertions(+), 1 deletion(-) > create mode 100644 test/cunit/odp_queue_test.c > > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am > index 927a5a5..46f46c9 100644 > --- a/test/cunit/Makefile.am > +++ b/test/cunit/Makefile.am > @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init > +bin_PROGRAMS = odp_init odp_queue > odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > endif > > +dist_odp_queue_SOURCES = odp_queue_test.c > dist_odp_init_SOURCES = odp_init_test.c > diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c > new file mode 100644 > index 0000000..04342a6 > --- /dev/null > +++ b/test/cunit/odp_queue_test.c > @@ -0,0 +1,168 @@ > +/* 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) /**< Max enqueue buf num */ > +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ > + > +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 (pool_base == NULL) { > + 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 (pool == ODP_BUFFER_POOL_INVALID) { > + printf("Pool create failed.\n"); > + return -1; > + } > + return 0; > +} > + > +static void test_odp_queue_base(void) > +{ > + odp_queue_t queue_creat_id; > + odp_queue_t queue_id; > + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; > + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; > + odp_buffer_pool_t msg_pool; > + odp_queue_param_t param; > + > + int i; > + odp_buffer_t buf; > + void *pRtn = NULL; > + > + /* test odp_queue_create */ > + memset(¶m, 0, sizeof(param)); > + param.sched.sync = ODP_SCHED_SYNC_NONE; > + > + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, ¶m); > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, odp_queue_sched_type(queue_creat_id)); > + > + /* test odp_queue_lookup */ > + queue_id = odp_queue_lookup("test_queue"); > + CU_ASSERT_EQUAL(queue_creat_id, queue_id); > + > + /* test odp_queue_set_context */ > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); > + > + /* test odp_queue_get_context*/ > + pRtn = odp_queue_get_context(queue_id); > + CU_ASSERT(&Queue_Contest == (int *)pRtn); > + > + /* apply for buffer */ > + msg_pool = odp_buffer_pool_lookup("msg_pool"); > + buf = odp_buffer_alloc(msg_pool); > + > + /* test odp_queue_enq and odp_queue_deq */ > + odp_queue_enq(queue_id, buf); > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); > + odp_buffer_free(buf); > + > + /* apply for mutili buffer */ > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + Enbuf[i] = odp_buffer_alloc(msg_pool); > + } > + > + /* test odp_queue_enq_multi and odp_queue_enq_multi */ > + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); > + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); odp_queue_*_multi should return number of buffers enqueued/dequeued(which is inline with existing queue management design document). IMO we should add multi queue operation test when the prototype finalizes in the design document. > + > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + /* test odp_queue_deq_multi */ > + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); > + /* buffer free */ > + odp_buffer_free(Enbuf[i]); > + } > + return; > + > +} > + > +static void test_odp_queue(void) > +{ > + > + int status; > + status = odp_init_global(NULL, NULL); > + CU_ASSERT_FATAL(0 == status); > + > + CU_ASSERT(0 == odp_init_local()) > + > + /* initialize buffer pool */ > + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); > + > + /* test odp none syne queue */ > + test_odp_queue_base(); > + > + status = odp_term_local(); > + CU_ASSERT(0 == status); > + > + status = odp_term_global(); > + CU_ASSERT(0 == status); > + return; > +} > + > + > + > +static int init(void) > +{ > + printf("\tODP version: %s\n", odp_version_api_str()); > + return 0; > +} > + > +static int finalize(void) > +{ > + 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(); > + > + ptr_suite = CU_add_suite("odp queue", init, finalize); > + if (NULL == ptr_suite) { > + CU_cleanup_registry(); > + return CU_get_error(); > + } > + > + /* add the tests to the queue suite */ > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { > + 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
Hi jacob, A) return number of buffers The odp_queue_deq_multi do return the number of buffer but the odp_queue_enq_multi is not. I think odp_queue_enq_multi is need to return the number of buffers too, because there is a limit of eight. When the user enqueue ten, in fact just eight buffers will be success , but the user don't know that. B) add multi queue operation I just add the base test of the queue this time , I believe that both multi queue operation and multi thread queue operation should be test. But i think it should be done next time later. yan.songming@linaro.org From: Jerin Jacob Date: 2014-11-04 14:16 To: Yan Songming CC: lng-odp@lists.linaro.org Subject: Re: [lng-odp] [PATCH v3] add tests for queue On Tue, Nov 04, 2014 at 12:31:03AM +0800, Yan Songming wrote: > From: "yan.songming" <yan.songming@linaro.org> > > Add the cunit test for none sync 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 | 4 +- > test/cunit/odp_queue_test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 171 insertions(+), 1 deletion(-) > create mode 100644 test/cunit/odp_queue_test.c > > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am > index 927a5a5..46f46c9 100644 > --- a/test/cunit/Makefile.am > +++ b/test/cunit/Makefile.am > @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init > +bin_PROGRAMS = odp_init odp_queue > odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > endif > > +dist_odp_queue_SOURCES = odp_queue_test.c > dist_odp_init_SOURCES = odp_init_test.c > diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c > new file mode 100644 > index 0000000..04342a6 > --- /dev/null > +++ b/test/cunit/odp_queue_test.c > @@ -0,0 +1,168 @@ > +/* 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) /**< Max enqueue buf num */ > +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ > + > +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 (pool_base == NULL) { > + 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 (pool == ODP_BUFFER_POOL_INVALID) { > + printf("Pool create failed.\n"); > + return -1; > + } > + return 0; > +} > + > +static void test_odp_queue_base(void) > +{ > + odp_queue_t queue_creat_id; > + odp_queue_t queue_id; > + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; > + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; > + odp_buffer_pool_t msg_pool; > + odp_queue_param_t param; > + > + int i; > + odp_buffer_t buf; > + void *pRtn = NULL; > + > + /* test odp_queue_create */ > + memset(¶m, 0, sizeof(param)); > + param.sched.sync = ODP_SCHED_SYNC_NONE; > + > + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, ¶m); > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); > + > + /* test odp_queue_type */ > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, odp_queue_sched_type(queue_creat_id)); > + > + /* test odp_queue_lookup */ > + queue_id = odp_queue_lookup("test_queue"); > + CU_ASSERT_EQUAL(queue_creat_id, queue_id); > + > + /* test odp_queue_set_context */ > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); > + > + /* test odp_queue_get_context*/ > + pRtn = odp_queue_get_context(queue_id); > + CU_ASSERT(&Queue_Contest == (int *)pRtn); > + > + /* apply for buffer */ > + msg_pool = odp_buffer_pool_lookup("msg_pool"); > + buf = odp_buffer_alloc(msg_pool); > + > + /* test odp_queue_enq and odp_queue_deq */ > + odp_queue_enq(queue_id, buf); > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); > + odp_buffer_free(buf); > + > + /* apply for mutili buffer */ > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + Enbuf[i] = odp_buffer_alloc(msg_pool); > + } > + > + /* test odp_queue_enq_multi and odp_queue_enq_multi */ > + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); > + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); odp_queue_*_multi should return number of buffers enqueued/dequeued(which is inline with existing queue management design document). IMO we should add multi queue operation test when the prototype finalizes in the design document. > + > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > + /* test odp_queue_deq_multi */ > + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); > + /* buffer free */ > + odp_buffer_free(Enbuf[i]); > + } > + return; > + > +} > + > +static void test_odp_queue(void) > +{ > + > + int status; > + status = odp_init_global(NULL, NULL); > + CU_ASSERT_FATAL(0 == status); > + > + CU_ASSERT(0 == odp_init_local()) > + > + /* initialize buffer pool */ > + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); > + > + /* test odp none syne queue */ > + test_odp_queue_base(); > + > + status = odp_term_local(); > + CU_ASSERT(0 == status); > + > + status = odp_term_global(); > + CU_ASSERT(0 == status); > + return; > +} > + > + > + > +static int init(void) > +{ > + printf("\tODP version: %s\n", odp_version_api_str()); > + return 0; > +} > + > +static int finalize(void) > +{ > + 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(); > + > + ptr_suite = CU_add_suite("odp queue", init, finalize); > + if (NULL == ptr_suite) { > + CU_cleanup_registry(); > + return CU_get_error(); > + } > + > + /* add the tests to the queue suite */ > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { > + 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
On Tue, Nov 04, 2014 at 07:02:47PM +0800, yan.songming@linaro.org wrote: > Hi jacob, > A) return number of buffers > The odp_queue_deq_multi do return the number of buffer but the odp_queue_enq_multi is not. Correct. But test case should honor the return value(number of buffers dequeued) from odp_queue_deq_multi. > I think odp_queue_enq_multi is need to return the number of buffers too, because there is a limit of eight. > When the user enqueue ten, in fact just eight buffers will be success , but the user don't know that. Not just that, a platfrom may have restriction on number buffers can be enqued at given point of time based on the resource avilablity. > B) add multi queue operation > I just add the base test of the queue this time , I believe that both multi queue operation and multi thread queue operation should be test. > But i think it should be done next time later. Agree. We should include odp_queue_enq_multi in testcase when linux generic has support for multi enqueue operataion which returns the number of enqueue buffers. > > > > yan.songming@linaro.org > > From: Jerin Jacob > Date: 2014-11-04 14:16 > To: Yan Songming > CC: lng-odp@lists.linaro.org > Subject: Re: [lng-odp] [PATCH v3] add tests for queue > On Tue, Nov 04, 2014 at 12:31:03AM +0800, Yan Songming wrote: > > From: "yan.songming" <yan.songming@linaro.org> > > > > Add the cunit test for none sync 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 | 4 +- > > test/cunit/odp_queue_test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 171 insertions(+), 1 deletion(-) > > create mode 100644 test/cunit/odp_queue_test.c > > > > diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am > > index 927a5a5..46f46c9 100644 > > --- a/test/cunit/Makefile.am > > +++ b/test/cunit/Makefile.am > > @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib > > if ODP_CUNIT_ENABLED > > TESTS = ${bin_PROGRAMS} > > check_PROGRAMS = ${bin_PROGRAMS} > > -bin_PROGRAMS = odp_init > > +bin_PROGRAMS = odp_init odp_queue > > odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > > +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit > > endif > > > > +dist_odp_queue_SOURCES = odp_queue_test.c > > dist_odp_init_SOURCES = odp_init_test.c > > diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c > > new file mode 100644 > > index 0000000..04342a6 > > --- /dev/null > > +++ b/test/cunit/odp_queue_test.c > > @@ -0,0 +1,168 @@ > > +/* 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) /**< Max enqueue buf num */ > > +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ > > + > > +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 (pool_base == NULL) { > > + 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 (pool == ODP_BUFFER_POOL_INVALID) { > > + printf("Pool create failed.\n"); > > + return -1; > > + } > > + return 0; > > +} > > + > > +static void test_odp_queue_base(void) > > +{ > > + odp_queue_t queue_creat_id; > > + odp_queue_t queue_id; > > + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; > > + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; > > + odp_buffer_pool_t msg_pool; > > + odp_queue_param_t param; > > + > > + int i; > > + odp_buffer_t buf; > > + void *pRtn = NULL; > > + > > + /* test odp_queue_create */ > > + memset(¶m, 0, sizeof(param)); > > + param.sched.sync = ODP_SCHED_SYNC_NONE; > > + > > + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, ¶m); > > + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); > > + > > + /* test odp_queue_type */ > > + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); > > + > > + /* test odp_queue_type */ > > + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, odp_queue_sched_type(queue_creat_id)); > > + > > + /* test odp_queue_lookup */ > > + queue_id = odp_queue_lookup("test_queue"); > > + CU_ASSERT_EQUAL(queue_creat_id, queue_id); > > + > > + /* test odp_queue_set_context */ > > + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); > > + > > + /* test odp_queue_get_context*/ > > + pRtn = odp_queue_get_context(queue_id); > > + CU_ASSERT(&Queue_Contest == (int *)pRtn); > > + > > + /* apply for buffer */ > > + msg_pool = odp_buffer_pool_lookup("msg_pool"); > > + buf = odp_buffer_alloc(msg_pool); > > + > > + /* test odp_queue_enq and odp_queue_deq */ > > + odp_queue_enq(queue_id, buf); > > + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); > > + odp_buffer_free(buf); > > + > > + /* apply for mutili buffer */ > > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > > + Enbuf[i] = odp_buffer_alloc(msg_pool); > > + } > > + > > + /* test odp_queue_enq_multi and odp_queue_enq_multi */ > > + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); > > + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); > > odp_queue_*_multi should return number of buffers > enqueued/dequeued(which is inline with existing queue management design document). > IMO we should add multi queue operation test when > the prototype finalizes in the design document. > > > > + > > + for(i=0; i<MAX_BUFFER_QUEUE; i++) { > > + /* test odp_queue_deq_multi */ > > + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); > > + /* buffer free */ > > + odp_buffer_free(Enbuf[i]); > > + } > > + return; > > + > > +} > > + > > +static void test_odp_queue(void) > > +{ > > + > > + int status; > > + status = odp_init_global(NULL, NULL); > > + CU_ASSERT_FATAL(0 == status); > > + > > + CU_ASSERT(0 == odp_init_local()) > > + > > + /* initialize buffer pool */ > > + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); > > + > > + /* test odp none syne queue */ > > + test_odp_queue_base(); > > + > > + status = odp_term_local(); > > + CU_ASSERT(0 == status); > > + > > + status = odp_term_global(); > > + CU_ASSERT(0 == status); > > + return; > > +} > > + > > + > > + > > +static int init(void) > > +{ > > + printf("\tODP version: %s\n", odp_version_api_str()); > > + return 0; > > +} > > + > > +static int finalize(void) > > +{ > > + 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(); > > + > > + ptr_suite = CU_add_suite("odp queue", init, finalize); > > + if (NULL == ptr_suite) { > > + CU_cleanup_registry(); > > + return CU_get_error(); > > + } > > + > > + /* add the tests to the queue suite */ > > + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { > > + 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
diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am index 927a5a5..46f46c9 100644 --- a/test/cunit/Makefile.am +++ b/test/cunit/Makefile.am @@ -6,8 +6,10 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init +bin_PROGRAMS = odp_init odp_queue odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit +odp_queue_LDFLAGS = $(AM_LDFLAGS) -static -lcunit endif +dist_odp_queue_SOURCES = odp_queue_test.c dist_odp_init_SOURCES = odp_init_test.c diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c new file mode 100644 index 0000000..04342a6 --- /dev/null +++ b/test/cunit/odp_queue_test.c @@ -0,0 +1,168 @@ +/* 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) /**< Max enqueue buf num */ +#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */ + +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 (pool_base == NULL) { + 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 (pool == ODP_BUFFER_POOL_INVALID) { + printf("Pool create failed.\n"); + return -1; + } + return 0; +} + +static void test_odp_queue_base(void) +{ + odp_queue_t queue_creat_id; + odp_queue_t queue_id; + odp_buffer_t Enbuf[MAX_BUFFER_QUEUE]; + odp_buffer_t Debuf[MAX_BUFFER_QUEUE]; + odp_buffer_pool_t msg_pool; + odp_queue_param_t param; + + int i; + odp_buffer_t buf; + void *pRtn = NULL; + + /* test odp_queue_create */ + memset(¶m, 0, sizeof(param)); + param.sched.sync = ODP_SCHED_SYNC_NONE; + + queue_creat_id = odp_queue_create("test_queue", ODP_QUEUE_TYPE_POLL, ¶m); + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); + + /* test odp_queue_type */ + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, odp_queue_type(queue_creat_id)); + + /* test odp_queue_type */ + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, odp_queue_sched_type(queue_creat_id)); + + /* test odp_queue_lookup */ + queue_id = odp_queue_lookup("test_queue"); + CU_ASSERT_EQUAL(queue_creat_id, queue_id); + + /* test odp_queue_set_context */ + CU_ASSERT(0 == odp_queue_set_context(queue_id, &Queue_Contest)); + + /* test odp_queue_get_context*/ + pRtn = odp_queue_get_context(queue_id); + CU_ASSERT(&Queue_Contest == (int *)pRtn); + + /* apply for buffer */ + msg_pool = odp_buffer_pool_lookup("msg_pool"); + buf = odp_buffer_alloc(msg_pool); + + /* test odp_queue_enq and odp_queue_deq */ + odp_queue_enq(queue_id, buf); + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); + odp_buffer_free(buf); + + /* apply for mutili buffer */ + for(i=0; i<MAX_BUFFER_QUEUE; i++) { + Enbuf[i] = odp_buffer_alloc(msg_pool); + } + + /* test odp_queue_enq_multi and odp_queue_enq_multi */ + odp_queue_enq_multi(queue_id, Enbuf, MAX_BUFFER_QUEUE); + odp_queue_deq_multi(queue_id, Debuf, MAX_BUFFER_QUEUE); + + for(i=0; i<MAX_BUFFER_QUEUE; i++) { + /* test odp_queue_deq_multi */ + CU_ASSERT_EQUAL(Enbuf[i], Debuf[i]); + /* buffer free */ + odp_buffer_free(Enbuf[i]); + } + return; + +} + +static void test_odp_queue(void) +{ + + int status; + status = odp_init_global(NULL, NULL); + CU_ASSERT_FATAL(0 == status); + + CU_ASSERT(0 == odp_init_local()) + + /* initialize buffer pool */ + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); + + /* test odp none syne queue */ + test_odp_queue_base(); + + status = odp_term_local(); + CU_ASSERT(0 == status); + + status = odp_term_global(); + CU_ASSERT(0 == status); + return; +} + + + +static int init(void) +{ + printf("\tODP version: %s\n", odp_version_api_str()); + return 0; +} + +static int finalize(void) +{ + 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(); + + ptr_suite = CU_add_suite("odp queue", init, finalize); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* add the tests to the queue suite */ + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { + 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(); +} +