Index: src/tests/.in/io.data
===================================================================
--- src/tests/.in/io.data	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
+++ src/tests/.in/io.data	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -0,0 +1,1 @@
+falseA 23 93 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz
Index: src/tests/Makefile.am
===================================================================
--- src/tests/Makefile.am	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/Makefile.am	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -15,4 +15,5 @@
 ###############################################################################
 
+
 debug=yes
 
@@ -24,4 +25,6 @@
 concurrent='-Econcurrent'
 endif
+
+TEST_PY = python ${srcdir}/test.py
 
 # applies to both programs
@@ -41,5 +44,5 @@
 TEST_FLAGS = $(if $(test), 2> $(test), )
 AM_CFLAGS = ${TEST_FLAGS} ${BUILD_FLAGS}
-CC = @CFA_BINDIR@/@CFA_NAME@
+CC = ${abs_top_builddir}/src/driver/cfa -DIN_DIR="${srcdir}/.in/"
 
 .PHONY : list
@@ -53,8 +56,8 @@
 
 all-local :
-	@+python test.py --debug=${debug} ${concurrent} ${quick_test}
+	@+${TEST_PY} --debug=${debug} ${concurrent} ${quick_test}
 
 all-tests :
-	@+python test.py --all --debug=${debug} ${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+${TEST_PY} --all --debug=${debug} ${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
@@ -62,76 +65,72 @@
 
 list :
-	@+python test.py --list ${concurrent}
+	@+${TEST_PY} --list ${concurrent}
 
 concurrency :
-	@+python test.py --debug=${debug} -Iconcurrent
+	@+${TEST_PY} --debug=${debug} -Iconcurrent
 
-.dummy : .dummy.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${BUILD_FLAGS} -XCFA -n ${<} -o ${@}				#don't use CFLAGS, this rule is not a real test
-
-
-% : %.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} -o ${@}
+% : ${srcdir}/%.c @CFA_BINDIR@/@CFA_NAME@
+	$(COMPILE) $(abspath ${<}) -o ${@}
 
 declarationSpecifier: declarationSpecifier.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 gccExtensions : gccExtensions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 extension : extension.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 attributes : attributes.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 functions: functions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 KRfunctions : KRfunctions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 sched-ext-parse : sched-ext-parse.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 gmp : gmp.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -lgmp ${<} -o ${@}
+	$(COMPILE) -lgmp $(abspath ${<}) -o ${@}
 
 completeTypeError : completeTypeError.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 fallthrough-ERROR: fallthrough.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 nested-types-ERR1: nested-types.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 nested-types-ERR2: nested-types.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR2 ${<} -o ${@}
+	$(COMPILE) -DERR2 $(abspath ${<}) -o ${@}
 
 # Constructor/destructor tests
 raii/dtor-early-exit-ERR1: raii/dtor-early-exit.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 raii/dtor-early-exit-ERR2: raii/dtor-early-exit.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR2 ${<} -o ${@}
+	$(COMPILE) -DERR2 $(abspath ${<}) -o ${@}
 
 raii/memberCtors-ERR1: raii/memberCtors.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 raii/ctor-autogen-ERR1: raii/ctor-autogen.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 # Warnings
 warnings/self-assignment: warnings/self-assignment.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} 2> ${@} -fsyntax-only
+	$(COMPILE) $(abspath ${<}) 2> ${@} -fsyntax-only
 
 #builtins
 builtins/sync: builtins/sync.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} 2> ${@} -fsyntax-only
+	$(COMPILE) $(abspath ${<}) 2> ${@} -fsyntax-only
Index: src/tests/Makefile.in
===================================================================
--- src/tests/Makefile.in	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/Makefile.in	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -103,5 +103,5 @@
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_FILES = config.py
 CONFIG_CLEAN_VPATH_FILES =
 am__dirstamp = $(am__leading_dot)dirstamp
@@ -180,5 +180,6 @@
 ETAGS = etags
 CTAGS = ctags
-am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/automake/depcomp
+am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.py.in \
+	$(top_srcdir)/automake/depcomp
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
@@ -191,5 +192,5 @@
 AWK = @AWK@
 BACKEND_CC = @BACKEND_CC@
-CC = @CFA_BINDIR@/@CFA_NAME@
+CC = ${abs_top_builddir}/src/driver/cfa -DIN_DIR="${srcdir}/.in/"
 CCAS = @CCAS@
 CCASDEPMODE = @CCASDEPMODE@
@@ -306,4 +307,5 @@
 @BUILD_CONCURRENCY_FALSE@concurrent = '-Econcurrent'
 @BUILD_CONCURRENCY_TRUE@concurrent = 
+TEST_PY = python ${srcdir}/test.py
 
 # applies to both programs
@@ -350,4 +352,6 @@
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
+config.py: $(top_builddir)/config.status $(srcdir)/config.py.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 avltree/$(am__dirstamp):
 	@$(MKDIR_P) avltree
@@ -731,8 +735,8 @@
 
 all-local :
-	@+python test.py --debug=${debug} ${concurrent} ${quick_test}
+	@+${TEST_PY} --debug=${debug} ${concurrent} ${quick_test}
 
 all-tests :
-	@+python test.py --all --debug=${debug} ${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+${TEST_PY} --all --debug=${debug} ${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
@@ -740,77 +744,74 @@
 
 list :
-	@+python test.py --list ${concurrent}
+	@+${TEST_PY} --list ${concurrent}
 
 concurrency :
-	@+python test.py --debug=${debug} -Iconcurrent
-
-.dummy : .dummy.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${BUILD_FLAGS} -XCFA -n ${<} -o ${@}				#don't use CFLAGS, this rule is not a real test
-
-% : %.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} -o ${@}
+	@+${TEST_PY} --debug=${debug} -Iconcurrent
+
+% : ${srcdir}/%.c @CFA_BINDIR@/@CFA_NAME@
+	$(COMPILE) $(abspath ${<}) -o ${@}
 
 declarationSpecifier: declarationSpecifier.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 gccExtensions : gccExtensions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 extension : extension.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 attributes : attributes.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 functions: functions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 KRfunctions : KRfunctions.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 sched-ext-parse : sched-ext-parse.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
+	$(COMPILE) -CFA -XCFA -p $(abspath ${<}) -o ${@}
 
 gmp : gmp.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -lgmp ${<} -o ${@}
+	$(COMPILE) -lgmp $(abspath ${<}) -o ${@}
 
 completeTypeError : completeTypeError.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 fallthrough-ERROR: fallthrough.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 nested-types-ERR1: nested-types.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 nested-types-ERR2: nested-types.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR2 ${<} -o ${@}
+	$(COMPILE) -DERR2 $(abspath ${<}) -o ${@}
 
 # Constructor/destructor tests
 raii/dtor-early-exit-ERR1: raii/dtor-early-exit.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 raii/dtor-early-exit-ERR2: raii/dtor-early-exit.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR2 ${<} -o ${@}
+	$(COMPILE) -DERR2 $(abspath ${<}) -o ${@}
 
 raii/memberCtors-ERR1: raii/memberCtors.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 raii/ctor-autogen-ERR1: raii/ctor-autogen.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
+	$(COMPILE) -DERR1 $(abspath ${<}) -o ${@}
 
 # Warnings
 warnings/self-assignment: warnings/self-assignment.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} 2> ${@} -fsyntax-only
+	$(COMPILE) $(abspath ${<}) 2> ${@} -fsyntax-only
 
 #builtins
 builtins/sync: builtins/sync.c @CFA_BINDIR@/@CFA_NAME@
-	${CC} ${AM_CFLAGS} ${CFLAGS} ${<} 2> ${@} -fsyntax-only
+	$(COMPILE) $(abspath ${<}) 2> ${@} -fsyntax-only
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
Index: src/tests/config.py.in
===================================================================
--- src/tests/config.py.in	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
+++ src/tests/config.py.in	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+config.py
+"""
+
+SRCDIR   = "@srcdir@"
+BUILDDIR = "@builddir@"
+HOSTARCH = "@host_cpu@"
Index: src/tests/io.data
===================================================================
--- src/tests/io.data	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ 	(revision )
@@ -1,1 +1,0 @@
-falseA 23 93 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz
Index: src/tests/io2.c
===================================================================
--- src/tests/io2.c	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/io2.c	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -1,10 +1,10 @@
-// 
+//
 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
 //
 // The contents of this file are covered under the licence agreement in the
 // file "LICENCE" distributed with Cforall.
-// 
-// io2.c -- 
-// 
+//
+// io2.c --
+//
 // Author           : Peter A. Buhr
 // Created On       : Wed Mar  2 16:56:02 2016
@@ -12,7 +12,10 @@
 // Last Modified On : Thu May 24 21:17:41 2018
 // Update Count     : 103
-// 
+//
 
 #include <fstream>
+
+ #define xstr(s) str(s)
+#define str(s) #s
 
 int main() {
@@ -38,5 +41,5 @@
 	char s1[size], s2[size];
 
-	ifstream in = { "io.data" };						// create / open file
+	ifstream in = { xstr(IN_DIR) "io.data" };						// create / open file
 
 	sout | "input bacis types" | endl;
Index: src/tests/pybin/settings.py
===================================================================
--- src/tests/pybin/settings.py	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/pybin/settings.py	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -1,3 +1,16 @@
+from __future__ import print_function
+
+import os
 import sys
+
+try :
+	sys.path.append(os.getcwd())
+	import config
+
+	SRCDIR = os.path.abspath(config.SRCDIR)
+	BUILDDIR = os.path.abspath(config.BUILDDIR)
+except:
+	print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
+	sys.exit(1)
 
 class Architecture:
@@ -5,4 +18,5 @@
 		'x64'			: 'x64',
 		'x86-64'		: 'x64',
+		'x86_64'		: 'x64',
 		'x86'			: 'x86',
 		'i386'		: 'x86',
@@ -25,5 +39,5 @@
 			self.cross_compile = False
 			try:
-				arch = machine_default()
+				arch = config.HOSTARCH
 				self.target = Architecture.makeCanonical( arch )
 			except KeyError:
@@ -66,12 +80,7 @@
 	arch       = Architecture(options.arch)
 
+
 def updateMakeCmd(force, jobs):
 	global make
 
 	make = "make" if not force else ("make -j%i" % jobs)
-
-
-def set_machine_default( func ):
-	global machine_default
-
-	machine_default = func
Index: src/tests/pybin/test_run.py
===================================================================
--- src/tests/pybin/test_run.py	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/pybin/test_run.py	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -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 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/pybin/tools.py	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -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,34 +160,14 @@
 		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, '')
 
 ################################################################################
 #               system
 ################################################################################
-
-# parses the Makefile to find the machine type (32-bit / 64-bit)
-def getMachineType():
-	sh('echo "void ?{}(int&a,int b){}int main(){return 0;}" > .dummy.c')
-	ret, out = make('.dummy', silent = True)
-
-	if ret != 0:
-		print("Failed to identify architecture:")
-		print(out)
-		print("Stopping")
-		rm( (".dummy.c",".dummy") )
-		sys.exit(1)
-
-	_, out = sh("file .dummy", print2stdout=False)
-	rm( (".dummy.c",".dummy") )
-
-	if settings.dry_run :
-		return 'x64'
-
-	return re.search(r"[^,]+,([^,]+),", out).group(1).strip()
-
 # count number of jobs to create
 def jobCount( options, tests ):
@@ -244,4 +233,2 @@
 	else:
 		print(text)
-
-settings.set_machine_default( getMachineType )
Index: src/tests/test.py
===================================================================
--- src/tests/test.py	(revision 40a7d9c4e045d2ccfb4f7032a6cc0e9e62d9c75c)
+++ src/tests/test.py	(revision f0b3f51fef07efa32e0bc86fc241753f438f52b0)
@@ -19,5 +19,5 @@
 
 	def matchTest(path):
-		match = re.search("(\.[\w\/\-_]*)\/.expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt", path)
+		match = re.search("%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt" % settings.SRCDIR, path)
 		if match :
 			test = Test()
@@ -116,8 +116,17 @@
 #               running test functions
 ################################################################################
+# fix the absolute paths in the output
+def fixoutput( fname ):
+	if not is_ascii(fname):
+		return
+
+	file_replace(fname, "%s/" % settings.SRCDIR, "")
+
+
 # logic to run a single test and return the result (No handling of printing or other test framework logic)
 def run_single_test(test):
 
 	# find the output file based on the test name and options flag
+	exe_file = test.target_executable();
 	out_file = test.target_output()
 	err_file = test.error_log()
@@ -129,5 +138,5 @@
 
 	# remove any outputs from the previous tests to prevent side effects
-	rm( (out_file, err_file, test.target()) )
+	rm( (out_file, err_file, exe_file) )
 
 	# build, skipping to next test on error
@@ -146,10 +155,10 @@
 	if make_ret == 0 or settings.dry_run:
 		before = time.time()
-		if settings.dry_run or fileIsExecutable(test.target()) :
+		if settings.dry_run or fileIsExecutable(exe_file) :
 			# run test
-			retcode, _ = sh("timeout 60 %s > %s 2>&1" % (test.target(), out_file), input = in_file)
+			retcode, _ = sh("timeout 60 %s > %s 2>&1" % (exe_file, out_file), input = in_file)
 		else :
 			# simply cat the result into the output
-			retcode, _ = sh("cat %s > %s" % (test.target(), out_file))
+			retcode, _ = sh("cat %s > %s" % (exe_file, out_file))
 
 		after = time.time()
@@ -170,4 +179,5 @@
 		else :
 			# fetch return code and error from the diff command
+			fixoutput(out_file)
 			retcode, error = diff(cmp_file, out_file)
 
@@ -241,6 +251,4 @@
 ################################################################################
 if __name__ == "__main__":
-	#always run from same folder
-	chdir()
 
 	# parse the command line arguments
