blob: 9a28aa3f86383623594ae6525cc36f7e5ce99688 [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]
33 [-g branch]
34 [-e environment]
Naresh Kamboju3a427952017-07-06 16:56:59 +053035 [-s True|False]
36 [-v LTP_VERSION]
Dan Rue58d3a882017-07-11 16:30:30 -050037 [-M Timeout_Multiplier]
38 [-R root_password]" 1>&2
Naresh Kambojuad19d882016-09-20 19:31:00 +053039 exit 0
40}
41
Dan Ruef4970552018-01-26 17:28:35 -060042while getopts "M:T:S:b:g:e:s:v:R:" arg; do
Naresh Kambojuad19d882016-09-20 19:31:00 +053043 case "$arg" in
44 T)
45 TST_CMDFILES="${OPTARG}"
Naresh Kamboju43e80742017-01-18 15:51:02 +053046 # shellcheck disable=SC2001
Naresh Kambojuad19d882016-09-20 19:31:00 +053047 LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
48 ;;
49 S)
Dan Ruef4970552018-01-26 17:28:35 -060050 if [ -z "${OPTARG##*http*}" ]; then
51 if [ -z "${OPTARG##*yaml*}" ]; then
52 # Skipfile is of type yaml
53 SKIPFILE_TMP="http-skipfile.yaml"
54 SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}"
55 else
56 # Skipfile is normal skipfile
57 SKIPFILE_TMP="http-skipfile"
58 SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}"
59 fi
60 # Download LTP skipfile from specified URL
61 if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then
62 error_msg "Failed to fetch ${OPTARG}"
63 exit 1
64 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 ;;
76 g)
77 export BRANCH="${OPTARG}"
78 ;;
79 e)
80 export ENVIRONMENT="${OPTARG}"
81 ;;
Naresh Kambojuad19d882016-09-20 19:31:00 +053082 # SKIP_INSTALL is true in case of Open Embedded builds
83 # SKIP_INSTALL is flase in case of Debian builds
84 s) SKIP_INSTALL="${OPTARG}";;
85 v) LTP_VERSION="${OPTARG}";;
Naresh Kamboju3bff06b2017-05-24 14:46:37 +053086 # Slow machines need more timeout Default is 5min and multiply * MINUTES
87 M) export LTP_TIMEOUT_MUL="${OPTARG}";;
Dan Rue58d3a882017-07-11 16:30:30 -050088 R) export PASSWD="${OPTARG}";;
Naresh Kambojuad19d882016-09-20 19:31:00 +053089 esac
90done
91
Dan Ruef4970552018-01-26 17:28:35 -060092if [ -n "${SKIPFILE_YAML}" ]; then
93 export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
94 generate_skipfile
95 if [ ! -f "${SKIPFILE_PATH}" ]; then
96 error_msg "Skipfile ${SKIPFILE} does not exist";
97 exit 1
98 fi
99 SKIPFILE="-S ${SKIPFILE_PATH}"
100fi
101
Naresh Kambojuad19d882016-09-20 19:31:00 +0530102# Install LTP test suite
103install_ltp() {
104 rm -rf /opt/ltp
105 mkdir -p /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530106 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530107 cd /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +0530108 # shellcheck disable=SC2140
Naresh Kambojuad19d882016-09-20 19:31:00 +0530109 wget https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
110 tar --strip-components=1 -Jxf ltp-full-"${LTP_VERSION}".tar.xz
111 ./configure
112 make -j8 all
113 make SKIP_IDCHECK=1 install
114}
115
Naresh Kambojuad19d882016-09-20 19:31:00 +0530116# Parse LTP output
117parse_ltp_output() {
Chase Qi3308d6b2017-08-07 15:19:35 +0800118 grep -E "PASS|FAIL|CONF" "$1" \
119 | awk '{print $1" "$2}' \
120 | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530121}
122
123# Run LTP test suite
124run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +0530125 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +0530126 cd "${LTP_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +0530127 # shellcheck disable=SC2174
128 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530129
Naresh Kamboju3a427952017-07-06 16:56:59 +0530130 pipe0_status "./runltp -p -q -f ${TST_CMDFILES} \
131 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
132 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
133 -d ${LTP_TMPDIR} \
134 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Naresh Kambojue1880532018-10-02 15:17:34 +0530135# check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530136
Naresh Kambojuad19d882016-09-20 19:31:00 +0530137 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
Naresh Kamboju3a427952017-07-06 16:56:59 +0530138 # Cleanup
Milosz Wasilewskicacf7382017-11-01 11:25:55 +0000139 # don't fail the whole test job if rm fails
140 rm -rf "${LTP_TMPDIR}" || true
Naresh Kambojuad19d882016-09-20 19:31:00 +0530141}
142
Dan Ruea7e86c42017-11-07 14:55:58 -0600143# Prepare system
144prep_system() {
145 # Stop systemd-timesyncd if running
146 if systemctl is-active systemd-timesyncd 2>/dev/null; then
147 info_msg "Stopping systemd-timesyncd"
148 systemctl stop systemd-timesyncd
149 fi
Dan Ruef07393e2017-11-13 09:55:43 -0600150 # userns07 requires kernel.unprivileged_userns_clone
151 if [ "$(sysctl -n kernel.unprivileged_userns_clone)" -eq 0 ]; then
152 info_msg "Enabling kernel.unprivileged_userns_clone"
153 sysctl -w kernel.unprivileged_userns_clone=1
154 fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600155}
156
Naresh Kambojuad19d882016-09-20 19:31:00 +0530157# Test run.
158! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600159create_out_dir "${OUTPUT}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530160
161info_msg "About to run ltp test..."
162info_msg "Output directory: ${OUTPUT}"
163
164if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
165 info_msg "install_ltp skipped"
166else
167 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530168 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530169 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100170 debian|ubuntu)
Dan Rue519f5b82017-11-06 16:03:53 -0600171 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 +0530172 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530173 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100174 centos|fedora)
Dan Rue519f5b82017-11-06 16:03:53 -0600175 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 +0530176 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530177 ;;
178 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530179 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530180 esac
Chase Qifee992c2017-06-19 17:02:50 +0800181
182 # Check if mkisofs or genisoimage installed for isofs test.
183 if echo "${TST_CMDFILES}" | grep 'fs'; then
184 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
185 if ! which mkisofs; then
186 if which genisoimage; then
187 ln -s "$(which genisoimage)" /usr/bin/mkisofs
188 else
189 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
190 fi
191 fi
192 fi
193
Naresh Kambojuad19d882016-09-20 19:31:00 +0530194 info_msg "Run install_ltp"
195 install_ltp
196fi
Dan Ruea7e86c42017-11-07 14:55:58 -0600197info_msg "Running prep_system"
198prep_system
Naresh Kambojuad19d882016-09-20 19:31:00 +0530199info_msg "Running run_ltp"
200run_ltp