[dpdk-dev,v2,01/11] eal: add common test assert macros

Message ID 20171214150138.25667-2-pbhagavatula@caviumnetworks.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Pavan Nikhilesh Dec. 14, 2017, 3:01 p.m. UTC
  Adding common test assertion macros for unit testing.
Taken from test/test.h.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
 lib/librte_eal/common/Makefile           |  2 +-
 lib/librte_eal/common/include/rte_test.h | 97 ++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/common/include/rte_test.h
  

Comments

Ananyev, Konstantin Dec. 14, 2017, 6:43 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> Sent: Thursday, December 14, 2017 3:01 PM
> To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> Ma, Liang J <liang.j.ma@intel.com>
> Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> 
> Adding common test assertion macros for unit testing.

Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
Konstantin

> Taken from test/test.h.
> 
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> ---
>  lib/librte_eal/common/Makefile           |  2 +-
>  lib/librte_eal/common/include/rte_test.h | 97 ++++++++++++++++++++++++++++++++
>  2 files changed, 98 insertions(+), 1 deletion(-)
>  create mode 100644 lib/librte_eal/common/include/rte_test.h
> 
> diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> index 9effd0d45..eba1059f2 100644
> --- a/lib/librte_eal/common/Makefile
> +++ b/lib/librte_eal/common/Makefile
> @@ -43,7 +43,7 @@ INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h
>  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
>  INC += rte_malloc.h rte_keepalive.h rte_time.h
>  INC += rte_service.h rte_service_component.h
> -INC += rte_bitmap.h rte_vfio.h
> +INC += rte_bitmap.h rte_vfio.h rte_test.h
> 
>  GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h
>  GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
> diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
> new file mode 100644
> index 000000000..256117f79
> --- /dev/null
> +++ b/lib/librte_eal/common/include/rte_test.h
> @@ -0,0 +1,97 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Cavium, Inc. All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *	 * Redistributions of source code must retain the above copyright
> + *	   notice, this list of conditions and the following disclaimer.
> + *	 * Redistributions in binary form must reproduce the above copyright
> + *	   notice, this list of conditions and the following disclaimer in
> + *	   the documentation and/or other materials provided with the
> + *	   distribution.
> + *	 * Neither the name of Cavium, Inc nor the names of its
> + *	   contributors may be used to endorse or promote products derived
> + *	   from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _RTE_TEST_H_
> +#define _RTE_TEST_H_
> +
> +#include <rte_log.h>
> +
> +#define RTE_TEST_ASSERT(cond, msg, ...) do {                                  \
> +	if (!(cond)) {                                                        \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_EQUAL(a, b, msg, ...) do {                            \
> +	if (!(a == b)) {                                                      \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) do {                        \
> +	if (!(a != b)) {                                                      \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_SUCCESS(val, msg, ...) do {                           \
> +	typeof(val) _val = (val);                                             \
> +	if (!(_val == 0)) {                                                   \
> +		RTE_LOG(DEBUG, EAL,                                           \
> +				"Test assert %s line %d failed (err %d): "    \
> +				msg "\n", __func__, __LINE__, _val,           \
> +				##__VA_ARGS__);                               \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_FAIL(val, msg, ...) do {                              \
> +	if (!(val != 0)) {                                                    \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_NULL(val, msg, ...) do {                              \
> +	if (!(val == NULL)) {                                                 \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#define RTE_TEST_ASSERT_NOT_NULL(val, msg, ...) do {                          \
> +	if (!(val != NULL)) {                                                 \
> +		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
> +				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
> +		return -1;                                                    \
> +	}                                                                     \
> +} while (0)
> +
> +#endif /* _RTE_TEST_H_ */
> --
> 2.14.1
  
Pavan Nikhilesh Dec. 15, 2017, 9:04 a.m. UTC | #2
On Thu, Dec 14, 2017 at 06:43:24PM +0000, Ananyev, Konstantin wrote:
>
>
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> > Sent: Thursday, December 14, 2017 3:01 PM
> > To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> > Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> > Ma, Liang J <liang.j.ma@intel.com>
> > Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> >
> > Adding common test assertion macros for unit testing.
>
> Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
> Konstantin

The existing RTE_ASSERT/VERIFY use rte_panic().

Pavan
>
> > Taken from test/test.h.
> >
> > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > ---
> >  lib/librte_eal/common/Makefile           |  2 +-
> >  lib/librte_eal/common/include/rte_test.h | 97 ++++++++++++++++++++++++++++++++
> >  2 files changed, 98 insertions(+), 1 deletion(-)
> >  create mode 100644 lib/librte_eal/common/include/rte_test.h
> >
> > diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> > index 9effd0d45..eba1059f2 100644
> > --- a/lib/librte_eal/common/Makefile
> > +++ b/lib/librte_eal/common/Makefile
> > @@ -43,7 +43,7 @@ INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h
> >  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
> >  INC += rte_malloc.h rte_keepalive.h rte_time.h
> >  INC += rte_service.h rte_service_component.h
> > -INC += rte_bitmap.h rte_vfio.h
> > +INC += rte_bitmap.h rte_vfio.h rte_test.h
> >
> >  GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h
> >  GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
> > diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
> > new file mode 100644
> > index 000000000..256117f79
> > --- /dev/null
> > +++ b/lib/librte_eal/common/include/rte_test.h
> > @@ -0,0 +1,97 @@
[...]
  
Ananyev, Konstantin Dec. 15, 2017, 10:58 a.m. UTC | #3
> -----Original Message-----
> From: Pavan Nikhilesh Bhagavatula [mailto:pbhagavatula@caviumnetworks.com]
> Sent: Friday, December 15, 2017 9:05 AM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com;
> Richardson, Bruce <bruce.richardson@intel.com>; Van Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>;
> hemant.agrawal@nxp.com; nipun.gupta@nxp.com; Ma, Liang J <liang.j.ma@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> 
> On Thu, Dec 14, 2017 at 06:43:24PM +0000, Ananyev, Konstantin wrote:
> >
> >
> > > -----Original Message-----
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> > > Sent: Thursday, December 14, 2017 3:01 PM
> > > To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> > > Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> > > Ma, Liang J <liang.j.ma@intel.com>
> > > Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > >
> > > Adding common test assertion macros for unit testing.
> >
> > Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
> > Konstantin
> 
> The existing RTE_ASSERT/VERIFY use rte_panic().

Yes, and wouldn't you expect that behavior from assert() call?
Seriously where do you plan to use it outside auto test framework?
Konstantin

> 
> Pavan
> >
> > > Taken from test/test.h.
> > >
> > > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > ---
> > >  lib/librte_eal/common/Makefile           |  2 +-
> > >  lib/librte_eal/common/include/rte_test.h | 97 ++++++++++++++++++++++++++++++++
> > >  2 files changed, 98 insertions(+), 1 deletion(-)
> > >  create mode 100644 lib/librte_eal/common/include/rte_test.h
> > >
> > > diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> > > index 9effd0d45..eba1059f2 100644
> > > --- a/lib/librte_eal/common/Makefile
> > > +++ b/lib/librte_eal/common/Makefile
> > > @@ -43,7 +43,7 @@ INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h
> > >  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
> > >  INC += rte_malloc.h rte_keepalive.h rte_time.h
> > >  INC += rte_service.h rte_service_component.h
> > > -INC += rte_bitmap.h rte_vfio.h
> > > +INC += rte_bitmap.h rte_vfio.h rte_test.h
> > >
> > >  GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h
> > >  GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
> > > diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
> > > new file mode 100644
> > > index 000000000..256117f79
> > > --- /dev/null
> > > +++ b/lib/librte_eal/common/include/rte_test.h
> > > @@ -0,0 +1,97 @@
> [...]
  
Pavan Nikhilesh Dec. 15, 2017, 11:32 a.m. UTC | #4
On Fri, Dec 15, 2017 at 10:58:10AM +0000, Ananyev, Konstantin wrote:
>
>
> > -----Original Message-----
> > From: Pavan Nikhilesh Bhagavatula [mailto:pbhagavatula@caviumnetworks.com]
> > Sent: Friday, December 15, 2017 9:05 AM
> > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com;
> > Richardson, Bruce <bruce.richardson@intel.com>; Van Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>;
> > hemant.agrawal@nxp.com; nipun.gupta@nxp.com; Ma, Liang J <liang.j.ma@intel.com>
> > Cc: dev@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> >
> > On Thu, Dec 14, 2017 at 06:43:24PM +0000, Ananyev, Konstantin wrote:
> > >
> > >
> > > > -----Original Message-----
> > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> > > > Sent: Thursday, December 14, 2017 3:01 PM
> > > > To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> > > > Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> > > > Ma, Liang J <liang.j.ma@intel.com>
> > > > Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > > Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > > >
> > > > Adding common test assertion macros for unit testing.
> > >
> > > Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
> > > Konstantin
> >
> > The existing RTE_ASSERT/VERIFY use rte_panic().
>
> Yes, and wouldn't you expect that behavior from assert() call?

We need to print out the number of successful/failure tests so, we need the
test to proceed even if an assert fails.
In case of `event_octeontx` we have added a new devargs 'selftest' that can be
used to test the driver from any given application.

> Seriously where do you plan to use it outside auto test framework?

We are moving pmd specific tests to respective pmd folder to reduce
clutter in auto test area (event devices for now) [1]. So, we need to access
the asserts from driver location instead of using CFLAGS to directly include
test.h for all the drivers it would be better to have it in eal/common as
rte_test.

[1] http://dpdk.org/ml/archives/dev/2017-December/083740.html

> Konstantin

Regards,
Pavan
>
> >
> > Pavan
> > >
> > > > Taken from test/test.h.
> > > >
> > > > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > > ---
> > > >  lib/librte_eal/common/Makefile           |  2 +-
> > > >  lib/librte_eal/common/include/rte_test.h | 97 ++++++++++++++++++++++++++++++++
> > > >  2 files changed, 98 insertions(+), 1 deletion(-)
> > > >  create mode 100644 lib/librte_eal/common/include/rte_test.h
> > > >
> > > > diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
> > > > index 9effd0d45..eba1059f2 100644
> > > > --- a/lib/librte_eal/common/Makefile
> > > > +++ b/lib/librte_eal/common/Makefile
> > > > @@ -43,7 +43,7 @@ INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h
> > > >  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
> > > >  INC += rte_malloc.h rte_keepalive.h rte_time.h
> > > >  INC += rte_service.h rte_service_component.h
> > > > -INC += rte_bitmap.h rte_vfio.h
> > > > +INC += rte_bitmap.h rte_vfio.h rte_test.h
> > > >
> > > >  GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h
> > > >  GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
> > > > diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
> > > > new file mode 100644
> > > > index 000000000..256117f79
> > > > --- /dev/null
> > > > +++ b/lib/librte_eal/common/include/rte_test.h
> > > > @@ -0,0 +1,97 @@
> > [...]
  
Jerin Jacob Jan. 10, 2018, 7:16 p.m. UTC | #5
-----Original Message-----
> Date: Fri, 15 Dec 2017 17:02:42 +0530
> From: Pavan Nikhilesh Bhagavatula <pbhagavatula@caviumnetworks.com>
> To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>,
>  "jerin.jacob@caviumnetworks.com" <jerin.jacob@caviumnetworks.com>,
>  "santosh.shukla@caviumnetworks.com" <santosh.shukla@caviumnetworks.com>,
>  "Richardson, Bruce" <bruce.richardson@intel.com>, "Van Haaren, Harry"
>  <harry.van.haaren@intel.com>, "Eads, Gage" <gage.eads@intel.com>,
>  "hemant.agrawal@nxp.com" <hemant.agrawal@nxp.com>, "nipun.gupta@nxp.com"
>  <nipun.gupta@nxp.com>, "Ma, Liang J" <liang.j.ma@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev]  [PATCH v2 01/11] eal: add common test assert macros
> User-Agent: NeoMutt/20170609 (1.8.3)
> 
> On Fri, Dec 15, 2017 at 10:58:10AM +0000, Ananyev, Konstantin wrote:
> >
> >
> > > -----Original Message-----
> > > From: Pavan Nikhilesh Bhagavatula [mailto:pbhagavatula@caviumnetworks.com]
> > > Sent: Friday, December 15, 2017 9:05 AM
> > > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com;
> > > Richardson, Bruce <bruce.richardson@intel.com>; Van Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>;
> > > hemant.agrawal@nxp.com; nipun.gupta@nxp.com; Ma, Liang J <liang.j.ma@intel.com>
> > > Cc: dev@dpdk.org
> > > Subject: Re: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > >
> > > On Thu, Dec 14, 2017 at 06:43:24PM +0000, Ananyev, Konstantin wrote:
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> > > > > Sent: Thursday, December 14, 2017 3:01 PM
> > > > > To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> > > > > Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> > > > > Ma, Liang J <liang.j.ma@intel.com>
> > > > > Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > > > Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > > > >
> > > > > Adding common test assertion macros for unit testing.
> > > >
> > > > Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
> > > > Konstantin
> > >
> > > The existing RTE_ASSERT/VERIFY use rte_panic().
> >
> > Yes, and wouldn't you expect that behavior from assert() call?
> 
> We need to print out the number of successful/failure tests so, we need the
> test to proceed even if an assert fails.
> In case of `event_octeontx` we have added a new devargs 'selftest' that can be
> used to test the driver from any given application.
> 
> > Seriously where do you plan to use it outside auto test framework?
> 
> We are moving pmd specific tests to respective pmd folder to reduce
> clutter in auto test area (event devices for now) [1]. So, we need to access
> the asserts from driver location instead of using CFLAGS to directly include
> test.h for all the drivers it would be better to have it in eal/common as
> rte_test.
> 
> [1] http://dpdk.org/ml/archives/dev/2017-December/083740.html

Cc: thomas@monjalon.net

Any objection to this patch and/or taking this patch through next-eventdev tree?
  
Thomas Monjalon Jan. 10, 2018, 8:18 p.m. UTC | #6
10/01/2018 20:16, Jerin Jacob:
> -----Original Message-----
> > Date: Fri, 15 Dec 2017 17:02:42 +0530
> > From: Pavan Nikhilesh Bhagavatula <pbhagavatula@caviumnetworks.com>
> > To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>,
> >  "jerin.jacob@caviumnetworks.com" <jerin.jacob@caviumnetworks.com>,
> >  "santosh.shukla@caviumnetworks.com" <santosh.shukla@caviumnetworks.com>,
> >  "Richardson, Bruce" <bruce.richardson@intel.com>, "Van Haaren, Harry"
> >  <harry.van.haaren@intel.com>, "Eads, Gage" <gage.eads@intel.com>,
> >  "hemant.agrawal@nxp.com" <hemant.agrawal@nxp.com>, "nipun.gupta@nxp.com"
> >  <nipun.gupta@nxp.com>, "Ma, Liang J" <liang.j.ma@intel.com>
> > Cc: dev@dpdk.org
> > Subject: Re: [dpdk-dev]  [PATCH v2 01/11] eal: add common test assert macros
> > User-Agent: NeoMutt/20170609 (1.8.3)
> > 
> > On Fri, Dec 15, 2017 at 10:58:10AM +0000, Ananyev, Konstantin wrote:
> > >
> > >
> > > > -----Original Message-----
> > > > From: Pavan Nikhilesh Bhagavatula [mailto:pbhagavatula@caviumnetworks.com]
> > > > Sent: Friday, December 15, 2017 9:05 AM
> > > > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com;
> > > > Richardson, Bruce <bruce.richardson@intel.com>; Van Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>;
> > > > hemant.agrawal@nxp.com; nipun.gupta@nxp.com; Ma, Liang J <liang.j.ma@intel.com>
> > > > Cc: dev@dpdk.org
> > > > Subject: Re: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > > >
> > > > On Thu, Dec 14, 2017 at 06:43:24PM +0000, Ananyev, Konstantin wrote:
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh
> > > > > > Sent: Thursday, December 14, 2017 3:01 PM
> > > > > > To: jerin.jacob@caviumnetworks.com; santosh.shukla@caviumnetworks.com; Richardson, Bruce <bruce.richardson@intel.com>; Van
> > > > > > Haaren, Harry <harry.van.haaren@intel.com>; Eads, Gage <gage.eads@intel.com>; hemant.agrawal@nxp.com; nipun.gupta@nxp.com;
> > > > > > Ma, Liang J <liang.j.ma@intel.com>
> > > > > > Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > > > > > Subject: [dpdk-dev] [PATCH v2 01/11] eal: add common test assert macros
> > > > > >
> > > > > > Adding common test assertion macros for unit testing.
> > > > >
> > > > > Wonder what's wrong with existing RTE_ASSERT() and RTE_VERIFY()?
> > > > > Konstantin
> > > >
> > > > The existing RTE_ASSERT/VERIFY use rte_panic().
> > >
> > > Yes, and wouldn't you expect that behavior from assert() call?
> > 
> > We need to print out the number of successful/failure tests so, we need the
> > test to proceed even if an assert fails.
> > In case of `event_octeontx` we have added a new devargs 'selftest' that can be
> > used to test the driver from any given application.
> > 
> > > Seriously where do you plan to use it outside auto test framework?
> > 
> > We are moving pmd specific tests to respective pmd folder to reduce
> > clutter in auto test area (event devices for now) [1]. So, we need to access
> > the asserts from driver location instead of using CFLAGS to directly include
> > test.h for all the drivers it would be better to have it in eal/common as
> > rte_test.
> > 
> > [1] http://dpdk.org/ml/archives/dev/2017-December/083740.html
> 
> Cc: thomas@monjalon.net
> 
> Any objection to this patch and/or taking this patch through next-eventdev tree?

I am OK with the idea.
But I have some comments on the patch (in v4).
  

Patch

diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
index 9effd0d45..eba1059f2 100644
--- a/lib/librte_eal/common/Makefile
+++ b/lib/librte_eal/common/Makefile
@@ -43,7 +43,7 @@  INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
-INC += rte_bitmap.h rte_vfio.h
+INC += rte_bitmap.h rte_vfio.h rte_test.h
 
 GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h
 GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
new file mode 100644
index 000000000..256117f79
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_test.h
@@ -0,0 +1,97 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Cavium, Inc. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *	 * Redistributions of source code must retain the above copyright
+ *	   notice, this list of conditions and the following disclaimer.
+ *	 * Redistributions in binary form must reproduce the above copyright
+ *	   notice, this list of conditions and the following disclaimer in
+ *	   the documentation and/or other materials provided with the
+ *	   distribution.
+ *	 * Neither the name of Cavium, Inc nor the names of its
+ *	   contributors may be used to endorse or promote products derived
+ *	   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_TEST_H_
+#define _RTE_TEST_H_
+
+#include <rte_log.h>
+
+#define RTE_TEST_ASSERT(cond, msg, ...) do {                                  \
+	if (!(cond)) {                                                        \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_EQUAL(a, b, msg, ...) do {                            \
+	if (!(a == b)) {                                                      \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) do {                        \
+	if (!(a != b)) {                                                      \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_SUCCESS(val, msg, ...) do {                           \
+	typeof(val) _val = (val);                                             \
+	if (!(_val == 0)) {                                                   \
+		RTE_LOG(DEBUG, EAL,                                           \
+				"Test assert %s line %d failed (err %d): "    \
+				msg "\n", __func__, __LINE__, _val,           \
+				##__VA_ARGS__);                               \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_FAIL(val, msg, ...) do {                              \
+	if (!(val != 0)) {                                                    \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_NULL(val, msg, ...) do {                              \
+	if (!(val == NULL)) {                                                 \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#define RTE_TEST_ASSERT_NOT_NULL(val, msg, ...) do {                          \
+	if (!(val != NULL)) {                                                 \
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "         \
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+		return -1;                                                    \
+	}                                                                     \
+} while (0)
+
+#endif /* _RTE_TEST_H_ */