Index: src/tests/pybin/settings.py
===================================================================
--- src/tests/pybin/settings.py	(revision ed45af6f6acde96306cc96f68086405acdb80877)
+++ src/tests/pybin/settings.py	(revision f85bc15883101cc8666be04202f70b30a32a52ff)
@@ -1,3 +1,16 @@
+from __future__ import print_function
+
+import os
 import sys
+
+try :
+	sys.path.append(os.getcwd())
+	from config import *
+
+	SRCDIR = os.path.abspath(SRCDIR)
+	BUILDDIR = os.path.abspath(BUILDDIR)
+except:
+	print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
+	sys.exit(1)
 
 class Architecture:
@@ -66,4 +79,5 @@
 	arch       = Architecture(options.arch)
 
+
 def updateMakeCmd(force, jobs):
 	global make
Index: src/tests/pybin/test_run.py
===================================================================
--- src/tests/pybin/test_run.py	(revision ed45af6f6acde96306cc96f68086405acdb80877)
+++ src/tests/pybin/test_run.py	(revision f85bc15883101cc8666be04202f70b30a32a52ff)
@@ -33,14 +33,14 @@
 
 	def expect(self):
-		return ("%s/.expect/%s%s.txt" % (self.path, self.name, '' if not self.arch else ".%s" % self.arch))
+		return ("%s.expect/%s%s.txt" % (os.path.join(settings.SRCDIR, self.path), self.name, '' if not self.arch else ".%s" % self.arch))
 
 	def error_log(self):
-		return ("%s/.err/%s.log"    % (self.path, self.name))
+		return ("%s.err/%s.log"    % (os.path.join(settings.BUILDDIR, self.path), self.name))
 
 	def output_log(self):
-		return ("%s/.out/%s.log"    % (self.path, self.name))
+		return ("%s.out/%s.log"    % (os.path.join(settings.BUILDDIR, self.path), self.name))
 
 	def input(self):
-		return ("%s/.in/%s.txt"     % (self.path, self.name))
+		return ("%s.in/%s.txt"     % (os.path.join(settings.SRCDIR, self.path), self.name))
 
 	def target_output(self):
@@ -49,4 +49,7 @@
 	def target(self):
 		return os.path.join(self.path, self.name)
+
+	def target_executable(self):
+		return os.path.join(settings.BUILDDIR, self.path, self.name)
 
 	@classmethod
Index: src/tests/pybin/tools.py
===================================================================
--- src/tests/pybin/tools.py	(revision ed45af6f6acde96306cc96f68086405acdb80877)
+++ src/tests/pybin/tools.py	(revision f85bc15883101cc8666be04202f70b30a32a52ff)
@@ -9,4 +9,5 @@
 import stat
 import sys
+import fileinput
 
 from pybin import settings
@@ -33,4 +34,19 @@
 		out, err = proc.communicate()
 		return proc.returncode, out
+
+def is_ascii(fname):
+	if not os.path.isfile(fname):
+		return False
+
+	code, out = sh("file %s" % fname, print2stdout = False)
+	if code != 0:
+		return False
+
+	match = re.search(".*: (.*)", out)
+
+	if not match:
+		return False
+
+	return match.group(1) == "ASCII text"
 
 # Remove 1 or more files silently
@@ -105,17 +121,8 @@
 # helper function to replace patterns in a file
 def file_replace(fname, pat, s_after):
-    # first, see if the pattern is even in the file.
-    with open(fname) as f:
-        if not any(re.search(pat, line) for line in f):
-            return # pattern does not occur in file so we are done.
-
-    # pattern is in the file, so perform replace operation.
-    with open(fname) as f:
-        out_fname = fname + ".tmp"
-        out = open(out_fname, "w")
-        for line in f:
-            out.write(re.sub(pat, s_after, line))
-        out.close()
-        os.rename(out_fname, fname)
+	file = fileinput.FileInput(fname, inplace=True, backup='.bak')
+	for line in file:
+		print(line.replace(pat, s_after), end='')
+	file.close()
 
 # helper function to check if a files contains only a specific string
@@ -140,5 +147,7 @@
 # transform path to canonical form
 def canonicalPath(path):
-	return os.path.join('.', os.path.normpath(path) )
+	abspath = os.path.abspath(__main__.__file__)
+	dname = os.path.dirname(abspath)
+	return os.path.join(dname, os.path.normpath(path) )
 
 # compare path even if form is different
@@ -151,9 +160,10 @@
 		for name in names:
 			path = os.path.join(dirname, name)
-
 			op( path )
 
 	# Start the walk
-	os.path.walk('.', step, '')
+	abspath = os.path.abspath(__main__.__file__)
+	dname = os.path.dirname(abspath)
+	os.path.walk(dname, step, '')
 
 ################################################################################
