v / vlib / v2 / gen / arm64 / tests / run_tests.v
101 lines · 85 sloc · 2.47 KB · e35325885cca6c2fbd76257048cfdd9e1de249de
Raw
1// Test runner for ARM64 backend tests
2// Run with: ./v run vlib/v2/gen/arm64/tests/run_tests.v
3// Or: cd vlib/v2/gen/arm64/tests && v run run_tests.v
4
5module main
6
7import os
8import time
9
10fn main() {
11 t0 := time.now()
12
13 vroot := os.dir(@VEXE)
14 v2_source := os.join_path(vroot, 'cmd', 'v2', 'v2.v')
15 v2_binary := os.join_path(vroot, 'cmd', 'v2', 'v2')
16 tests_dir := os.join_path(vroot, 'vlib', 'v2', 'gen', 'arm64', 'tests')
17
18 // Build v2 compiler
19 println('[*] Building v2...')
20 build_res := os.execute('${@VEXE} ${v2_source} -o ${v2_binary}')
21 if build_res.exit_code != 0 {
22 eprintln('Error: Failed to build v2')
23 eprintln(build_res.output)
24 exit(1)
25 }
26
27 // Find all test files (*.v except run_tests.v)
28 test_files := os.ls(tests_dir) or {
29 eprintln('Error: Cannot list tests directory')
30 exit(1)
31 }
32
33 mut passed := 0
34 mut failed := 0
35 mut test_count := 0
36
37 for file in test_files {
38 if !file.ends_with('.v') || file == 'run_tests.v' {
39 continue
40 }
41 test_count++
42 test_path := os.join_path(tests_dir, file)
43 test_name := file.replace('.v', '')
44
45 println('\n[*] Testing: ${file}')
46
47 // Run v2 with ARM64 backend
48 v2_output := os.join_path(tests_dir, 'test_${test_name}')
49 v2_cmd := '${v2_binary} -backend arm64 ${test_path} -o ${v2_output}'
50 v2_res := os.execute(v2_cmd)
51 if v2_res.exit_code != 0 {
52 eprintln(' [FAIL] v2 compilation failed')
53 eprintln(v2_res.output)
54 failed++
55 continue
56 }
57
58 // Run the generated binary
59 gen_res := os.execute(v2_output)
60 if gen_res.exit_code != 0 {
61 eprintln(' [FAIL] Generated binary exited with code ${gen_res.exit_code}')
62 eprintln(gen_res.output)
63 failed++
64 continue
65 }
66
67 // Run reference compiler
68 ref_res := os.execute('${@VEXE} -n -w -enable-globals run ${test_path}')
69 if ref_res.exit_code != 0 {
70 eprintln(' [FAIL] Reference compilation failed')
71 eprintln(ref_res.output)
72 failed++
73 continue
74 }
75
76 // Compare outputs
77 expected := ref_res.output.trim_space().replace('\r\n', '\n')
78 actual := gen_res.output.trim_space().replace('\r\n', '\n')
79
80 if expected == actual {
81 println(' [PASS] Output matches reference')
82 passed++
83 } else {
84 println(' [FAIL] Output mismatch')
85 println(' Expected:\n${expected}')
86 println(' Got:\n${actual}')
87 failed++
88 }
89
90 // Clean up
91 os.rm(v2_output) or {}
92 }
93
94 println('\n========================================')
95 println('Results: ${passed}/${test_count} tests passed')
96 if failed > 0 {
97 println('${failed} tests FAILED')
98 exit(1)
99 }
100 println('Total time: ${time.since(t0)}')
101}
102