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

tests/integration: added libfaketime support, fixes TIME_PASSES

this needs more work to find the correct libfaketime library
(newer version is required for FAKETIME_TIMESTAMP_FILE)
we may bundle it as it's small
parent f65b197c
Branches
Tags
No related merge requests found
#
# 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
......@@ -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
......
......@@ -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:
......
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