blob: b2f9cec4c35970075840ebe78fd711a8b4ff7243 (
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
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
|
#!/bin/bash
set -x
# shellcheck disable=SC1091
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT="$(readlink -f "${0}")"
# Absolute path this script is in. /home/user/bin
SCRIPTPATH="$(dirname "${SCRIPT}")"
echo "Script path is: ${SCRIPTPATH}"
# List of test cases
TST_CMDFILES=""
# List of test cases to be skipped
SKIPFILE=""
# List of test cases to be skipped in yaml/skipgen format
SKIPFILE_YAML=""
BOARD=""
BRANCH=""
ENVIRONMENT=""
# LTP version
LTP_VERSION="20180926"
TEST_PROGRAM=ltp
# https://github.com/linux-test-project/ltp.git
TEST_GIT_URL=""
TEST_DIR="$(pwd)/${TEST_PROGRAM}"
BUILD_FROM_TAR="false"
SHARD_NUMBER=1
SHARD_INDEX=1
LTP_TMPDIR=/ltp-tmp
LTP_INSTALL_PATH=/opt/ltp
usage() {
echo "Usage: ${0} [-T mm,math,syscalls]
[-S skipfile-lsk-juno]
[-b board]
[-d temp directory]
[-g branch]
[-e environment]
[-i install path]
[-s True|False]
[-v LTP_VERSION]
[-M Timeout_Multiplier]
[-R root_password]
[-u git url]
[-p build directory]
[-t build from tarfile ]
[-c sharding bucket to run ]
[-n number of shard buckets to create ]
" 1>&2
exit 0
}
while getopts "M:T:S:b:d:g:e:i:s:v:R:u:p:t:c:n:" arg; do
case "$arg" in
T)
TST_CMDFILES="${OPTARG}"
# shellcheck disable=SC2001
LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
;;
S)
if [ -z "${OPTARG##*http*}" ]; then
if [ -z "${OPTARG##*yaml*}" ]; then
# Skipfile is of type yaml
SKIPFILE_TMP="http-skipfile.yaml"
SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}"
else
# Skipfile is normal skipfile
SKIPFILE_TMP="http-skipfile"
SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}"
fi
# Download LTP skipfile from specified URL
if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then
error_msg "Failed to fetch ${OPTARG}"
fi
elif [ "${OPTARG##*.}" = "yaml" ]; then
# yaml skipfile; use skipgen to generate a skipfile
SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}"
else
# Regular LTP skipfile. Absolute or relative path?
if [ "${OPTARG:0:1}" == "/" ]; then
SKIPFILE="-S ${OPTARG}"
else
SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
fi
fi
;;
b)
export BOARD="${OPTARG}"
;;
d)
export LTP_TMPDIR="${OPTARG}"
;;
g)
export BRANCH="${OPTARG}"
;;
e)
export ENVIRONMENT="${OPTARG}"
;;
i)
export LTP_INSTALL_PATH="${OPTARG}"
;;
# SKIP_INSTALL is true in case of Open Embedded builds
# SKIP_INSTALL is flase in case of Debian builds
s) SKIP_INSTALL="${OPTARG}";;
v) LTP_VERSION="${OPTARG}";;
# Slow machines need more timeout Default is 5min and multiply * MINUTES
M) export LTP_TIMEOUT_MUL="${OPTARG}";;
R) export PASSWD="${OPTARG}";;
u)
if [[ "$OPTARG" != '' ]]; then
TEST_GIT_URL="$OPTARG"
TEST_TARFILE=""
fi
;;
p)
if [[ "$OPTARG" != '' ]]; then
TEST_DIR="$OPTARG"
fi
;;
t)
BUILD_FROM_TAR="$OPTARG"
;;
c)
SHARD_INDEX="$OPTARG"
;;
n)
SHARD_NUMBER="$OPTARG"
;;
*)
usage
error_msg "No flag ${OPTARG}"
;;
esac
done
TEST_TARFILE=https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
if [ -n "${SKIPFILE_YAML}" ]; then
export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
generate_skipfile
if [ ! -f "${SKIPFILE_PATH}" ]; then
error_msg "Skipfile ${SKIPFILE} does not exist";
fi
SKIPFILE="-S ${SKIPFILE_PATH}"
fi
# Parse LTP output
parse_ltp_output() {
grep -E "PASS|FAIL|CONF" "$1" \
| awk '{print $1" "$2}' \
| sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}"
}
# Run LTP test suite
run_ltp() {
# shellcheck disable=SC2164
cd "${LTP_INSTALL_PATH}"
# shellcheck disable=SC2174
mkdir -m 777 -p "${LTP_TMPDIR}"
for file in ${TST_CMDFILES//,/ }; do
cat runtest/"${file}" >>alltests
done
sed -i 's/#.*$//;/^$/d' alltests
split --verbose --numeric-suffixes=1 -n l/"${SHARD_INDEX}"/"${SHARD_NUMBER}" alltests >runtest/shardfile
echo "============== Tests to run ==============="
cat runtest/shardfile
echo "===========End Tests to run ==============="
pipe0_status "./runltp -p -q -f shardfile \
-l ${OUTPUT}/LTP_${LOG_FILE}.log \
-C ${OUTPUT}/LTP_${LOG_FILE}.failed \
-d ${LTP_TMPDIR} \
${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
# check_return "runltp_${LOG_FILE}"
parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
# Cleanup
# don't fail the whole test job if rm fails
rm -rf "${LTP_TMPDIR}" || true
rm -rf alltests || true
}
# Prepare system
prep_system() {
# Stop systemd-timesyncd if running
if systemctl is-active systemd-timesyncd 2>/dev/null; then
info_msg "Stopping systemd-timesyncd"
systemctl stop systemd-timesyncd
fi
# userns07 requires kernel.unprivileged_userns_clone
if [ -f "/proc/sys/kernel/unprivileged_userns_clone" ]; then
info_msg "Enabling kernel.unprivileged_userns_clone"
sysctl -w kernel.unprivileged_userns_clone=1
else
info_msg "Kernel has no support of unprivileged_userns_clone"
fi
}
get_tarfile() {
local test_tarfile="$1"
mkdir "${TEST_DIR}"
pushd "${TEST_DIR}" || exit 1
wget "${test_tarfile}"
tar --strip-components=1 -Jxf "$(basename "${test_tarfile}")"
popd || exit 1
}
build_install_tests() {
rm -rf "${LTP_INSTALL_PATH}"
pushd "${TEST_DIR}" || exit 1
[[ -n "${TEST_GIT_URL}" ]] && make autotools
./configure
make -j"$(proc)" all
make SKIP_IDCHECK=1 install
popd || exit 1
}
install() {
dist=
dist_name
# shellcheck disable=SC2154
case "${dist}" in
debian|ubuntu)
[[ -n "${TEST_GIT_URL}" ]] && pkgs="git"
pkgs="${pkgs} xz-utils flex bison build-essential wget curl net-tools quota genisoimage sudo libaio-dev libattr1-dev libcap-dev expect automake acl autotools-dev autoconf m4 pkgconf"
install_deps "${pkgs}" "${SKIP_INSTALL}"
;;
centos|fedora)
[[ -n "${TEST_GIT_URL}" ]] && pkgs="git-core"
pkgs="${pkgs} xz flex bison make automake gcc gcc-c++ kernel-devel wget curl net-tools quota genisoimage sudo libaio-devel libattr-devel libcap-devel m4 expect acl pkgconf"
install_deps "${pkgs}" "${SKIP_INSTALL}"
;;
*)
warn_msg "Unsupported distribution: package install skipped"
esac
# Check if mkisofs or genisoimage installed for isofs test.
if echo "${TST_CMDFILES}" | grep 'fs'; then
# link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
if ! which mkisofs; then
if which genisoimage; then
ln -s "$(which genisoimage)" /usr/bin/mkisofs
else
warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
fi
fi
fi
}
# Test run.
! check_root && error_msg "This script must be run as root"
create_out_dir "${OUTPUT}"
info_msg "About to run ltp test..."
info_msg "Output directory: ${OUTPUT}"
if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then
info_msg "${TEST_PROGRAM} installation skipped altogether"
else
install
fi
if [ ! -d "${LTP_INSTALL_PATH}" ]; then
if [ "${BUILD_FROM_TAR}" = "true" ] || [ "${BUILD_FROM_TAR}" = "True" ]; then
get_tarfile "${TEST_TARFILE}"
elif [ -n "${TEST_GIT_URL}" ]; then
get_test_program "${TEST_GIT_URL}" "${TEST_DIR}" "${LTP_VERSION}" "${TEST_PROGRAM}"
else
error_msg "I'm confused, get me out of here, can't fetch tar or test version."
fi
build_install_tests
fi
info_msg "Running prep_system"
prep_system
info_msg "Running run_ltp"
run_ltp
|