mirror of
https://github.com/vlang/v.git
synced 2025-09-15 23:42:28 +03:00
Make REPL tests parallel too
This commit is contained in:
parent
84438c0139
commit
64a9f43405
4 changed files with 115 additions and 31 deletions
|
@ -3,6 +3,9 @@ module main
|
|||
import os
|
||||
import compiler.tests.repl.runner
|
||||
import benchmark
|
||||
import runtime
|
||||
import sync
|
||||
import filepath
|
||||
|
||||
fn test_the_v_compiler_can_be_invoked() {
|
||||
vexec := runner.full_path_to_v(5)
|
||||
|
@ -23,21 +26,79 @@ fn test_the_v_compiler_can_be_invoked() {
|
|||
assert r_error.output == '`nonexisting.v` does not exist'
|
||||
}
|
||||
|
||||
struct Session {
|
||||
mut:
|
||||
options runner.RunnerOptions
|
||||
bmark benchmark.Benchmark
|
||||
ntask int
|
||||
ntask_mtx &sync.Mutex
|
||||
waitgroup &sync.WaitGroup
|
||||
}
|
||||
|
||||
fn test_all_v_repl_files() {
|
||||
options := runner.new_options()
|
||||
mut bmark := benchmark.new_benchmark()
|
||||
for file in options.files {
|
||||
bmark.step()
|
||||
fres := runner.run_repl_file(options.wd, options.vexec, file) or {
|
||||
bmark.fail()
|
||||
eprintln(bmark.step_message_fail(err))
|
||||
mut session := &Session{
|
||||
options: runner.new_options()
|
||||
bmark: benchmark.new_benchmark()
|
||||
ntask: 0
|
||||
ntask_mtx: sync.new_mutex()
|
||||
waitgroup: sync.new_waitgroup()
|
||||
}
|
||||
|
||||
// warmup, and ensure that the vrepl is compiled in single threaded mode if it does not exist
|
||||
runner.run_repl_file(os.cachedir(), session.options.vexec, 'vlib/compiler/tests/repl/nothing.repl') or {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
session.bmark.set_total_expected_steps( session.options.files.len )
|
||||
mut ncpus := runtime.nr_cpus()
|
||||
$if windows {
|
||||
// See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019
|
||||
ncpus = 1
|
||||
}
|
||||
session.waitgroup.add( ncpus )
|
||||
for i:=0; i < ncpus; i++ {
|
||||
go process_in_thread(session)
|
||||
}
|
||||
session.waitgroup.wait()
|
||||
session.bmark.stop()
|
||||
println(session.bmark.total_message('total time spent running REPL files'))
|
||||
}
|
||||
|
||||
fn process_in_thread( session mut Session ){
|
||||
cdir := os.cachedir()
|
||||
mut tls_bench := benchmark.new_benchmark()
|
||||
tls_bench.set_total_expected_steps( session.bmark.nexpected_steps )
|
||||
for {
|
||||
session.ntask_mtx.lock()
|
||||
session.ntask++
|
||||
idx := session.ntask-1
|
||||
session.ntask_mtx.unlock()
|
||||
|
||||
if idx >= session.options.files.len { break }
|
||||
tls_bench.cstep = idx
|
||||
|
||||
tfolder := filepath.join( cdir, 'vrepl_tests_$idx')
|
||||
if os.is_dir( tfolder ) {
|
||||
os.rmdir_recursive( tfolder )
|
||||
}
|
||||
os.mkdir( tfolder ) or { panic(err) }
|
||||
|
||||
file := os.realpath( filepath.join( session.options.wd, session.options.files[ idx ] ) )
|
||||
session.bmark.step()
|
||||
tls_bench.step()
|
||||
fres := runner.run_repl_file(tfolder, session.options.vexec, file) or {
|
||||
session.bmark.fail()
|
||||
tls_bench.fail()
|
||||
os.rmdir_recursive( tfolder )
|
||||
eprintln(tls_bench.step_message_fail(err))
|
||||
assert false
|
||||
continue
|
||||
}
|
||||
bmark.ok()
|
||||
println(bmark.step_message_ok(fres))
|
||||
session.bmark.ok()
|
||||
tls_bench.ok()
|
||||
os.rmdir_recursive( tfolder )
|
||||
println(tls_bench.step_message_ok(fres))
|
||||
assert true
|
||||
}
|
||||
bmark.stop()
|
||||
println(bmark.total_message('total time spent running REPL files'))
|
||||
session.waitgroup.done()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
filepath
|
||||
)
|
||||
|
||||
struct RunnerOptions {
|
||||
pub struct RunnerOptions {
|
||||
pub:
|
||||
wd string
|
||||
vexec string
|
||||
|
@ -22,12 +22,12 @@ pub fn full_path_to_v(dirs_in int) string {
|
|||
for i := 0; i < dirs_in; i++ {
|
||||
path = filepath.dir(path)
|
||||
}
|
||||
vexec := path + os.path_separator + vname
|
||||
vexec := filepath.join( path, vname )
|
||||
/*
|
||||
args := os.args
|
||||
vreal := os.realpath('v')
|
||||
myself := os.realpath( os.executable() )
|
||||
wd := os.getwd() + os.path_separator
|
||||
wd := os.getwd()
|
||||
println('args are: $args')
|
||||
println('vreal : $vreal')
|
||||
println('myself : $myself')
|
||||
|
@ -55,17 +55,24 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
|
|||
content := fcontent.replace('\r', '')
|
||||
input := content.all_before('===output===\n')
|
||||
output := content.all_after('===output===\n')
|
||||
|
||||
input_temporary_filename := 'input_temporary_filename.txt'
|
||||
|
||||
fname := filepath.filename( file )
|
||||
input_temporary_filename := os.realpath(filepath.join( wd, 'input_temporary_filename.txt'))
|
||||
os.write_file(input_temporary_filename, input)
|
||||
rcmd := '"$vexec" repl < $input_temporary_filename'
|
||||
os.write_file( os.realpath(filepath.join( wd, 'original.txt' ) ), fcontent )
|
||||
rcmd := '"$vexec" repl -replfolder "$wd" -replprefix "${fname}." < $input_temporary_filename'
|
||||
r := os.exec(rcmd) or {
|
||||
os.rm(input_temporary_filename)
|
||||
return error('Could not execute: $rcmd')
|
||||
}
|
||||
os.rm(input_temporary_filename)
|
||||
|
||||
result := r.output.replace('\r','').replace('>>> ', '').replace('>>>', '').replace('... ', '').all_after('Use Ctrl-C or `exit` to exit\n').replace(wd, '' )
|
||||
|
||||
result := r.output.replace('\r','')
|
||||
.replace('>>> ', '')
|
||||
.replace('>>>', '')
|
||||
.replace('... ', '')
|
||||
.all_after('Use Ctrl-C or `exit` to exit\n')
|
||||
.replace(wd + os.path_separator, '' )
|
||||
|
||||
if result != output {
|
||||
file_result := '${file}.result.txt'
|
||||
|
@ -120,7 +127,7 @@ $diff
|
|||
}
|
||||
|
||||
pub fn new_options() RunnerOptions {
|
||||
wd := os.getwd() + os.path_separator
|
||||
wd := os.getwd()
|
||||
vexec := full_path_to_v(5)
|
||||
mut files := []string
|
||||
if os.args.len > 1 {
|
||||
|
@ -136,7 +143,7 @@ pub fn new_options() RunnerOptions {
|
|||
}
|
||||
|
||||
pub fn new_prod_options() RunnerOptions {
|
||||
wd := os.getwd() + os.path_separator
|
||||
wd := os.getwd()
|
||||
vexec := full_path_to_v(4)
|
||||
mut files := []string
|
||||
if os.args.len > 1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue