-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mips_cpu_bus.sh
executable file
·189 lines (149 loc) · 5.27 KB
/
test_mips_cpu_bus.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
rm -rf test/bin1
rm -rf test/bin1/r_type
rm -rf test/bin1/i_type
rm -rf test/bin1/j_type
rm -rf test/tmp1
rm -rf test/tmp1/r_type
rm -rf test/tmp1/i_type
rm -rf test/tmp1/j_type
rm -rf test/hex1
rm -rf test/hex1/r_type
rm -rf test/hex1/i_type
rm -rf test/hex1/j_type
rm -rf test/results1
rm -rf test/simulator1
mkdir -p test/bin1
mkdir -p test/bin1/r_type
mkdir -p test/bin1/i_type
mkdir -p test/bin1/j_type
mkdir -p test/tmp1
mkdir -p test/tmp1/r_type
mkdir -p test/tmp1/i_type
mkdir -p test/tmp1/j_type
mkdir -p test/hex1
mkdir -p test/hex1/r_type
mkdir -p test/hex1/i_type
mkdir -p test/hex1/j_type
mkdir -p test/results1
mkdir -p test/simulator1
### get file input
SOURCEDIR="$1"
INSTRUCTION="$2"
lower_level=("${SOURCEDIR}/mips_cpu_*.v"
"${SOURCEDIR}/mips_cpu/*.v"
)
if [ -z "$INSTRUCTION" ]; then
i=1
touch test/results1/result1.csv
#>&2 echo "Instruction has not been specified. Proceeding with all functional tests."
for type in r i j e s ; do
TESTS="test/tests/${type}_type/*.s"
#>&2 echo "Commencing ${type} type instruction tests."
echo "${type} tests:" >> test/results1/result1.csv
for t in $TESTS; do
TESTCASE="$t"
basename "$TESTCASE" >/dev/null
hexname="$(basename -- $TESTCASE)"
hexed="${hexname%.*}"
exec 5< $t
### first line specifies what is being tested
read -r line <&5
testType="${line:1:${#line}-1}"
### gives the expected value
read -r line <&5
expectedValue="${line:1:${#line}-1}"
### read test id
read -r line <&5
testId="${line:1:${#line}-1}"
### read additional comment
read -r line <&5
comment="${line:1:${#line}-1}"
### assemble input file
mipsel-linux-gnu-gcc -c test/tests/${type}_type/$hexed.s -o test/tmp1/${type}_type/$hexed.o &>/dev/null
mipsel-linux-gnu-objcopy -O binary --only-section=.text test/tmp1/${type}_type/$hexed.o test/bin1/${type}_type/$hexed.bin
hexdump -v test/bin1/${type}_type/$hexed.bin > test/hex1/${type}_type/$hexed.hex.txt -e '1/4 "%08x " "\n"'
###compile testbench
iverilog -g 2012 \
test/mips_cpu_bus_tb_delay1.v test/RAM_32x2048_delay1.v ${lower_level[@]} -s mips_cpu_bus_tb_delay1 -Pmips_cpu_bus_tb_delay1.RAM_INIT_FILE=\"test/hex1/${type}_type/$hexed.hex.txt\" -o test/simulator1/mips_cpu_bus_tb_delay1_$hexed 2>/dev/null
###run testbench
set +e
test/simulator1/mips_cpu_bus_tb_delay1_$hexed > test/results1/mips_cpu_bus_tb_delay1_$hexed.txt
output=$(tail -n 1 test/results1/mips_cpu_bus_tb_delay1_${hexed}.txt)
#echo "out $output"
#echo "exp $expectedValue"
set -e
###testing for failure code
# if [[ "${output}" -ne 0 ]]; then
# echo "${testType}_${testId} "fail" ${output}" >> test/results1/result1_${INSTRUCTION}.csv
# fi
###compare output to expected
bool="Fail"
if [ $output -eq $expectedValue ]; then
bool="Pass"
fi
file_base_name=${t##*/}
file_base_name=${file_base_name%.s}
echo $file_base_name ${testType} ${bool}
#echo "${testType}_${testId} ${bool} ${comment}" >> test/results1/result1.csv
#echo ""
done
done
else
i=1
for type in r i j e s ; do
TESTS="test/tests/${type}_type/*.s"
touch test/results1/result1_${INSTRUCTION}.csv
#>&2 echo "Instruction has been specified. Proceeding with ${INSTRUCTION} test."
for t in $TESTS; do
TESTCASE="$t"
basename "$TESTCASE" >/dev/null
hexname="$(basename -- $TESTCASE)"
hexed="${hexname%.*}"
exec 5< $t
### first line specifies what is being tested
read -r line <&5
testType="${line:1:${#line}-1}"
### gives the expected value
read -r line <&5
expectedValue="${line:1:${#line}-1}"
### read test id
read -r line <&5
testId="${line:1:${#line}-1}"
### read additional comment
read -r line <&5
comment="${line:1:${#line}-1}"
if [ "$testType" == "$INSTRUCTION" ]; then
### assemble input file
mipsel-linux-gnu-gcc -c test/tests/${type}_type/$hexed.s -o test/tmp1/${type}_type/$hexed.o &>/dev/null
mipsel-linux-gnu-objcopy -O binary --only-section=.text test/tmp1/${type}_type/$hexed.o test/bin1/${type}_type/$hexed.bin 2>&1 >/dev/null
hexdump -v test/bin1/${type}_type/$hexed.bin > test/hex1/${type}_type/$hexed.hex.txt -e '1/4 "%08x " "\n"'
###compile testbench
iverilog -g 2012 \
test/mips_cpu_bus_tb_delay1.v test/RAM_32x2048_delay1.v ${lower_level[@]} -s mips_cpu_bus_tb_delay1 -Pmips_cpu_bus_tb_delay1.RAM_INIT_FILE=\"test/hex1/${type}_type/$hexed.hex.txt\" -o test/simulator1/mips_cpu_bus_tb_delay1_$hexed 2>/dev/null
###run testbench
set +e
test/simulator1/mips_cpu_bus_tb_delay1_$hexed > test/results1/mips_cpu_bus_tb_delay1_$hexed.txt
output=$(tail -n 1 test/results1/mips_cpu_bus_tb_delay1_${hexed}.txt)
#echo "out $output"
#echo "exp $expectedValue"
set -e
###testing for failure code
# if [[ "${output}" -ne 0 ]]; then
# echo "${testType}_${testId} "fail" ${output}" >> test/results1/result1_${INSTRUCTION}.csv
# fi
###compare output to expected
bool="Fail"
if [ $output -eq $expectedValue ]; then
bool="Pass"
fi
file_base_name=${t##*/}
file_base_name=${file_base_name%.s}
echo $file_base_name ${testType} ${bool}
#echo "${testType}_${testId} ${bool} ${comment}" >> test/results1/result1_${INSTRUCTION}.csv
#echo ${bool}
#echo ""
fi
done
done
fi