summaryrefslogtreecommitdiff
path: root/automated/linux/ltp-open-posix/ltp.sh
blob: aba3ef973e3f1e306f6d47f295726769c670df79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

set -x

# shellcheck disable=SC1091
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT="$(readlink -f "${0}")"
# Absolute path this script is in. /home/user/bin
SCRIPTPATH="$(dirname "${SCRIPT}")"
echo "Script path is: ${SCRIPTPATH}"
# List of test cases
TST_CMDFILES=""
# LTP version
LTP_VERSION="20180118"
LTP_TMPDIR=/ltp-tmp

LTP_PATH=/opt/ltp

usage() {
    echo "Usage: ${0} [-T conformance|functional|stress]
                      [-s True|False]
                      [-v LTP_VERSION]
                      [-M Timeout_Multiplier]
                      [-R root_password]" 1>&2
    exit 0
}

while getopts "M:T:s:v:R:" arg; do
   case "$arg" in
     T)
        TST_CMDFILES="${OPTARG}"
        # shellcheck disable=SC2001
        LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
        ;;
     # SKIP_INSTALL_PKG is true in case of Open Embedded builds
     # SKIP_INSTALL_PKG is flase in case of Debian builds
     s) SKIP_INSTALL_PKG="${OPTARG}";;
     v) LTP_VERSION="${OPTARG}";;
     # Slow machines need more timeout Default is 5min and multiply * MINUTES
     M) export LTP_TIMEOUT_MUL="${OPTARG}";;
     R) export PASSWD="${OPTARG}";;
  esac
done

# Install LTP test suite
install_ltp() {
    # shellcheck disable=SC2140
    wget https://github.com/linux-test-project/ltp/releases/download/"${LTP_VERSION}"/ltp-full-"${LTP_VERSION}".tar.xz
    tar --strip-components=1 -Jxf ltp-full-"${LTP_VERSION}".tar.xz
    cd testcases/open_posix_testsuite
    make generate-makefiles
}

# Parse LTP output
parse_ltp_output() {
    grep -E "PASS|FAIL|CONF"  "$1" \
        | awk '{print $1" "$2}' \
        | sed 's/PASS/pass/; s/FAIL/fail/; s/CONF/skip/'  >> "${RESULT_FILE}"
}

# Run LTP test suite
run_ltp() {
    # shellcheck disable=SC2164
    # shellcheck disable=SC2174

    make ${TST_CMDFILES}-all || true 
    make ${TST_CMDFILES}-test "tee ${OUTPUT}/LTP_${LOG_FILE}.out" 
    check_return "runltp_${TST_CMDFILES}"

    parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
    # Cleanup
    # don't fail the whole test job if rm fails
}

# Test run.
! check_root && error_msg "This script must be run as root"
create_out_dir "${OUTPUT}"

info_msg "About to run ltp test..."
info_msg "Output directory: ${OUTPUT}"

if [ "${SKIP_INSTALL_PKG}" = "False" ] || [ "${SKIP_INSTALL_PKG}" = "False" ]; then
    dist_name
    # shellcheck disable=SC2154
    case "${dist}" in
      debian|ubuntu)
        pkgs="xz-utils flex bison build-essential wget curl net-tools quota genisoimage sudo libaio-dev expect automake acl"
        install_deps "${pkgs}" "${SKIP_INSTALL_PKG}"
        ;;
      centos|fedora)
        pkgs="xz flex bison make automake gcc gcc-c++ kernel-devel wget curl net-tools quota genisoimage sudo libaio expect acl"
        install_deps "${pkgs}" "${SKIP_INSTALL_PKG}"
        ;;
      *)
        warn_msg "Unsupported distribution: package install skipped"
    esac

fi
info_msg "Installing ltp"
install_ltp
info_msg "Running run_ltp"
run_ltp