From 4bb5d7de8b01782e0593f93613512b6f6bc44d3b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 8 Feb 2020 18:01:10 +0200 Subject: [PATCH] tooling: use term.header for tests --- tools/modules/testing/common.v | 26 +++++++++++++++++--------- tools/vtest-compiler.v | 6 ++++-- tools/vtest-fmt.v | 8 ++++---- tools/vtest.v | 2 +- vlib/runtime/runtime.v | 12 ++++++++++++ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/tools/modules/testing/common.v b/tools/modules/testing/common.v index 884c8aa45a..f71f819e7e 100644 --- a/tools/modules/testing/common.v +++ b/tools/modules/testing/common.v @@ -80,17 +80,17 @@ pub fn (ts mut TestSession) test() { ts.files = remaining_files ts.benchmark.set_total_expected_steps(remaining_files.len) - mut ncpus := runtime.nr_cpus() + mut njobs := runtime.nr_jobs() $if msvc { // NB: MSVC can not be launched in parallel, without giving it // the option /FS because it uses a shared PDB file, which should // be locked, but that makes writing slower... // See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019 // Instead, just run tests on 1 core for now. - ncpus = 1 - } - ts.waitgroup.add( ncpus ) - for i:=0; i < ncpus; i++ { + njobs = 1 + } + ts.waitgroup.add( njobs ) + for i:=0; i < njobs; i++ { go process_in_thread(ts) } ts.waitgroup.wait() @@ -140,7 +140,7 @@ fn (ts mut TestSession) process_files() { ts.benchmark.step() tls_bench.step() if show_stats { - eprintln('-------------------------------------------------') + eprintln(term.h_divider('-')) status := os.system(cmd) if status == 0 { ts.benchmark.ok() @@ -196,8 +196,8 @@ pub fn v_build_failing(zargs string, folder string) bool { parent_dir := filepath.dir(vexe) vlib_should_be_present(parent_dir) vargs := zargs.replace(vexe, '') - eprintln(main_label) - eprintln(' v compiler args: "$vargs"') + eheader(main_label) + eprintln('v compiler args: "$vargs"') mut session := new_test_session(vargs) files := os.walk_ext(filepath.join(parent_dir,folder), '.v') mut mains := files.filter(!it.contains('modules') && !it.contains('preludes')) @@ -231,7 +231,7 @@ pub fn build_v_cmd_failed(cmd string) bool { } pub fn building_any_v_binaries_failed() bool { - eprintln('Building V binaries...') + eheader('Building V binaries...') eprintln('VFLAGS is: "' + os.getenv('VFLAGS') + '"') vexe := testing.vexe_path() parent_dir := filepath.dir(vexe) @@ -262,3 +262,11 @@ pub fn building_any_v_binaries_failed() bool { eprintln(bmark.total_message('building v binaries')) return failed } + +pub fn eheader(msg string) { + eprintln(term.header(msg,'-')) +} + +pub fn header(msg string) { + println(term.header(msg,'-')) +} diff --git a/tools/vtest-compiler.v b/tools/vtest-compiler.v index af5579645d..460b2cf298 100644 --- a/tools/vtest-compiler.v +++ b/tools/vtest-compiler.v @@ -43,7 +43,8 @@ fn v_test_compiler(vargs string) { } } building_tools_failed := testing.v_build_failing(vargs, 'tools') - eprintln('\nTesting all _test.v files...') + eprintln('') + testing.eheader('Testing all _test.v files...') mut compiler_test_session := testing.new_test_session(vargs) compiler_test_session.files << os.walk_ext(parent_dir, '_test.v') compiler_test_session.test() @@ -54,7 +55,8 @@ fn v_test_compiler(vargs string) { building_live_failed := testing.v_build_failing(vargs + '-live', filepath.join('examples','hot_reload')) eprintln('') v_module_install_cmd := '$vexe install nedpals.args' - eprintln('\nInstalling a v module with: $v_module_install_cmd ') + eprintln('') + testing.eheader('Installing a v module with: $v_module_install_cmd') mut vmark := benchmark.new_benchmark() ret := os.system(v_module_install_cmd) if ret != 0 { diff --git a/tools/vtest-fmt.v b/tools/vtest-fmt.v index 086d8579be..03e652480b 100644 --- a/tools/vtest-fmt.v +++ b/tools/vtest-fmt.v @@ -8,13 +8,13 @@ import ( const ( known_failing_exceptions = ['./examples/vweb/vweb_example.v', './tools/gen_vc.v', - './tools/modules/vgit/vgit.v', // generics + './tools/modules/vgit/vgit.v', // generics './tools/preludes/live_main.v', './tools/preludes/live_shared.v', './tools/preludes/tests_assertions.v', './tools/preludes/tests_with_stats.v', - './tools/performance_compare.v', // generics - './tools/oldv.v', // generics + './tools/performance_compare.v', // generics + './tools/oldv.v', // generics './tutorials/code/blog/article.v', './tutorials/code/blog/blog.v', './vlib/arrays/arrays.v', @@ -45,7 +45,7 @@ fn main() { fn v_test_formatting(vargs string) { all_v_files := v_files() - eprintln('Run "v fmt" over all .v files') + testing.eheader('Run "v fmt" over all .v files') mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker') vfmt_test_session.files << all_v_files vfmt_test_session.test() diff --git a/tools/vtest.v b/tools/vtest.v index 3c99bf0b55..dea43a6ce7 100644 --- a/tools/vtest.v +++ b/tools/vtest.v @@ -45,7 +45,7 @@ pub fn main() { println('Unrecognized test file $targ .') } - println('Testing...') + testing.header('Testing...') ts.test() println( ts.benchmark.total_message('running V _test.v files') ) diff --git a/vlib/runtime/runtime.v b/vlib/runtime/runtime.v index f15a7c11ce..e0e29609ba 100644 --- a/vlib/runtime/runtime.v +++ b/vlib/runtime/runtime.v @@ -4,6 +4,8 @@ module runtime +import os + //$if linux { fn C.sysconf(name int) i64 //} @@ -19,6 +21,16 @@ pub fn nr_cpus() int { return nr_cpus_nix() } +pub fn nr_jobs() int { + mut cpus := nr_cpus() + // allow for overrides, for example using `VJOBS=32 ./v test .` + vjobs := os.getenv('VJOBS').int() + if vjobs > 0 { + cpus = vjobs + } + return cpus +} + pub fn is_32bit() bool { mut x := false $if x32 { x = true }