Makefile.am | 31 ++++++++++++++++++++++++++++++-
configure.ac | 1 +
m4/cmocka.m4 | 33 +++++++++++++++++++++++++++++++++
test/libslapd/pblock/analytics.c | 17 +++++++++++++++++
test/libslapd/test.c | 26 ++++++++++++++++++++++++++
test/main.c | 16 ++++++++++++++++
test/test_slapd.h | 31 +++++++++++++++++++++++++++++++
7 files changed, 154 insertions(+), 1 deletion(-)
New commits:
commit dccf277980b6e5f19b4628bdfc03b40c5bf63412
Author: William Brown <firstyear(a)redhat.com>
Date: Wed Feb 1 10:21:42 2017 +1000
Ticket 49111 - Integrate cmocka skeleton to Directory Server
Bug Description: This adds a skeleton cmocka to Directory Server. This is just
the build and configure components, with a minimal test.c that shows how we
can seperate our test cases for best usage.
Fix Description: Add cmocka and a corresponding enable flag.
https://fedorahosted.org/389/ticket/49111
Author: wibrown
Review by: nhosoi (Thanks!)
diff --git a/Makefile.am b/Makefile.am
index 78248e5..7c7ab0a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -38,6 +38,14 @@ else
WITH_SYSTEMD = 0
endif
+if WITH_CMOCKA
+CMOCKA_INCLUDES = @cmocka_inc@
+CMOCKA_LINKS = @cmocka_lib@
+else
+CMOCKA_INCLUDES =
+CMOCKA_LINKS =
+endif
+
# these paths are dependent on the settings of prefix and exec_prefix which may be
specified
# at make time. So we cannot use AC_DEFINE in the configure.ac because that would set
the
# values prior to their being defined. Defining them here ensures that they are
properly
@@ -54,7 +62,7 @@ PATH_DEFINES =
-DLOCALSTATEDIR="\"$(localstatedir)\""
-DSYSCONFDIR="\"$(sysconfd
-DSBINDIR="\"$(sbindir)\""
-DPLUGINDIR="\"$(serverplugindir)\"" \
-DTEMPLATEDIR="\"$(sampledatadir)\""
-DSYSTEMSCHEMADIR="\"$(systemschemadir)\""
-AM_CPPFLAGS = $(DEBUG_DEFINES) $(GCCSEC_DEFINES) $(ASAN_DEFINES) $(DS_DEFINES)
$(DS_INCLUDES) $(PATH_DEFINES) $(SYSTEMD_DEFINES)
+AM_CPPFLAGS = $(DEBUG_DEFINES) $(GCCSEC_DEFINES) $(ASAN_DEFINES) $(DS_DEFINES)
$(DS_INCLUDES) $(PATH_DEFINES) $(SYSTEMD_DEFINES) $(CMOCKA_INCLUDES)
PLUGIN_CPPFLAGS = $(AM_CPPFLAGS) @openldap_inc@ @ldapsdk_inc@ @nss_inc@ @nspr_inc@
@systemd_inc@
# We need to make sure that libpthread is linked before libc on HP-UX.
if HPUX
@@ -1826,6 +1834,27 @@ rsearch_bin_SOURCES = ldap/servers/slapd/tools/rsearch/nametable.c
\
rsearch_bin_CPPFLAGS = $(AM_CPPFLAGS) @openldap_inc@ @ldapsdk_inc@ @nss_inc@ @nspr_inc@
rsearch_bin_LDADD = $(NSPR_LINK) $(NSS_LINK) $(LDAPSDK_LINK) $(SASL_LINK) $(LIBSOCKET)
+#-------------------------
+# CMOCKA TEST PROGRAMS
+#-------------------------
+if WITH_CMOCKA
+
+check_PROGRAMS = test_slapd
+
+test_slapd_SOURCES = test/main.c \
+ test/libslapd/test.c \
+ test/libslapd/pblock/analytics.c
+test_slapd_LDADD = libslapd.la
+test_slapd_LDFLAGS = $(AM_CPPFLAGS) $(CMOCKA_LINKS)
+test_slapd_CPPFLAGS = $(AM_CPPFLAGS) @nspr_inc@
+
+
+
+endif
+#------------------------
+# end cmocka tests
+#------------------------
+
# these are for the config files and scripts that we need to generate and replace
# the paths and other tokens with the real values set during configure/make
# note that we cannot just use AC_OUTPUT to do this for us, since it will do things like
this:
diff --git a/configure.ac b/configure.ac
index d07e00f..38e6480 100644
--- a/configure.ac
+++ b/configure.ac
@@ -688,6 +688,7 @@ m4_include(m4/pcre.m4)
m4_include(m4/selinux.m4)
m4_include(m4/nunc-stans.m4)
m4_include(m4/systemd.m4)
+m4_include(m4/cmocka.m4)
PACKAGE_BASE_VERSION=`echo $PACKAGE_VERSION | awk -F\. '{print
$1"."$2}'`
AC_SUBST(PACKAGE_BASE_VERSION)
diff --git a/m4/cmocka.m4 b/m4/cmocka.m4
new file mode 100644
index 0000000..bb7d4d3
--- /dev/null
+++ b/m4/cmocka.m4
@@ -0,0 +1,33 @@
+## BEGIN COPYRIGHT BLOCK
+## Copyright (c) 2016, William Brown <william at blackhats dot net dot au>
+## All rights reserved.
+##
+## License: License: GPL (version 3 or any later version).
+## See LICENSE for details.
+## END COPYRIGHT BLOCK
+
+AC_MSG_CHECKING(for --enable-cmocka)
+AC_ARG_ENABLE(cmocka, AS_HELP_STRING([--enable-cmocka], [Enable cmocka based tests
(default: no)]),
+[
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([WITH_CMOCKA], [1], [With cmocka unit tests])
+ with_cmocka="yes"
+ AC_MSG_CHECKING(for cmocka)
+ if $PKG_CONFIG --exists cmocka; then
+ cmocka_inc=`$PKG_CONFIG --cflags cmocka`
+ cmocka_lib=`$PKG_CONFIG --libs cmocka`
+ AC_MSG_RESULT([using system cmocka])
+ else
+ AC_MSG_ERROR([pkg-config could not find cmocka!])
+ fi
+],
+[
+ AC_MSG_RESULT(no)
+ with_cmocka="0"
+])
+
+AM_CONDITIONAL([WITH_CMOCKA], [test "$with_cmocka" = "yes"])
+AC_SUBST(cmocka_inc)
+AC_SUBST(cmocka_lib)
+
+
diff --git a/test/libslapd/pblock/analytics.c b/test/libslapd/pblock/analytics.c
new file mode 100644
index 0000000..2493299
--- /dev/null
+++ b/test/libslapd/pblock/analytics.c
@@ -0,0 +1,17 @@
+
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#include "../../test_slapd.h"
+
+void
+test_libslapd_pblock_analytics(void **state __attribute__((unused))) {
+ /* It works! */
+ assert_int_equal(1, 1);
+}
+
diff --git a/test/libslapd/test.c b/test/libslapd/test.c
new file mode 100644
index 0000000..62831c6
--- /dev/null
+++ b/test/libslapd/test.c
@@ -0,0 +1,26 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#include "../test_slapd.h"
+
+void
+test_libslapd_hello(void **state __attribute__((unused))) {
+ /* It works! */
+ assert_int_equal(1, 1);
+}
+
+int
+run_libslapd_tests (void) {
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_libslapd_hello),
+ cmocka_unit_test(test_libslapd_pblock_analytics),
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..d84f8df
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,16 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#include "test_slapd.h"
+
+int
+main ( int argc __attribute__((unused)), char **argv __attribute__((unused))) {
+ int result = 0;
+ result += run_libslapd_tests();
+ return result;
+}
diff --git a/test/test_slapd.h b/test/test_slapd.h
new file mode 100644
index 0000000..1f35b7f
--- /dev/null
+++ b/test/test_slapd.h
@@ -0,0 +1,31 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#pragma once
+
+#include <config.h>
+#include <slapi-plugin.h>
+
+/* For cmocka */
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+/* Test runners */
+int run_libslapd_tests (void);
+
+/* == The tests == */
+
+/* libslapd */
+void test_libslapd_hello(void **state);
+
+/* libslapd-pblock-analytics */
+void test_libslapd_pblock_analytics(void **state);
+
+