blob: 3a7f5ba576e8656ae9466e819ee92145b982f31e [file] [log] [blame]
Naresh Kambojud7141702016-11-16 16:24:40 +05301#!/bin/sh
2
3# shellcheck disable=SC1091
4. ../../lib/sh-test-lib
5
6OUTPUT="$(pwd)/output"
7RESULT_FILE="${OUTPUT}/result.txt"
8RESULT_LOG="${OUTPUT}/result_log.txt"
Naresh Kamboju62d34f02017-05-15 18:12:20 +05309TMP_LOG="${OUTPUT}/tmp_log.txt"
Naresh Kambojud7141702016-11-16 16:24:40 +053010TEST_PASS_LOG="${OUTPUT}/test_pass_log.txt"
11TEST_FAIL_LOG="${OUTPUT}/test_fail_log.txt"
12TEST_SKIP_LOG="${OUTPUT}/test_skip_log.txt"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053013CWD=""
Anders Roxellc44e2c12024-06-19 20:44:49 +020014LIBHUGETLBFS_PATH=""
Naresh Kambojud7141702016-11-16 16:24:40 +053015
16WORD_SIZE="64"
Naresh Kamboju69416ab2017-12-08 12:29:49 +053017VERSION="02df38e93e25e07f4d54edae94fb4ec90b7a2824"
Naresh Kambojud7141702016-11-16 16:24:40 +053018
19usage() {
20 echo "Usage: $0 [-b <4|64>] [-s <true>] [-v <libhugetlbfs-version>]" 1>&2
21 exit 1
22}
23
Anders Roxellc44e2c12024-06-19 20:44:49 +020024while getopts "b:p:s:v:" o; do
Naresh Kambojud7141702016-11-16 16:24:40 +053025 case "$o" in
26 b) WORD_SIZE="${OPTARG}" ;;
Anders Roxellc44e2c12024-06-19 20:44:49 +020027 p) LIBHUGETLBFS_PATH="${OPTARG}" ;;
Naresh Kambojud7141702016-11-16 16:24:40 +053028 s) SKIP_INSTALL="${OPTARG}" ;;
29 v) VERSION="${OPTARG}" ;;
30 *) usage ;;
31 esac
32done
33
34parse_output() {
Naresh Kamboju62d34f02017-05-15 18:12:20 +053035 # Avoid results summary lines start with "*"
36 sed -i -e 's/\//-/g' "${TMP_LOG}"
37 # shellcheck disable=SC2063
38 grep -v "*" "${TMP_LOG}" | tee -a "${RESULT_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053039 # Parse each type of results
Naresh Kamboju69416ab2017-12-08 12:29:49 +053040 grep -E "PASS" "${RESULT_LOG}" | tee -a "${TEST_PASS_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053041 sed -i -e 's/ (inconclusive)//g' "${TEST_PASS_LOG}"
42 sed -i -e 's/(//g' "${TEST_PASS_LOG}"
43 sed -i -e 's/)://g' "${TEST_PASS_LOG}"
44 sed -i -e 's/://g' "${TEST_PASS_LOG}"
45 awk '{for (i=1; i<NF-1; i++) printf $i "-"; print $i " " $NF}' "${TEST_PASS_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
Naresh Kamboju62d34f02017-05-15 18:12:20 +053046 sed -i -e 's/PASS/pass/g' "${RESULT_FILE}"
Naresh Kambojud7141702016-11-16 16:24:40 +053047
Naresh Kamboju69416ab2017-12-08 12:29:49 +053048 grep -E "FAIL" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_FAIL_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053049 sed -i -e 's/ (inconclusive)//g' "${TEST_FAIL_LOG}"
50 sed -i -e 's/(//g' "${TEST_FAIL_LOG}"
51 sed -i -e 's/)//g' "${TEST_FAIL_LOG}"
52 sed -i -e 's/://g' "${TEST_FAIL_LOG}"
Naresh Kamboju62d34f02017-05-15 18:12:20 +053053 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "fail"}' "${TEST_FAIL_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
Naresh Kambojud7141702016-11-16 16:24:40 +053054
Naresh Kamboju69416ab2017-12-08 12:29:49 +053055 grep -E "SKIP" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
56 grep -E "Bad configuration" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053057 sed -i -e 's/ (inconclusive)//g' "${TEST_SKIP_LOG}"
58 sed -i -e 's/(//g' "${TEST_SKIP_LOG}"
59 sed -i -e 's/)//g' "${TEST_SKIP_LOG}"
60 sed -i -e 's/://g' "${TEST_SKIP_LOG}"
Naresh Kamboju62d34f02017-05-15 18:12:20 +053061 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "skip"}' "${TEST_SKIP_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
Naresh Kambojuf13e64b2017-06-13 16:45:17 +053062
63 # Replace "=" with "_" in test case names
64 sed -i -e 's/=/_/g' "${RESULT_FILE}"
65 # Clean up
Naresh Kamboju62d34f02017-05-15 18:12:20 +053066 rm -rf "${TMP_LOG}" "${RESULT_LOG}" "${TEST_PASS_LOG}" "${TEST_FAIL_LOG}" "${TEST_SKIP_LOG}"
67
Naresh Kambojud7141702016-11-16 16:24:40 +053068}
69
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053070libhugetlbfs_setup() {
Naresh Kambojud7141702016-11-16 16:24:40 +053071 mount_point="/mnt/hugetlb/"
72 # Allocate hugepages
73 echo 200 > /proc/sys/vm/nr_hugepages
74 umount "${mount_point}" > /dev/null 2>&1 || true
75 mkdir -p "${mount_point}"
76 mount -t hugetlbfs hugetlbfs "${mount_point}"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053077}
Naresh Kambojud7141702016-11-16 16:24:40 +053078
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053079libhugetlbfs_cleanup() {
80 umount "${mount_point}" > /dev/null 2>&1 || true
81 if [ -n "${CWD}" ]; then
82 # shellcheck disable=SC2164
83 cd "${CWD}"
84 rm -rf libhugetlbfs-"${VERSION}" > /dev/null 2>&1 || true
85 rm -rf libhugetlbfs-"${VERSION}".tar.gz > /dev/null 2>&1 || true
86 fi
87}
88
89libhugetlbfs_build_test() {
Naresh Kamboju69416ab2017-12-08 12:29:49 +053090 CWD=$(pwd)
91
Naresh Kambojud7141702016-11-16 16:24:40 +053092 # shellcheck disable=SC2140
93 # Upstream tree
Naresh Kamboju69416ab2017-12-08 12:29:49 +053094 # wget https://github.com/libhugetlbfs/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
95 # tar -xvf libhugetlbfs-"${VERSION}".tar.gz
96 # # shellcheck disable=SC2164
97 # cd libhugetlbfs-"${VERSION}"
98 # make BUILDTYPE=NATIVEONLY
99
100 # En lieu of an actual libhugetlbfs release, fetch a tarball from a github
101 # commit and write a version file explicitly.
102 wget -O libhugetlbfs-"${VERSION}".tar.gz https://github.com/libhugetlbfs/libhugetlbfs/tarball/"${VERSION}"
103 mkdir libhugetlbfs-"${VERSION}"
104 tar -xvf libhugetlbfs-"${VERSION}".tar.gz --strip=1 -C libhugetlbfs-"${VERSION}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530105 # shellcheck disable=SC2164
106 cd libhugetlbfs-"${VERSION}"
Naresh Kamboju69416ab2017-12-08 12:29:49 +0530107 echo "${VERSION}" > version
Naresh Kambojud7141702016-11-16 16:24:40 +0530108 make BUILDTYPE=NATIVEONLY
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530109}
110
111libhugetlbfs_run_test() {
Naresh Kambojud7141702016-11-16 16:24:40 +0530112 # shellcheck disable=SC2164
113 cd tests
114 # Run tests
115 # Redirect stdout (not stderr)
Naresh Kamboju62d34f02017-05-15 18:12:20 +0530116 ./run_tests.py -b "${WORD_SIZE}" | tee -a "${TMP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530117 parse_output
Naresh Kambojud7141702016-11-16 16:24:40 +0530118}
119
120install() {
121 dist_name
122 # shellcheck disable=SC2154
123 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100124 debian|ubuntu)
Naresh Kambojud7141702016-11-16 16:24:40 +0530125 pkgs="binutils gcc make python sed tar wget"
126 install_deps "${pkgs}" "${SKIP_INSTALL}"
127 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100128 fedora|centos)
Naresh Kambojud7141702016-11-16 16:24:40 +0530129 pkgs="binutils gcc glibc-static make python sed tar wget"
130 install_deps "${pkgs}" "${SKIP_INSTALL}"
131 ;;
132 esac
133}
134
135# Test run.
136! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600137create_out_dir "${OUTPUT}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530138# shellcheck disable=SC2164
139cd "${OUTPUT}"
140
141info_msg "About to run libhugetlbfs test..."
142info_msg "Output directory: ${OUTPUT}"
143
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000144if [ -f /proc/config.gz ]
145then
Naresh Kambojud7141702016-11-16 16:24:40 +0530146CONFIG_HUGETLBFS=$(zcat /proc/config.gz | grep "CONFIG_HUGETLBFS=")
147CONFIG_HUGETLB_PAGE=$(zcat /proc/config.gz | grep "CONFIG_HUGETLB_PAGE=")
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000148elif [ -f /boot/config-"$(uname -r)" ]
149then
150KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
151CONFIG_HUGETLBFS=$(grep "CONFIG_HUGETLBFS=" "${KERNEL_CONFIG_FILE}")
152CONFIG_HUGETLB_PAGE=$(grep "CONFIG_HUGETLB_PAGE=" "${KERNEL_CONFIG_FILE}")
153else
154exit_on_skip "libhugetlb-pre-requirements" "Kernel config file not available"
155fi
156
Naresh Kambojud7141702016-11-16 16:24:40 +0530157HUGETLBFS=$(grep hugetlbfs /proc/filesystems | awk '{print $2}')
158
159[ "${CONFIG_HUGETLBFS}" = "CONFIG_HUGETLBFS=y" ] && [ "${CONFIG_HUGETLB_PAGE}" = "CONFIG_HUGETLB_PAGE=y" ] && [ "${HUGETLBFS}" = "hugetlbfs" ]
160exit_on_skip "libhugetlb-pre-requirements" "Kernel config CONFIG_HUGETLBFS=y and CONFIG_HUGETLB_PAGE=y not enabled"
161
162# Install packages
163install
164
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530165# Setup libhugetlbfs mount point
166libhugetlbfs_setup
167
Anders Roxellc44e2c12024-06-19 20:44:49 +0200168if [ -n "${LIBHUGETLBFS_PATH}" ] && [ -d "${LIBHUGETLBFS_PATH}" ]
169then
170 overlay=yes
171else
172 LIBHUGETLBFS_PATH="$(find /usr/lib*/libhugetlbfs -type f -name run_tests.py)"
173fi
Naresh Kamboju272a8582017-06-20 12:46:15 +0530174
Anders Roxellc44e2c12024-06-19 20:44:49 +0200175
176if [ -n "${overlay}" ]
177then
178 echo "pre built libhugtlbfs found in overlays"
179 cd "${LIBHUGETLBFS_PATH}" || exit
180elif [ -n "${LIBHUGETLBFS_PATH}" ]
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530181then
Naresh Kamboju272a8582017-06-20 12:46:15 +0530182 echo "pre built libhugetlbfs found on rootfs"
183 # shellcheck disable=SC2164
184 cd /usr/lib*/libhugetlbfs
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530185else
186 # Build libhugetlbfs tests
187 libhugetlbfs_build_test
188fi
189
190# Run libhugetlbfs tests
191libhugetlbfs_run_test
192
193# Unmount libhugetlbfs mount point
194libhugetlbfs_cleanup