forked from Xilinx-CNS/onload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonload_mktest
More file actions
executable file
·290 lines (248 loc) · 8.78 KB
/
Copy pathonload_mktest
File metadata and controls
executable file
·290 lines (248 loc) · 8.78 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash -eu
# SPDX-License-Identifier: BSD-2-Clause
# X-SPDX-Copyright-Text: (c) Copyright 2010-2021 Xilinx, Inc.
##############################################################################
# Mix specified netdriver + onload from this tree
# Push to onload-tests repo
# See http://intranet.solarflarecom.com/staffwiki/OpenOnloadRepos
# Puts the changes onto a staging branch for subsequent review
##############################################################################
set -o pipefail
bin=$(cd $(dirname "$0") && /bin/pwd)
me=$(basename "$0")
err() { echo >&2 "$*"; }
log() { err "$me: $*"; }
fail() { log "$*"; exit 1; }
try() { "$@" || fail "FAILED: $*"; }
# Constants
staging_branch="onload_mktest_staging"
# Settings
legacyrepo="/project/hg/incoming/v5"
netrepo="/project/ci/git/linux-net"
fwrepo="/project/hg/incoming/sfutils_config"
fwtag=""
legacytag="default"
git=${GIT_PATH:-"git"}
usage() {
err
err "usage:"
err " $me [options] <net driver changeset>"
err
err "options:"
err " --netrepo=<path-to-repository> repository to get drivers from"
err " --legacyrepo=<path-to-repository> legacy repository to get common 'v5' files from"
err " --fwtag=<tag>"
err " --legacytag=<tag>"
err " --debug"
err " --nomcdi"
exit 1
}
# Create the commit log for a new patch
newpatch() {
local pname="$1"
local msg="$2"
echo "onload_mktest_$pname: $msg"
}
# Commit a patch if there's something to commit
commitif() {
"$git" status -s -uno
if [ -n "$( $git status --porcelain -uno)" ]; then
git commit -m "$*"
else
echo "nothing to commit: omitting patch"
fi
}
# Execute a git command in a given repository.
git-in() {
local repo="$1"
shift
# This is preferable to using --git-dir because then the user does
# not have to specify the .git directory for non-bare repos.
( cd "$repo" && "$git" "$@" )
}
# Export a set of files from a given revision of a given repository
hg-export() {
local repo="$1"
local rev="$2"
shift 2
(
cd $repo
hg archive -r "$rev" \
$(for i in "$@"; do echo "-I $i"; done) \
-t tar -p '.' -
)
}
# Export a set of files from a given revision of a given repository
git-export() {
local repo="$1"
local rev="$2"
local whitelist="$3"
local blacklist="$4"
shift 4
(
cd $repo
local extant_files=$(git ls-tree -r --name-only $rev "$@" \
| grep -E "$whitelist" | grep -Ev "$blacklist")
"$git" archive $rev $extant_files
)
}
###############################################################################
# main()
push=false
mcdi=true
tmpdir=
# CLI handling
while [ $# -gt 0 ]; do
case "$1" in
--netrepo=*) netrepo=${1#--netrepo=};;
--netrepo) shift; netrepo="$1";;
--legacyrepo=*) legacyrepo=${1#--legacyrepo=};;
--legacyrepo) shift; legacyrepo="$1";;
--fwtag=*) fwtag=${1#--fwtag=};;
--fwtag) shift; fwtag="$1";;
--legacytag=*) legacytag=${1#--legacytag=};;
--legacytag) shift; legacytag="$1";;
--debug) set -x;;
--nomcdi) mcdi=false;;
-*) usage;;
*) break;;
esac
shift
done
[ $# = 1 ] || usage
netrev=$1
###############################################################################
echo "*** Please consult http://tinderbox/ to check that the current onload test engine is building without error on the default branch (to avoid bad tags) ***"
read -p "Press enter to proceed ..."
echo "Thanks, proceeding ..."
echo "===== Sanity checks ====="
[ "$EUID" != "0" ] || fail "Please do not run as root"
export PATH="$bin:$PATH"
top=$(mmaketool --toppath)
[ -d "$top" ] || fail "Is mmaketool in your PATH?"
cd "$top"
[ -n "$netrepo" ] || netrepo="$top"
[ -d "$netrepo" ] || fail "--netrepo is not valid"
onloadid=$("$git" describe --always --dirty=+)
[ "${onloadid/\+/|/}" == "${onloadid}" ] ||
fail "onload repo has local changes. See git status."
"$git" checkout -b "$staging_branch" || \
fail "$staging_branch branch already exists; clean up before re-running"
# Validate the supplied net revision spec
rawnetrev=$(git-in "$netrepo" rev-parse --verify "$netrev") || \
fail "Unknown revision '$netrev' in '$netrepo'"
# Canonicalise the supplied net revision spec if not a tag
git-in "$netrepo" rev-parse -q --verify "refs/tags/${netrev}" > /dev/null ||
netrev="${rawnetrev}"
if [ -n "$fwtag" ] && ! hg -R "$fwrepo" id -r "$fwtag" > /dev/null 2>&1; then
fail "'$fwtag' does not exist in '$fwrepo'."
fi
if $mcdi; then
[ -d "$legacyrepo" ] || fail "--legacyrepo is not valid"
if [ -n "$legacytag" ] && ! hg -R "$legacyrepo" id -r "$legacytag" > /dev/null 2>&1; then
fail "'$legacytag' does not exist in '$legacyrepo'."
fi
# Canonicalise the legacy name if it is not a valid tag
if [ "$legacytag" == tip ] || [ "$(hg id -R "$legacyrepo" -r "$legacytag" -t)" != "$legacytag" ]; then
legacytag=$(hg id -R "$legacyrepo" --id -r ${legacytag})
fi
fi
###############################################################################
tmpdir=$(mktemp -d $me.XXXXXX)
echo "In case of failure, please clean up temporary directory: $tmpdir"
echo -e "\n\n===== revert to specified net driver ====="
commitlog=$(newpatch net_driver "Replacing net driver with ${netrev}")
# Compute net driver files that should be added and removed, excluding
# the glue makefile from consideration
legacy_driver_path=src/driver/linux_net/
netgot="$tmpdir/netgot"
netwant="$tmpdir/netwant"
glue_makefile_pattern="mmake.mk$"
# We need the whole of the drivers and include directories, as well as
# the top level makefile and some scripts
whitelist="^((scripts/export.sh)|(scripts/kernel_compat_funcs.sh)|(scripts/Makefile.common)|(include)|(drivers.*mmake.mk)|(drivers/bus)|(drivers/net/ethernet/sfc(/trace/events)?/[^/]+$))|(Makefile)|(phy_power)|(reset_nic)|(set_carrier)|(user_compat.sh)|(req.h)"
# We don't want directories to be listed or other unnecessary files
blacklist="(/$)|(xen/)|(load.*\.sh)|(unittest)|(systemtap)|(kscripts)|(dummycommit)|(doc/)|(Kconfig)|(export\.sh)|(^tools)"
# We use || true for the grep here to allow the case where we currently
# have no files, as the script is run with -o pipefail.
"$git" ls-files \
src/driver/linux_net \
| (grep -v ${glue_makefile_pattern} || true) | sort > ${netgot}
git-export "$netrepo" "$netrev" "$whitelist" "$blacklist" \
| tar xv -C $legacy_driver_path \
| sed s,^,${legacy_driver_path},g \
| sort > "$netwant"
grep -q "$glue_makefile_pattern" "$netwant" && \
fail "mmake.mk found in non v5-style driver source would overwrite static glue."
for file in $(comm -1 ${netgot} ${netwant}); do
"$git" add ${file}
done
for file in $(comm -1 -3 ${netwant} ${netgot}); do
"$git" rm ${file}
done
# Avoid unnecessary utilities
utils_makefile=${legacy_driver_path}/drivers/net/ethernet/sfc/util/Makefile
sed -i 's,^TARGETS *:=.*$,TARGETS := phy_power reset_nic set_carrier,g' ${utils_makefile}
git add ${utils_makefile}
commitif $commitlog
if [ -n "$fwtag" ]; then
echo -e "\n\n===== set specified firmware by changing imports.mk ====="
commitlog=$(newpatch firmware "$me: Change to import firmware ${netrev}")
sed -i -n '/FIRMWARE_VERSION/!p' imports.mk
echo "FIRMWARE_VERSION=${fwtag}" >> imports.mk
"$git" add imports.mk
commitif "$commitlog"
fi
if $mcdi; then
echo -e "\n\n===== copying specified MCDI header ====="
commitlog=$(newpatch mcdi "Replacing MCDI header with ${legacytag}")
importhdr="mc_driver_pcol.h"
sourcedir="src/include/ci/mgmt/"
destdir="src/include/ci/efhw/"
transformpath="s+${sourcedir}+${destdir}+"
# Archive the correct revision of the header, then extract it to the
# correct onload location
files=$(hg-export "$legacyrepo" "$legacytag" \
"${sourcedir}/${importhdr}" | \
tar xv --transform="$transformpath" | sed $transformpath)
# This substitutes the appropriate licence for imported files.
perl -ni - ${destdir}/${importhdr} << 'EOF'
BEGIN {
$state = "IDLE";
$pstate = "";
}
if ($state eq "IDLE") {
print "/* SP"."DX-License-Identifier: GPL-2.0 */\n";
print "/* X-SP"."DX-Copyright-Text: (c) Copyright Xilinx, Inc. */\n";
$nstate = m,^/\*, ? "COMMENT" : "ERROR";
} elsif ($state eq "COMMENT") {
if (m,confidential and proprietary,) {
$nstate = "BOILERPLATE";
}
} elsif ($state eq "BOILERPLATE") {
if (m,^ *\*+/,) {
$nstate = "BODY";
}
} elsif ($state eq "BODY") {
print $_;
}
if ($nstate ne $state) {
$pstate = $state;
$state = $nstate;
}
END {
if ($state ne "BODY") {
print STDERR "finished processing file in non-terminal state $state (previous state $pstate)\n";
exit 1;
}
}
EOF
"$git" add $files
commitif "$commitlog"
fi
[ -n "$tmpdir" ] && rm -Rf ${tmpdir}
echo
echo "The next steps are manual:"
echo " 1. Test the branch $staging_branch in tinderbox"
echo " 2. Merge into your release or master branch"
echo " 3. Push"