diff --git a/tests/integration.mk b/tests/integration.mk index a76845a2c2cd0ba85603d7d64e883891f51a9b8c..d59b1bf445b3532446784626dce792f8de316591 100644 --- a/tests/integration.mk +++ b/tests/integration.mk @@ -1,27 +1,20 @@ # # Integration tests # - -# Mocked calls library -libmock_calls_SOURCES := tests/mock_calls.c -libmock_calls_LIBS := $(tests_LIBS) $(python_LIBS) -libmock_calls_DEPEND := $(libkres) -$(eval $(call make_lib,libmock_calls,tests)) - -# Python module for tests -_test_integration_SOURCES := tests/test_integration.c -_test_integration_LIBS := -Ltests -lmock_calls $(libmock_calls_LIBS) -_test_integration_DEPEND := $(libmock_calls) -$(eval $(call make_shared,_test_integration,tests)) +CWRAP_PATH := $(shell pkg-config --libs socket_wrapper) +# TODO: find this in ld search paths +# TODO: this requires newer version than is in the Debian to support FAKETIME_TIMESTAMP_FILE +# TODO: maybe we can bundle it (it's small enough) +FAKETIME_PATH := $(wildcard ~/.local/lib/faketime/libfaketime.so.1) # Targets ifeq ($(PLATFORM),Darwin) - preload_syms := DYLD_INSERT_LIBRARIES=tests/libmock_calls.dylib + preload_syms := DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES="$(FAKETIME_PATH):$(CWRAP_PATH)" else - preload_syms := LD_PRELOAD=$(shell pkg-config --libs socket_wrapper) + preload_syms := LD_PRELOAD="$(FAKETIME_PATH):$(CWRAP_PATH)" endif -check-integration: $(libmock_calls) $(_test_integration) +check-integration: $(call preload_LIBS) $(preload_syms) tests/test_integration.py tests/testdata .PHONY: check-integration diff --git a/tests/pydnstest/scenario.py b/tests/pydnstest/scenario.py index c75950db0b5931e7e823a502a6ea7537ed67951e..60ecc4e1f92a771116a30b2ee7a9edc8880f4594 100644 --- a/tests/pydnstest/scenario.py +++ b/tests/pydnstest/scenario.py @@ -6,6 +6,7 @@ import binascii import socket import os import itertools +from datetime import datetime class Entry: """ @@ -313,13 +314,15 @@ class Step: def __time_passes(self, ctx): """ Modify system time. """ -# ctx.scenario.time = int(self.args[1]) -# ctx.set_time(ctx.scenario.time) + ctx.time += int(self.args[1]) + time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w') + time_file.write(datetime.fromtimestamp(ctx.time).strftime('%Y-%m-%d %H:%M:%S') + "\n") class Scenario: def __init__(self, info): """ Initialize scenario with description. """ self.info = info + self.time = 0 self.ranges = [] self.steps = [] self.current_step = None diff --git a/tests/test_integration.py b/tests/test_integration.py index 4d72ebba5e72e75a200db5b64ea94069496253fd..bc9537cb254fe69774932e2f9e6f9beeb5415012 100755 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -10,6 +10,7 @@ import time import signal import stat from pydnstest import scenario, testserver, test +from datetime import datetime # Test debugging TEST_DEBUG = 0 @@ -52,6 +53,13 @@ if TEST_DEBUG > 0: testserver.syn_print(None,"default_iface: {}, child_iface: {}, tmpdir {}".format(DEFAULT_IFACE, CHILD_IFACE, TMPDIR)) del_files(TMPDIR) +# Set up libfaketime +os.environ["FAKETIME_NO_CACHE"] = "1" +os.environ["FAKETIME_TIMESTAMP_FILE"] = '%s/.time' % TMPDIR +time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w') +time_file.write(datetime.fromtimestamp(0).strftime('%Y-%m-%d %H:%M:%S')) +time_file.close() + def get_next(file_in): """ Return next token from the input stream. """ while True: