On 2 January 2015 at 00:55, Jerin Jacob <jerin.ja...@caviumnetworks.com>
wrote:

> On Wed, Dec 31, 2014 at 11:30:03AM -0500, Mike Holmes wrote:
> > On 31 December 2014 at 01:33, Jerin Jacob <
> jerin.ja...@caviumnetworks.com>
> > wrote:
> >
> > > On Mon, Dec 29, 2014 at 09:24:01PM -0500, Mike Holmes wrote:
> > > > Add tests for odp_thread_core and odp_thread_id
> > > >
> > > > Signed-off-by: Mike Holmes <mike.hol...@linaro.org>
> > > > ---
> > > >  test/validation/.gitignore   |  1 +
> > > >  test/validation/Makefile.am  |  5 +++--
> > > >  test/validation/odp_thread.c | 47
> > > ++++++++++++++++++++++++++++++++++++++++++++
> > > >  3 files changed, 51 insertions(+), 2 deletions(-)
> > > >  create mode 100644 test/validation/odp_thread.c
> > > >
> > > > diff --git a/test/validation/.gitignore b/test/validation/.gitignore
> > > > index d08db73..5b80834 100644
> > > > --- a/test/validation/.gitignore
> > > > +++ b/test/validation/.gitignore
> > > > @@ -8,3 +8,4 @@ odp_shm
> > > >  odp_system
> > > >  odp_pktio
> > > >  odp_buffer
> > > > +odp_thread
> > > > diff --git a/test/validation/Makefile.am
> b/test/validation/Makefile.am
> > > > index c0545b7..d52fbdb 100644
> > > > --- a/test/validation/Makefile.am
> > > > +++ b/test/validation/Makefile.am
> > > > @@ -6,9 +6,9 @@ AM_LDFLAGS += -static
> > > >  TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform}
> > > >
> > > >  if ODP_CUNIT_ENABLED
> > > > -TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule
> > > odp_pktio_run odp_buffer odp_system
> > > > +TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule
> > > odp_pktio_run odp_buffer odp_system odp_thread
> > > >  check_PROGRAMS = ${bin_PROGRAMS}
> > > > -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule
> > > odp_pktio odp_buffer odp_system
> > > > +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule
> > > odp_pktio odp_buffer odp_system odp_thread
> > > >  odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
> > > >  odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer
> > > >  endif
> > > > @@ -27,3 +27,4 @@ dist_odp_buffer_SOURCES =
> > > buffer/odp_buffer_pool_test.c \
> > > >                         buffer/odp_packet_test.c \
> > > >                         odp_buffer.c common/odp_cunit_common.c
> > > >  dist_odp_system_SOURCES = odp_system.c common/odp_cunit_common.c
> > > > +dist_odp_thread_SOURCES = odp_thread.c common/odp_cunit_common.c
> > > > diff --git a/test/validation/odp_thread.c
> b/test/validation/odp_thread.c
> > > > new file mode 100644
> > > > index 0000000..1c03b16
> > > > --- /dev/null
> > > > +++ b/test/validation/odp_thread.c
> > > > @@ -0,0 +1,47 @@
> > > > +/* Copyright (c) 2014, Linaro Limited
> > > > + * All rights reserved.
> > > > + *
> > > > + * SPDX-License-Identifier:     BSD-3-Clause
> > > > + */
> > > > +
> > > > +#include <odp.h>
> > > > +#include <odp_cunit_common.h>
> > > > +
> > > > +static void *run_thread_id_core(void *arg)
> > > > +{
> > > > +     int thr, core;
> > > > +     pthrd_arg *thrdarg = arg;
> > > > +
> > > > +     thr = odp_thread_id();
> > > > +     core = odp_thread_core();
> > > > +
> > > > +     /* cores start from 0 */
> > > > +     CU_ASSERT((core >= 0) && (core <= thrdarg->numthrds-1));
> > >
> > > thrdarg is pointing to the stack(allocated in
> test_odp_thread_id_core()).
> > > Use odp shared mem
> > > to share the data between the cores or in this case,
> > > odp_sys_core_count()/MAX_WORKERS can
> > > be use here to find thrdarg->numthrds in run_thread_id_core()
> > >
> > >
> > Will do
> >
> >
> > > > +     /* threads start from 1 */
> > > > +     CU_ASSERT((thr >= 1) && (core <= thrdarg->numthrds));
> > >
> > > Is there any specific reason why thread id has to be start from one(Why
> > > not zero)?
> > >
> >
> > Only because in this test the main thread will have run and so it will
> have
> > taken 0 already.
>
> Its bit of odp platform implementation specific.Runtime environments like
> baremetal may map
> thread to core directly.so in that case, core 0(thread 0) can be executed
> in
> run_thread_id_core(). IMO, we need to change the assert to thr >= 0
>
>
No problem I am just looking for the loosest sunny day test because the API
documentation specifies almost nothing, I will change that.


>
> >
> >
> > >
> > > > +     return arg;
> > > > +}
> > > > +
> > > > +static void test_odp_thread_id_core(void)
> > > > +{
> > > > +     pthrd_arg thrdarg;
> > > > +
> > > > +     thrdarg.numthrds = odp_sys_core_count();
> > > > +
> > > > +     if (thrdarg.numthrds > MAX_WORKERS)
> > > > +             thrdarg.numthrds = MAX_WORKERS;
> > > > +
> > > > +     odp_cunit_thread_create(run_thread_id_core, &thrdarg);
> > > > +     odp_cunit_thread_exit(&thrdarg);
> > > > +}
> > > > +
> > > > +CU_TestInfo test_odp_thread[] = {
> > > > +     {"id & core range",  test_odp_thread_id_core},
> > > > +     CU_TEST_INFO_NULL,
> > > > +};
> > > > +
> > > > +CU_SuiteInfo odp_testsuites[] = {
> > > > +     {"Thread", NULL, NULL, NULL, NULL, test_odp_thread},
> > > > +     CU_SUITE_INFO_NULL,
> > > > +};
> > > > +
> > > > --
> > > > 2.1.0
> > > >
> > > >
> > > > _______________________________________________
> > > > 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
>



-- 
*Mike Holmes*
Linaro  Sr Technical Manager
LNG - ODP
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to