v4 / vlib / v3 / tests / sha3_issue_compile_test.v
39 lines · 34 sloc · 1.21 KB · 0d8be928c481b431d012f4078639bef01189ce1e
Raw
1import os
2
3const sha3_issue_vexe = @VEXE
4const sha3_issue_tests_dir = os.dir(@FILE)
5const sha3_issue_v3_dir = os.dir(sha3_issue_tests_dir)
6const sha3_issue_vlib_dir = os.dir(sha3_issue_v3_dir)
7const sha3_issue_v3_src = os.join_path(sha3_issue_v3_dir, 'v3.v')
8
9// test_sha3_issue_26961_compile validates that v3 can compile the sha3 benchmark
10// program from https://github.com/vlang/v/issues/26961 .
11fn test_sha3_issue_26961_compile() {
12 pid := os.getpid()
13 v3_bin := os.join_path(os.temp_dir(), 'v3_sha3_issue_26961_${pid}')
14 os.rm(v3_bin) or {}
15 build :=
16 os.execute('${sha3_issue_vexe} -gc none -path "${sha3_issue_vlib_dir}|@vlib|@vmodules" -o ${v3_bin} ${sha3_issue_v3_src}')
17 assert build.exit_code == 0, build.output
18
19 src := os.join_path(os.temp_dir(), 'v3_sha3_issue_26961_${pid}.v')
20 bin := os.join_path(os.temp_dir(), 'v3_sha3_issue_26961_bin_${pid}')
21 os.write_file(src, 'import crypto.sha3
22import time
23
24fn main() {
25 a := []u8{len: 10_000_000}
26 t1 := time.now()
27 _ := sha3.sum512(a)
28 println(time.since(t1))
29}
30') or {
31 panic(err)
32 }
33 os.rm(bin) or {}
34 os.rm(bin + '.c') or {}
35
36 compile := os.execute('${v3_bin} ${src} -b c -o ${bin}')
37 assert compile.exit_code == 0, compile.output
38 assert os.exists(bin), compile.output
39}
40