From e635677589fa9fed6310e8ec2c3cab7afa93b9ce Mon Sep 17 00:00:00 2001 From: Daniel Walter Date: Wed, 31 Aug 2016 10:11:14 +0200 Subject: Add Makefile for unittests Signed-off-by: Daniel Walter Signed-off-by: David Oberhollenzer --- .gitignore | 2 ++ Makefile.am | 4 ++++ configure.ac | 16 ++++++++++++++++ tests/unittests/Makemodule.am | 16 ++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/unittests/Makemodule.am diff --git a/.gitignore b/.gitignore index d50dbc2..c11a45e 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,8 @@ ubirmvol ubirsvol ubiupdatevol volrefcnt +mtdlib_test +ubilib_test tests/fs-tests/fs_help_all.sh tests/fs-tests/fs_run_all.sh tests/fs-tests/stress/fs_stress00.sh diff --git a/Makefile.am b/Makefile.am index 5caa5ca..a3457c0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,3 +48,7 @@ include tests/checkfs/Makemodule.am include tests/fs-tests/Makemodule.am include tests/mtd-tests/Makemodule.am endif + +if UNIT_TESTS +include tests/unittests/Makemodule.am +endif diff --git a/configure.ac b/configure.ac index 637d692..18ff9af 100644 --- a/configure.ac +++ b/configure.ac @@ -3,6 +3,20 @@ AC_PREREQ([2.60]) m4_define([RELEASE], 1.5.2) AC_INIT([mtd-utils], [RELEASE], [linux-mtd@lists.infradead.org], mtd-utils) + + +AC_ARG_ENABLE([unit-tests], + [AS_HELP_STRING([--enable-unit-tests], [Compile unit test programs])], + [case "${enableval}" in + yes) AM_CONDITIONAL([UNIT_TESTS], [true]) ;; + no) AM_CONDITIONAL([UNIT_TESTS], [false]) ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-unit-tests]) ;; + esac], + [AM_CONDITIONAL([UNIT_TESTS], [false])]) + +AM_COND_IF([UNIT_TESTS], [: ${CFLAGS=""}], []) + + AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign subdir-objects dist-bzip2]) AM_SILENT_RULES([yes]) @@ -78,6 +92,8 @@ AM_CONDITIONAL([HAVE_EXECINFO], [test "x$execinfo_found" == "xyes"]) PKG_CHECK_MODULES(ZLIB, [ zlib ]) PKG_CHECK_MODULES(UUID, [ uuid ]) +AM_COND_IF([UNIT_TESTS], [PKG_CHECK_MODULES(CMOCKA, [ cmocka ])], []) + AM_COND_IF([WITHOUT_LZO], [], [ have_lzo="yes" AC_ARG_VAR([LZO_CFLAGS], [C compiler flags for lzo]) diff --git a/tests/unittests/Makemodule.am b/tests/unittests/Makemodule.am new file mode 100644 index 0000000..b7bad94 --- /dev/null +++ b/tests/unittests/Makemodule.am @@ -0,0 +1,16 @@ +ubilib_test_SOURCES = tests/unittests/libubi_test.c ubi-utils/libubi.c +ubilib_test_LDADD = $(CMOCKA_LIBS) +ubilib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=stat -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek +ubilib_test_CPPFLAGS = -O0 --std=gnu99 $(CMOCKA_CFLAGS) -I ubi-utils/include -I include -DSYSFS_ROOT='"tests/unittests/sysfs_mock"' + +mtdlib_test_SOURCES = tests/unittests/libmtd_test.c lib/libmtd.c lib/libmtd_legacy.c +mtdlib_test_LDADD = $(CMOCKA_LIBS) +mtdlib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=stat -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=write +mtdlib_test_CPPFLAGS = -O0 --std=gnu99 $(CMOCKA_CFLAGS) -I lib/ -I include -DSYSFS_ROOT='"tests/unittests/sysfs_mock"' + +TEST_BINS = \ + ubilib_test \ + mtdlib_test + + +noinst_PROGRAMS += $(TEST_BINS) -- cgit v1.2.3