-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
test
executable file
·209 lines (192 loc) · 4.5 KB
/
test
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
#!/bin/bash
usage() {
echo "usage: $PROGNAME [-p patch] <build|install|boot|test|patchcheck|bisect>..." >&2
exit 1
}
PROGNAME=$0
WORKING_DIR=$(pwd)
if [ $# -lt 1 ] ; then
usage
fi
PATCH=""
while getopts p: OPT ; do
case $OPT in
p)
PATCH=$(realpath $OPTARG)
if [ ! \( -f $PATCH -a -f $PATCH \) ] ; then
echo "invalid patch file: $PATCH" >&2
fi
;;
\?)
usage
;;
esac
done
shift $((OPTIND - 1))
CONFFILE=ktest.conf
SUBCOMMAND=$1
BOOT_VM_IF_NECESSARY=1
case $SUBCOMMAND in
build|install)
BOOT_VM_IF_NECESSARY=0
;;
boot)
;;
test)
if [ $# -lt 2 ] ; then
echo "usage: $0 test <test path>" >&2
exit 1
fi
TEST=$2
if [ ! -f ${TEST} -o ! -x ${TEST} ] ; then
echo "${TEST} should be executable test program" >&2
exit 1
fi
TEST=$(realpath ${TEST})
;;
patchcheck)
if [ $# -lt 4 ] ; then
echo "usage: $0 patchcheck <start> <end> [build|install|boot|test] [test path]" >&2
echo " <start>: the first patch of the test target patchset" >&2
echo " <end>: the last patch of the test target patchset" >&2
exit 1
fi
PATCHCHECK_START=$2
PATCHCHECK_END=$3
PATCHCHECK_TYPE=$4
case $PATCHCHECK_TYPE in
build|install)
BOOT_VM_IF_NECESSARY=0
;;
boot)
;;
test)
if [ $# -lt 5 ] ; then
echo "usage: $0 patchcheck <start> <end> test <test path>" >&2
exit 1
fi
TEST=$5
if [ ! -f ${TEST} -o ! -x ${TEST} ] ; then
echo "${TEST} should be executable test program" >&2
exit 1
fi
TEST=$(realpath ${TEST})
;;
*)
echo "usage: $0 patchcheck <start> <end> [build|install|boot|test] [test path]" >&2
echo " <start>: the first patch of the test target patchset" >&2
echo " <end>: the last patch of the test target patchset" >&2
exit 1
;;
esac
;;
bisect)
if [ $# -lt 4 ] ; then
echo "usage: $0 bisect <good> <bad> [build|install|boot|test] [test path]" >&2
echo " <good>: the patch which passes test" >&2
echo " <bad>: the patthc which fails test" >&2
exit 1
fi
BISECT_GOOD=$2
BISECT_BAD=$3
BISECT_TYPE=$4
case $BISECT_TYPE in
build|install)
BOOT_VM_IF_NECESSARY=0
;;
boot)
;;
test)
if [ $# -lt 5 ] ; then
echo "usage: $0 bisect <good> <bad> test <test path>" >&2
exit 1
fi
TEST=$5
if [ ! -f ${TEST} -o ! -x ${TEST} ] ; then
echo "${TEST} should be executable test program" >&2
exit 1
fi
TEST=$(realpath ${TEST})
;;
*)
echo "usage: $0 bisect <good> <bad> [build|install|boot|test] [test path]" >&2
echo " <good>: the patch which passes test" >&2
echo " <bad>: the patthc which fails test" >&2
exit 1
;;
esac
;;
*)
echo "subcommand shoulld be <build|install|boot|test|patchcheck|bisect>: ${SUBCOMMAND}" >&2
exit 1
;;
esac
trap "_cleanup ; exit 0" 0 1 2 3 15
function _cleanup {
cd $WORKING_DIR
if [ -n "$PATCH" ] ; then
pushd linux
git checkout $ORIGIN
git branch -D $TEMPORARY_BRANCH
popd
fi
restore_ktest_conf
}
function modify_ktest_conf {
sed -i -e '/^TEST_START/,$s/^/# /' $CONFFILE
sed -i -e '$aTEST_START' $CONFFILE
sed -i -e "\$aTEST_TYPE = ${SUBCOMMAND}" $CONFFILE
case $SUBCOMMAND in
test)
sed -i -e "\$aTEST = ${TEST}" $CONFFILE
;;
patchcheck)
sed -i -e "\$aPATCHCHECK_START = ${PATCHCHECK_START}" $CONFFILE
sed -i -e "\$aPATCHCHECK_END = ${PATCHCHECK_END}" $CONFFILE
sed -i -e "\$aPATCHCHECK_TYPE = ${PATCHCHECK_TYPE}" $CONFFILE
if [ $PATCHCHECK_TYPE = test ] ; then
sed -i -e "\$aTEST = ${TEST}" $CONFFILE
fi
;;
bisect)
sed -i -e "\$aBISECT_GOOD = ${BISECT_GOOD}" $CONFFILE
sed -i -e "\$aBISECT_BAD = ${BISECT_BAD}" $CONFFILE
sed -i -e "\$aBISECT_TYPE = ${BISECT_TYPE}" $CONFFILE
if [ $BISECT_TYPE = test ] ; then
sed -i -e "\$aTEST = ${TEST}" $CONFFILE
fi
;;
esac
}
function restore_ktest_conf {
pushd ktest
sed -i -e '/^TEST_START/,$d' $CONFFILE
sed -i -e '/^# TEST_START/,$s/^# //' $CONFFILE
popd
}
pushd ktest
modify_ktest_conf
popd
if [ $BOOT_VM_IF_NECESSARY -eq 1 ] ; then
IS_VM_DOWN=0
pushd elkdat
vagrant status | grep ktest | grep -q shutoff && IS_VM_DOWN=1
if [ $IS_VM_DOWN -eq 1 ] ; then
vagrant up
fi
popd
fi
if [ -n "$PATCH" ] ; then
pushd linux
ORIGIN=$(git status | sed -nr -e "1s/^(HEAD detached at |On branch )(.*)$/\2/p")
TEMPORARY_BRANCH=elkdat-test
git checkout -b $TEMPORARY_BRANCH
if ! git am $PATCH ; then
git am --abort
popd
exit 1
fi
popd
fi
cd ktest
./ktest.pl