blob: 3becdd4fd7ab3e47c7131c9397359b1ece633619 [file] [log] [blame]
Naresh Kambojuad19d882016-09-20 19:31:00 +05301#!/bin/bash
2
Dan Rue9e11dcd2017-10-04 11:29:04 -05003set -x
4
Chase Qi890c1202017-06-19 16:09:27 +08005# shellcheck disable=SC1091
Naresh Kambojuad19d882016-09-20 19:31:00 +05306. ../../lib/sh-test-lib
7OUTPUT="$(pwd)/output"
8RESULT_FILE="${OUTPUT}/result.txt"
9# Absolute path to this script. /home/user/bin/foo.sh
Naresh Kamboju43e80742017-01-18 15:51:02 +053010SCRIPT="$(readlink -f "${0}")"
Naresh Kambojuad19d882016-09-20 19:31:00 +053011# Absolute path this script is in. /home/user/bin
Naresh Kamboju43e80742017-01-18 15:51:02 +053012SCRIPTPATH="$(dirname "${SCRIPT}")"
13echo "Script path is: ${SCRIPTPATH}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053014# List of test cases
15TST_CMDFILES=""
16# List of test cases to be skipped
17SKIPFILE=""
Dan Ruef4970552018-01-26 17:28:35 -060018# List of test cases to be skipped in yaml/skipgen format
19SKIPFILE_YAML=""
20BOARD=""
21BRANCH=""
22ENVIRONMENT=""
Naresh Kambojuad19d882016-09-20 19:31:00 +053023# LTP version
Naresh Kamboju52f02572018-11-20 19:52:18 +053024LTP_VERSION="20180926"
Anders Roxell67acee62020-10-21 08:52:24 +020025TEST_PROGRAM=ltp
26# https://github.com/linux-test-project/ltp.git
27TEST_GIT_URL=""
28TEST_DIR="$(pwd)/${TEST_PROGRAM}"
29BUILD_FROM_TAR="false"
Anders Roxella384c312022-10-25 09:02:44 +020030SHARD_NUMBER=1
31SHARD_INDEX=1
Anders Roxell67acee62020-10-21 08:52:24 +020032
Anders Roxell1e4165f2024-06-12 14:45:20 +020033RUNNER=""
34
Naresh Kamboju9bce9162017-07-13 12:56:27 +053035LTP_TMPDIR=/ltp-tmp
Naresh Kambojuad19d882016-09-20 19:31:00 +053036
Anders Roxell67acee62020-10-21 08:52:24 +020037LTP_INSTALL_PATH=/opt/ltp
Naresh Kambojuad19d882016-09-20 19:31:00 +053038
39usage() {
Naresh Kamboju3a427952017-07-06 16:56:59 +053040 echo "Usage: ${0} [-T mm,math,syscalls]
41 [-S skipfile-lsk-juno]
Dan Ruef4970552018-01-26 17:28:35 -060042 [-b board]
Anders Roxell05c1e172019-04-02 05:08:34 +020043 [-d temp directory]
Dan Ruef4970552018-01-26 17:28:35 -060044 [-g branch]
45 [-e environment]
Rémi Durafforte08fea42021-01-04 14:31:02 +010046 [-i install path]
Naresh Kamboju3a427952017-07-06 16:56:59 +053047 [-s True|False]
48 [-v LTP_VERSION]
Dan Rue58d3a882017-07-11 16:30:30 -050049 [-M Timeout_Multiplier]
Anders Roxell67acee62020-10-21 08:52:24 +020050 [-R root_password]
Anders Roxell1e4165f2024-06-12 14:45:20 +020051 [-r new runner (kirk)]
Anders Roxell67acee62020-10-21 08:52:24 +020052 [-u git url]
53 [-p build directory]
54 [-t build from tarfile ]
Anders Roxella384c312022-10-25 09:02:44 +020055 [-c sharding bucket to run ]
56 [-n number of shard buckets to create ]
Anders Roxell67acee62020-10-21 08:52:24 +020057" 1>&2
Naresh Kambojuad19d882016-09-20 19:31:00 +053058 exit 0
59}
60
Anders Roxell1e4165f2024-06-12 14:45:20 +020061while getopts "M:T:S:b:d:g:e:i:s:v:R:r:u:p:t:c:n:" arg; do
Naresh Kambojuad19d882016-09-20 19:31:00 +053062 case "$arg" in
63 T)
64 TST_CMDFILES="${OPTARG}"
Naresh Kamboju43e80742017-01-18 15:51:02 +053065 # shellcheck disable=SC2001
Naresh Kambojuad19d882016-09-20 19:31:00 +053066 LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
67 ;;
68 S)
Dan Ruef4970552018-01-26 17:28:35 -060069 if [ -z "${OPTARG##*http*}" ]; then
70 if [ -z "${OPTARG##*yaml*}" ]; then
71 # Skipfile is of type yaml
72 SKIPFILE_TMP="http-skipfile.yaml"
73 SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}"
74 else
75 # Skipfile is normal skipfile
76 SKIPFILE_TMP="http-skipfile"
77 SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}"
78 fi
79 # Download LTP skipfile from specified URL
80 if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then
81 error_msg "Failed to fetch ${OPTARG}"
Dan Ruef4970552018-01-26 17:28:35 -060082 fi
83 elif [ "${OPTARG##*.}" = "yaml" ]; then
84 # yaml skipfile; use skipgen to generate a skipfile
85 SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053086 else
Rémi Durafforte7cc8a22021-01-05 14:04:03 +010087 # Regular LTP skipfile. Absolute or relative path?
88 if [ "${OPTARG:0:1}" == "/" ]; then
89 SKIPFILE="-S ${OPTARG}"
90 else
91 SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
92 fi
Naresh Kambojuad19d882016-09-20 19:31:00 +053093 fi
94 ;;
Dan Ruef4970552018-01-26 17:28:35 -060095 b)
96 export BOARD="${OPTARG}"
97 ;;
Anders Roxell05c1e172019-04-02 05:08:34 +020098 d)
99 export LTP_TMPDIR="${OPTARG}"
100 ;;
Dan Ruef4970552018-01-26 17:28:35 -0600101 g)
102 export BRANCH="${OPTARG}"
103 ;;
104 e)
105 export ENVIRONMENT="${OPTARG}"
106 ;;
Rémi Durafforte08fea42021-01-04 14:31:02 +0100107 i)
108 export LTP_INSTALL_PATH="${OPTARG}"
109 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +0530110 # SKIP_INSTALL is true in case of Open Embedded builds
111 # SKIP_INSTALL is flase in case of Debian builds
112 s) SKIP_INSTALL="${OPTARG}";;
113 v) LTP_VERSION="${OPTARG}";;
Naresh Kamboju3bff06b2017-05-24 14:46:37 +0530114 # Slow machines need more timeout Default is 5min and multiply * MINUTES
115 M) export LTP_TIMEOUT_MUL="${OPTARG}";;
Dan Rue58d3a882017-07-11 16:30:30 -0500116 R) export PASSWD="${OPTARG}";;
Anders Roxell1e4165f2024-06-12 14:45:20 +0200117 r) export RUNNER="${OPTARG}";;
Anders Roxell67acee62020-10-21 08:52:24 +0200118 u)
119 if [[ "$OPTARG" != '' ]]; then
120 TEST_GIT_URL="$OPTARG"
121 TEST_TARFILE=""
122 fi
123 ;;
124 p)
125 if [[ "$OPTARG" != '' ]]; then
126 TEST_DIR="$OPTARG"
127 fi
128 ;;
129 t)
130 BUILD_FROM_TAR="$OPTARG"
131 ;;
Anders Roxella384c312022-10-25 09:02:44 +0200132 c)
133 SHARD_INDEX="$OPTARG"
134 ;;
135 n)
136 SHARD_NUMBER="$OPTARG"
137 ;;
Anders Roxell446b84f2019-04-03 05:30:21 +0200138 *)
139 usage
140 error_msg "No flag ${OPTARG}"
141 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +0530142 esac
143done
144
Anders Roxell67acee62020-10-21 08:52:24 +0200145TEST_TARFILE=https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
146
Dan Ruef4970552018-01-26 17:28:35 -0600147if [ -n "${SKIPFILE_YAML}" ]; then
148 export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
149 generate_skipfile
150 if [ ! -f "${SKIPFILE_PATH}" ]; then
151 error_msg "Skipfile ${SKIPFILE} does not exist";
Dan Ruef4970552018-01-26 17:28:35 -0600152 fi
153 SKIPFILE="-S ${SKIPFILE_PATH}"
154fi
155
Naresh Kambojuad19d882016-09-20 19:31:00 +0530156# Parse LTP output
157parse_ltp_output() {
Chase Qi3308d6b2017-08-07 15:19:35 +0800158 grep -E "PASS|FAIL|CONF" "$1" \
159 | awk '{print $1" "$2}' \
160 | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530161}
162
Anders Roxell1e4165f2024-06-12 14:45:20 +0200163parse_ltp_json_results() {
164 jq -r '.results| .[]| "\(.test_fqn) \(.test.result)"' "$1" \
165 | sed 's/brok/fail/; s/conf/skip/' >> "${RESULT_FILE}"
Antonio Terceiroaac60d92025-03-10 16:44:48 -0300166 for test_fqn in $(jq -r '.results| .[]| .test_fqn' "$1"); do
167 jq -r '.results | .[] | select(.test_fqn == "'"${test_fqn}"'") | .test.log' "$1" > ${OUTPUT}/${test_fqn}.log
168 done
Anders Roxell1e4165f2024-06-12 14:45:20 +0200169}
170
Naresh Kambojuad19d882016-09-20 19:31:00 +0530171# Run LTP test suite
172run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +0530173 # shellcheck disable=SC2164
Anders Roxell67acee62020-10-21 08:52:24 +0200174 cd "${LTP_INSTALL_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +0530175 # shellcheck disable=SC2174
176 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530177
Anders Roxella384c312022-10-25 09:02:44 +0200178 for file in ${TST_CMDFILES//,/ }; do
179 cat runtest/"${file}" >>alltests
180 done
181 sed -i 's/#.*$//;/^$/d' alltests
182 split --verbose --numeric-suffixes=1 -n l/"${SHARD_INDEX}"/"${SHARD_NUMBER}" alltests >runtest/shardfile
183 echo "============== Tests to run ==============="
184 cat runtest/shardfile
185 echo "===========End Tests to run ==============="
186
Anders Roxell1e4165f2024-06-12 14:45:20 +0200187 if [ -n "${RUNNER}" ]; then
188 eval "${RUNNER}" --version
189 # shellcheck disable=SC2181
190 if [ $? -ne "0" ]; then
191 error_msg "${RUNNER} is not installed into the file system."
192 fi
193 pipe0_status "${RUNNER} --framework ltp --run-suite shardfile \
194 -d ${LTP_TMPDIR} --env LTP_COLORIZE_OUTPUT=0 \
Antonio Terceiroa1312792025-03-07 15:00:15 -0300195 ${SKIPFILE_PATH:+--skip-file} ${SKIPFILE_PATH} \
Anders Roxell1e4165f2024-06-12 14:45:20 +0200196 --json-report /tmp/kirk-report.json \
197 --verbose" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
198 parse_ltp_json_results "/tmp/kirk-report.json"
Anders Roxell48fa9012025-02-27 14:32:28 +0100199 rm "/tmp/kirk-report.json"
Anders Roxell1e4165f2024-06-12 14:45:20 +0200200 else
201 pipe0_status "./runltp -p -q -f shardfile \
Naresh Kamboju3a427952017-07-06 16:56:59 +0530202 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
203 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
204 -d ${LTP_TMPDIR} \
205 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Anders Roxell1e4165f2024-06-12 14:45:20 +0200206 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
207 fi
Naresh Kambojue1880532018-10-02 15:17:34 +0530208# check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530209
Naresh Kamboju3a427952017-07-06 16:56:59 +0530210 # Cleanup
Milosz Wasilewskicacf7382017-11-01 11:25:55 +0000211 # don't fail the whole test job if rm fails
212 rm -rf "${LTP_TMPDIR}" || true
Anders Roxell0466d2c2022-12-07 10:12:07 +0100213 rm -rf alltests || true
Naresh Kambojuad19d882016-09-20 19:31:00 +0530214}
215
Dan Ruea7e86c42017-11-07 14:55:58 -0600216# Prepare system
217prep_system() {
218 # Stop systemd-timesyncd if running
219 if systemctl is-active systemd-timesyncd 2>/dev/null; then
220 info_msg "Stopping systemd-timesyncd"
221 systemctl stop systemd-timesyncd
222 fi
Dan Ruef07393e2017-11-13 09:55:43 -0600223 # userns07 requires kernel.unprivileged_userns_clone
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800224 if [ -f "/proc/sys/kernel/unprivileged_userns_clone" ]; then
Dan Ruef07393e2017-11-13 09:55:43 -0600225 info_msg "Enabling kernel.unprivileged_userns_clone"
226 sysctl -w kernel.unprivileged_userns_clone=1
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800227 else
228 info_msg "Kernel has no support of unprivileged_userns_clone"
Dan Ruef07393e2017-11-13 09:55:43 -0600229 fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600230}
231
Anders Roxell67acee62020-10-21 08:52:24 +0200232get_tarfile() {
233 local test_tarfile="$1"
234 mkdir "${TEST_DIR}"
235 pushd "${TEST_DIR}" || exit 1
Naresh Kambojuad19d882016-09-20 19:31:00 +0530236
Anders Roxell67acee62020-10-21 08:52:24 +0200237 wget "${test_tarfile}"
238 tar --strip-components=1 -Jxf "$(basename "${test_tarfile}")"
239 popd || exit 1
240}
Naresh Kambojuad19d882016-09-20 19:31:00 +0530241
Anders Roxell67acee62020-10-21 08:52:24 +0200242build_install_tests() {
243 rm -rf "${LTP_INSTALL_PATH}"
244 pushd "${TEST_DIR}" || exit 1
245 [[ -n "${TEST_GIT_URL}" ]] && make autotools
246 ./configure
247 make -j"$(proc)" all
248 make SKIP_IDCHECK=1 install
249 popd || exit 1
250}
251
252install() {
253 dist=
Naresh Kambojuad19d882016-09-20 19:31:00 +0530254 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530255 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530256 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100257 debian|ubuntu)
Anders Roxell67acee62020-10-21 08:52:24 +0200258 [[ -n "${TEST_GIT_URL}" ]] && pkgs="git"
259 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"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530260 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530261 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100262 centos|fedora)
Anders Roxell67acee62020-10-21 08:52:24 +0200263 [[ -n "${TEST_GIT_URL}" ]] && pkgs="git-core"
Anders Roxell1c0eeb32022-01-20 12:05:32 +0100264 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"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530265 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530266 ;;
267 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530268 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530269 esac
Chase Qifee992c2017-06-19 17:02:50 +0800270
271 # Check if mkisofs or genisoimage installed for isofs test.
272 if echo "${TST_CMDFILES}" | grep 'fs'; then
273 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
274 if ! which mkisofs; then
275 if which genisoimage; then
276 ln -s "$(which genisoimage)" /usr/bin/mkisofs
277 else
278 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
279 fi
280 fi
281 fi
Anders Roxell67acee62020-10-21 08:52:24 +0200282}
Chase Qifee992c2017-06-19 17:02:50 +0800283
Anders Roxell67acee62020-10-21 08:52:24 +0200284# Test run.
285! check_root && error_msg "This script must be run as root"
286create_out_dir "${OUTPUT}"
287
288info_msg "About to run ltp test..."
289info_msg "Output directory: ${OUTPUT}"
290
291if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then
292 info_msg "${TEST_PROGRAM} installation skipped altogether"
293else
294 install
295fi
296
Rémi Durafforte7cc8a22021-01-05 14:04:03 +0100297if [ ! -d "${LTP_INSTALL_PATH}" ]; then
Anders Roxell67acee62020-10-21 08:52:24 +0200298 if [ "${BUILD_FROM_TAR}" = "true" ] || [ "${BUILD_FROM_TAR}" = "True" ]; then
299 get_tarfile "${TEST_TARFILE}"
300 elif [ -n "${TEST_GIT_URL}" ]; then
301 get_test_program "${TEST_GIT_URL}" "${TEST_DIR}" "${LTP_VERSION}" "${TEST_PROGRAM}"
302 else
303 error_msg "I'm confused, get me out of here, can't fetch tar or test version."
304 fi
305 build_install_tests
Naresh Kambojuad19d882016-09-20 19:31:00 +0530306fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600307info_msg "Running prep_system"
308prep_system
Naresh Kambojuad19d882016-09-20 19:31:00 +0530309info_msg "Running run_ltp"
310run_ltp