-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoit.sh
More file actions
executable file
·85 lines (69 loc) · 2.09 KB
/
doit.sh
File metadata and controls
executable file
·85 lines (69 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# This script runs the testbench
# Usage: ./doit.sh <file1.cpp> <file2.cpp>
# Constants
SCRIPT_DIR=$(dirname "$(realpath "$0")")
TEST_FOLDER=$(realpath "$SCRIPT_DIR/tests")
RTL_FOLDER=$(realpath "$SCRIPT_DIR/../rtl")
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)
RESET=$(tput sgr0)
# Variables
passes=0
fails=0
# Handle terminal arguments
if [[ $# -eq 0 ]]; then
# If no arguments provided, run all tests
files=(${TEST_FOLDER}/*.cpp)
else
# If arguments provided, use them as input files
files=("$@")
fi
# Cleanup
rm -rf obj_dir
cd $SCRIPT_DIR
# Iterate through files
for file in "${files[@]}"; do
name=$(basename "$file" _tb.cpp | cut -f1 -d\-)
# If verify.cpp -> we are testing the top module
if [ $name == "verify.cpp" ]; then
name="top"
fi
# Automatically detect latest GoogleTest installation under Homebrew
GTEST_BASE=$(brew --prefix googletest 2>/dev/null)
if [ -z "$GTEST_BASE" ]; then
echo "${RED}Error: GoogleTest not found via Homebrew.${RESET}"
exit 1
fi
# Construct include and lib paths dynamically
GTEST_INCLUDE="$GTEST_BASE/include"
GTEST_LIB="$GTEST_BASE/lib"
# Translate Verilog -> C++ including testbench
verilator -Wall --trace \
-cc ${RTL_FOLDER}/${name}.sv \
--exe ${file} \
-y ${RTL_FOLDER} \
--prefix "Vdut" \
-o Vdut \
-CFLAGS "-std=c++17 -isystem ${GTEST_INCLUDE}" \
-LDFLAGS "-L${GTEST_LIB} -lgtest -lgtest_main -lpthread"
# Build C++ project with automatically generated Makefile
make -j -C obj_dir/ -f Vdut.mk
# Run executable simulation file
./obj_dir/Vdut
# Check if the test succeeded or not
if [ $? -eq 0 ]; then
((passes++))
else
((fails++))
fi
done
# Exit as a pass or fail (for CI purposes)
if [ $fails -eq 0 ]; then
echo "${GREEN}Success! All ${passes} test(s) passed!"
exit 0
else
total=$((passes + fails))
echo "${RED}Failure! Only ${passes} test(s) passed out of ${total}."
exit 1
fi