summaryrefslogtreecommitdiff
path: root/tcwg-benchmark.sh
blob: 6128b125386fb52bfdd3b5461a6b8a2045ee2a7f (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
173
174
175
176
177
178
179
180
#!/bin/bash

# Clean: shellcheck -e 2001 ./tcwg-benchmark.sh

set -ex

# Make shellcheck happy and workaround Jenkins not defining variables
# for empty arguments.
build_container_tag="${build_container_tag-xenial-tcwg-tested}"
toolchain_url="$toolchain_url"
toolchain_type="${toolchain_type-auto}"
bench_list="$bench_list"
cflags="$cflags"
extension="$extension"
testmode="$testmode"
iterations="$iterations"
run_profile="$run_profile"
sysroot="$sysroot"
fileserver="$fileserver"
forceinstall="$forceinstall"
builder="$builder"
results_id="$results_id"
BUILD_NUMBER="$BUILD_NUMBER"
NODE_NAME="$NODE_NAME"
WORKSPACE="$WORKSPACE"
reboot="$reboot"
ignore_errors="$ignore_errors"

# Jenkins doesn't define variables when parameter value is empty (like cflags),
# so enable "set -u" only after above binding of variables.
set -u

if echo "$builder" | grep -q ".*-[0-9]\+"; then
    docker_host_opt="--arch amd64 --node $builder"
else
    docker_host_opt="--label $builder"
fi

# Make sure to cleanup build container if something goes
# wrong when preparing the test environment
trap "cleanup_all_containers" EXIT
./start-container-docker.sh $docker_host_opt --distro "$build_container_tag" --task build --prefix build_ > build-container.sh
build_container_host=
build_container_port=
. ./build-container.sh

. jenkins-helpers.sh

case "$toolchain_url" in
    "ssh://"*)
	ccprefix="${toolchain_url##ssh://}"
	if [ x"$sysroot" = x"tarball" ]; then
            echo "ERROR: Unsupported sysroot $sysroot for toolchain_url $toolchain_url"
            exit 1
	fi
	;;
    "http://"*".tar.xz"|"https://"*".tar.xz")
	toolchaindir=$(untar_url "$toolchain_url" "$WORKSPACE" "--strip-components 1")
	;;
    "rsync://"*)
	ccprefix="${toolchain_url##rsync://}"
	# We want to access the remote toolchain via a container, to
	# avoid problems with the hosts's ssh server restrictions on the
	# number of simulaneous connexions.
	# We copy it to the build container (assuming it uses the same
	# architecture as the machine pointed to by $toolchain_url).
	# Assume ccprefix looks like /path/bin/target-triplet-, and
	# compute 'path'.
	src_toolchaindir=$(dirname $(dirname ${ccprefix}))
	toolchaindir="${WORKSPACE}/toolchain-${BUILD_NUMBER}"
	rsync -az --delete "$src_toolchaindir/" "$toolchaindir/"
	;;
    *)
	echo "ERROR: Cannot handle toolchain_url: $toolchain_url"
	exit 1
	;;
esac

case "$toolchain_url" in
    "http://"*|"https://"*|"rsync://"*)
	case "$toolchain_type" in
	    "gnu"|"llvm") ;;
	    "auto")
		if [ x"$(find "$toolchaindir" -path "*bin/*gcc" | wc -l)" != x"0" ]; then
		    toolchain_type="gnu"
		elif [ x"$(find "$toolchaindir" -path "*bin/*clang" | wc -l)" != x"0" ]; then
		    toolchain_type="llvm"
		else
		    echo "ERROR: Cannot autodetect toolchain type"
		    exit 1
		fi
		;;
	    *)
		echo "ERROR: wrong toolchain_type: $toolchain_type"
		exit 1
		;;
	esac

	case "$toolchain_type" in
	    "gnu") ccname="gcc" ;;
	    "llvm") ccname="clang" ;;
	esac
	ccpath=$(find "$toolchaindir" -path "*bin/*$ccname")
	if [ $(echo "$ccpath" | wc -w) -ne 1 ]; then
	    echo "ERROR: found more than one compiler: $ccpath"
	    exit 1
	fi
	ccprefix=$(echo "$ccpath" | sed -e "s/$ccname\$//")
	# Copy toolchain to the build container.
	rsync -a --delete -e "ssh -p$build_container_port" "$toolchaindir/" "$build_container_host:$toolchaindir/"
	ccprefix="$build_container_host:$build_container_port:$ccprefix"
	;;
esac

case "$sysroot" in
    "tarball")
	sysroot="$build_container_host:$(find "$toolchaindir" -name "libc")"
	;;
    "http://"*|"https://"*)
	sysrootdir=$(untar_url "$sysroot" "$WORKSPACE" "--strip-components 1")
	# Copy toolchain to the build container.
	rsync -a --delete -e "ssh -p$build_container_port" "$sysrootdir/" "$build_container_host:$sysrootdir/"
	sysroot="$build_container_host:$sysrootdir"
	;;
    "")
	# Use system sysroot.
	;;
    *)
	echo "ERROR: Cannot handle sysroot: $sysroot"
	exit 1
	;;
esac

# Slaves for this job are virtual slaves on dev-01,
# convert the slave name into the target board name
boardname=$(echo "${NODE_NAME}" | sed 's/-bmk//').tcwglab
hw_type=$(print_hw_id_for_node "$NODE_NAME")

results_id=$(echo "$results_id" \
		    | sed -e "s/<hw_type>/$hw_type/g" \
			  -e "s/<build_num>/$BUILD_NUMBER/g")
if echo "$results_id" | grep -q "\.\."; then
    echo "ERROR: results_id should not escape /home/tcwg-benchmark/results* hierarchy; do not use \"..\""
    exit 1
fi

rsync -az --delete bmk-scripts/ "$boardname:bmk-scripts/"

if $reboot; then
    # Reboot the board
    ssh $boardname sudo /sbin/reboot || true
    # Wait until the ssh server is ready
    sleep 30 # Give time to the board to shutdown
    ret=0
    wait_for_ssh_server $boardname 22 100 || ret=$?
fi

case "$testmode" in
    build|verify) input_size="test" ;;
    benchmark) input_size="ref" ;;
esac

build_container_exec ssh -t "$boardname" bmk-scripts/run.sh \
                     --bench "$(printf '%q' "$bench_list")" \
                     --config "${BUILD_NUMBER}-$run_profile" \
                     --cflags "$(printf '%q' "$cflags")" \
                     --ccprefix "$ccprefix" \
		     --extension "$extension" \
		     --ignore_errors "$ignore_errors" \
		     --input_size "$input_size" \
		     --iterations "$iterations" \
		     --run_profile "$run_profile" \
                     "${sysroot:+--sysroot "$sysroot"}" \
                     --toolchain "$toolchain_type" \
                     --resultsdest "dev-01.tcwglab:/home/tcwg-benchmark/results-${results_id}/${NODE_NAME}" \
                     --nodename "${NODE_NAME}" \
                     --forceinstall "${forceinstall}" \
                     --verbose true

exit 0