blob: d1b03dc0510299ee4cb224942ea4445257de3881 [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}"
166}
167
Naresh Kambojuad19d882016-09-20 19:31:00 +0530168# Run LTP test suite
169run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +0530170 # shellcheck disable=SC2164
Anders Roxell67acee62020-10-21 08:52:24 +0200171 cd "${LTP_INSTALL_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +0530172 # shellcheck disable=SC2174
173 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530174
Anders Roxella384c312022-10-25 09:02:44 +0200175 for file in ${TST_CMDFILES//,/ }; do
176 cat runtest/"${file}" >>alltests
177 done
178 sed -i 's/#.*$//;/^$/d' alltests
179 split --verbose --numeric-suffixes=1 -n l/"${SHARD_INDEX}"/"${SHARD_NUMBER}" alltests >runtest/shardfile
180 echo "============== Tests to run ==============="
181 cat runtest/shardfile
182 echo "===========End Tests to run ==============="
183
Anders Roxell1e4165f2024-06-12 14:45:20 +0200184 if [ -n "${RUNNER}" ]; then
185 eval "${RUNNER}" --version
186 # shellcheck disable=SC2181
187 if [ $? -ne "0" ]; then
188 error_msg "${RUNNER} is not installed into the file system."
189 fi
190 pipe0_status "${RUNNER} --framework ltp --run-suite shardfile \
191 -d ${LTP_TMPDIR} --env LTP_COLORIZE_OUTPUT=0 \
192 --skip-file ${SKIPFILE_PATH} \
193 --json-report /tmp/kirk-report.json \
194 --verbose" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
195 parse_ltp_json_results "/tmp/kirk-report.json"
196 else
197 pipe0_status "./runltp -p -q -f shardfile \
Naresh Kamboju3a427952017-07-06 16:56:59 +0530198 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
199 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
200 -d ${LTP_TMPDIR} \
201 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Anders Roxell1e4165f2024-06-12 14:45:20 +0200202 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
203 fi
Naresh Kambojue1880532018-10-02 15:17:34 +0530204# check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530205
Naresh Kamboju3a427952017-07-06 16:56:59 +0530206 # Cleanup
Milosz Wasilewskicacf7382017-11-01 11:25:55 +0000207 # don't fail the whole test job if rm fails
208 rm -rf "${LTP_TMPDIR}" || true
Anders Roxell0466d2c2022-12-07 10:12:07 +0100209 rm -rf alltests || true
Naresh Kambojuad19d882016-09-20 19:31:00 +0530210}
211
Dan Ruea7e86c42017-11-07 14:55:58 -0600212# Prepare system
213prep_system() {
214 # Stop systemd-timesyncd if running
215 if systemctl is-active systemd-timesyncd 2>/dev/null; then
216 info_msg "Stopping systemd-timesyncd"
217 systemctl stop systemd-timesyncd
218 fi
Dan Ruef07393e2017-11-13 09:55:43 -0600219 # userns07 requires kernel.unprivileged_userns_clone
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800220 if [ -f "/proc/sys/kernel/unprivileged_userns_clone" ]; then
Dan Ruef07393e2017-11-13 09:55:43 -0600221 info_msg "Enabling kernel.unprivileged_userns_clone"
222 sysctl -w kernel.unprivileged_userns_clone=1
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800223 else
224 info_msg "Kernel has no support of unprivileged_userns_clone"
Dan Ruef07393e2017-11-13 09:55:43 -0600225 fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600226}
227
Anders Roxell67acee62020-10-21 08:52:24 +0200228get_tarfile() {
229 local test_tarfile="$1"
230 mkdir "${TEST_DIR}"
231 pushd "${TEST_DIR}" || exit 1
Naresh Kambojuad19d882016-09-20 19:31:00 +0530232
Anders Roxell67acee62020-10-21 08:52:24 +0200233 wget "${test_tarfile}"
234 tar --strip-components=1 -Jxf "$(basename "${test_tarfile}")"
235 popd || exit 1
236}
Naresh Kambojuad19d882016-09-20 19:31:00 +0530237
Anders Roxell67acee62020-10-21 08:52:24 +0200238build_install_tests() {
239 rm -rf "${LTP_INSTALL_PATH}"
240 pushd "${TEST_DIR}" || exit 1
241 [[ -n "${TEST_GIT_URL}" ]] && make autotools
242 ./configure
243 make -j"$(proc)" all
244 make SKIP_IDCHECK=1 install
245 popd || exit 1
246}
247
248install() {
249 dist=
Naresh Kambojuad19d882016-09-20 19:31:00 +0530250 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530251 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530252 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100253 debian|ubuntu)
Anders Roxell67acee62020-10-21 08:52:24 +0200254 [[ -n "${TEST_GIT_URL}" ]] && pkgs="git"
255 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 +0530256 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530257 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100258 centos|fedora)
Anders Roxell67acee62020-10-21 08:52:24 +0200259 [[ -n "${TEST_GIT_URL}" ]] && pkgs="git-core"
Anders Roxell1c0eeb32022-01-20 12:05:32 +0100260 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 +0530261 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530262 ;;
263 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530264 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530265 esac
Chase Qifee992c2017-06-19 17:02:50 +0800266
267 # Check if mkisofs or genisoimage installed for isofs test.
268 if echo "${TST_CMDFILES}" | grep 'fs'; then
269 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
270 if ! which mkisofs; then
271 if which genisoimage; then
272 ln -s "$(which genisoimage)" /usr/bin/mkisofs
273 else
274 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
275 fi
276 fi
277 fi
Anders Roxell67acee62020-10-21 08:52:24 +0200278}
Chase Qifee992c2017-06-19 17:02:50 +0800279
Anders Roxell67acee62020-10-21 08:52:24 +0200280# Test run.
281! check_root && error_msg "This script must be run as root"
282create_out_dir "${OUTPUT}"
283
284info_msg "About to run ltp test..."
285info_msg "Output directory: ${OUTPUT}"
286
287if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then
288 info_msg "${TEST_PROGRAM} installation skipped altogether"
289else
290 install
291fi
292
Rémi Durafforte7cc8a22021-01-05 14:04:03 +0100293if [ ! -d "${LTP_INSTALL_PATH}" ]; then
Anders Roxell67acee62020-10-21 08:52:24 +0200294 if [ "${BUILD_FROM_TAR}" = "true" ] || [ "${BUILD_FROM_TAR}" = "True" ]; then
295 get_tarfile "${TEST_TARFILE}"
296 elif [ -n "${TEST_GIT_URL}" ]; then
297 get_test_program "${TEST_GIT_URL}" "${TEST_DIR}" "${LTP_VERSION}" "${TEST_PROGRAM}"
298 else
299 error_msg "I'm confused, get me out of here, can't fetch tar or test version."
300 fi
301 build_install_tests
Naresh Kambojuad19d882016-09-20 19:31:00 +0530302fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600303info_msg "Running prep_system"
304prep_system
Naresh Kambojuad19d882016-09-20 19:31:00 +0530305info_msg "Running run_ltp"
306run_ltp