Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision d65f92c77f5cc157071fd474ca2ad557b54f447b)
+++ tests/Makefile.am	(revision 5c4a473263a1f2ef808350180716b59825140af6)
@@ -22,4 +22,5 @@
 debug=yes
 installed=no
+archiveerrors=
 
 INSTALL_FLAGS=-in-tree
@@ -58,8 +59,8 @@
 #----------------------------------------------------------------------------------------------------------------
 all-local :
-	@+${TEST_PY} --debug=${debug} --install=${installed} ${concurrent} ${timeouts} ${quick_test}
+	@+${TEST_PY} --debug=${debug} --install=${installed} --archive-errors=${archiveerrors} ${concurrent} ${timeouts} ${quick_test}
 
 all-tests :
-	@+${TEST_PY} --debug=${debug} --install=${installed} ${concurrent} ${timeouts} --all # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+${TEST_PY} --debug=${debug} --install=${installed} --archive-errors=${archiveerrors} ${concurrent} ${timeouts} --all # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
Index: tests/Makefile.in
===================================================================
--- tests/Makefile.in	(revision d65f92c77f5cc157071fd474ca2ad557b54f447b)
+++ tests/Makefile.in	(revision 5c4a473263a1f2ef808350180716b59825140af6)
@@ -378,4 +378,5 @@
 debug = yes
 installed = no
+archiveerrors = 
 INSTALL_FLAGS = -in-tree
 DEBUG_FLAGS = -debug -O0
@@ -777,8 +778,8 @@
 #----------------------------------------------------------------------------------------------------------------
 all-local :
-	@+${TEST_PY} --debug=${debug} --install=${installed} ${concurrent} ${timeouts} ${quick_test}
+	@+${TEST_PY} --debug=${debug} --install=${installed} --archive-errors=${archiveerrors} ${concurrent} ${timeouts} ${quick_test}
 
 all-tests :
-	@+${TEST_PY} --debug=${debug} --install=${installed} ${concurrent} ${timeouts} --all # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+${TEST_PY} --debug=${debug} --install=${installed} --archive-errors=${archiveerrors} ${concurrent} ${timeouts} --all # '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
Index: tests/pybin/settings.py
===================================================================
--- tests/pybin/settings.py	(revision d65f92c77f5cc157071fd474ca2ad557b54f447b)
+++ tests/pybin/settings.py	(revision 5c4a473263a1f2ef808350180716b59825140af6)
@@ -4,5 +4,8 @@
 from . import tools
 
+global original_path
+
 try :
+	original_path = os.getcwd()
 	testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
 	sys.path.append(testpath)
@@ -118,5 +121,9 @@
 	global timeout
 	global output_width
+<<<<<<< HEAD
 	global distcc
+=======
+	global archive
+>>>>>>> master
 
 	dry_run      = options.dry_run
@@ -128,5 +135,9 @@
 	timeout      = Timeouts(options.timeout, options.global_timeout)
 	output_width = 24
+<<<<<<< HEAD
 	distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
+=======
+	archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
+>>>>>>> master
 
 	if distribute and not os.environ.get('DISTCC_LOG'):
Index: tests/pybin/tools.py
===================================================================
--- tests/pybin/tools.py	(revision d65f92c77f5cc157071fd474ca2ad557b54f447b)
+++ tests/pybin/tools.py	(revision 5c4a473263a1f2ef808350180716b59825140af6)
@@ -2,4 +2,5 @@
 import argparse
 import contextlib
+import datetime
 import fileinput
 import multiprocessing
@@ -289,4 +290,10 @@
 	return out.strip()
 
+# get pretty string for time of day
+def pretty_now():
+	ts = time.time()
+	print(ts, file=sys.stderr)
+	return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
+
 # check if arguments is yes or no
 def yes_no(string):
@@ -320,4 +327,21 @@
 	return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
 
+def core_archive(dst, name, exe):
+	# Get the files to copy
+	core = os.path.join(os.getcwd(), "core" )
+
+	# Uncomment if we want timestamps on coredumps
+	# dst  = os.path.join(dst, "%s_%s" % (name, pretty_now()))
+
+	# make a directory for this test
+	mkdir(os.path.join(dst, "dir"))
+
+	# moves the files
+	mv( core, os.path.join(dst, "core" ) )
+	mv( exe , os.path.join(dst, name   ) )
+
+	# return explanatory test
+	return "Archiving %s (executable and core) to %s" % (os.path.relpath(exe, settings.BUILDDIR), os.path.relpath(dst, settings.original_path))
+
 class Timed:
     def __enter__(self):
Index: tests/test.py
===================================================================
--- tests/test.py	(revision d65f92c77f5cc157071fd474ca2ad557b54f447b)
+++ tests/test.py	(revision 5c4a473263a1f2ef808350180716b59825140af6)
@@ -91,4 +91,5 @@
 	parser.add_argument('--all', help='Run all test available', action='store_true')
 	parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
+	parser.add_argument('--archive-errors', help='If called with a valid path, on test crashes the test script will copy the core dump and the executable to the specified path.', type=str, default='')
 	parser.add_argument('-j', '--jobs', help='Number of tests to run simultaneously', type=int)
 	parser.add_argument('--list-comp', help='List all valide arguments', action='store_true')
@@ -179,4 +180,7 @@
 			error = error + info if error else info
 
+			if settings.archive:
+				error = error + '\n' + core_archive(settings.archive, test.target(), exe_file)
+
 
 
@@ -295,5 +299,5 @@
 	# users may want to simply list the tests
 	if options.list_comp :
-		print("-h --help --debug --dry-run --list --arch --all --regenerate-expected --install --timeout --global-timeout -j --jobs ", end='')
+		print("-h --help --debug --dry-run --list --arch --all --regenerate-expected --archive-errors --install --timeout --global-timeout -j --jobs ", end='')
 		print(" ".join(map(lambda t: "%s" % (t.target()), tests)))
 
