summaryrefslogtreecommitdiff
path: root/lib/testrunner
blob: d00afa582ae79b9237ba16e93314f3862b87c7a1 (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
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
#!/usr/bin/env bash
#
# Test wrapper run inside the VM

set -o nounset
set -o errexit
set -o errtrace

export PS4='+`basename ${BASH_SOURCE[0]}`:${LINENO}:${FUNCNAME[0]:+${FUNCNAME[0]}()}+ '
KERNEL_ARCH=""

export PATH=$PATH:/root/.cargo/bin

. /host/$ktest_env

ktest_dir="/host/$ktest_dir"
ktest_tmp="/host/$ktest_tmp"
ktest_out="/host/$ktest_out"

rm -f /ktest /ktest-out
ln -sf $ktest_dir /ktest
ln -sf $ktest_out /ktest-out

# Some home directories are in weird places:
mkdir -p $(dirname $home)
ln -sf /host/$home $home

ktest_no_cleanup_tmpdir=1

log_verbose "Testrunner starting"

mkdir -p /root/.ssh
if cat /host/$home/.ssh/id*.pub > /root/.ssh/authorized_keys; then
    chmod 600 /root/.ssh/authorized_keys || true
else
    echo "Create an ssh key for ssh access"
fi

mkdir -p /lib/modules
ln -sf /host/$ktest_kernel_binary/lib/modules/* /lib/modules

dmesg --console-on
dmesg --console-level 8

echo 1 > /proc/sys/kernel/sysrq
ulimit -c unlimited

# Log file system visible to host

# Core dump settings
echo 1 > /proc/sys/fs/suid_dumpable
echo "|/bin/cp --sparse=always /dev/stdin $ktest_out/core.%e.PID%p.SIG%s.TIME%t" > /proc/sys/kernel/core_pattern
ulimit -c unlimited

# Virtual block device tweaks
echo none | tee /sys/block/[vs]d*/queue/scheduler >/dev/null 2>&1 || true

# Check if we are running the crashdump kernel
if [[ -s /proc/vmcore ]]; then
    echo "Collecting crash dump..."
    cp --sparse=always /proc/vmcore "$ktest_out/vmcore" || true
    sync
    poweroff
fi

# If debugging crash dumps, add "console=hvc0" to the append line
# below:
#if $ktest_crashdump; then
#    kexec -p /host/$ktest_kernel_binary/vmlinuz --append="root=$ktest_root_dev rw maxcpus=1" || true
#fi

NR_REBOOTS=0
EXPECTED_REBOOT=0
[[ -e /NR_REBOOTS ]]		&& NR_REBOOTS=$(</NR_REBOOTS)
[[ -e /EXPECTED_REBOOT ]]	&& EXPECTED_REBOOT=$(</EXPECTED_REBOOT)

if [[ $NR_REBOOTS != $EXPECTED_REBOOT ]]; then
    echo "UNEXPECTED REBOOT: got $NR_REBOOTS expected $EXPECTED_REBOOT"
    echo "TEST FAILED"
    exit 1
fi

echo $((NR_REBOOTS + 1)) | dd of=/NR_REBOOTS oflag=direct 2> /dev/null

if compgen -G "$ktest_tmp/*.deb" > /dev/null; then
    if ! output=$(dpkg -i $ktest_tmp/*.deb); then
	echo $output
	exit 1
    fi
fi

for i in "${ktest_make_install[@]}"; do
    pushd "/host/$i" > /dev/null
    if [[ -f autogen.sh && ! -f configure ]]; then
	run_quiet "autogen $(basename $i)" ./autogen.sh
    fi
    if [[ -f configure && ! -f Makefile ]]; then
	run_quiet "configure $(basename $i)" ./configure
    fi
    run_quiet "building $(basename $i)" make -j $ktest_cpus
    run_quiet "installing $(basename $i)" make -j $ktest_cpus install
    popd > /dev/null
done

# Update hosts file
local_ip=$(ip address show eth0 | awk -F' ' '$1 == "inet" { print $2 }' | awk -F'/' '{ print $1 }')
echo "$local_ip" "$(hostname)" >> /etc/hosts

get_stratch_devs()
{
    echo
    sfdisk -X gpt /dev/sdb 
}

copy_to_host()
{
    cat /sys/kernel/debug/tracing/trace > $ktest_out/trace.txt

    # Code coverage
    local gcov_dir=/sys/kernel/debug/gcov

    if [[ -d $gcov_dir ]]; then
	# find a destination dir that doesn't exist, so we can copy multiple
	# sets of gcov data from different tests/reboots and merge them later

	for i in {0..99}; do
	    dst=$ktest_out/gcov.$i

	    if [[ ! -d $dst ]]; then
		cp -dR $gcov_dir/$ktest_kernel_build "$dst"
		break
	    fi
	done
    fi

    sync
}

check_taint()
{
    read taint < /proc/sys/kernel/tainted

    if [[ $taint != 0 && ! $ktest_allow_taint ]]; then
	echo "Failure because kernel tainted - check log for warnings"
	echo "TEST FAILED"
	exit 0
    fi
}

do_reboot()
{
    copy_to_host
    check_taint

    echo $((NR_REBOOTS + 1)) | dd of=/EXPECTED_REBOOT oflag=direct 2> /dev/null
    echo b > /proc/sysrq-trigger
}

echo -n "Kernel version: "
uname -r

if [[ -z $ktest_tests ]] && ! $ktest_tests_unknown; then
    echo "No tests found"
    echo "TEST FAILED"
    exit 1
fi

ktest_tests=$(echo $ktest_tests)

if [[ $ktest_tests = "none" ]]; then
    echo "No tests to run"
    echo "TEST FAILED"
    exit 0
fi

trap 'pkill -P $$ >/dev/null' EXIT
cd /root

export ktest_failfast
export ktest_interactive
export ktest_verbose
export ktest_priority
export ktest_out

set +e
/host/$ktest_test init

ret=0
iterations=0
while [[ $ret = 0 ]]; do
    /host/$ktest_test run-tests $ktest_tests
    ret=$?
    pkill -P $$ >/dev/null || true
    [[ $ret != 0 ]]	&& break
    $ktest_loop		|| break

    iterations=$((iterations + 1))
    echo "SUCCESSFUL ITERATIONS $iterations"
done

copy_to_host
check_taint

echo -n "Kernel version: "
uname -r

if [[ $ret = 0 ]]; then
    echo "TEST SUCCESS"
else
    echo "TEST FAILED"
fi