summaryrefslogtreecommitdiff
path: root/automated/linux/ltp-open-posix/ltp-open-posix.sh
blob: 2cec032eb6251a6a09d6399ef58c3a651b4cba2d (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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}"
LOG_FILE="open_posix_testsuite"
SKIP_INSTALL="true"
# List of test cases
TEST="conformance functional stress"
# LTP version
LTP_VERSION="20180515"
LTP_TMPDIR=/ltp-tmp

LTP_PRE_INSTALL=/opt/ltp
LTP_PATH=/opt/ltp/testcases/open_posix_testsuite

while getopts "s:v:" arg; do
   case "$arg" in
     s) SKIP_INSTALL="${OPTARG}";;
     v) LTP_VERSION="${OPTARG}";;
   esac
done

# Install LTP open posix test suite
install_ltp_open_posix() {
    rm -rf "${LTP_PRE_INSTALL}"
    mkdir -p "${LTP_PRE_INSTALL}"
    # shellcheck disable=SC2164
    cd "${LTP_PRE_INSTALL}"
    # 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
    ./configure --with-open-posix-testsuite
    # shellcheck disable=SC2164
    cd "${LTP_PATH}"
    make generate-makefiles | tee -a ${OUTPUT}/LTP_${LOG_FILE}.out

    for EACH_TEST in ${TEST}
    do
      make ${EACH_TEST}-all | tee -a ${OUTPUT}/LTP_${LOG_FILE}.out
    done
}

# Parse LTP output
parse_ltp_output() {
    for EACH_TEST in ${TEST}
    do
      sed -i -e "s/\// /g" logfile.${EACH_TEST}-test
      grep -E ": PASS"  logfile.${EACH_TEST}-test \
         | awk '{print $(NF-2)" "$(NF)}' \
         | sed 's/://g; s/PASS/pass/'  >> "${RESULT_FILE}"
      grep -E ": FAILED|: UNSUPPORTED|: UNTESTED"  logfile.${EACH_TEST}-test \
         | awk '{print $(NF-3)" "$(NF-1)}' \
         | sed 's/://g; s/FAILED/fail/; s/UNSUPPORTED/skip/; s/UNTESTED/skip/'  >> "${RESULT_FILE}"
    done

}

# Run LTP test suite
run_ltp_open_posix() {
    # shellcheck disable=SC2164
    cd "${LTP_PATH}"
    for EACH_TEST in ${TEST}
    do
      make ${EACH_TEST}-test | tee -a ${OUTPUT}/LTP_${LOG_FILE}.out
    done

    check_return "runltp_${LOG_FILE}"

    parse_ltp_output "${OUTPUT}/LTP_${LOG_FILE}.log"
}

# Prepare system
prep_system() {
    # Stop systemd-timesyncd if running
    if systemctl is-active systemd-timesyncd 2>/dev/null; then
        info_msg "Stopping systemd-timesyncd"
        systemctl stop systemd-timesyncd || true
    fi
    # userns07 requires kernel.unprivileged_userns_clone
    if [ "$(sysctl -n kernel.unprivileged_userns_clone)" -eq 0 ]; then
        info_msg "Enabling kernel.unprivileged_userns_clone"
        sysctl -w kernel.unprivileged_userns_clone=1 || true
    fi
}

# 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}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
    info_msg "install-ltp-open-posix skipped"
else
    dist_name
    # shellcheck disable=SC2154
    case "${dist}" in
      debian|ubuntu)
        pkgs="xz-utils flex bison build-essential wget curl net-tools sudo libaio-dev expect automake acl"
        install_deps "${pkgs}" "${SKIP_INSTALL}"
        ;;
      centos|fedora)
        pkgs="xz flex bison make automake gcc gcc-c++ kernel-devel wget curl net-tools sudo libaio expect acl"
        install_deps "${pkgs}" "${SKIP_INSTALL}"
        ;;
      *)
        warn_msg "Unsupported distribution: package install skipped"
    esac

    info_msg "Run install-ltp-open-posix"
    install_ltp_open_posix
fi
info_msg "Running prep_system"
prep_system
info_msg "Running run-ltp-open-posix"
run_ltp_open_posix