Index: src/tests/test.py
===================================================================
--- src/tests/test.py	(revision 592b9fa3cfeca3a21eec108d4e3bc3463feb8e54)
+++ src/tests/test.py	(revision 075d8620a9e3b58251b90d775e62e592aafc6750)
@@ -9,9 +9,10 @@
 
 import argparse
+import multiprocessing
 import os
 import re
+import signal
 import stat
 import sys
-import multiprocessing
 
 ################################################################################
@@ -27,10 +28,14 @@
 def getMachineType():
 	sh('echo "void ?{}(int*a,int b){}int main(){return 0;}" > .dummy.c')
-	ret, out = sh("make .dummy", print2stdout=False)
+	ret, out = sh("make .dummy -s", print2stdout=False)
+	
 	if ret != 0:
 		print("Failed to identify architecture:")
 		print(out)
 		print("Stopping")
+		sh("rm -f .dummy.c > /dev/null 2>&1")
+		sh("rm -f .dummy > /dev/null 2>&1")
 		sys.exit(1)
+
 	_, out = sh("file .dummy", print2stdout=False)
 	sh("rm -f .dummy.c > /dev/null 2>&1")
@@ -119,102 +124,103 @@
 def run_single_test(test, generate, dry_run, debug):
 
-	# find the output file based on the test name and options flag
-	out_file = (".out/%s.log" % test.name) if not generate else (".expect/%s.txt" % test.path)
-	err_file = ".err/%s.log" % test.name
-
-	# remove any outputs from the previous tests to prevent side effects
-	sh("rm -f %s" % out_file, dry_run)
-	sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
-
-	options = "-debug" if debug else "-nodebug";
-
-	# build, skipping to next test on error
-	make_ret, _ = sh("""%s test=yes EXTRA_FLAGS="-quiet %s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run)
-
-	# if the make command succeds continue otherwise skip to diff
-	if make_ret == 0 :
-		# fetch optional input
-		stdinput = "< .in/%s.txt" % test.name if isfile(".in/%s.txt" % test.path) else ""
-
-		if fileIsExecutable(test.name) :
-			# run test
-			sh("./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run)
+	try : 
+		# find the output file based on the test name and options flag
+		out_file = (".out/%s.log" % test.name) if not generate else (".expect/%s.txt" % test.path)
+		err_file = ".err/%s.log" % test.name
+
+		# remove any outputs from the previous tests to prevent side effects
+		sh("rm -f %s" % out_file, dry_run)
+		sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
+
+		options = "-debug" if debug else "-nodebug";
+
+		# build, skipping to next test on error
+		make_ret, _ = sh("""%s test=yes EXTRA_FLAGS="-quiet %s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run)
+
+		# if the make command succeds continue otherwise skip to diff
+		if make_ret == 0 :
+			# fetch optional input
+			stdinput = "< .in/%s.txt" % test.name if isfile(".in/%s.txt" % test.path) else ""
+
+			if fileIsExecutable(test.name) :
+				# run test
+				sh("./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run)
+			else :
+				# simply cat the result into the output
+				sh("cat %s > %s" % (test.name, out_file), dry_run)
+
 		else :
-			# simply cat the result into the output
-			sh("cat %s > %s" % (test.name, out_file), dry_run)
-
+			# command failed save the log to less temporary file
+			sh("mv %s %s" % (err_file, out_file), dry_run)
+
+		retcode = 0
+		error = None
+
+		# # fix output to prevent make depth to cause issues
+		# fix_MakeLevel(out_file)
+
+		if generate :
+			# if we are ounly generating the output we still need to check that the test actually exists
+			if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.name) :
+				retcode = 1;
+				error = "\t\tNo make target for test %s!" % test.name
+				sh("rm %s" % out_file, False)
+
+		else :
+			# diff the output of the files
+			diff_cmd = ("diff --ignore-all-space "
+						"--ignore-blank-lines "
+						"--old-group-format='\t\tmissing lines :\n"
+						"%%<' \\\n"
+						"--new-group-format='\t\tnew lines :\n"
+						"%%>' \\\n"
+						"--unchanged-group-format='%%=' \\"
+						"--changed-group-format='\t\texpected :\n"
+						"%%<\n"
+						"\t\tgot :\n"
+						"%%>' \\\n"
+						"--new-line-format='\t\t%%dn\t%%L' \\\n"
+						"--old-line-format='\t\t%%dn\t%%L' \\\n"
+						"--unchanged-line-format='' \\\n"
+						".expect/%s.txt .out/%s.log")
+
+			# fetch return code and error from the diff command
+			retcode, error = sh(diff_cmd % (test.path, test.name), dry_run, False)	
+	finally :
+		# clean the executable
+		sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
+
+	return retcode, error
+
+def run_test_instance(t, generate, dry_run, debug) :
+
+	signal.signal(signal.SIGINT, signal.SIG_DFL)
+	# print formated name
+	name_txt = "%20s  " % t.name
+
+	#run the test instance and collect the result
+	test_failed, error = run_single_test(t, generate, dry_run, debug)
+
+	# update output based on current action
+	if generate :
+		failed_txt = "ERROR"
+		success_txt = "Done"
 	else :
-		# command failed save the log to less temporary file
-		sh("mv %s %s" % (err_file, out_file), dry_run)
-
-	retcode = 0
-	error = None
-
-	# # fix output to prevent make depth to cause issues
-	# fix_MakeLevel(out_file)
-
-	if generate :
-		# if we are ounly generating the output we still need to check that the test actually exists
-		if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.name) :
-			retcode = 1;
-			error = "\t\tNo make target for test %s!" % test.name
-			sh("rm %s" % out_file, False)
-
-	else :
-		# diff the output of the files
-		diff_cmd = ("diff --ignore-all-space "
-					"--ignore-blank-lines "
-					"--old-group-format='\t\tmissing lines :\n"
-					"%%<' \\\n"
-					"--new-group-format='\t\tnew lines :\n"
-					"%%>' \\\n"
-					"--unchanged-group-format='%%=' \\"
-					"--changed-group-format='\t\texpected :\n"
-					"%%<\n"
-					"\t\tgot :\n"
-					"%%>' \\\n"
-					"--new-line-format='\t\t%%dn\t%%L' \\\n"
-					"--old-line-format='\t\t%%dn\t%%L' \\\n"
-					"--unchanged-line-format='' \\\n"
-					".expect/%s.txt .out/%s.log")
-
-		# fetch return code and error from the diff command
-		retcode, error = sh(diff_cmd % (test.path, test.name), dry_run, False)
-
-	# clean the executable
-	sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
-
-	return retcode, error
-
-def run_test_instance(t, generate, dry_run, debug) :
-	try :
-		# print formated name
-		name_txt = "%20s  " % t.name
-
-		#run the test instance and collect the result
-		test_failed, error = run_single_test(t, generate, dry_run, debug)
-
-		# update output based on current action
-		if generate :
-			failed_txt = "ERROR"
-			success_txt = "Done"
-		else :
-			failed_txt = "FAILED"
-			success_txt = "PASSED"
-
-		#print result with error if needed
-		text = name_txt + (failed_txt if test_failed else success_txt)
-		out = sys.stdout
-		if error :
-			text = text + "\n" + error
-			out = sys.stderr
-
-		print(text, file = out);
-		sys.stdout.flush()
-		sys.stderr.flush()
-		return test_failed
-
-	except KeyboardInterrupt:
-		test_failed = True
+		failed_txt = "FAILED"
+		success_txt = "PASSED"
+
+	#print result with error if needed
+	text = name_txt + (failed_txt if test_failed else success_txt)
+	out = sys.stdout
+	if error :
+		text = text + "\n" + error
+		out = sys.stderr
+
+	print(text, file = out);
+	sys.stdout.flush()
+	sys.stderr.flush()
+	signal.signal(signal.SIGINT, signal.SIG_IGN)
+
+	return test_failed
 
 
@@ -231,5 +237,7 @@
 
 	# for each test to run
+	original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
 	pool = Pool(jobs)
+	signal.signal(signal.SIGINT, original_sigint_handler)
 	try :
 		results = pool.map_async(partial(run_test_instance, generate=generate, dry_run=dry_run, debug=debug), tests ).get(9999)
@@ -260,4 +268,8 @@
 #               main loop
 ################################################################################
+abspath = os.path.abspath(__file__)
+dname = os.path.dirname(abspath)
+os.chdir(dname)
+
 # create a parser with the arguments for the tests script
 parser = argparse.ArgumentParser(description='Script which runs cforall tests')
@@ -269,12 +281,15 @@
 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('-j', '--jobs', help='Number of tests to run simultaneously', type=int, default='8')
+parser.add_argument('--list-comp', help='List all valide arguments', action='store_true')
 parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run')
+
 
 # parse the command line arguments
 options = parser.parse_args()
+do_list = options.list or options.list_comp
 
 # script must have at least some tests to run
-if (len(options.tests) > 0  and     options.all and not options.list) \
-or (len(options.tests) == 0 and not options.all and not options.list) :
+if (len(options.tests) > 0  and     options.all and not do_list) \
+or (len(options.tests) == 0 and not options.all and not do_list) :
 	print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
 	parser.print_help()
@@ -285,5 +300,5 @@
 
 # if user wants all tests than no other treatement of the test list is required
-if options.all or options.list :
+if options.all or do_list :
 	tests = allTests
 
@@ -320,29 +335,33 @@
 tests.sort(key=lambda t: t.name)
 
-# check if the user already passed in a number of jobs for multi-threading
-make_flags = environ.get('MAKEFLAGS')
-make_jobs_fds = re.search("--jobserver-(auth|fds)=\s*([0-9]+),([0-9]+)", make_flags) if make_flags else None
-if make_jobs_fds :
-	tokens = os.read(int(make_jobs_fds.group(2)), 1024)
-	options.jobs = len(tokens)
-	os.write(int(make_jobs_fds.group(3)), tokens)
+# users may want to simply list the tests
+if options.list_comp :
+	print("-h --help --debug --concurrent --dry-run --list --all --regenerate-expected -j --jobs ", end='')
+	print(" ".join(map(lambda t: "%s" % (t.name), tests)))
+
+elif options.list :
+	print("\n".join(map(lambda t: "%s (%s)" % (t.name, t.path), tests)))
+
 else :
-	options.jobs = multiprocessing.cpu_count()
-
-# make sure we have a valid number of jobs that corresponds to user input
-if options.jobs <= 0 :
-	print('ERROR: Invalid number of jobs', file=sys.stderr)
-	sys.exit(1)
-
-options.jobs = min( options.jobs, len(tests) )
-
-print('Running (%s) on %i cores' % ("debug" if options.debug else "no debug", options.jobs))
-make_cmd = "make" if make_flags else ("make -j%i" % options.jobs)
-
-# users may want to simply list the tests
-if options.list :
-	print("\n".join(map(lambda t: "%s (%s)" % (t.name, t.path), tests)))
-
-else :
+	# check if the user already passed in a number of jobs for multi-threading
+	make_flags = environ.get('MAKEFLAGS')
+	make_jobs_fds = re.search("--jobserver-(auth|fds)=\s*([0-9]+),([0-9]+)", make_flags) if make_flags else None
+	if make_jobs_fds :
+		tokens = os.read(int(make_jobs_fds.group(2)), 1024)
+		options.jobs = len(tokens)
+		os.write(int(make_jobs_fds.group(3)), tokens)
+	else :
+		options.jobs = multiprocessing.cpu_count()
+
+	# make sure we have a valid number of jobs that corresponds to user input
+	if options.jobs <= 0 :
+		print('ERROR: Invalid number of jobs', file=sys.stderr)
+		sys.exit(1)
+
+	options.jobs = min( options.jobs, len(tests) )
+
+	print('Running (%s) on %i cores' % ("debug" if options.debug else "no debug", options.jobs))
+	make_cmd = "make" if make_flags else ("make -j%i" % options.jobs)
+
 	# otherwise run all tests and make sure to return the correct error code
 	sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run, options.jobs, options.debug) )
