From 5eff725e80bbefebc5ebdc9d53285f6a28d8864e Mon Sep 17 00:00:00 2001
From: Grigorii Demidov <grigorii.demidov@nic.cz>
Date: Fri, 31 Jul 2015 11:31:10 +0200
Subject: [PATCH] tests: libfaketime search

---
 Makefile             |  1 +
 help.mk              |  1 +
 platform.mk          | 15 +++++++++++++++
 tests/integration.mk | 16 +++++-----------
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 5c0ca5463..215076115 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,7 @@ $(eval $(call find_python))
 $(eval $(call find_lib,libmemcached,1.0))
 $(eval $(call find_lib,hiredis))
 $(eval $(call find_lib,socket_wrapper))
+$(eval $(call find_libfaketime))
 
 # Work around luajit on OS X
 ifeq ($(PLATFORM), Darwin)
diff --git a/help.mk b/help.mk
index 1ceef2f30..8740ff6e0 100644
--- a/help.mk
+++ b/help.mk
@@ -21,4 +21,5 @@ info:
 	$(info [$(HAS_libmemcached)] libmemcached (modules/memcached))
 	$(info [$(HAS_hiredis)] hiredis (modules/redis))
 	$(info [$(HAS_socket_wrapper)] socket_wrapper (lib))
+	$(info [$(HAS_libfaketime)] libfaketime (lib))
 	$(info )
diff --git a/platform.mk b/platform.mk
index 39712ed7a..724cd4222 100644
--- a/platform.mk
+++ b/platform.mk
@@ -31,6 +31,13 @@ else
     endif
 endif
 
+# Libfaketime name
+ifeq ($(PLATFORM),Darwin)
+        libfaketime_name := libfaketime.1$(LIBEXT)
+else
+        libfaketime_name := libfaketime$(LIBEXT).1
+endif
+
 # Silent compilation
 ifeq ($(V),1)
 	quiet = $($1)
@@ -124,3 +131,11 @@ define find_python
 	python_LIBS := $(shell $(PYTHON) -c "from distutils import sysconfig as c;print('-L%s -lpython%s' % (c.get_config_var('LIBDIR'), c.get_config_var('VERSION')))")
 	$(call have_lib,python)
 endef
+
+# Find libfaketime
+define find_libfaketime
+        SPACED_PATH := $(subst :, ,$(PATH))
+        libfaketime_LIBS := $(shell find $(HOME)/.local /usr/local $(S_PATH) -name $(libfaketime_name) -print -quit 2> /dev/null)
+	$(call have_lib,libfaketime)
+endef
+
diff --git a/tests/integration.mk b/tests/integration.mk
index d59b1bf44..d68fbf914 100644
--- a/tests/integration.mk
+++ b/tests/integration.mk
@@ -1,20 +1,14 @@
 #
 # 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)
+
+CWRAP_PATH := $(socket_wrapper_LIBS)
+FAKETIME_PATH := $(libfaketime_LIBS)
 
 # Targets
-ifeq ($(PLATFORM),Darwin)
-	preload_syms := DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES="$(FAKETIME_PATH):$(CWRAP_PATH)"
-else
-	preload_syms := LD_PRELOAD="$(FAKETIME_PATH):$(CWRAP_PATH)"
-endif
+preload_syms := LD_PRELOAD="$(FAKETIME_PATH):$(CWRAP_PATH)"
 
-check-integration:
+check-integration: $(libmock_calls) $(_test_integration)
 	$(call preload_LIBS) $(preload_syms) tests/test_integration.py tests/testdata
 
 .PHONY: check-integration
-- 
GitLab