From 53a9329ab6a75a7a76f0d8bc3c0e53415a486bd2 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 22 Mar 2020 10:44:15 +0200 Subject: [PATCH] valgrind: nicer output --- vlib/v/tests/valgrind/valgrind_test.v | 63 +++++++++++++++++---------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index 116842920b..de6c6dbb1f 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -1,41 +1,56 @@ import os import term +import benchmark fn test_all() { - $if !linux { - println('Valgrind tests can only be run on Linux.') + if os.user_os() != 'linux' && os.getenv('FORCE_VALGRIND_TEST').len == 0 { + eprintln('Valgrind tests can only be run reliably on Linux for now.') + eprintln('You can still do it by setting FORCE_VALGRIND_TEST=1 .') exit(0) } - exe := os.executable() - dir := os.dir(exe) - vexe := os.dir(os.dir(os.dir(os.dir(dir)))) + '/v' - println(vexe) - println(dir) - println(111) - // files := os.ls('$dir/vlib/v/tests/valgrind/') or { + bench_message := 'memory leak checking with valgrind' + mut bench := benchmark.new_benchmark() + eprintln(term.header(bench_message,'-')) + dir := os.resource_abs_path('') + vexe := os.getenv('VEXE') files := os.ls(dir) or { panic(err) } tests := files.filter(it.ends_with('.vv')) + bench.set_total_expected_steps(tests.len) for test in tests { - os.system('cp $dir/$test x.v') // cant run .vv file - println(test) - res := os.exec('$vexe x.v') or { - println('valgrind $test failed') - assert false + bench.step() + full_test_path := os.real_path(test) + os.system('cp ${dir}/${test} x.v') // cant run .vv file + res := os.exec('$vexe -b v2 x.v') or { + bench.fail() + eprintln(bench.step_message_fail('valgrind $test failed')) continue } - println(res.output) - os.exec('valgrind ./x') or { - println('valgrind $test failed') - assert false - continue - } - println(res.output) if res.exit_code != 0 { - println('valgrind $test failed') - assert false + bench.fail() + eprintln(bench.step_message_fail('file: $full_test_path could not be compiled.')) + eprintln(res.output) + continue } + valgrind_res := os.exec('valgrind --error-exitcode=1 --leak-check=full ./x') or { + bench.fail() + eprintln(bench.step_message_fail('valgrind could not be executed')) + continue + } + if valgrind_res.exit_code != 0 { + bench.fail() + eprintln(bench.step_message_fail('failed valgrind check for $test')) + eprintln(valgrind_res.output) + continue + } + bench.ok() + eprintln(bench.step_message_ok('testing file: $test')) + } + bench.stop() + eprintln(term.h_divider('-')) + eprintln(bench.total_message(bench_message)) + if bench.nfail > 0 { + exit(1) } - println(tests) }