ci: fix another options_test.v failute, refactor for readability
parent
b5d8c53a0c
commit
76f70d51f3
|
@ -4,49 +4,53 @@ import time
|
||||||
|
|
||||||
const vexe = @VEXE
|
const vexe = @VEXE
|
||||||
|
|
||||||
const vroot = os.real_path(@VMODROOT)
|
|
||||||
|
|
||||||
fn testsuite_begin() {
|
|
||||||
os.chdir(vroot) or {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_cflags() ? {
|
fn test_cflags() ? {
|
||||||
println('> test whether -cflags is passed to the backend C compiler')
|
os.chdir(os.real_path(@VMODROOT)) or {}
|
||||||
compilation := os.execute('"$vexe" -cflags NONSENSE_OPTION examples/hello_world.v')
|
|
||||||
assert compilation.exit_code != 0
|
|
||||||
println('> NONSENSE_OPTION failed the C build, OK')
|
|
||||||
//
|
|
||||||
mut debug_arg := '-g3 -O0'
|
mut debug_arg := '-g3 -O0'
|
||||||
mut optimised_arg := '-O1'
|
mut optimised_arg := '-O1'
|
||||||
$if msvc {
|
$if msvc {
|
||||||
debug_arg = '/MDd /D_DEBUG'
|
debug_arg = '/MDd /D_DEBUG'
|
||||||
optimised_arg = '/O1'
|
optimised_arg = '/O1'
|
||||||
}
|
}
|
||||||
tmpdir := os.temp_dir()
|
|
||||||
//
|
//
|
||||||
dbgexe := os.join_path(os.temp_dir(), 'debug_hw.exe')
|
println('> test whether -cflags is passed to the backend C compiler')
|
||||||
debug_sw := time.new_stopwatch()
|
fail := custom_compile('failing.exe', 'NONSENSE_OPTION')
|
||||||
debug_compilation := os.execute('"$vexe" -cflags "$debug_arg" -o "$dbgexe" examples/hello_world.v')
|
assert fail.compilation.exit_code != 0
|
||||||
debug_delta := debug_sw.elapsed().microseconds()
|
println('> NONSENSE_OPTION failed the C build, OK')
|
||||||
assert debug_compilation.exit_code == 0
|
|
||||||
debug_file_size := os.file_size(dbgexe)
|
|
||||||
assert debug_file_size > 0
|
|
||||||
println('> debug build took: $debug_delta ms with "$debug_arg", file size: $debug_file_size')
|
|
||||||
//
|
//
|
||||||
optexe := os.join_path(os.temp_dir(), 'optimised_hw.exe')
|
dbg := custom_compile('debug_hw.exe', debug_arg)
|
||||||
optimised_sw := time.new_stopwatch()
|
assert dbg.compilation.exit_code == 0
|
||||||
optimised_compilation := os.execute('"$vexe" -cflags "$optimised_arg" -o "$optexe" examples/hello_world.v')
|
assert dbg.file_size > 0
|
||||||
optimised_delta := optimised_sw.elapsed().microseconds()
|
//
|
||||||
assert optimised_compilation.exit_code == 0
|
opt := custom_compile('optimised_hw.exe', optimised_arg)
|
||||||
optimised_file_size := os.file_size(optexe)
|
assert opt.compilation.exit_code == 0
|
||||||
assert optimised_file_size > 0
|
assert opt.file_size > 0
|
||||||
println('> optimised build took: $optimised_delta ms with "$optimised_arg", file size: $optimised_file_size')
|
|
||||||
//
|
//
|
||||||
$if !tinyc {
|
$if !tinyc {
|
||||||
// tcc does almost no optimisations, so the differences are very insignificant
|
// tcc does almost no optimisations, so the differences are very insignificant
|
||||||
assert optimised_file_size != debug_file_size // optimised_file_size should be smaller in general, but not on the Ubuntu CI for some reason :-|
|
assert opt.file_size != dbg.file_size // optimised_file_size should be smaller in general, but not on the Ubuntu CI for some reason :-|
|
||||||
assert optimised_delta >= debug_delta
|
// assert optimised_delta >= debug_delta // this is not reliable on the CIs :-|
|
||||||
}
|
}
|
||||||
os.rm(optexe) or {}
|
os.rm(opt.exe) or {}
|
||||||
os.rm(dbgexe) or {}
|
os.rm(dbg.exe) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn custom_compile(fname string, cflags_options string) Results {
|
||||||
|
mut res := Results{}
|
||||||
|
res.exe = os.join_path(os.temp_dir(), fname)
|
||||||
|
res.sw = time.new_stopwatch()
|
||||||
|
res.compilation = os.execute('"$vexe" -cflags "$cflags_options" -o "$res.exe" examples/hello_world.v')
|
||||||
|
res.delta = res.sw.elapsed().microseconds()
|
||||||
|
res.file_size = os.file_size(res.exe)
|
||||||
|
println('> $fname build took: $res.delta ms with "$cflags_options", file size: $res.file_size')
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Results {
|
||||||
|
mut:
|
||||||
|
exe string
|
||||||
|
sw time.StopWatch
|
||||||
|
compilation os.Result
|
||||||
|
delta i64
|
||||||
|
file_size u64
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue