[PATCH weston v6 1/4] Added simple unit/integration test framework and corresponding test program.

Pekka Paalanen ppaalanen at gmail.com
Tue Jul 7 05:57:42 PDT 2015


On Thu,  2 Jul 2015 23:36:44 -0700
"Jon A. Cruz" <jonc at osg.samsung.com> wrote:

> Added a simple C-based test framework and an example program
> that uses it to run through some simple unit tests.
> 
> This is new code inspired primarily by the approaches of Google
> Test, Boost Test, JUnit and TestNG. Factors of others were also
> considered during design and implementation.
> 
> Signed-off-by: Jon A. Cruz <jonc at osg.samsung.com>

> diff --git a/Makefile.am b/Makefile.am
> index f493d16..4f0a450 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -932,7 +932,8 @@ endif
>  # Shared utilities
>  #
>  
> -noinst_LTLIBRARIES += libshared.la libshared-cairo.la
> +noinst_LTLIBRARIES += libshared.la libshared-cairo.la \
> +	libzunitc.la libzunitcmain.la
>  
>  libshared_la_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS)
>  
> @@ -971,6 +972,37 @@ libshared_cairo_la_SOURCES =			\
>  	shared/frame.c				\
>  	shared/cairo-util.h
>  
> +libzunitc_la_SOURCES = \
> +	tools/zunitc/inc/zunitc/zunitc.h	\
> +	tools/zunitc/inc/zunitc/zunitc_impl.h	\
> +	tools/zunitc/src/zuc_base_logger.c	\
> +	tools/zunitc/src/zuc_base_logger.h	\
> +	tools/zunitc/src/zuc_collector.c	\
> +	tools/zunitc/src/zuc_collector.h	\
> +	tools/zunitc/src/zuc_context.h		\
> +	tools/zunitc/src/zuc_event.h		\
> +	tools/zunitc/src/zuc_event_listener.h	\
> +	tools/zunitc/src/zuc_types.h		\
> +	tools/zunitc/src/zunitc_impl.c		\
> +	shared/helpers.h
> +
> +libzunitc_la_CFLAGS = \
> +	$(AM_CFLAGS)				\
> +	-I$(top_srcdir)/tools/zunitc/inc
> +
> +libzunitc_la_LIBADD = \
> +	libshared.la
> +
> +libzunitcmain_la_SOURCES = \
> +	tools/zunitc/src/main.c
> +
> +libzunitcmain_la_CFLAGS = \
> +	$(AM_CFLAGS)				\
> +	-I$(top_srcdir)/tools/zunitc/inc
> +
> +libzunitcmain_la_LIBADD =	\
> +	libzunitc.la		\
> +	libshared.la
>  
>  #
>  # tests subdirectory
> @@ -983,7 +1015,8 @@ internal_tests = 				\
>  
>  shared_tests =					\
>  	config-parser.test			\
> -	vertex-clip.test
> +	vertex-clip.test			\
> +	zuctest
>  
>  module_tests =					\
>  	surface-test.la				\
> @@ -1216,6 +1249,22 @@ setbacklight_CFLAGS = $(AM_CFLAGS) $(SETBACKLIGHT_CFLAGS)
>  setbacklight_LDADD = $(SETBACKLIGHT_LIBS)
>  endif
>  
> +all-local: zuctest$(EXEEXT)

Is this needed as zuctest is in shared_tests?

> +noinst_PROGRAMS += zuctest$(EXEEXT)

This shouldn't be needed, because shared_tests are already added to
noinst_PROGRAMS.

> +
> +zuctest_LDADD =			\
> +	libzunitc.la		\
> +	libzunitcmain.la
> +
> +zuctest_CFLAGS =				\
> +	$(AM_CFLAGS)				\
> +	-I$(top_srcdir)/tools/zunitc/inc
> +
> +zuctest_SOURCES =				\
> +	tools/zunitc/test/fixtures_test.c	\
> +	tools/zunitc/test/zunitc_test.c
> +
>  EXTRA_DIST +=							\
>  	tests/weston-tests-env					\
>  	tests/internal-screenshot.ini				\

> diff --git a/tools/zunitc/test/zunitc_test.c b/tools/zunitc/test/zunitc_test.c
> new file mode 100644
> index 0000000..177c6bc
> --- /dev/null
> +++ b/tools/zunitc/test/zunitc_test.c

> +ZUC_TEST(other_test, math_monkey)
> +{
> +	ZUC_ASSERT_TRUE(1);
> +	ZUC_ASSERT_TRUE(3);
> +	ZUC_ASSERT_FALSE(0);
> +
> +	ZUC_ASSERT_TRUE(1);
> +	ZUC_ASSERT_TRUE(3);
> +	ZUC_ASSERT_FALSE(0);
> +
> +	ZUC_ASSERT_EQ(5, 2 + 3);
> +	ZUC_ASSERT_EQ(5, 2 + 3);
> +
> +	int b = 9;
> +	ZUC_ASSERT_NE(1, 2);
> +	ZUC_ASSERT_NE(b, b + 2);
> +
> +	ZUC_ASSERT_NE(1, 2);
> +	ZUC_ASSERT_NE(b, b + 1);
> +
> +	ZUC_ASSERT_LT(1, 2);
> +	ZUC_ASSERT_LT(1, 3);
> +
> +	ZUC_ASSERT_LE(1, 2);
> +	ZUC_ASSERT_LE(1, 3);
> +
> +	ZUC_ASSERT_LE(1, 1);
> +	ZUC_ASSERT_LE(1, 1);
> +
> +	ZUC_ASSERT_GT(2, 1);
> +	ZUC_ASSERT_GT(3, 1);
> +
> +	ZUC_ASSERT_GE(1, 1);
> +	ZUC_ASSERT_GE(1, 1);
> +
> +	ZUC_ASSERT_GE(2, 1);
> +	ZUC_ASSERT_GE(3, 1);

This test is quite repetitive. :-)

Why does this not work:

$ ./zuctest --zuc-filter=base_test
Note: test filter = base_test
...
and then it runs *all* tests, rather than none (I screwed up the
filter) or just the filtered ones?
The filtering does not seem to work.


$ ./zuctest --zuv-filter=laa
./zuctest: unrecognized option '--zuv-filter=laa'
Try './zuctest --help' for more information.

That works fine.

And --zuc-repeat=3 seems to work ok.


Inspite of the above and style issues, I decided to land this patch. It
will be easier to refine it with follow-up patches than to revise this
beast. All the fundamentals seems to be alright now.

Pushed:
   492c12f..5a75a41  master -> master


Thanks,
pq


More information about the wayland-devel mailing list