blob: 73ad3e2d4017ad6f2915c3dcc4f407bac28af88a [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=""
Naresh Kambojud7141702016-11-16 16:24:40 +053014
15WORD_SIZE="64"
16VERSION="2.20"
17
18usage() {
19 echo "Usage: $0 [-b <4|64>] [-s <true>] [-v <libhugetlbfs-version>]" 1>&2
20 exit 1
21}
22
23while getopts "b:s:v:" o; do
24 case "$o" in
25 b) WORD_SIZE="${OPTARG}" ;;
26 s) SKIP_INSTALL="${OPTARG}" ;;
27 v) VERSION="${OPTARG}" ;;
28 *) usage ;;
29 esac
30done
31
32parse_output() {
Naresh Kamboju62d34f02017-05-15 18:12:20 +053033 # Avoid results summary lines start with "*"
34 sed -i -e 's/\//-/g' "${TMP_LOG}"
35 # shellcheck disable=SC2063
36 grep -v "*" "${TMP_LOG}" | tee -a "${RESULT_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053037 # Parse each type of results
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053038 egrep "PASS" "${RESULT_LOG}" | tee -a "${TEST_PASS_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053039 sed -i -e 's/ (inconclusive)//g' "${TEST_PASS_LOG}"
40 sed -i -e 's/(//g' "${TEST_PASS_LOG}"
41 sed -i -e 's/)://g' "${TEST_PASS_LOG}"
42 sed -i -e 's/://g' "${TEST_PASS_LOG}"
43 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 +053044 sed -i -e 's/PASS/pass/g' "${RESULT_FILE}"
Naresh Kambojud7141702016-11-16 16:24:40 +053045
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053046 egrep "FAIL" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_FAIL_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053047 sed -i -e 's/ (inconclusive)//g' "${TEST_FAIL_LOG}"
48 sed -i -e 's/(//g' "${TEST_FAIL_LOG}"
49 sed -i -e 's/)//g' "${TEST_FAIL_LOG}"
50 sed -i -e 's/://g' "${TEST_FAIL_LOG}"
Naresh Kamboju62d34f02017-05-15 18:12:20 +053051 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 +053052
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053053 egrep "SKIP" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
54 egrep "Bad configuration" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053055 sed -i -e 's/ (inconclusive)//g' "${TEST_SKIP_LOG}"
56 sed -i -e 's/(//g' "${TEST_SKIP_LOG}"
57 sed -i -e 's/)//g' "${TEST_SKIP_LOG}"
58 sed -i -e 's/://g' "${TEST_SKIP_LOG}"
Naresh Kamboju62d34f02017-05-15 18:12:20 +053059 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 +053060
61 # Replace "=" with "_" in test case names
62 sed -i -e 's/=/_/g' "${RESULT_FILE}"
63 # Clean up
Naresh Kamboju62d34f02017-05-15 18:12:20 +053064 rm -rf "${TMP_LOG}" "${RESULT_LOG}" "${TEST_PASS_LOG}" "${TEST_FAIL_LOG}" "${TEST_SKIP_LOG}"
65
Naresh Kambojud7141702016-11-16 16:24:40 +053066}
67
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053068libhugetlbfs_setup() {
Naresh Kambojud7141702016-11-16 16:24:40 +053069 mount_point="/mnt/hugetlb/"
70 # Allocate hugepages
71 echo 200 > /proc/sys/vm/nr_hugepages
72 umount "${mount_point}" > /dev/null 2>&1 || true
73 mkdir -p "${mount_point}"
74 mount -t hugetlbfs hugetlbfs "${mount_point}"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053075}
Naresh Kambojud7141702016-11-16 16:24:40 +053076
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053077libhugetlbfs_cleanup() {
78 umount "${mount_point}" > /dev/null 2>&1 || true
79 if [ -n "${CWD}" ]; then
80 # shellcheck disable=SC2164
81 cd "${CWD}"
82 rm -rf libhugetlbfs-"${VERSION}" > /dev/null 2>&1 || true
83 rm -rf libhugetlbfs-"${VERSION}".tar.gz > /dev/null 2>&1 || true
84 fi
85}
86
87libhugetlbfs_build_test() {
Naresh Kambojud7141702016-11-16 16:24:40 +053088 # shellcheck disable=SC2140
89 # Upstream tree
90# wget https://github.com/libhugetlbfs/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
91 #TODO
92 # Private tree with CentOS build fix
93 # When patch is upstream remove private tree and enable upstream tree
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053094 wget http://github.com/nareshkamboju/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
95 CWD=$(pwd)
Naresh Kambojud7141702016-11-16 16:24:40 +053096 tar -xvf libhugetlbfs-"${VERSION}".tar.gz
97 # shellcheck disable=SC2164
98 cd libhugetlbfs-"${VERSION}"
99 make BUILDTYPE=NATIVEONLY
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530100}
101
102libhugetlbfs_run_test() {
Naresh Kambojud7141702016-11-16 16:24:40 +0530103 # shellcheck disable=SC2164
104 cd tests
105 # Run tests
106 # Redirect stdout (not stderr)
Naresh Kamboju62d34f02017-05-15 18:12:20 +0530107 ./run_tests.py -b "${WORD_SIZE}" | tee -a "${TMP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530108 parse_output
Naresh Kambojud7141702016-11-16 16:24:40 +0530109}
110
111install() {
112 dist_name
113 # shellcheck disable=SC2154
114 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100115 debian|ubuntu)
Naresh Kambojud7141702016-11-16 16:24:40 +0530116 pkgs="binutils gcc make python sed tar wget"
117 install_deps "${pkgs}" "${SKIP_INSTALL}"
118 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100119 fedora|centos)
Naresh Kambojud7141702016-11-16 16:24:40 +0530120 pkgs="binutils gcc glibc-static make python sed tar wget"
121 install_deps "${pkgs}" "${SKIP_INSTALL}"
122 ;;
123 esac
124}
125
126# Test run.
127! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600128create_out_dir "${OUTPUT}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530129# shellcheck disable=SC2164
130cd "${OUTPUT}"
131
132info_msg "About to run libhugetlbfs test..."
133info_msg "Output directory: ${OUTPUT}"
134
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000135if [ -f /proc/config.gz ]
136then
Naresh Kambojud7141702016-11-16 16:24:40 +0530137CONFIG_HUGETLBFS=$(zcat /proc/config.gz | grep "CONFIG_HUGETLBFS=")
138CONFIG_HUGETLB_PAGE=$(zcat /proc/config.gz | grep "CONFIG_HUGETLB_PAGE=")
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000139elif [ -f /boot/config-"$(uname -r)" ]
140then
141KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
142CONFIG_HUGETLBFS=$(grep "CONFIG_HUGETLBFS=" "${KERNEL_CONFIG_FILE}")
143CONFIG_HUGETLB_PAGE=$(grep "CONFIG_HUGETLB_PAGE=" "${KERNEL_CONFIG_FILE}")
144else
145exit_on_skip "libhugetlb-pre-requirements" "Kernel config file not available"
146fi
147
Naresh Kambojud7141702016-11-16 16:24:40 +0530148HUGETLBFS=$(grep hugetlbfs /proc/filesystems | awk '{print $2}')
149
150[ "${CONFIG_HUGETLBFS}" = "CONFIG_HUGETLBFS=y" ] && [ "${CONFIG_HUGETLB_PAGE}" = "CONFIG_HUGETLB_PAGE=y" ] && [ "${HUGETLBFS}" = "hugetlbfs" ]
151exit_on_skip "libhugetlb-pre-requirements" "Kernel config CONFIG_HUGETLBFS=y and CONFIG_HUGETLB_PAGE=y not enabled"
152
153# Install packages
154install
155
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530156# Setup libhugetlbfs mount point
157libhugetlbfs_setup
158
Naresh Kamboju272a8582017-06-20 12:46:15 +0530159PRE_BUILD_PATH="$(find /usr/lib*/libhugetlbfs -type f -name run_tests.py)"
160
161if [ -n "${PRE_BUILD_PATH}" ]
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530162then
Naresh Kamboju272a8582017-06-20 12:46:15 +0530163 echo "pre built libhugetlbfs found on rootfs"
164 # shellcheck disable=SC2164
165 cd /usr/lib*/libhugetlbfs
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530166else
167 # Build libhugetlbfs tests
168 libhugetlbfs_build_test
169fi
170
171# Run libhugetlbfs tests
172libhugetlbfs_run_test
173
174# Unmount libhugetlbfs mount point
175libhugetlbfs_cleanup