Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Dan Rue | 9e11dcd | 2017-10-04 11:29:04 -0500 | [diff] [blame] | 3 | set -x |
| 4 | |
Chase Qi | 890c120 | 2017-06-19 16:09:27 +0800 | [diff] [blame] | 5 | # shellcheck disable=SC1091 |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 6 | . ../../lib/sh-test-lib |
| 7 | OUTPUT="$(pwd)/output" |
| 8 | RESULT_FILE="${OUTPUT}/result.txt" |
| 9 | # Absolute path to this script. /home/user/bin/foo.sh |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 10 | SCRIPT="$(readlink -f "${0}")" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 11 | # Absolute path this script is in. /home/user/bin |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 12 | SCRIPTPATH="$(dirname "${SCRIPT}")" |
| 13 | echo "Script path is: ${SCRIPTPATH}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 14 | # List of test cases |
| 15 | TST_CMDFILES="" |
| 16 | # List of test cases to be skipped |
| 17 | SKIPFILE="" |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 18 | # List of test cases to be skipped in yaml/skipgen format |
| 19 | SKIPFILE_YAML="" |
| 20 | BOARD="" |
| 21 | BRANCH="" |
| 22 | ENVIRONMENT="" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 23 | # LTP version |
Naresh Kamboju | 52f0257 | 2018-11-20 19:52:18 +0530 | [diff] [blame] | 24 | LTP_VERSION="20180926" |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 25 | TEST_PROGRAM=ltp |
| 26 | # https://github.com/linux-test-project/ltp.git |
| 27 | TEST_GIT_URL="" |
| 28 | TEST_DIR="$(pwd)/${TEST_PROGRAM}" |
| 29 | BUILD_FROM_TAR="false" |
| 30 | |
Naresh Kamboju | 9bce916 | 2017-07-13 12:56:27 +0530 | [diff] [blame] | 31 | LTP_TMPDIR=/ltp-tmp |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 32 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 33 | LTP_INSTALL_PATH=/opt/ltp |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 34 | |
| 35 | usage() { |
Naresh Kamboju | 3a42795 | 2017-07-06 16:56:59 +0530 | [diff] [blame] | 36 | echo "Usage: ${0} [-T mm,math,syscalls] |
| 37 | [-S skipfile-lsk-juno] |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 38 | [-b board] |
Anders Roxell | 05c1e17 | 2019-04-02 05:08:34 +0200 | [diff] [blame] | 39 | [-d temp directory] |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 40 | [-g branch] |
| 41 | [-e environment] |
Rémi Duraffort | e08fea4 | 2021-01-04 14:31:02 +0100 | [diff] [blame] | 42 | [-i install path] |
Naresh Kamboju | 3a42795 | 2017-07-06 16:56:59 +0530 | [diff] [blame] | 43 | [-s True|False] |
| 44 | [-v LTP_VERSION] |
Dan Rue | 58d3a88 | 2017-07-11 16:30:30 -0500 | [diff] [blame] | 45 | [-M Timeout_Multiplier] |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 46 | [-R root_password] |
| 47 | [-u git url] |
| 48 | [-p build directory] |
| 49 | [-t build from tarfile ] |
| 50 | " 1>&2 |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 51 | exit 0 |
| 52 | } |
| 53 | |
Rémi Duraffort | e08fea4 | 2021-01-04 14:31:02 +0100 | [diff] [blame] | 54 | while getopts "M:T:S:b:d:g:e:i:s:v:R:u:p:t:" arg; do |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 55 | case "$arg" in |
| 56 | T) |
| 57 | TST_CMDFILES="${OPTARG}" |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 58 | # shellcheck disable=SC2001 |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 59 | LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,') |
| 60 | ;; |
| 61 | S) |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 62 | if [ -z "${OPTARG##*http*}" ]; then |
| 63 | if [ -z "${OPTARG##*yaml*}" ]; then |
| 64 | # Skipfile is of type yaml |
| 65 | SKIPFILE_TMP="http-skipfile.yaml" |
| 66 | SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}" |
| 67 | else |
| 68 | # Skipfile is normal skipfile |
| 69 | SKIPFILE_TMP="http-skipfile" |
| 70 | SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}" |
| 71 | fi |
| 72 | # Download LTP skipfile from specified URL |
| 73 | if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then |
| 74 | error_msg "Failed to fetch ${OPTARG}" |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 75 | fi |
| 76 | elif [ "${OPTARG##*.}" = "yaml" ]; then |
| 77 | # yaml skipfile; use skipgen to generate a skipfile |
| 78 | SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 79 | else |
Rémi Duraffort | e7cc8a2 | 2021-01-05 14:04:03 +0100 | [diff] [blame] | 80 | # Regular LTP skipfile. Absolute or relative path? |
| 81 | if [ "${OPTARG:0:1}" == "/" ]; then |
| 82 | SKIPFILE="-S ${OPTARG}" |
| 83 | else |
| 84 | SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}" |
| 85 | fi |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 86 | fi |
| 87 | ;; |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 88 | b) |
| 89 | export BOARD="${OPTARG}" |
| 90 | ;; |
Anders Roxell | 05c1e17 | 2019-04-02 05:08:34 +0200 | [diff] [blame] | 91 | d) |
| 92 | export LTP_TMPDIR="${OPTARG}" |
| 93 | ;; |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 94 | g) |
| 95 | export BRANCH="${OPTARG}" |
| 96 | ;; |
| 97 | e) |
| 98 | export ENVIRONMENT="${OPTARG}" |
| 99 | ;; |
Rémi Duraffort | e08fea4 | 2021-01-04 14:31:02 +0100 | [diff] [blame] | 100 | i) |
| 101 | export LTP_INSTALL_PATH="${OPTARG}" |
| 102 | ;; |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 103 | # SKIP_INSTALL is true in case of Open Embedded builds |
| 104 | # SKIP_INSTALL is flase in case of Debian builds |
| 105 | s) SKIP_INSTALL="${OPTARG}";; |
| 106 | v) LTP_VERSION="${OPTARG}";; |
Naresh Kamboju | 3bff06b | 2017-05-24 14:46:37 +0530 | [diff] [blame] | 107 | # Slow machines need more timeout Default is 5min and multiply * MINUTES |
| 108 | M) export LTP_TIMEOUT_MUL="${OPTARG}";; |
Dan Rue | 58d3a88 | 2017-07-11 16:30:30 -0500 | [diff] [blame] | 109 | R) export PASSWD="${OPTARG}";; |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 110 | u) |
| 111 | if [[ "$OPTARG" != '' ]]; then |
| 112 | TEST_GIT_URL="$OPTARG" |
| 113 | TEST_TARFILE="" |
| 114 | fi |
| 115 | ;; |
| 116 | p) |
| 117 | if [[ "$OPTARG" != '' ]]; then |
| 118 | TEST_DIR="$OPTARG" |
| 119 | fi |
| 120 | ;; |
| 121 | t) |
| 122 | BUILD_FROM_TAR="$OPTARG" |
| 123 | ;; |
Anders Roxell | 446b84f | 2019-04-03 05:30:21 +0200 | [diff] [blame] | 124 | *) |
| 125 | usage |
| 126 | error_msg "No flag ${OPTARG}" |
| 127 | ;; |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 128 | esac |
| 129 | done |
| 130 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 131 | TEST_TARFILE=https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz |
| 132 | |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 133 | if [ -n "${SKIPFILE_YAML}" ]; then |
| 134 | export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile" |
| 135 | generate_skipfile |
| 136 | if [ ! -f "${SKIPFILE_PATH}" ]; then |
| 137 | error_msg "Skipfile ${SKIPFILE} does not exist"; |
Dan Rue | f497055 | 2018-01-26 17:28:35 -0600 | [diff] [blame] | 138 | fi |
| 139 | SKIPFILE="-S ${SKIPFILE_PATH}" |
| 140 | fi |
| 141 | |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 142 | # Parse LTP output |
| 143 | parse_ltp_output() { |
Chase Qi | 3308d6b | 2017-08-07 15:19:35 +0800 | [diff] [blame] | 144 | grep -E "PASS|FAIL|CONF" "$1" \ |
| 145 | | awk '{print $1" "$2}' \ |
| 146 | | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/' >> "${RESULT_FILE}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | # Run LTP test suite |
| 150 | run_ltp() { |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 151 | # shellcheck disable=SC2164 |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 152 | cd "${LTP_INSTALL_PATH}" |
Naresh Kamboju | ff5f6c3 | 2017-07-11 14:50:32 +0530 | [diff] [blame] | 153 | # shellcheck disable=SC2174 |
| 154 | mkdir -m 777 -p "${LTP_TMPDIR}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 155 | |
Naresh Kamboju | 3a42795 | 2017-07-06 16:56:59 +0530 | [diff] [blame] | 156 | pipe0_status "./runltp -p -q -f ${TST_CMDFILES} \ |
| 157 | -l ${OUTPUT}/LTP_${LOG_FILE}.log \ |
| 158 | -C ${OUTPUT}/LTP_${LOG_FILE}.failed \ |
| 159 | -d ${LTP_TMPDIR} \ |
| 160 | ${SKIPFILE}" "tee ${OUTPUT}/LTP_${LOG_FILE}.out" |
Naresh Kamboju | e188053 | 2018-10-02 15:17:34 +0530 | [diff] [blame] | 161 | # check_return "runltp_${LOG_FILE}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 162 | |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 163 | parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log" |
Naresh Kamboju | 3a42795 | 2017-07-06 16:56:59 +0530 | [diff] [blame] | 164 | # Cleanup |
Milosz Wasilewski | cacf738 | 2017-11-01 11:25:55 +0000 | [diff] [blame] | 165 | # don't fail the whole test job if rm fails |
| 166 | rm -rf "${LTP_TMPDIR}" || true |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 167 | } |
| 168 | |
Dan Rue | a7e86c4 | 2017-11-07 14:55:58 -0600 | [diff] [blame] | 169 | # Prepare system |
| 170 | prep_system() { |
| 171 | # Stop systemd-timesyncd if running |
| 172 | if systemctl is-active systemd-timesyncd 2>/dev/null; then |
| 173 | info_msg "Stopping systemd-timesyncd" |
| 174 | systemctl stop systemd-timesyncd |
| 175 | fi |
Dan Rue | f07393e | 2017-11-13 09:55:43 -0600 | [diff] [blame] | 176 | # userns07 requires kernel.unprivileged_userns_clone |
Shawn Guo | e7f9f1c | 2019-06-12 10:40:47 +0800 | [diff] [blame] | 177 | if [ -f "/proc/sys/kernel/unprivileged_userns_clone" ]; then |
Dan Rue | f07393e | 2017-11-13 09:55:43 -0600 | [diff] [blame] | 178 | info_msg "Enabling kernel.unprivileged_userns_clone" |
| 179 | sysctl -w kernel.unprivileged_userns_clone=1 |
Shawn Guo | e7f9f1c | 2019-06-12 10:40:47 +0800 | [diff] [blame] | 180 | else |
| 181 | info_msg "Kernel has no support of unprivileged_userns_clone" |
Dan Rue | f07393e | 2017-11-13 09:55:43 -0600 | [diff] [blame] | 182 | fi |
Dan Rue | a7e86c4 | 2017-11-07 14:55:58 -0600 | [diff] [blame] | 183 | } |
| 184 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 185 | get_tarfile() { |
| 186 | local test_tarfile="$1" |
| 187 | mkdir "${TEST_DIR}" |
| 188 | pushd "${TEST_DIR}" || exit 1 |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 189 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 190 | wget "${test_tarfile}" |
| 191 | tar --strip-components=1 -Jxf "$(basename "${test_tarfile}")" |
| 192 | popd || exit 1 |
| 193 | } |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 194 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 195 | build_install_tests() { |
| 196 | rm -rf "${LTP_INSTALL_PATH}" |
| 197 | pushd "${TEST_DIR}" || exit 1 |
| 198 | [[ -n "${TEST_GIT_URL}" ]] && make autotools |
| 199 | ./configure |
| 200 | make -j"$(proc)" all |
| 201 | make SKIP_IDCHECK=1 install |
| 202 | popd || exit 1 |
| 203 | } |
| 204 | |
| 205 | install() { |
| 206 | dist= |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 207 | dist_name |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 208 | # shellcheck disable=SC2154 |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 209 | case "${dist}" in |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame] | 210 | debian|ubuntu) |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 211 | [[ -n "${TEST_GIT_URL}" ]] && pkgs="git" |
| 212 | 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 Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 213 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 214 | ;; |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame] | 215 | centos|fedora) |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 216 | [[ -n "${TEST_GIT_URL}" ]] && pkgs="git-core" |
Anders Roxell | 1c0eeb3 | 2022-01-20 12:05:32 +0100 | [diff] [blame] | 217 | 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 Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 218 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 219 | ;; |
| 220 | *) |
Naresh Kamboju | 43e8074 | 2017-01-18 15:51:02 +0530 | [diff] [blame] | 221 | warn_msg "Unsupported distribution: package install skipped" |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 222 | esac |
Chase Qi | fee992c | 2017-06-19 17:02:50 +0800 | [diff] [blame] | 223 | |
| 224 | # Check if mkisofs or genisoimage installed for isofs test. |
| 225 | if echo "${TST_CMDFILES}" | grep 'fs'; then |
| 226 | # link mkisofs to genisoimage on distributions that have replaced mkisofs with genisoimage. |
| 227 | if ! which mkisofs; then |
| 228 | if which genisoimage; then |
| 229 | ln -s "$(which genisoimage)" /usr/bin/mkisofs |
| 230 | else |
| 231 | warn_msg "Neither mkisofs nor genisoimage found! Either of them is required by isofs test." |
| 232 | fi |
| 233 | fi |
| 234 | fi |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 235 | } |
Chase Qi | fee992c | 2017-06-19 17:02:50 +0800 | [diff] [blame] | 236 | |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 237 | # Test run. |
| 238 | ! check_root && error_msg "This script must be run as root" |
| 239 | create_out_dir "${OUTPUT}" |
| 240 | |
| 241 | info_msg "About to run ltp test..." |
| 242 | info_msg "Output directory: ${OUTPUT}" |
| 243 | |
| 244 | if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then |
| 245 | info_msg "${TEST_PROGRAM} installation skipped altogether" |
| 246 | else |
| 247 | install |
| 248 | fi |
| 249 | |
Rémi Duraffort | e7cc8a2 | 2021-01-05 14:04:03 +0100 | [diff] [blame] | 250 | if [ ! -d "${LTP_INSTALL_PATH}" ]; then |
Anders Roxell | 67acee6 | 2020-10-21 08:52:24 +0200 | [diff] [blame] | 251 | if [ "${BUILD_FROM_TAR}" = "true" ] || [ "${BUILD_FROM_TAR}" = "True" ]; then |
| 252 | get_tarfile "${TEST_TARFILE}" |
| 253 | elif [ -n "${TEST_GIT_URL}" ]; then |
| 254 | get_test_program "${TEST_GIT_URL}" "${TEST_DIR}" "${LTP_VERSION}" "${TEST_PROGRAM}" |
| 255 | else |
| 256 | error_msg "I'm confused, get me out of here, can't fetch tar or test version." |
| 257 | fi |
| 258 | build_install_tests |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 259 | fi |
Dan Rue | a7e86c4 | 2017-11-07 14:55:58 -0600 | [diff] [blame] | 260 | info_msg "Running prep_system" |
| 261 | prep_system |
Naresh Kamboju | ad19d88 | 2016-09-20 19:31:00 +0530 | [diff] [blame] | 262 | info_msg "Running run_ltp" |
| 263 | run_ltp |