Skip to content
Snippets Groups Projects
Commit a415a5e0 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

tests: build fixes, reverted non-mocked override

parent 90b9bea6
Branches
Tags
No related merge requests found
......@@ -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])
......
# 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
......
......@@ -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);
}
......
......@@ -15,6 +15,7 @@
*/
#include "tests/test.h"
#include <cmocka.h>
#include <libknot/internal/mempool.h>
#include "lib/cache.h"
......
......@@ -15,6 +15,7 @@
*/
#include "tests/test.h"
#include <cmocka.h>
#include "lib/context.h"
......
......@@ -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;
}
......@@ -15,6 +15,8 @@
*/
#include "tests/test.h"
#include <cmocka.h>
#include "lib/resolve.h"
static void test_resolve_nullparams(void **state)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment