[3/4] tests: Move ARRAY_LENGTH to a shared header for reuse

Submitted by Bryce Harrington on Nov. 20, 2014, 1:18 a.m.

Details

Message ID 1416446316-14598-3-git-send-email-bryce@osg.samsung.com
State Accepted
Commit 22ea306ce2e49807832317dd4ea111f2c5b9f47d
Headers show

Not browsing as part of any series.

Commit Message

Bryce Harrington Nov. 20, 2014, 1:18 a.m.
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
---
 tests/presentation-test.c  | 2 --
 tests/weston-test-runner.h | 4 +++-
 2 files changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/presentation-test.c b/tests/presentation-test.c
index b99e93d..f97e5b3 100644
--- a/tests/presentation-test.c
+++ b/tests/presentation-test.c
@@ -31,8 +31,6 @@ 
 #include "weston-test-client-helper.h"
 #include "presentation_timing-client-protocol.h"
 
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
 static inline void *
 xzalloc(size_t size)
 {
diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h
index e1db040..193b76d 100644
--- a/tests/weston-test-runner.h
+++ b/tests/weston-test-runner.h
@@ -41,6 +41,8 @@  struct weston_test {
 	int must_fail;
 } __attribute__ ((aligned (32)));
 
+#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
+
 #define TEST_BEGIN(name, arg)					\
 	static void name(arg)
 
@@ -67,7 +69,7 @@  struct weston_test {
 #define ARG_TEST(name, ret, test_data)				\
 	TEST_COMMON(name, name, ret, test_data,			\
 		    sizeof(test_data[0]),			\
-		    sizeof(test_data) / sizeof (test_data[0]))	\
+		    ARRAY_LENGTH(test_data))			\
 	TEST_BEGIN(name, void *data)				\
 
 #define TEST(name) NO_ARG_TEST(name, 0)

Comments

IMO it'd be good to add guards (#ifndef ARRAY_LENGTH) around this macro,
because it is used extensively in wayland/weston and in the future it may
happen that
it'll be redefined by some included header.

Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>

On 20 November 2014 at 02:18, Bryce Harrington <bryce@osg.samsung.com>
wrote:

> Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
> ---
>  tests/presentation-test.c  | 2 --
>  tests/weston-test-runner.h | 4 +++-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tests/presentation-test.c b/tests/presentation-test.c
> index b99e93d..f97e5b3 100644
> --- a/tests/presentation-test.c
> +++ b/tests/presentation-test.c
> @@ -31,8 +31,6 @@
>  #include "weston-test-client-helper.h"
>  #include "presentation_timing-client-protocol.h"
>
> -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
> -
>  static inline void *
>  xzalloc(size_t size)
>  {
> diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h
> index e1db040..193b76d 100644
> --- a/tests/weston-test-runner.h
> +++ b/tests/weston-test-runner.h
> @@ -41,6 +41,8 @@ struct weston_test {
>         int must_fail;
>  } __attribute__ ((aligned (32)));
>
> +#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
> +
>  #define TEST_BEGIN(name, arg)                                  \
>         static void name(arg)
>
> @@ -67,7 +69,7 @@ struct weston_test {
>  #define ARG_TEST(name, ret, test_data)                         \
>         TEST_COMMON(name, name, ret, test_data,                 \
>                     sizeof(test_data[0]),                       \
> -                   sizeof(test_data) / sizeof (test_data[0]))  \
> +                   ARRAY_LENGTH(test_data))                    \
>         TEST_BEGIN(name, void *data)                            \
>
>  #define TEST(name) NO_ARG_TEST(name, 0)
> --
> 1.9.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
On Fri, Nov 28, 2014 at 12:41:21PM +0100, Marek Chalupa wrote:
> IMO it'd be good to add guards (#ifndef ARRAY_LENGTH) around this macro,
> because it is used extensively in wayland/weston and in the future it may
> happen that
> it'll be redefined by some included header.

Right, I'll send a followup patch next week to do that if someone
doesn't beat me to it.

Thanks for the reviews!

Bryce
 
> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
> 
> On 20 November 2014 at 02:18, Bryce Harrington <bryce@osg.samsung.com>
> wrote:
> 
> > Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
> > ---
> >  tests/presentation-test.c  | 2 --
> >  tests/weston-test-runner.h | 4 +++-
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/tests/presentation-test.c b/tests/presentation-test.c
> > index b99e93d..f97e5b3 100644
> > --- a/tests/presentation-test.c
> > +++ b/tests/presentation-test.c
> > @@ -31,8 +31,6 @@
> >  #include "weston-test-client-helper.h"
> >  #include "presentation_timing-client-protocol.h"
> >
> > -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
> > -
> >  static inline void *
> >  xzalloc(size_t size)
> >  {
> > diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h
> > index e1db040..193b76d 100644
> > --- a/tests/weston-test-runner.h
> > +++ b/tests/weston-test-runner.h
> > @@ -41,6 +41,8 @@ struct weston_test {
> >         int must_fail;
> >  } __attribute__ ((aligned (32)));
> >
> > +#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
> > +
> >  #define TEST_BEGIN(name, arg)                                  \
> >         static void name(arg)
> >
> > @@ -67,7 +69,7 @@ struct weston_test {
> >  #define ARG_TEST(name, ret, test_data)                         \
> >         TEST_COMMON(name, name, ret, test_data,                 \
> >                     sizeof(test_data[0]),                       \
> > -                   sizeof(test_data) / sizeof (test_data[0]))  \
> > +                   ARRAY_LENGTH(test_data))                    \
> >         TEST_BEGIN(name, void *data)                            \
> >
> >  #define TEST(name) NO_ARG_TEST(name, 0)
> > --
> > 1.9.1
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >