From: Marek VavruĊĦa Date: Sat, 17 Jan 2015 21:56:32 +0000 (+0100) Subject: tests: build fixes, reverted non-mocked override X-Git-Tag: v1.0.0-beta1~363^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a415a5e03f4f35842e58cd9001eaf4cb4025080e;p=thirdparty%2Fknot-resolver.git tests: build fixes, reverted non-mocked override --- diff --git a/configure.ac b/configure.ac index 62d7a2613..cd3d43b0e 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 37ce059be..653640dcb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/test.h b/tests/test.h index 8a3a32292..4d864009e 100644 --- a/tests/test.h +++ b/tests/test.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -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); } diff --git a/tests/test_cache.c b/tests/test_cache.c index fb4444adb..26627e28a 100644 --- a/tests/test_cache.c +++ b/tests/test_cache.c @@ -15,6 +15,7 @@ */ #include "tests/test.h" +#include #include #include "lib/cache.h" diff --git a/tests/test_context.c b/tests/test_context.c index 27fe8feea..f9fee51cb 100644 --- a/tests/test_context.c +++ b/tests/test_context.c @@ -15,6 +15,7 @@ */ #include "tests/test.h" +#include #include "lib/context.h" diff --git a/tests/test_integration.c b/tests/test_integration.c index d383cb05e..15d95091a 100644 --- a/tests/test_integration.c +++ b/tests/test_integration.c @@ -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; } diff --git a/tests/test_resolve.c b/tests/test_resolve.c index 50b38f2d9..878ce54b5 100644 --- a/tests/test_resolve.c +++ b/tests/test_resolve.c @@ -15,6 +15,8 @@ */ #include "tests/test.h" +#include + #include "lib/resolve.h" static void test_resolve_nullparams(void **state)