blob: 033728b8a95525ad5a7f06078ac74d2afaf0de7b [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}"
64 exit 1
65 fi
66 elif [ "${OPTARG##*.}" = "yaml" ]; then
67 # yaml skipfile; use skipgen to generate a skipfile
68 SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053069 else
Dan Ruef4970552018-01-26 17:28:35 -060070 # Regular LTP skipfile
71 SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053072 fi
73 ;;
Dan Ruef4970552018-01-26 17:28:35 -060074 b)
75 export BOARD="${OPTARG}"
76 ;;
Anders Roxell05c1e172019-04-02 05:08:34 +020077 d)
78 export LTP_TMPDIR="${OPTARG}"
79 ;;
Dan Ruef4970552018-01-26 17:28:35 -060080 g)
81 export BRANCH="${OPTARG}"
82 ;;
83 e)
84 export ENVIRONMENT="${OPTARG}"
85 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +053086 # SKIP_INSTALL is true in case of Open Embedded builds
87 # SKIP_INSTALL is flase in case of Debian builds
88 s) SKIP_INSTALL="${OPTARG}";;
89 v) LTP_VERSION="${OPTARG}";;
Naresh Kamboju3bff06b2017-05-24 14:46:37 +053090 # Slow machines need more timeout Default is 5min and multiply * MINUTES
91 M) export LTP_TIMEOUT_MUL="${OPTARG}";;
Dan Rue58d3a882017-07-11 16:30:30 -050092 R) export PASSWD="${OPTARG}";;
Naresh Kambojuad19d882016-09-20 19:31:00 +053093 esac
94done
95
Dan Ruef4970552018-01-26 17:28:35 -060096if [ -n "${SKIPFILE_YAML}" ]; then
97 export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
98 generate_skipfile
99 if [ ! -f "${SKIPFILE_PATH}" ]; then
100 error_msg "Skipfile ${SKIPFILE} does not exist";
101 exit 1
102 fi
103 SKIPFILE="-S ${SKIPFILE_PATH}"
104fi
105
Naresh Kambojuad19d882016-09-20 19:31:00 +0530106# Install LTP test suite
107install_ltp() {
108 rm -rf /opt/ltp
109 mkdir -p /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530110 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530111 cd /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530112 # shellcheck disable=SC2140
Naresh Kambojuad19d882016-09-20 19:31:00 +0530113 wget https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
114 tar --strip-components=1 -Jxf ltp-full-"${LTP_VERSION}".tar.xz
115 ./configure
116 make -j8 all
117 make SKIP_IDCHECK=1 install
118}
119
Naresh Kambojuad19d882016-09-20 19:31:00 +0530120# Parse LTP output
121parse_ltp_output() {
Chase Qi3308d6b2017-08-07 15:19:35 +0800122 grep -E "PASS|FAIL|CONF" "$1" \
123 | awk '{print $1" "$2}' \
124 | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530125}
126
127# Run LTP test suite
128run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +0530129 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530130 cd "${LTP_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +0530131 # shellcheck disable=SC2174
132 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530133
Naresh Kamboju3a427952017-07-06 16:56:59 +0530134 pipe0_status "./runltp -p -q -f ${TST_CMDFILES} \
135 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
136 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
137 -d ${LTP_TMPDIR} \
138 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Naresh Kambojue1880532018-10-02 15:17:34 +0530139# check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530140
Naresh Kambojuad19d882016-09-20 19:31:00 +0530141 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
Naresh Kamboju3a427952017-07-06 16:56:59 +0530142 # Cleanup
Milosz Wasilewskicacf7382017-11-01 11:25:55 +0000143 # don't fail the whole test job if rm fails
144 rm -rf "${LTP_TMPDIR}" || true
Naresh Kambojuad19d882016-09-20 19:31:00 +0530145}
146
Dan Ruea7e86c42017-11-07 14:55:58 -0600147# Prepare system
148prep_system() {
149 # Stop systemd-timesyncd if running
150 if systemctl is-active systemd-timesyncd 2>/dev/null; then
151 info_msg "Stopping systemd-timesyncd"
152 systemctl stop systemd-timesyncd
153 fi
Dan Ruef07393e2017-11-13 09:55:43 -0600154 # userns07 requires kernel.unprivileged_userns_clone
155 if [ "$(sysctl -n kernel.unprivileged_userns_clone)" -eq 0 ]; then
156 info_msg "Enabling kernel.unprivileged_userns_clone"
157 sysctl -w kernel.unprivileged_userns_clone=1
158 fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600159}
160
Naresh Kambojuad19d882016-09-20 19:31:00 +0530161# Test run.
162! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600163create_out_dir "${OUTPUT}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530164
165info_msg "About to run ltp test..."
166info_msg "Output directory: ${OUTPUT}"
167
168if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
169 info_msg "install_ltp skipped"
170else
171 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530172 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530173 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100174 debian|ubuntu)
Dan Rue519f5b82017-11-06 16:03:53 -0600175 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 +0530176 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530177 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100178 centos|fedora)
Dan Rue519f5b82017-11-06 16:03:53 -0600179 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 +0530180 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530181 ;;
182 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530183 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530184 esac
Chase Qifee992c2017-06-19 17:02:50 +0800185
186 # Check if mkisofs or genisoimage installed for isofs test.
187 if echo "${TST_CMDFILES}" | grep 'fs'; then
188 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
189 if ! which mkisofs; then
190 if which genisoimage; then
191 ln -s "$(which genisoimage)" /usr/bin/mkisofs
192 else
193 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
194 fi
195 fi
196 fi
197
Naresh Kambojuad19d882016-09-20 19:31:00 +0530198 info_msg "Run install_ltp"
199 install_ltp
200fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600201info_msg "Running prep_system"
202prep_system
Naresh Kambojuad19d882016-09-20 19:31:00 +0530203info_msg "Running run_ltp"
204run_ltp