From bb04a71a8e4d6e4b365c85ecc332585de645363a Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 24 Jun 2024 03:05:44 +0200 Subject: [PATCH] Consolidate tests scripts into one --- tests/functional/single_cells/run-test.sh | 116 +++++++++++++----- tests/functional/single_cells/run-test_smt.sh | 91 -------------- 2 files changed, 87 insertions(+), 120 deletions(-) delete mode 100755 tests/functional/single_cells/run-test_smt.sh diff --git a/tests/functional/single_cells/run-test.sh b/tests/functional/single_cells/run-test.sh index 67cdf4a11c4..fd1b178e45a 100755 --- a/tests/functional/single_cells/run-test.sh +++ b/tests/functional/single_cells/run-test.sh @@ -1,80 +1,138 @@ #!/bin/bash -# Initialize an array to store the names of failing RTLIL files and their failure types -declare -A failing_files -# Initialize an array to store the names of successful RTLIL files -declare -A successful_files +declare -A cxx_failing_files +declare -A smt_failing_files +declare -A cxx_successful_files +declare -A smt_successful_files -# Function to run the test on a given RTLIL file -run_test() { - # Define the common variable for the relative path +run_cxx_test() { BASE_PATH="../../../" local rtlil_file=$1 - # Extract the base name without extension local base_name=$(basename "$rtlil_file" .v) - # Run yosys to process each RTLIL file if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; write_functional_cxx my_module_functional_cxx.cc"; then echo "Yosys processed $rtlil_file successfully." - # Compile the generated C++ files with vcd_harness.cpp 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 echo "Compilation successful." - # Generate VCD files with base_name if ./vcd_harness ${base_name}_functional_cxx.vcd; then - # Run yosys to process each RTLIL file 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 echo "Yosys sim $rtlil_file successfully." - successful_files["$rtlil_file"]="Success" + cxx_successful_files["$rtlil_file"]="Success" else ${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" echo "Yosys simulation of $rtlil_file failed. There is a discrepancy with functional cxx" - failing_files["$rtlil_file"]="Yosys sim failure" + cxx_failing_files["$rtlil_file"]="Yosys sim failure" fi else echo "Failed to generate VCD files for $rtlil_file." - failing_files["$rtlil_file"]="VCD generation failure" + cxx_failing_files["$rtlil_file"]="VCD generation failure" fi else echo "Failed to compile harness for $rtlil_file." - failing_files["$rtlil_file"]="Compilation failure" + cxx_failing_files["$rtlil_file"]="Compilation failure" fi else echo "Yosys failed to process $rtlil_file." - failing_files["$rtlil_file"]="Yosys failure" + cxx_failing_files["$rtlil_file"]="Yosys failure" fi } -# Main function to run all tests +run_smt_test() { + BASE_PATH="../../../" + + local rtlil_file=$1 + + local base_name=$(basename "$rtlil_file" .il) + + if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; write_functional_smt2 ${base_name}.smt2"; then + echo "Yosys processed $rtlil_file successfully." + # TODO: which SMT solver should be run? + if z3 "${base_name}.smt2"; then + echo "SMT file ${base_name}.smt2 is valid ." + + if python3 using_smtio.py "${base_name}.smt2"; then + echo "Python script generated VCD file for $rtlil_file successfully." + + if [ -f "${base_name}.smt2.vcd" ]; then + echo "VCD file ${base_name}.vcd generated successfully by Python." + + 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 + echo "Yosys simulation for $rtlil_file completed successfully." + smt_successful_files["$rtlil_file"]="Success" + else + echo "Yosys simulation failed for $rtlil_file." + smt_failing_files["$rtlil_file"]="Yosys simulation failure" + fi + else + + echo "Failed to generate VCD file (${base_name}.vcd) for $rtlil_file. " + smt_failing_files["$rtlil_file"]="VCD generation failure" + fi + else + echo "Failed to run Python script for $rtlil_file." + smt_failing_files["$rtlil_file"]="Python script failure" + fi + else + echo "SMT file for $rtlil_file is invalid" + smt_failing_files["$rtlil_file"]="Invalid SMT" + fi + else + echo "Yosys failed to process $rtlil_file." + smt_failing_files["$rtlil_file"]="Yosys failure" + fi +} + + run_all_tests() { - # Loop through all RTLIL files in the rtlil directory + return_code=0 for rtlil_file in rtlil/*.il; do - run_test "$rtlil_file" + run_cxx_test "$rtlil_file" + run_smt_test "$rtlil_file" done - - # Check if the array of failing files is empty - if [ ${#failing_files[@]} -eq 0 ]; then + + echo "C++ tests results:" + if [ ${#cxx_failing_files[@]} -eq 0 ]; then + echo "All files passed." + echo "The following files passed:" + for file in "${!cxx_successful_files[@]}"; do + echo "$file" + done + else + echo "The following files failed:" + for file in "${!cxx_failing_files[@]}"; do + echo "$file: ${cxx_failing_files[$file]}" + done + echo "The following files passed:" + for file in "${!cxx_successful_files[@]}"; do + echo "$file" + done + return_code=1 + fi + + echo "SMT tests results:" + if [ ${#smt_failing_files[@]} -eq 0 ]; then echo "All files passed." echo "The following files passed:" - for file in "${!successful_files[@]}"; do + for file in "${!smt_successful_files[@]}"; do echo "$file" done - return 0 else echo "The following files failed:" - for file in "${!failing_files[@]}"; do - echo "$file: ${failing_files[$file]}" + for file in "${!smt_failing_files[@]}"; do + echo "$file: ${smt_failing_files[$file]}" done echo "The following files passed:" - for file in "${!successful_files[@]}"; do + for file in "${!smt_successful_files[@]}"; do echo "$file" done - return 1 + return_code=1 fi + return $return_code } # If the script is being sourced, do not execute the tests diff --git a/tests/functional/single_cells/run-test_smt.sh b/tests/functional/single_cells/run-test_smt.sh deleted file mode 100755 index 42e1a7c4b65..00000000000 --- a/tests/functional/single_cells/run-test_smt.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash - -# Initialize an array to store the names of failing RTLIL files and their failure types -declare -A failing_files -# Initialize an array to store the names of successful RTLIL files -declare -A successful_files - -# Function to run the test on a given RTLIL file -run_test() { - # Define the common variable for the relative path - BASE_PATH="../../../" - - local rtlil_file=$1 - - # Extract the base name without extension - local base_name=$(basename "$rtlil_file" .il) - - # Run yosys to process each RTLIL file - if ${BASE_PATH}yosys -p "read_rtlil $rtlil_file; write_functional_smt2 ${base_name}.smt2"; then - echo "Yosys processed $rtlil_file successfully." - # Check that the smt file generated is valid - # Execute the Python script to create a VCD file from the SMT2 file - if z3 "${base_name}.smt2"; then - echo "SMT file ${base_name}.smt2 is valid ." - - if python3 using_smtio.py "${base_name}.smt2"; then - echo "Python script generated VCD file for $rtlil_file successfully." - - # Check if VCD file was generated successfully - if [ -f "${base_name}.smt2.vcd" ]; then - echo "VCD file ${base_name}.vcd generated successfully by Python." - - # Run yosys simulation to generate a reference VCD file - 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 - echo "Yosys simulation for $rtlil_file completed successfully." - successful_files["$rtlil_file"]="Success" - else - echo "Yosys simulation failed for $rtlil_file." - failing_files["$rtlil_file"]="Yosys simulation failure" - fi - else - - echo "Failed to generate VCD file (${base_name}.vcd) for $rtlil_file. " - failing_files["$rtlil_file"]="VCD generation failure" - fi - else - echo "Failed to run Python script for $rtlil_file." - failing_files["$rtlil_file"]="Python script failure" - fi - else - echo "SMT file for $rtlil_file is invalid" - failing_files["$rtlil_file"]="Invalid SMT" - fi - else - echo "Yosys failed to process $rtlil_file." - failing_files["$rtlil_file"]="Yosys failure" - fi -} - -# Main function to run all tests -run_all_tests() { - # Loop through all RTLIL files in the rtlil directory - for rtlil_file in rtlil/*.il; do - run_test "$rtlil_file" - done - - # Check if the array of failing files is empty - if [ ${#failing_files[@]} -eq 0 ]; then - echo "All files passed." - echo "The following files passed:" - for file in "${!successful_files[@]}"; do - echo "$file" - done - return 0 - else - echo "The following files failed:" - for file in "${!failing_files[@]}"]; do - echo "$file: ${failing_files[$file]}" -done -echo "The following files passed:" -for file in "${!successful_files[@]}"]; do - echo "$file" - done - return 1 - fi - } - - # If the script is being sourced, do not execute the tests - if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - run_all_tests - fi