Commit 44e064a1 authored by Matthew P. Russell's avatar Matthew P. Russell
Browse files

run_valgrind function

parent 95cca0f5
......@@ -58,6 +58,36 @@ def run(args):
universal_newlines = True)
return result
# run_valgrind runs valgrind on a test
def run_valgrind(test):
valgrind_command = ['valgrind',
'--leak-check=full',
'--show-leak-kinds=all',
'./a.out',
test]
VALGRIND_RESULT = run(valgrind_command)
# memory errors force nonzero return code
if VALGRIND_RESULT.returncode != 0:
valgrind_passed = False
else:
valgrind_passed = True # will set to False if leaks are present
passphrase = "All heap blocks were freed -- no leaks are possible"
if passphrase not in VALGRIND_RESULT.stderr:
# only capture the part after "LEAK SUMMARY"
VALGRIND_INFO = VALGRIND_RESULT.stderr.split("LEAK SUMMARY")[1]
# check for leaks
for line in VALGRIND_INFO.split('\n'):
if "lost" in line and "0 bytes in 0 blocks" not in line:
valgrind_passed = False
break
return (valgrind_passed, VALGRIND_RESULT)
# cleanup removes the copied driver
def cleanup():
run(['make', 'clean'])
......@@ -158,46 +188,19 @@ for test in test_names:
TEST_RESULT = run(["./a.out", test])
# if here, then the regular test failed
if TEST_RESULT.returncode != 0:
if TEST_RESULT.returncode != 0: # test failed
inform("test failed", color=FAILURE)
if abs(test_result.returncode) == 11:
inform("segmentation fault!", color=FAILURE)
inform("valgrind failed by default", color=FAILURE)
print_ostreams(TEST_RESULT)
# if here, test PASSED
else:
else: # test passed
num_tests_passed += 1
inform("test passed", color=SUCCESS)
print_ostreams(TEST_RESULT)
# Run valgrind
valgrind_command = ['valgrind',
'--leak-check=full',
'--show-leak-kinds=all',
'./a.out',
test]
VALGRIND_RESULT = run(valgrind_command)
# memory errors force nonzero return code
if VALGRIND_RESULT.returncode != 0:
valgrind_passed = False
else:
valgrind_passed = True # will set to False if leaks are present
passphrase = "All heap blocks were freed -- no leaks are possible"
if passphrase not in VALGRIND_RESULT.stderr:
# only capture the part after "LEAK SUMMARY"
VALGRIND_INFO = VALGRIND_RESULT.stderr.split("LEAK SUMMARY")[1]
# check for leaks
for line in VALGRIND_INFO.split('\n'):
if "lost" in line and "0 bytes in 0 blocks" not in line:
valgrind_passed = False
break
valgrind_passed, VALGRIND_RESULT = run_valgrind(test)
if valgrind_passed:
inform("valgrind passed", color=SUCCESS)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment