aboutsummaryrefslogtreecommitdiff
path: root/coremark.sh
blob: 34ad188f95761561c32b6e0f7d97c58e82bb1454 (plain)
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
#!/bin/bash
# Simple script to build the STM32 HAL library (to interface with the
# clocks), then build and execute coremark on the target board.
set -e

usage()
{
    cat <<EOF
Usage: $0 [OPT]

	Options:
	--ccprefix prefix
	--cflags cflags
	--hw_tag {STM32L476RGTx|etc}
	--forceinstall true/false
	--ldflags ldflags
	--resultsdest host:/path/
	--verbose true/false
EOF
    exit 1
}

ccprefix=
cflags=
ldflags="default"
forceinstall=false
hw_tag=STM32L476RGTx
resultsdest=

while [ $# -ge 1 ]
do
    case $1 in
	--ccprefix)
	    ccprefix="$2"
	    shift
	    ;;
	--cflags)
	    cflags="$2"
	    shift
	    ;;
	--ldflags)
	    ldflags="$2"
	    shift
	    ;;
	--hw_tag)
	    hw_tag="$2"
	    shift
	    ;;
	--forceinstall)
	    forceinstall=$2
	    shift
	    ;;
	--resultsdest)
	    resultsdest="$2"
	    shift
	    ;;
	--verbose)
	    verbose="$2"
	    shift
	    ;;
	*)
	    echo "ERROR: Wrong argument: $1"
	    usage
	    ;;
    esac
    shift
done

if $verbose; then
    verbose="set -x"
else
    verbose="set +x"
fi

$verbose

# Sanity checks
[ x"${hw_tag}" = x ] && usage
[ x"${resultsdest}" = x ] && usage
case ${forceinstall} in
    true|false) ;;
    *)
	echo ERROR: Wrong value for --forceinstall: $forceinstall
	usage ;;
esac

if ${forceinstall} ; then
    rm -rf stm32-hal coremark
fi

[ ! -d stm32-hal ] && git clone https://git.linaro.org/toolchain/stm32-hal.git
cd stm32-hal
make CROSS_COMPILE=$ccprefix TARGET=$hw_tag clean all
cd ..

[ ! -d coremark ] && git clone ssh://dev-private-git.linaro.org/restricted-benchmarks/coremark.git
cd coremark

# ../ is bmk-scripts
rsync -av ../stm32-coremark/ stm32/

# Cleanup artifacts from previous runs
rm -f coremark.exe run?.log size.txt

make CROSS_COMPILE=$ccprefix \
     TARGET=$hw_tag \
     BOARD=$hw_tag \
     CLOCK=USE_HAL_CLOCK \
     PORT_DIR=stm32 \
     HAL_BSP=$PWD/../stm32-hal \
     XCFLAGS="$cflags $ldflags" \
     ITERATIONS=3000 \
     clean run &
res=0 && wait $! || res=$?

dest=$resultsdest
case "$dest" in
    *":"*":"*)
	dest_host="$(echo $dest | cut -d: -f 1):"
	dest_port=(-e "ssh -p$(echo $dest | cut -d: -f 2)")
	dest_dir="$(echo $dest | cut -d: -f 3)"
	;;
    *":"*)
	dest_host="$(echo $dest | cut -d: -f 1):"
	dest_port=()
	dest_dir="$(echo $dest | cut -d: -f 2)"
	;;
    *)
	dest_host=""
	dest_port=()
	dest_dir="$dest"
	;;
esac

declare status ticks
if ! [ -f coremark.exe ]; then
    status="failed-to-build"
    ticks="-1"
elif [ $res != 0 ]; then
    # coremark.exe exists, but $res is non-zero
    status="failed-to-run"
    ticks="-1"
else
    # coremark.exe exists, $res is zero
    status="success"
    ticks=$(grep 'Total ticks' run1.log | awk '{print $4;}')
fi

echo "benchmark,symbol,status" > status.csv
echo "coremark,coremark,$status" >> status.csv

echo "benchmark,symbol,sample" > results.csv
echo "coremark,coremark,$ticks" >> results.csv

if [ -f coremark.exe ]; then
    size -A coremark.exe > size.txt
fi

results=(status.csv results.csv)
for i in run?.log size.txt coremark.exe; do
    if [ -f "$i" ]; then
	results+=("$i")
    fi
done

rsync --rsync-path="mkdir -p $dest_dir && rsync" "${dest_port[@]}" -a \
      "${results[@]}" $dest_host$dest_dir/

# Compress exe for uploading to artifacts in jenkins.
if [ -f coremark.exe ]; then
    xz coremark.exe
fi