]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests: build fixes, reverted non-mocked override
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sat, 17 Jan 2015 21:56:32 +0000 (22:56 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 18 Jan 2015 09:50:04 +0000 (10:50 +0100)
configure.ac
tests/Makefile.am
tests/test.h
tests/test_cache.c
tests/test_context.c
tests/test_integration.c
tests/test_resolve.c

index 62d7a26137ac008d9f4b2f317894b7fe616ee471..cd3d43b0edf34f9028f4ac65f0caa5bd6f832081 100644 (file)
@@ -28,7 +28,7 @@ LT_INIT
 PKG_PROG_PKG_CONFIG
 
 # Check for dependencies
-AC_CHECK_FUNCS([opendir, mkdtemp, gettimeofday, time])
+AC_CHECK_FUNCS([opendir mkdtemp gettimeofday time])
 PKG_CHECK_MODULES([libknot], [libknot])
 PKG_CHECK_MODULES([libuv], [libuv], [build_daemon=yes], [build_daemon=no])
 PKG_CHECK_MODULES([cmocka], [cmocka], [build_tests=yes], [build_tests=no])
index 37ce059be64b88f62c30b289a353519a79339123..653640dcb89a365abba61fcc58fe00ce32502fb3 100644 (file)
@@ -1,6 +1,3 @@
-# Unit tests
-if BUILD_TESTS
-
 AM_CPPFLAGS = \
        -include $(top_builddir)/config.h \
        -I$(top_srcdir)/lib \
@@ -12,6 +9,8 @@ LDADD = \
        $(libknot_LIBS) \
        $(cmocka_LIBS)
 
+# Unit tests
+if BUILD_TESTS
 
 check_PROGRAMS = \
        test_cache \
@@ -23,6 +22,10 @@ check-local-exec: $(check_PROGRAMS)
        @echo "---- Executing unit tests ----"
        $(top_builddir)/tests/runtests -b $(top_builddir)/tests $(check_PROGRAMS)
 
+else
+
+check-local-exec:
+
 endif
 
 # Integration tests
@@ -30,21 +33,21 @@ if BUILD_INTEGRATION
 
 check_LTLIBRARIES = _test_integration.la
 _test_integration_la_SOURCES = test_integration.c
-_test_integration_la_CPPFLAGS = $(PYTHON_CPPFLAGS) $(AM_CPPFLAGS)
-_test_integration_la_LDFLAGS = -rpath $(abs_builddir) -module -shared -avoid-version --wrap=gettimeofday
+_test_integration_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_CPPFLAGS)
+_test_integration_la_LDFLAGS = $(LDFLAGS) -rpath $(abs_builddir) -module -shared -avoid-version --wrap=gettimeofday
 _test_integration_la_LIBADD = $(top_builddir)/lib/libkresolve_static.la $(libknot_LIBS) $(PYTHON_LIBS)
 
-convenience-link: $(noinst_LTLIBRARIES)
-       @for soname in `echo | $(EGREP) "^dlname=" $(noinst_LTLIBRARIES) | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do  \
+convenience-link: $(check_LTLIBRARIES)
+       @for soname in `echo | $(EGREP) "^dlname=" $(check_LTLIBRARIES) | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do  \
                rm -f $(abs_builddir)/$$soname; $(LN_S) $(abs_builddir)/.libs/$$soname $$soname || true;\
        done
 
 check-local-integration: convenience-link
        @echo "---- Executing integration tests ----"
-       echo ./test_integration.py testdata
+       @$(abs_builddir)/test_integration.py testdata
 
 clean-local:
-       @for soname in `echo | $(EGREP) "^dlname=" $(noinst_LTLIBRARIES) | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do  \
+       @for soname in `echo | $(EGREP) "^dlname=" $(check_LTLIBRARIES) | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do  \
                test -L $(abs_builddir)/$$soname && rm -f $(abs_builddir)/$$soname || true; \
        done
 else
index 8a3a3229221742592d3ffb879b55ee04abe23e93..4d864009e72650f9a03cae84d4f3cce4cff3250c 100644 (file)
@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <dirent.h>
 #include <unistd.h>
-#include <cmocka.h>
 
 #include <libknot/internal/mempattern.h>
 #include <libknot/descriptor.h>
@@ -62,7 +61,8 @@ static inline int test_tmpdir_remove(const char *path)
 /*! \brief Create temporary directory. */
 static inline const char* test_tmpdir_create(void)
 {
-       static char env_path[64] = "./tmpXXXXXX";
+       static char env_path[64];
+       strcpy(env_path, "./tmpXXXXXX");
        return mkdtemp(env_path);
 }
 
index fb4444adb235421b6c83db8bf7c7f9bc579d12f9..26627e28a818daaa37d704b25999a04e8c3682d9 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "tests/test.h"
+#include <cmocka.h>
 
 #include <libknot/internal/mempool.h>
 #include "lib/cache.h"
index 27fe8feeace0c4ae8266f729c79e1c28eaa2099f..f9fee51cb0561282f1662351bfa50d1f49860988 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "tests/test.h"
+#include <cmocka.h>
 
 #include "lib/context.h"
 
index d383cb05e8dafd0eff3fb73e1040c5034ef1e2e4..15d95091a2c86402511adb766aef243e01a4dba3 100644 (file)
@@ -46,12 +46,9 @@ static PyObject* init(PyObject* self, PyObject* args)
        test_mm_ctx_init(&global_mm);
        kr_context_init(&global_context, &global_mm);
        global_tmpdir = test_tmpdir_create();
+       assert(global_tmpdir);
        global_context.cache = kr_cache_open(global_tmpdir, &global_mm, CACHE_SIZE);
-       if (global_context.cache == NULL) {
-               test_tmpdir_remove(global_tmpdir);
-               kr_context_deinit(&global_context);
-               return NULL;
-       }
+       assert(global_context.cache);
 
        return Py_BuildValue("s", PACKAGE_STRING " (integration tests)");
 }
@@ -146,12 +143,8 @@ PyMODINIT_FUNC init_test_integration(void)
 
 int __wrap_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
-       if (_mock_fd < 0) {
-               gettimeofday(tv, tz);
-       } else {
-               memcpy(tv, &_mock_time, sizeof(struct timeval));
-       }
        fprintf(stderr, "gettimeofday = %ld\n", tv->tv_sec);
+       memcpy(tv, &_mock_time, sizeof(struct timeval));
        return 0;
 }
 
@@ -160,11 +153,7 @@ int net_unbound_socket(int type, const struct sockaddr_storage *ss)
        char addr_str[SOCKADDR_STRLEN];
        sockaddr_tostr(addr_str, sizeof(addr_str), ss);
        fprintf(stderr, "%s (%d, %s)\n", __func__, type, addr_str);
-       if (_mock_fd < 0) {
-               return net_unbound_socket(type, ss);
-       } else {
-               return _mock_fd;
-       }
+       return _mock_fd;
 }
 
 int net_bound_socket(int type, const struct sockaddr_storage *ss)
@@ -172,11 +161,7 @@ int net_bound_socket(int type, const struct sockaddr_storage *ss)
        char addr_str[SOCKADDR_STRLEN];
        sockaddr_tostr(addr_str, sizeof(addr_str), ss);
        fprintf(stderr, "%s (%d, %s)\n", __func__, type, addr_str);
-       if (_mock_fd < 0) {
-               return net_bound_socket(type, ss);
-       } else {
-               return _mock_fd;
-       }
+       return _mock_fd;
 }
 
 int net_connected_socket(int type, const struct sockaddr_storage *dst_addr,
@@ -186,19 +171,11 @@ int net_connected_socket(int type, const struct sockaddr_storage *dst_addr,
        sockaddr_tostr(dst_addr_str, sizeof(dst_addr_str), dst_addr);
        sockaddr_tostr(src_addr_str, sizeof(src_addr_str), src_addr);
        fprintf(stderr, "%s (%d, %s, %s, %u)\n", __func__, type, dst_addr_str, src_addr_str, flags);
-       if (_mock_fd < 0) {
-               return net_connected_socket(type, dst_addr, src_addr, flags);
-       } else {
-               return _mock_fd;
-       }
+       return _mock_fd;
 }
 
 int net_is_connected(int fd)
 {
        fprintf(stderr, "%s (%d)\n", __func__, fd);
-       if (fd < 0) {
-               return false;
-       } else {
-               return net_is_connected(fd);
-       }
+       return true;
 }
index 50b38f2d9c0ad8473c724c255e89a0f782c88890..878ce54b5a94d36071c9856ecc1b075055dfa2da 100644 (file)
@@ -15,6 +15,8 @@
  */
 
 #include "tests/test.h"
+#include <cmocka.h>
+
 #include "lib/resolve.h"
 
 static void test_resolve_nullparams(void **state)