2019-12-14 15:57:28 +03:00
|
|
|
module main
|
|
|
|
|
2019-08-18 18:21:48 +03:00
|
|
|
import os
|
2019-09-15 18:08:16 +03:00
|
|
|
import compiler.tests.repl.runner
|
2019-09-16 17:29:06 +03:00
|
|
|
import benchmark
|
2020-01-20 19:06:36 +03:00
|
|
|
import runtime
|
|
|
|
import sync
|
|
|
|
import filepath
|
2019-08-26 13:51:48 +03:00
|
|
|
|
|
|
|
fn test_the_v_compiler_can_be_invoked() {
|
2020-03-03 17:02:50 +03:00
|
|
|
vexec := runner.full_path_to_v(5)
|
2019-08-26 13:51:48 +03:00
|
|
|
println('vexecutable: $vexec')
|
|
|
|
assert vexec != ''
|
2019-10-16 02:49:51 +03:00
|
|
|
vcmd := '"$vexec" --version'
|
2019-12-30 07:23:54 +03:00
|
|
|
r := os.exec(vcmd) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
// println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
|
2019-08-26 13:51:48 +03:00
|
|
|
assert r.exit_code == 0
|
2019-10-16 02:49:51 +03:00
|
|
|
vcmd_error := '"$vexec" nonexisting.v'
|
2019-12-30 07:23:54 +03:00
|
|
|
r_error := os.exec(vcmd_error) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
// println('"$vcmd_error" exit_code: $r_error.exit_code | output: $r_error.output')
|
2019-08-26 13:51:48 +03:00
|
|
|
assert r_error.exit_code == 1
|
|
|
|
assert r_error.output == '`nonexisting.v` does not exist'
|
|
|
|
}
|
|
|
|
|
2020-01-20 19:06:36 +03:00
|
|
|
struct Session {
|
|
|
|
mut:
|
|
|
|
options runner.RunnerOptions
|
|
|
|
bmark benchmark.Benchmark
|
|
|
|
ntask int
|
|
|
|
ntask_mtx &sync.Mutex
|
|
|
|
waitgroup &sync.WaitGroup
|
|
|
|
}
|
|
|
|
|
2019-09-15 18:08:16 +03:00
|
|
|
fn test_all_v_repl_files() {
|
2020-01-20 19:06:36 +03:00
|
|
|
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 )
|
2020-01-21 01:04:26 +03:00
|
|
|
mut ncpus := 0
|
|
|
|
ncpus = runtime.nr_cpus()
|
2020-01-20 19:06:36 +03:00
|
|
|
$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++ {
|
2020-01-21 01:04:26 +03:00
|
|
|
go process_in_thread(session,i)
|
2020-01-20 19:06:36 +03:00
|
|
|
}
|
|
|
|
session.waitgroup.wait()
|
|
|
|
session.bmark.stop()
|
|
|
|
println(session.bmark.total_message('total time spent running REPL files'))
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:04:26 +03:00
|
|
|
fn process_in_thread( session mut Session, thread_id int ){
|
2020-01-20 19:06:36 +03:00
|
|
|
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()
|
2020-03-03 17:02:50 +03:00
|
|
|
|
2020-01-20 19:06:36 +03:00
|
|
|
if idx >= session.options.files.len { break }
|
|
|
|
tls_bench.cstep = idx
|
|
|
|
|
|
|
|
tfolder := filepath.join( cdir, 'vrepl_tests_$idx')
|
|
|
|
if os.is_dir( tfolder ) {
|
2020-03-03 17:02:50 +03:00
|
|
|
os.rmdir_all( tfolder )
|
2020-01-20 19:06:36 +03:00
|
|
|
}
|
|
|
|
os.mkdir( tfolder ) or { panic(err) }
|
2020-03-03 17:02:50 +03:00
|
|
|
|
|
|
|
file := session.options.files[ idx ]
|
2020-01-20 19:06:36 +03:00
|
|
|
session.bmark.step()
|
|
|
|
tls_bench.step()
|
|
|
|
fres := runner.run_repl_file(tfolder, session.options.vexec, file) or {
|
|
|
|
session.bmark.fail()
|
|
|
|
tls_bench.fail()
|
2020-03-03 17:02:50 +03:00
|
|
|
os.rmdir_all( tfolder )
|
2020-01-20 19:06:36 +03:00
|
|
|
eprintln(tls_bench.step_message_fail(err))
|
2019-08-26 13:51:48 +03:00
|
|
|
assert false
|
2019-09-15 18:08:16 +03:00
|
|
|
continue
|
2019-08-26 13:51:48 +03:00
|
|
|
}
|
2020-01-20 19:06:36 +03:00
|
|
|
session.bmark.ok()
|
|
|
|
tls_bench.ok()
|
2020-03-03 17:02:50 +03:00
|
|
|
os.rmdir_all( tfolder )
|
2020-01-20 19:06:36 +03:00
|
|
|
println(tls_bench.step_message_ok(fres))
|
2019-09-15 18:08:16 +03:00
|
|
|
assert true
|
2019-08-26 13:51:48 +03:00
|
|
|
}
|
2020-01-20 19:06:36 +03:00
|
|
|
session.waitgroup.done()
|
2019-08-22 14:15:11 +03:00
|
|
|
}
|