path: root/Makefile
diff options
authorTomohiro Kusumi <>2018-10-26 09:35:40 -0700
committerJens Axboe <>2018-10-26 10:24:19 -0600
commitb8b0e1eea7780a02ff67f0caeba446cc403f1b37 (patch)
tree3e20e67dc0668bc87042245150707b88f1025278 /Makefile
parentd7e92306bde2117702ed96b7c5647d9485869047 (diff)
unittests: add CUnit based unittest framework
CUnit is C version of *unit framework to help write test cases. unittests/* are compiled only if CUnit exists, and detected on build time in ./configure like any other build time detection, by running a simple CUnit initialization code. Some OS/distros have binary package for CUnit. In case of Fedora and FreeBSD, they both install shared library ( and CUnit headers required to compile fio's unittests. Fedora: # dnf install CUnit FreeBSD: # pkg install cunit To build and install CUnit from upstream source, do below. # ./bootstrap && make && make install Note that make install seems to install binaries and headers under ~/CUnitHome/ by default. After applying actual test cases in the next few commits, running ./unittests/unittest will print results to stdout. These are examples of test cases, and one can add more tests. -- Example of unittest results # ./unittests/unittest CUnit - A unit testing framework for C - Version 2.1-3 Suite: lib/memalign.c Test: memalign/1 ...passed Suite: lib/strntol.c Test: strntol/1 ...passed Test: strntol/2 ...FAILED 1. unittests/lib/strntol.c:24 - CU_ASSERT_EQUAL(*endp,'\0') Test: strntol/3 ...passed Suite: oslib/strlcat.c Test: strlcat/1 ...passed Test: strlcat/2 ...FAILED 1. unittests/oslib/strlcat.c:28 - CU_ASSERT_EQUAL(strcmp(dst, ""),0) Suite: oslib/strndup.c Test: strndup/1 ...passed Test: strndup/2 ...passed Test: strndup/3 ...passed Run Summary: Type Total Ran Passed Failed Inactive suites 4 4 n/a 0 0 tests 9 9 7 2 0 asserts 18 18 16 2 n/a Elapsed time = 0.000 seconds Signed-off-by: Tomohiro Kusumi <> Signed-off-by: Jens Axboe <>
Diffstat (limited to 'Makefile')
1 files changed, 17 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 4721b789..461d7842 100644
--- a/Makefile
+++ b/Makefile
@@ -300,6 +300,16 @@ T_PROGS += $(T_VS_PROGS)
+UT_OBJS = unittests/unittest.o
+UT_PROGS = unittests/unittest
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_CC = @echo ' ' CC $@;
@@ -326,7 +336,7 @@ mandir = $(prefix)/man
sharedir = $(prefix)/share/fio
.PHONY: all install clean test
.PHONY: FORCE cscope
@@ -467,8 +477,13 @@ t/fio-verify-state: $(T_VS_OBJS)
t/time-test: $(T_TT_OBJS)
+unittests/unittest: $(UT_OBJS) $(UT_TARGET_OBJS)
+ $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(UT_OBJS) $(UT_TARGET_OBJS) -lcunit
clean: FORCE
- @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] profiles/*.[do] t/*.[do] config-host.mak config-host.h[ch] lex.yy.c exp/*.[do] lexer.h
+ @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(UT_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio unittests/unittest FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] profiles/*.[do] t/*.[do] unittests/*.[do] unittests/*/*.[do] config-host.mak config-host.h[ch] lex.yy.c exp/*.[do] lexer.h
@rm -rf doc/output
distclean: clean FORCE