blob: 1c6d92f11b5b830fe809d6443c9a06efadfc9a9c [file] [log] [blame]
Naresh Kambojuad19d882016-09-20 19:31:00 +05301#!/bin/bash
2
Chase Qi890c1202017-06-19 16:09:27 +08003# shellcheck disable=SC1091
Naresh Kambojuad19d882016-09-20 19:31:00 +05304. ../../lib/sh-test-lib
5OUTPUT="$(pwd)/output"
6RESULT_FILE="${OUTPUT}/result.txt"
7# Absolute path to this script. /home/user/bin/foo.sh
Naresh Kamboju43e80742017-01-18 15:51:02 +05308SCRIPT="$(readlink -f "${0}")"
Naresh Kambojuad19d882016-09-20 19:31:00 +05309# Absolute path this script is in. /home/user/bin
Naresh Kamboju43e80742017-01-18 15:51:02 +053010SCRIPTPATH="$(dirname "${SCRIPT}")"
11echo "Script path is: ${SCRIPTPATH}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053012# List of test cases
13TST_CMDFILES=""
14# List of test cases to be skipped
15SKIPFILE=""
16# LTP version
Naresh Kamboju336e3212017-05-17 18:15:02 +053017LTP_VERSION="20170516"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +053018LTP_TMPDIR="${HOME}/ltp-tmp"
Naresh Kambojuad19d882016-09-20 19:31:00 +053019
20LTP_PATH=/opt/ltp
21
22usage() {
Naresh Kamboju3a427952017-07-06 16:56:59 +053023 echo "Usage: ${0} [-T mm,math,syscalls]
24 [-S skipfile-lsk-juno]
25 [-s True|False]
26 [-v LTP_VERSION]
27 [-M Timeout_Multiplier]" 1>&2
Naresh Kambojuad19d882016-09-20 19:31:00 +053028 exit 0
29}
30
Naresh Kamboju3bff06b2017-05-24 14:46:37 +053031while getopts "M:T:S:s:v:" arg; do
Naresh Kambojuad19d882016-09-20 19:31:00 +053032 case "$arg" in
33 T)
34 TST_CMDFILES="${OPTARG}"
Naresh Kamboju43e80742017-01-18 15:51:02 +053035 # shellcheck disable=SC2001
Naresh Kambojuad19d882016-09-20 19:31:00 +053036 LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
37 ;;
38 S)
39 OPT=$(echo "${OPTARG}" | grep "http")
40 if [ -z "${OPT}" ] ; then
41 # LTP skipfile
Naresh Kamboju43e80742017-01-18 15:51:02 +053042 SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053043 else
44 # Download LTP skipfile from speficied URL
Naresh Kamboju43e80742017-01-18 15:51:02 +053045 wget "${OPTARG}" -O "skipfile"
46 SKIPFILE="skipfile"
47 SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053048 fi
49 ;;
50 # SKIP_INSTALL is true in case of Open Embedded builds
51 # SKIP_INSTALL is flase in case of Debian builds
52 s) SKIP_INSTALL="${OPTARG}";;
53 v) LTP_VERSION="${OPTARG}";;
Naresh Kamboju3bff06b2017-05-24 14:46:37 +053054 # Slow machines need more timeout Default is 5min and multiply * MINUTES
55 M) export LTP_TIMEOUT_MUL="${OPTARG}";;
Naresh Kambojuad19d882016-09-20 19:31:00 +053056 esac
57done
58
59# Install LTP test suite
60install_ltp() {
61 rm -rf /opt/ltp
62 mkdir -p /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +053063 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +053064 cd /opt/ltp
Naresh Kamboju43e80742017-01-18 15:51:02 +053065 # shellcheck disable=SC2140
Naresh Kambojuad19d882016-09-20 19:31:00 +053066 wget https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
67 tar --strip-components=1 -Jxf ltp-full-"${LTP_VERSION}".tar.xz
68 ./configure
69 make -j8 all
70 make SKIP_IDCHECK=1 install
71}
72
Naresh Kambojuad19d882016-09-20 19:31:00 +053073# Parse LTP output
74parse_ltp_output() {
Chase Qi890c1202017-06-19 16:09:27 +080075 grep -E "PASS|FAIL|CONF" "$1" | awk '{print $1" "$2}' | sed s/CONF/SKIP/ >> "${RESULT_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053076}
77
78# Run LTP test suite
79run_ltp() {
Naresh Kamboju43e80742017-01-18 15:51:02 +053080 # shellcheck disable=SC2164
Naresh Kambojuad19d882016-09-20 19:31:00 +053081 cd "${LTP_PATH}"
Naresh Kambojuff5f6c32017-07-11 14:50:32 +053082 # shellcheck disable=SC2174
83 mkdir -m 777 -p "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053084
Naresh Kamboju3a427952017-07-06 16:56:59 +053085 pipe0_status "./runltp -p -q -f ${TST_CMDFILES} \
86 -l ${OUTPUT}/LTP_${LOG_FILE}.log \
87 -C ${OUTPUT}/LTP_${LOG_FILE}.failed \
88 -d ${LTP_TMPDIR} \
89 ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out"
Naresh Kamboju43e80742017-01-18 15:51:02 +053090 check_return "runltp_${LOG_FILE}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053091
Naresh Kambojuad19d882016-09-20 19:31:00 +053092 parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
Naresh Kamboju3a427952017-07-06 16:56:59 +053093 # Cleanup
Naresh Kambojuff5f6c32017-07-11 14:50:32 +053094 rm -rf "${LTP_TMPDIR}"
Naresh Kambojuad19d882016-09-20 19:31:00 +053095}
96
97# Test run.
98! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -060099create_out_dir "${OUTPUT}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530100
101info_msg "About to run ltp test..."
102info_msg "Output directory: ${OUTPUT}"
103
104if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
105 info_msg "install_ltp skipped"
106else
107 dist_name
Naresh Kamboju43e80742017-01-18 15:51:02 +0530108 # shellcheck disable=SC2154
Naresh Kambojuad19d882016-09-20 19:31:00 +0530109 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100110 debian|ubuntu)
Chase Qi01a53c62017-06-21 16:37:52 +0800111 pkgs="xz-utils flex bison build-essential wget curl net-tools quota genisoimage sudo"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530112 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530113 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100114 centos|fedora)
Chase Qi01a53c62017-06-21 16:37:52 +0800115 pkgs="xz flex bison make automake gcc gcc-c++ kernel-devel wget curl net-tools quota genisoimage sudo"
Naresh Kamboju43e80742017-01-18 15:51:02 +0530116 install_deps "${pkgs}" "${SKIP_INSTALL}"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530117 ;;
118 *)
Naresh Kamboju43e80742017-01-18 15:51:02 +0530119 warn_msg "Unsupported distribution: package install skipped"
Naresh Kambojuad19d882016-09-20 19:31:00 +0530120 esac
Chase Qifee992c2017-06-19 17:02:50 +0800121
122 # Check if mkisofs or genisoimage installed for isofs test.
123 if echo "${TST_CMDFILES}" | grep 'fs'; then
124 # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage.
125 if ! which mkisofs; then
126 if which genisoimage; then
127 ln -s "$(which genisoimage)" /usr/bin/mkisofs
128 else
129 warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test."
130 fi
131 fi
132 fi
133
Naresh Kambojuad19d882016-09-20 19:31:00 +0530134 info_msg "Run install_ltp"
135 install_ltp
136fi
137info_msg "Running run_ltp"
138run_ltp