-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkunit.sh
More file actions
executable file
·198 lines (185 loc) · 5.74 KB
/
Copy pathkunit.sh
File metadata and controls
executable file
·198 lines (185 loc) · 5.74 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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0
BAZEL=tools/bazel
BIN_DIR=common/tools/testing/android/bin
ACLOUD=$BIN_DIR/acloudb.sh
TRADEFED=prebuilts/tradefed/filegroups/tradefed/tradefed.sh
TESTSDIR=$PWD/out/tests
LOG_DIR=$PWD/out/test_logs/$(date +%Y%m%d_%H%M%S)
JDK_PATH=prebuilts/jdk/jdk11/linux-x86
print_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "This script builds kernel, launches cvd and runs selftests on it."
echo "Available options:"
echo " --skip-kernel-build Skip the kernel building step"
echo " --skip-cvd-launch Skip the CVD launch step"
echo " --skip-cvd-kill Do not kill CVD launched by running this script"
echo " -d, --dist-dir=DIR The kernel dist dir (default is /tmp/kernel_dist)"
echo " -s, --serial=SERIAL The device serial number."
echo " If serial is specified, cuttlefish device launch will be skipped"
echo " -t, --test=TEST_NAME The test target name. Can be repeated"
echo " If test is not specified, all kselftests will be run"
echo " -h, --help Display this help message and exit"
echo ""
echo "Examples:"
echo "$0"
echo "$0 -t regmap-kunit.ko -t lib_test.ko"
echo "$0 -s 127.0.0.1:45549"
echo ""
exit 0
}
BUILD_KERNEL=true
LAUNCH_CVD=true
KILL_CVD=true
DIST_DIR=/tmp/kernel_dist
SERIAL_NUMBER=
MODULE_NAME="kunit"
TEST_FILTERS=
SELECTED_TESTS=
while test $# -gt 0; do
case "$1" in
-h|--help)
print_help
;;
--skip-kernel-build)
BUILD_KERNEL=false
shift
;;
--skip-cvd-launch)
LAUNCH_CVD=false
shift
;;
--skip-cvd-kill)
KILL_CVD=false
shift
;;
-d)
shift
if test $# -gt 0; then
DIST_DIR=$1
else
echo "kernel distribution directory is not specified"
exit 1
fi
shift
;;
--dist-dir*)
DIST_DIR=$(echo $1 | sed -e "s/^[^=]*=//g")
shift
;;
-s)
shift
if test $# -gt 0; then
SERIAL_NUMBER=$1
BUILD_KERNEL=false
LAUNCH_CVD=false
KILL_CVD=false
else
echo "device serial is not specified"
exit 1
fi
shift
;;
--serial*)
BUILD_KERNEL=false
LAUNCH_CVD=false
KILL_CVD=false
SERIAL_NUMBER=$(echo $1 | sed -e "s/^[^=]*=//g")
shift
;;
-t)
shift
if test $# -gt 0; then
TEST_NAME=$1
SELECTED_TESTS+="$TEST_NAME "
TEST_FILTERS+="--include-filter '$MODULE_NAME $TEST_NAME' "
else
echo "test name is not specified"
exit 1
fi
shift
;;
--test*)
TEST_NAME=$(echo $1 | sed -e "s/^[^=]*=//g")
SELECTED_TESTS+="$TEST_NAME "
TEST_FILTERS+="--include-filter '$MODULE_NAME $TEST_NAME'"
shift
;;
*)
;;
esac
done
if $BUILD_KERNEL; then
echo "Building kernel..."
# TODO: add support to build kernel for physical device
$BAZEL run //common-modules/virtual-device:virtual_device_x86_64_dist -- --dist_dir=$DIST_DIR
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Command succeeded"
else
echo "Command failed with exit code $exit_code"
exit 1
fi
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Build kernel succeeded"
else
echo "Build kernel failed with exit code $exit_code"
exit 1
fi
fi
if $LAUNCH_CVD; then
echo "Launching cvd..."
CVD_OUT=$($ACLOUD create --local-kernel-image $DIST_DIR)
echo $CVD_OUT
INSTANCE_NAME=$(echo "$CVD_OUT" | grep -o "ins-[^\[]*")
SERIAL_STRING=$(echo "$CVD_OUT" | grep -oE 'device serial: ([0-9]+\.){3}[0-9]+:[0-9]+')
SERIAL_NUMBER=$(echo "$SERIAL_STRING" | sed 's/device serial: //')
echo "acloud launched device $SERIAL_NUMBER with instance $INSTANCE_NAME"
fi
if [ -z "$SERIAL_NUMBER" ]; then
echo "Device serial is not provided by acloud or by command line flag -s|--serial flag"
exit 1
else
echo "Test with device: $SERIAL_NUMBER"
fi
echo "Get abi from device $SERIAL_NUMBER"
ABI=$(adb -s $SERIAL_NUMBER shell getprop ro.product.cpu.abi)
echo "Building kunit tests according to device $SERIAL_NUMBER ro.product.cpu.abi $ABI ..."
# $ tools/bazel run -- //common:kunit_tests_x86_64_install -v --destdir /tmp/kunit_tests
case $ABI in
arm64*)
$BAZEL run //common:kunit_tests_arm64 -- -v --destdir $TESTSDIR
;;
x86_64*)
$BAZEL run //common:kunit_tests_x86_64 -- -v --destdir $TESTSDIR
;;
*)
echo "$ABI not supported"
exit 1
;;
esac
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Build kunit succeeded"
else
echo "Build kunit failed with exit code $exit_code"
exit 1
fi
if [ -z "$SELECTED_TESTS" ]; then
echo "Running all KUnit tests with device $SERIAL_NUMBER..."
TEST_FILTERS="--include-filter $MODULE_NAME"
else
echo "Running $SELECTED_TESTS with device $SERIAL_NUMBER ..."
fi
tf_cli="JAVA_HOME=$JDK_PATH PATH=$JDK_PATH/bin:$PATH $TRADEFED run commandAndExit \
template/local_min --template:map test=suite/test_mapping_suite \
$TEST_FILTERS --tests-dir=$TESTSDIR --log-file-path=$LOG_DIR \
--primary-abi-only -s $SERIAL_NUMBER"
echo "Runing tradefed command: $tf_cli"
eval $tf_cli
if $LAUNCH_CVD && $KILL_CVD; then
echo "Test finished. Deleting cvd instance $INSTANCE_NAME ..."
$ACLOUD delete --instance-names $INSTANCE_NAME
fi