Skip to content

Commit 6363d40

Browse files
committed
Add Dhrystone test script
The script calculates median absolute deviation (MAD) and filters out outliers. Usage: tests/dhrystone.sh Reference output: Running Dhrystone benchmark - Run 1 Running Dhrystone benchmark - Run 2 Running Dhrystone benchmark - Run 3 Running Dhrystone benchmark - Run 4 Running Dhrystone benchmark - Run 5 Running Dhrystone benchmark - Run 6 Running Dhrystone benchmark - Run 7 Running Dhrystone benchmark - Run 8 Running Dhrystone benchmark - Run 9 Running Dhrystone benchmark - Run 10 --------------------- Average DMIPS (Excluding Outliers): 693.50 ---------------------
1 parent 94b9699 commit 6363d40

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

tests/cc-selfhost.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
#!/usr/bin/env bash
22

3-
function fail()
4-
{
5-
echo "*** Fail"
6-
exit 1
7-
}
3+
source tests/common.sh
84

9-
O=build
105
S=tests/cc
11-
RUN=$O/rv32emu
12-
13-
if [ ! -f $RUN ]; then
14-
echo "No build/rv32emu found!"
15-
exit 1
16-
fi
176

187
echo "Generating cross compiler..."
198
cat $S/stdlib.c $S/emit.c $S/cc.c | cc -o $O/cc-native -x c - || fail

tests/common.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function fail()
2+
{
3+
echo "*** Fail"
4+
exit 1
5+
}
6+
7+
O=build
8+
RUN=$O/rv32emu
9+
10+
if [ ! -f $RUN ]; then
11+
echo "No build/rv32emu found!"
12+
exit 1
13+
fi

tests/dhrystone.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
source tests/common.sh
4+
5+
num_runs=10
6+
7+
function run_dhrystone()
8+
{
9+
# Run Dhrystone and extract the DMIPS value
10+
# output=$($RUN $O/dhrystone.elf)
11+
# dmips=$(echo "$output" | grep -oE '[0-9]+' | awk 'NR==5{print}')
12+
# echo "$dmips"
13+
output=$($RUN $O/dhrystone.elf 2>&1)
14+
local exit_code=$?
15+
[ $exit_code -ne 0 ] && fail
16+
dmips=$(echo "$output" | grep -oE '[0-9]+' | awk 'NR==5{print}')
17+
echo "$dmips"
18+
}
19+
20+
# Run Dhrystone benchmark and collect DMIPS values
21+
dmips_values=()
22+
for ((i=1; i<=$num_runs; i++))
23+
do
24+
echo "Running Dhrystone benchmark - Run $i"
25+
dmips=$(run_dhrystone)
26+
exit_code=$?
27+
[ $exit_code -ne 0 ] && fail
28+
dmips_values+=("$dmips")
29+
done
30+
31+
# Filter out non-numeric values
32+
filtered_dmips=()
33+
for dmips in "${dmips_values[@]}"
34+
do
35+
if [[ $dmips =~ ^[0-9]+$ ]]; then
36+
filtered_dmips+=("$dmips")
37+
fi
38+
done
39+
40+
# Calculate average DMIPS excluding outliers
41+
num_filtered=${#filtered_dmips[@]}
42+
if ((num_filtered > 0)); then
43+
total_filtered_dmips=0
44+
for dmips in "${filtered_dmips[@]}"
45+
do
46+
total_filtered_dmips=$(echo "$total_filtered_dmips + $dmips" | bc -l)
47+
done
48+
average_filtered_dmips=$(echo "scale=2; $total_filtered_dmips / $num_filtered" | bc -l)
49+
echo "---------------------"
50+
echo "Average DMIPS (Excluding Outliers): $average_filtered_dmips"
51+
echo "---------------------"
52+
else
53+
fail
54+
fi

0 commit comments

Comments
 (0)