On (24/02/15 16:55), Jakub Hrozek wrote:
Hi,
the attached two patches add a way to detect pre-1.0 cmocka and adds
compatible definitions in the first patch and uses them to convert a
single unit test.
I found the approach ugly myself, so much that I'm considering converting
all cmocka-based tests to cmocka-1.0 and don't compile the cmocka tests at
all unless 1.0 or later is present on the system. It's not functionality
after all, "just" tests and for CI we could add cmocka-1.0 to the CI
system ourselves..
Opinions?
+1 for patch.
I already see deprecated warnings. cmocka 1.0 is in f21 updates-testing
From e699b9e8b35e680404ce653c986ec9a030dd23aa Mon Sep 17 00:00:00
2001
From: Jakub Hrozek <jhrozek(a)redhat.com>
Date: Tue, 24 Feb 2015 16:09:12 +0100
Subject: [PATCH 1/2] tests: Add backwards-compatible declarations for pre-1.0
cmocka
---
src/external/libcmocka.m4 | 12 ++++++++++++
src/tests/cmocka/common_mock.h | 14 ++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/src/external/libcmocka.m4 b/src/external/libcmocka.m4
index 740d9ad254b50563d4d1cbcab3d10f5920ffd79f..15e5e9294848bca08bd81e288762fae979dcc8b1
100644
--- a/src/external/libcmocka.m4
+++ b/src/external/libcmocka.m4
@@ -15,4 +15,16 @@ AC_DEFUN([AM_CHECK_CMOCKA],
[AC_MSG_WARN([No libcmocka library found, cmocka tests will not be built])]
)
AM_CONDITIONAL([HAVE_CMOCKA], [test x$have_cmocka = xyes])
+
+ dnl Check if we have the new runner or the legacy one
+ SAVE_CFLAGS=$CFLAGS
+ SAVE_LIBS=$LIBS
+ CFLAGS="$CFLAGS $CMOCKA_CFLAGS"
+ LIBS="$LIBS $CMOCKA_LIBS"
+
+ AC_CHECK_FUNCS([_cmocka_run_group_tests])
+
+ CFLAGS=$SAVE_CFLAGS
+ LIBS=$SAVE_LIBS
+
])
diff --git a/src/tests/cmocka/common_mock.h b/src/tests/cmocka/common_mock.h
index f305e6ffc45c61db92494c8b50ea11fbc2b10634..d12a77531fcd47149ef335144981ea45eac889cf
100644
--- a/src/tests/cmocka/common_mock.h
+++ b/src/tests/cmocka/common_mock.h
@@ -53,4 +53,18 @@ enum sss_test_wrapper_call {
WRAP_CALL_REAL
};
+#ifdef HAVE__CMOCKA_RUN_GROUP_TESTS
+#define SSS_CM_FIXTURE_TYPE int
+#define SSS_CM_FIXTURE_RET return 0
+#define SSS_CM_TEST struct CMUnitTest
+#define SSS_CM_TEST_SETUP_TEARDOWN cmocka_unit_test_setup_teardown
+#define SSS_CM_TEST_RUN(tests) cmocka_run_group_tests(tests, NULL, NULL)
+#else
+#define SSS_CM_FIXTURE_TYPE void
+#define SSS_CM_FIXTURE_RET return
+#define SSS_CM_TEST UnitTest
+#define SSS_CM_TEST_SETUP_TEARDOWN unit_test_setup_teardown
What about?
#define cmocka_unit_test_setup_teardown unit_test_setup_teardown
+#define SSS_CM_TEST_RUN(tests) run_tests(tests)
#define
cmocka_run_group_tests(tests, NULL, NULL) run_tests(tests)
It will reduce changes in future if we drop support for old cmocka.
LS