Skip to content

Commit b62ecd4

Browse files
nathanlynchtyreld
authored andcommitted
build system: add support for cmocka-based tests
Add an --enable-tests switch to configure, which is off by default. When enabled, check for a recent version of cmocka (https://cmocka.org/) libraries to build tests with. It is intended that 'configure --enable-tests' without a suitable cmocka installation results in an error. For now, the set of tests is empty. Signed-off-by: Nathan Lynch <[email protected]> Signed-off-by: Tyrel Datwyler <[email protected]>
1 parent 2cb840a commit b62ecd4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/m4/ltsugar.m4
1919
/m4/ltversion.m4
2020
/stamp-h1
21+
/test-suite.log
2122

2223
# Build outputs that appear in subdirectories
2324
*.la

Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ library_include_HEADERS += \
6969
noinst_HEADERS += librtasevent_src/rtas_event.h \
7070
librtasevent_src/rtas_src_codes.c
7171

72+
if ENABLE_TESTS
73+
74+
TESTS = $(check_PROGRAMS)
75+
76+
endif # ENABLE_TESTS
77+
7278
abixml_dir = $(srcdir)/data/abixml
7379
librtas_abi_xml = $(abixml_dir)/librtas/$(host_cpu)-$(host_os).xml
7480
librtasevent_abi_xml = $(abixml_dir)/librtasevent/$(host_cpu)-$(host_os).xml

configure.ac

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ AC_CHECK_PROGS([cmd_abidiff], [abidiff])
2525
LT_INIT
2626
LT_LANG([C])
2727

28+
# Detection of missing pkg-config macros, per Autoconf manual.
29+
m4_pattern_forbid([^PKG_])
30+
31+
PKG_PROG_PKG_CONFIG
32+
33+
AC_MSG_CHECKING([whether to enable tests])
34+
AC_ARG_ENABLE([tests],
35+
[AS_HELP_STRING([--enable-tests],
36+
[enable tests (default is no)])],
37+
[enable_tests=$enableval],
38+
[enable_tests="no"])
39+
AC_MSG_RESULT([$enable_tests])
40+
AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = "yes"])
41+
if test "$enable_tests" = "yes"; then
42+
cmocka_min_ver=1.1.7
43+
PKG_CHECK_MODULES([CMOCKA],
44+
[cmocka >= $cmocka_min_ver],
45+
[cmocka_available="yes"],
46+
[cmocka_available="no"])
47+
if test "$cmocka_available" = "no"; then
48+
AC_MSG_ERROR([--enable-tests requires cmocka >= $cmocka_min_ver])
49+
fi
50+
fi
51+
2852
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
2953

3054
AC_CONFIG_FILES([Makefile librtas.spec])

0 commit comments

Comments
 (0)