|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Initialize an array to store the names of failing RTLIL files and their failure types |
4 |
| -declare -A failing_files |
5 |
| -# Initialize an array to store the names of successful RTLIL files |
6 |
| -declare -A successful_files |
| 3 | +declare -A cxx_failing_files |
| 4 | +declare -A smt_failing_files |
| 5 | +declare -A cxx_successful_files |
| 6 | +declare -A smt_successful_files |
7 | 7 |
|
8 |
| -# Function to run the test on a given RTLIL file |
9 |
| -run_test() { |
10 |
| - # Define the common variable for the relative path |
| 8 | +run_cxx_test() { |
11 | 9 | BASE_PATH="../../../"
|
12 | 10 |
|
13 | 11 | local rtlil_file=$1
|
14 | 12 |
|
15 |
| - # Extract the base name without extension |
16 | 13 | local base_name=$(basename "$rtlil_file" .v)
|
17 | 14 |
|
18 |
| - # Run yosys to process each RTLIL file |
19 | 15 | if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; write_functional_cxx my_module_functional_cxx.cc"; then
|
20 | 16 | echo "Yosys processed $rtlil_file successfully."
|
21 | 17 |
|
22 |
| - # Compile the generated C++ files with vcd_harness.cpp |
23 | 18 | if ${CXX:-g++} -g -fprofile-arcs -ftest-coverage vcd_harness.cc -I ${BASE_PATH}backends/functional/cxx_runtime/ -std=c++17 -o vcd_harness; then
|
24 | 19 | echo "Compilation successful."
|
25 |
| - # Generate VCD files with base_name |
26 | 20 | if ./vcd_harness ${base_name}_functional_cxx.vcd; then
|
27 | 21 |
|
28 |
| - # Run yosys to process each RTLIL file |
29 | 22 | if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; sim -r ${base_name}_functional_cxx.vcd -scope gold -vcd ${base_name}_yosys_sim.vcd -timescale 1us -sim-gold"; then
|
30 | 23 | echo "Yosys sim $rtlil_file successfully."
|
31 |
| - successful_files["$rtlil_file"]="Success" |
| 24 | + cxx_successful_files["$rtlil_file"]="Success" |
32 | 25 | else
|
33 | 26 | ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; sim -vcd ${base_name}_yosys_sim.vcd -r ${base_name}_functional_cxx.vcd -scope gold -timescale 1us"
|
34 | 27 | echo "Yosys simulation of $rtlil_file failed. There is a discrepancy with functional cxx"
|
35 |
| - failing_files["$rtlil_file"]="Yosys sim failure" |
| 28 | + cxx_failing_files["$rtlil_file"]="Yosys sim failure" |
36 | 29 | fi
|
37 | 30 |
|
38 | 31 | else
|
39 | 32 | echo "Failed to generate VCD files for $rtlil_file."
|
40 |
| - failing_files["$rtlil_file"]="VCD generation failure" |
| 33 | + cxx_failing_files["$rtlil_file"]="VCD generation failure" |
41 | 34 | fi
|
42 | 35 | else
|
43 | 36 | echo "Failed to compile harness for $rtlil_file."
|
44 |
| - failing_files["$rtlil_file"]="Compilation failure" |
| 37 | + cxx_failing_files["$rtlil_file"]="Compilation failure" |
45 | 38 | fi
|
46 | 39 | else
|
47 | 40 | echo "Yosys failed to process $rtlil_file."
|
48 |
| - failing_files["$rtlil_file"]="Yosys failure" |
| 41 | + cxx_failing_files["$rtlil_file"]="Yosys failure" |
49 | 42 | fi
|
50 | 43 | }
|
51 | 44 |
|
52 |
| -# Main function to run all tests |
| 45 | +run_smt_test() { |
| 46 | + BASE_PATH="../../../" |
| 47 | + |
| 48 | + local rtlil_file=$1 |
| 49 | + |
| 50 | + local base_name=$(basename "$rtlil_file" .il) |
| 51 | + |
| 52 | + if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; write_functional_smt2 ${base_name}.smt2"; then |
| 53 | + echo "Yosys processed $rtlil_file successfully." |
| 54 | + # TODO: which SMT solver should be run? |
| 55 | + if z3 "${base_name}.smt2"; then |
| 56 | + echo "SMT file ${base_name}.smt2 is valid ." |
| 57 | + |
| 58 | + if python3 using_smtio.py "${base_name}.smt2"; then |
| 59 | + echo "Python script generated VCD file for $rtlil_file successfully." |
| 60 | + |
| 61 | + if [ -f "${base_name}.smt2.vcd" ]; then |
| 62 | + echo "VCD file ${base_name}.vcd generated successfully by Python." |
| 63 | + |
| 64 | + if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; sim -vcd ${base_name}_yosys.vcd -r ${base_name}.smt2.vcd -scope gold -timescale 1us"; then |
| 65 | + echo "Yosys simulation for $rtlil_file completed successfully." |
| 66 | + smt_successful_files["$rtlil_file"]="Success" |
| 67 | + else |
| 68 | + echo "Yosys simulation failed for $rtlil_file." |
| 69 | + smt_failing_files["$rtlil_file"]="Yosys simulation failure" |
| 70 | + fi |
| 71 | + else |
| 72 | + |
| 73 | + echo "Failed to generate VCD file (${base_name}.vcd) for $rtlil_file. " |
| 74 | + smt_failing_files["$rtlil_file"]="VCD generation failure" |
| 75 | + fi |
| 76 | + else |
| 77 | + echo "Failed to run Python script for $rtlil_file." |
| 78 | + smt_failing_files["$rtlil_file"]="Python script failure" |
| 79 | + fi |
| 80 | + else |
| 81 | + echo "SMT file for $rtlil_file is invalid" |
| 82 | + smt_failing_files["$rtlil_file"]="Invalid SMT" |
| 83 | + fi |
| 84 | + else |
| 85 | + echo "Yosys failed to process $rtlil_file." |
| 86 | + smt_failing_files["$rtlil_file"]="Yosys failure" |
| 87 | + fi |
| 88 | +} |
| 89 | + |
| 90 | + |
53 | 91 | run_all_tests() {
|
54 |
| - # Loop through all RTLIL files in the rtlil directory |
| 92 | + return_code=0 |
55 | 93 | for rtlil_file in rtlil/*.il; do
|
56 |
| - run_test "$rtlil_file" |
| 94 | + run_cxx_test "$rtlil_file" |
| 95 | + run_smt_test "$rtlil_file" |
57 | 96 | done
|
58 |
| - |
59 |
| - # Check if the array of failing files is empty |
60 |
| - if [ ${#failing_files[@]} -eq 0 ]; then |
| 97 | + |
| 98 | + echo "C++ tests results:" |
| 99 | + if [ ${#cxx_failing_files[@]} -eq 0 ]; then |
| 100 | + echo "All files passed." |
| 101 | + echo "The following files passed:" |
| 102 | + for file in "${!cxx_successful_files[@]}"; do |
| 103 | + echo "$file" |
| 104 | + done |
| 105 | + else |
| 106 | + echo "The following files failed:" |
| 107 | + for file in "${!cxx_failing_files[@]}"; do |
| 108 | + echo "$file: ${cxx_failing_files[$file]}" |
| 109 | + done |
| 110 | + echo "The following files passed:" |
| 111 | + for file in "${!cxx_successful_files[@]}"; do |
| 112 | + echo "$file" |
| 113 | + done |
| 114 | + return_code=1 |
| 115 | + fi |
| 116 | + |
| 117 | + echo "SMT tests results:" |
| 118 | + if [ ${#smt_failing_files[@]} -eq 0 ]; then |
61 | 119 | echo "All files passed."
|
62 | 120 | echo "The following files passed:"
|
63 |
| - for file in "${!successful_files[@]}"; do |
| 121 | + for file in "${!smt_successful_files[@]}"; do |
64 | 122 | echo "$file"
|
65 | 123 | done
|
66 |
| - return 0 |
67 | 124 | else
|
68 | 125 | echo "The following files failed:"
|
69 |
| - for file in "${!failing_files[@]}"; do |
70 |
| - echo "$file: ${failing_files[$file]}" |
| 126 | + for file in "${!smt_failing_files[@]}"; do |
| 127 | + echo "$file: ${smt_failing_files[$file]}" |
71 | 128 | done
|
72 | 129 | echo "The following files passed:"
|
73 |
| - for file in "${!successful_files[@]}"; do |
| 130 | + for file in "${!smt_successful_files[@]}"; do |
74 | 131 | echo "$file"
|
75 | 132 | done
|
76 |
| - return 1 |
| 133 | + return_code=1 |
77 | 134 | fi
|
| 135 | + return $return_code |
78 | 136 | }
|
79 | 137 |
|
80 | 138 | # If the script is being sourced, do not execute the tests
|
|
0 commit comments