2019-12-14 13:57:28 +01:00
|
|
|
module main
|
|
|
|
|
2019-08-18 17:21:48 +02:00
|
|
|
import os
|
2019-09-15 17:08:16 +02:00
|
|
|
import compiler.tests.repl.runner
|
2019-09-16 16:29:06 +02:00
|
|
|
import benchmark
|
2020-01-20 17:06:36 +01:00
|
|
|
import sync
|
2019-08-26 12:51:48 +02:00
|
|
|
|
|
|
|
fn test_the_v_compiler_can_be_invoked() {
|
2020-03-03 15:02:50 +01:00
|
|
|
vexec := runner.full_path_to_v(5)
|
2019-08-26 12:51:48 +02:00
|
|
|
println('vexecutable: $vexec')
|
|
|
|
assert vexec != ''
|
2020-03-06 18:53:29 +01:00
|
|
|
vcmd := '"$vexec" -version'
|
2019-12-30 05:23:54 +01:00
|
|
|
r := os.exec(vcmd) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
// println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
|
2019-08-26 12:51:48 +02:00
|
|
|
assert r.exit_code == 0
|
2019-10-16 01:49:51 +02:00
|
|
|
vcmd_error := '"$vexec" nonexisting.v'
|
2019-12-30 05:23:54 +01: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 12:51:48 +02:00
|
|
|
assert r_error.exit_code == 1
|
2020-03-06 18:53:29 +01:00
|
|
|
assert r_error.output == "V error: nonexisting.v doesn't exist"
|
2019-08-26 12:51:48 +02:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:06:36 +01:00
|
|
|
struct Session {
|
|
|
|
mut:
|
2020-03-04 20:28:42 +01:00
|
|
|
options runner.RunnerOptions
|
|
|
|
bmark benchmark.Benchmark
|
2020-01-20 17:06:36 +01:00
|
|
|
}
|
|
|
|
|
2019-09-15 17:08:16 +02:00
|
|
|
fn test_all_v_repl_files() {
|
2020-01-20 17:06:36 +01:00
|
|
|
mut session := &Session{
|
|
|
|
options: runner.new_options()
|
|
|
|
bmark: benchmark.new_benchmark()
|
|
|
|
}
|
|
|
|
// warmup, and ensure that the vrepl is compiled in single threaded mode if it does not exist
|
2020-03-08 15:57:47 +01:00
|
|
|
runner.run_repl_file(os.cache_dir(), session.options.vexec, 'vlib/compiler/tests/repl/nothing.repl') or {
|
2020-01-20 17:06:36 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-03-04 20:28:42 +01:00
|
|
|
session.bmark.set_total_expected_steps(session.options.files.len)
|
|
|
|
mut pool_repl := sync.new_pool_processor({
|
|
|
|
callback: worker_repl
|
|
|
|
})
|
|
|
|
pool_repl.set_shared_context(session)
|
2020-01-20 17:06:36 +01:00
|
|
|
$if windows {
|
2020-03-04 20:28:42 +01:00
|
|
|
// See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019
|
|
|
|
pool_repl.set_max_jobs(1)
|
2020-01-20 17:06:36 +01:00
|
|
|
}
|
2020-03-05 18:37:57 +01:00
|
|
|
pool_repl.work_on_items(session.options.files)
|
2020-01-20 17:06:36 +01:00
|
|
|
session.bmark.stop()
|
|
|
|
println(session.bmark.total_message('total time spent running REPL files'))
|
|
|
|
}
|
|
|
|
|
2020-03-04 20:28:42 +01:00
|
|
|
fn worker_repl(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
|
2020-03-08 15:57:47 +01:00
|
|
|
cdir := os.cache_dir()
|
2020-03-04 20:28:42 +01:00
|
|
|
mut session := &Session(p.get_shared_context())
|
|
|
|
mut tls_bench := &benchmark.Benchmark(p.get_thread_context(idx))
|
|
|
|
if isnil(tls_bench) {
|
|
|
|
tls_bench = benchmark.new_benchmark_pointer()
|
|
|
|
tls_bench.set_total_expected_steps(session.bmark.nexpected_steps)
|
|
|
|
p.set_thread_context(idx, tls_bench)
|
|
|
|
}
|
|
|
|
tls_bench.cstep = idx
|
2020-03-09 02:23:34 +01:00
|
|
|
tfolder := os.join_path(cdir, 'vrepl_tests_$idx')
|
2020-03-04 20:28:42 +01:00
|
|
|
if os.is_dir(tfolder) {
|
|
|
|
os.rmdir_all(tfolder)
|
|
|
|
}
|
|
|
|
os.mkdir(tfolder) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
file := p.get_string_item(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_all(tfolder)
|
|
|
|
eprintln(tls_bench.step_message_fail(err))
|
|
|
|
assert false
|
|
|
|
return sync.no_result
|
2019-08-26 12:51:48 +02:00
|
|
|
}
|
2020-03-04 20:28:42 +01:00
|
|
|
session.bmark.ok()
|
|
|
|
tls_bench.ok()
|
|
|
|
os.rmdir_all(tfolder)
|
|
|
|
println(tls_bench.step_message_ok(fres))
|
|
|
|
assert true
|
|
|
|
return sync.no_result
|
2019-08-22 13:15:11 +02:00
|
|
|
}
|