summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Walter <dwalter@sigma-star.at>2016-08-31 10:11:14 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-11-17 11:36:56 +0100
commite635677589fa9fed6310e8ec2c3cab7afa93b9ce (patch)
tree7fd732eea10c4144f0068d8b45ce99d585694fdc
parent005cef532697be0746c72632f94cfeae67a2a187 (diff)
Add Makefile for unittests
Signed-off-by: Daniel Walter <dwalter@sigma-star.at> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac16
-rw-r--r--tests/unittests/Makemodule.am16
4 files changed, 38 insertions, 0 deletions
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)