blob: 7536242b3746d45dba6107fe0c08df635fccae99 [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"
Naresh Kamboju9bce9162017-07-13 12:56:27 +053025LTP_TMPDIR=/ltp-tmp
Naresh Kambojuad19d882016-09-20 19:31:00 +053026
27LTP_PATH=/opt/ltp
28
29usage() {
Naresh Kamboju3a427952017-07-06 16:56:59 +053030 echo "Usage: ${0} [-T mm,math,syscalls]
31 [-S skipfile-lsk-juno]
Dan Ruef4970552018-01-26 17:28:35 -060032 [-b board]
Anders Roxell05c1e172019-04-02 05:08:34 +020033 [-d temp directory]
Dan Ruef4970552018-01-26 17:28:35 -060034 [-g branch]
35 [-e environment]
Naresh Kamboju3a427952017-07-06 16:56:59 +053036 [-s True|False]
37 [-v LTP_VERSION]
Dan Rue58d3a882017-07-11 16:30:30 -050038 [-M Timeout_Multiplier]
39 [-R root_password]" 1>&2
Naresh Kambojuad19d882016-09-20 19:31:00 +053040 exit 0
41}
42
Anders Roxell05c1e172019-04-02 05:08:34 +020043while getopts "M:T:S:b:d:g:e:s:v:R:" arg; do
Naresh Kambojuad19d882016-09-20 19:31:00 +053044 case "$arg" in
45 T)
46 TST_CMDFILES="${OPTARG}"
Naresh Kamboju43e80742017-01-18 15:51:02 +053047 # shellcheck disable=SC2001
Naresh Kambojuad19d882016-09-20 19:31:00 +053048 LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
49 ;;
50 S)
Dan Ruef4970552018-01-26 17:28:35 -060051 if [ -z "${OPTARG##*http*}" ]; then
52 if [ -z "${OPTARG##*yaml*}" ]; then
53 # Skipfile is of type yaml
54 SKIPFILE_TMP="http-skipfile.yaml"
55 SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}"
56 else
57 # Skipfile is normal skipfile
58 SKIPFILE_TMP="http-skipfile"
59 SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}"
60 fi
61 # Download LTP skipfile from specified URL
62 if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then
63 error_msg "Failed to fetch ${OPTARG}"
Dan Ruef4970552018-01-26 17:28:35 -060064 fi
65 elif [ "${OPTARG##*.}" = "yaml" ]; then
66 # yaml skipfile; use skipgen to generate a skipfile
67 SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053068 else
Dan Ruef4970552018-01-26 17:28:35 -060069 # Regular LTP skipfile
70 SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053071 fi
72 ;;
Dan Ruef4970552018-01-26 17:28:35 -060073 b)
74 export BOARD="${OPTARG}"
75 ;;
Anders Roxell05c1e172019-04-02 05:08:34 +020076 d)
77 export LTP_TMPDIR="${OPTARG}"
78 ;;
Dan Ruef4970552018-01-26 17:28:35 -060079 g)
80 export BRANCH="${OPTARG}"
81 ;;
82 e)
83 export ENVIRONMENT="${OPTARG}"
84 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +053085 # SKIP_INSTALL is true in case of Open Embedded builds
86 # SKIP_INSTALL is flase in case of Debian builds
87 s) SKIP_INSTALL="${OPTARG}";;
88 v) LTP_VERSION="${OPTARG}";;
Naresh Kamboju3bff06b2017-05-24 14:46:37 +053089 # Slow machines need more timeout Default is 5min and multiply * MINUTES
90 M) export LTP_TIMEOUT_MUL="${OPTARG}";;
Dan Rue58d3a882017-07-11 16:30:30 -050091 R) export PASSWD="${OPTARG}";;
Anders Roxell446b84f2019-04-03 05:30:21 +020092 *)
93 usage
94 error_msg "No flag ${OPTARG}"
95 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +053096 esac
97done
98
Dan Ruef4970552018-01-26 17:28:35 -060099if [ -n "${SKIPFILE_YAML}" ]; then
100 export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
101 generate_skipfile
102 if [ ! -f "${SKIPFILE_PATH}" ]; then
103 error_msg "Skipfile ${SKIPFILE} does not exist";
Dan Ruef4970552018-01-26 17:28:35 -0600104 fi
105 SKIPFILE="-S ${SKIPFILE_PATH}"
106fi
107
Naresh Kambojuad19d882016-09-20 19:31:00 +0530108# Install LTP test suite
109install_ltp() {
110 rm -rf /opt/ltp
111 mkdir -p /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530112 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530113 cd /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530114 # shellcheck disable=SC2140
Naresh Kambojuad19d882016-09-20 19:31:00 +0530115 wget https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
116 tar --strip-components=1 -Jxf ltp-full-"${LTP_VERSION}".tar.xz
117 ./configure
118 make -j8 all
119 make SKIP_IDCHECK=1 install
120}
121
Naresh Kambojuad19d882016-09-20 19:31:00 +0530122# Parse LTP output
123parse_ltp_output() {
Chase Qi3308d6b2017-08-07 15:19:35 +0800124 grep -E "PASS|FAIL|CONF" "$1" \
125 | awk '{print $1" "$2}' \
126 | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530127}
128
129# Run LTP test suite
130run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +0530131 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530132 cd "${LTP_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +0530133 # shellcheck disable=SC2174
134 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530135
Naresh Kamboju3a427952017-07-06 16:56:59 +0530136 pipe0_status "./runltp -p -q -f ${TST_CMDFILES} \
137 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
138 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
139 -d ${LTP_TMPDIR} \
140 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Naresh Kambojue1880532018-10-02 15:17:34 +0530141# check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530142
Naresh Kambojuad19d882016-09-20 19:31:00 +0530143 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
Naresh Kamboju3a427952017-07-06 16:56:59 +0530144 # Cleanup
Milosz Wasilewskicacf7382017-11-01 11:25:55 +0000145 # don't fail the whole test job if rm fails
146 rm -rf "${LTP_TMPDIR}" || true
Naresh Kambojuad19d882016-09-20 19:31:00 +0530147}
148
Dan Ruea7e86c42017-11-07 14:55:58 -0600149# Prepare system
150prep_system() {
151 # Stop systemd-timesyncd if running
152 if systemctl is-active systemd-timesyncd 2>/dev/null; then
153 info_msg "Stopping systemd-timesyncd"
154 systemctl stop systemd-timesyncd
155 fi
Dan Ruef07393e2017-11-13 09:55:43 -0600156 # userns07 requires kernel.unprivileged_userns_clone
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800157 if [ -f "/proc/sys/kernel/unprivileged_userns_clone" ]; then
Dan Ruef07393e2017-11-13 09:55:43 -0600158 info_msg "Enabling kernel.unprivileged_userns_clone"
159 sysctl -w kernel.unprivileged_userns_clone=1
Shawn Guoe7f9f1c2019-06-12 10:40:47 +0800160 else
161 info_msg "Kernel has no support of unprivileged_userns_clone"
Dan Ruef07393e2017-11-13 09:55:43 -0600162 fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600163}
164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530165# Test run.
166! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600167create_out_dir "${OUTPUT}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530168
169info_msg "About to run ltp test..."
170info_msg "Output directory: ${OUTPUT}"
171
172if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
173 info_msg "install_ltp skipped"
174else
175 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530176 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530177 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100178 debian|ubuntu)
Dan Rue519f5b82017-11-06 16:03:53 -0600179 pkgs="xz-utils flex bison build-essential wget curl net-tools quota genisoimage sudo libaio-dev expect automake acl"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530180 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530181 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100182 centos|fedora)
Dan Rue519f5b82017-11-06 16:03:53 -0600183 pkgs="xz flex bison make automake gcc gcc-c++ kernel-devel wget curl net-tools quota genisoimage sudo libaio expect acl"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530184 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530185 ;;
186 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530187 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530188 esac
Chase Qifee992c2017-06-19 17:02:50 +0800189
190 # Check if mkisofs or genisoimage installed for isofs test.
191 if echo "${TST_CMDFILES}" | grep 'fs'; then
192 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
193 if ! which mkisofs; then
194 if which genisoimage; then
195 ln -s "$(which genisoimage)" /usr/bin/mkisofs
196 else
197 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
198 fi
199 fi
200 fi
201
Naresh Kambojuad19d882016-09-20 19:31:00 +0530202 info_msg "Run install_ltp"
203 install_ltp
204fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600205info_msg "Running prep_system"
206prep_system
Naresh Kambojuad19d882016-09-20 19:31:00 +0530207info_msg "Running run_ltp"
208run_ltp