blob: e8f57f3f807b64815dde3a6c96b8aa927a02bfe5 [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"
9TEST_PASS_LOG="${OUTPUT}/test_pass_log.txt"
10TEST_FAIL_LOG="${OUTPUT}/test_fail_log.txt"
11TEST_SKIP_LOG="${OUTPUT}/test_skip_log.txt"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053012CWD=""
Naresh Kambojud7141702016-11-16 16:24:40 +053013
14WORD_SIZE="64"
15VERSION="2.20"
16
17usage() {
18 echo "Usage: $0 [-b <4|64>] [-s <true>] [-v <libhugetlbfs-version>]" 1>&2
19 exit 1
20}
21
22while getopts "b:s:v:" o; do
23 case "$o" in
24 b) WORD_SIZE="${OPTARG}" ;;
25 s) SKIP_INSTALL="${OPTARG}" ;;
26 v) VERSION="${OPTARG}" ;;
27 *) usage ;;
28 esac
29done
30
31parse_output() {
32 # Parse each type of results
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053033 egrep "PASS" "${RESULT_LOG}" | tee -a "${TEST_PASS_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053034 sed -i -e 's/ (inconclusive)//g' "${TEST_PASS_LOG}"
35 sed -i -e 's/(//g' "${TEST_PASS_LOG}"
36 sed -i -e 's/)://g' "${TEST_PASS_LOG}"
37 sed -i -e 's/://g' "${TEST_PASS_LOG}"
38 awk '{for (i=1; i<NF-1; i++) printf $i "-"; print $i " " $NF}' "${TEST_PASS_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
39
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053040 egrep "FAIL" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_FAIL_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053041 sed -i -e 's/ (inconclusive)//g' "${TEST_FAIL_LOG}"
42 sed -i -e 's/(//g' "${TEST_FAIL_LOG}"
43 sed -i -e 's/)//g' "${TEST_FAIL_LOG}"
44 sed -i -e 's/://g' "${TEST_FAIL_LOG}"
45 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "FAIL"}' "${TEST_FAIL_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
46
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053047 egrep "SKIP" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
48 egrep "Bad configuration" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053049 sed -i -e 's/ (inconclusive)//g' "${TEST_SKIP_LOG}"
50 sed -i -e 's/(//g' "${TEST_SKIP_LOG}"
51 sed -i -e 's/)//g' "${TEST_SKIP_LOG}"
52 sed -i -e 's/://g' "${TEST_SKIP_LOG}"
53 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "SKIP"}' "${TEST_SKIP_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053054 rm -rf "${RESULT_LOG}" "${TEST_PASS_LOG}" "${TEST_FAIL_LOG}" "${TEST_SKIP_LOG}"
Naresh Kambojud7141702016-11-16 16:24:40 +053055}
56
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053057libhugetlbfs_setup() {
Naresh Kambojud7141702016-11-16 16:24:40 +053058 mount_point="/mnt/hugetlb/"
59 # Allocate hugepages
60 echo 200 > /proc/sys/vm/nr_hugepages
61 umount "${mount_point}" > /dev/null 2>&1 || true
62 mkdir -p "${mount_point}"
63 mount -t hugetlbfs hugetlbfs "${mount_point}"
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053064}
Naresh Kambojud7141702016-11-16 16:24:40 +053065
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053066libhugetlbfs_cleanup() {
67 umount "${mount_point}" > /dev/null 2>&1 || true
68 if [ -n "${CWD}" ]; then
69 # shellcheck disable=SC2164
70 cd "${CWD}"
71 rm -rf libhugetlbfs-"${VERSION}" > /dev/null 2>&1 || true
72 rm -rf libhugetlbfs-"${VERSION}".tar.gz > /dev/null 2>&1 || true
73 fi
74}
75
76libhugetlbfs_build_test() {
Naresh Kambojud7141702016-11-16 16:24:40 +053077 # shellcheck disable=SC2140
78 # Upstream tree
79# wget https://github.com/libhugetlbfs/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
80 #TODO
81 # Private tree with CentOS build fix
82 # When patch is upstream remove private tree and enable upstream tree
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053083 wget http://github.com/nareshkamboju/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
84 CWD=$(pwd)
Naresh Kambojud7141702016-11-16 16:24:40 +053085 tar -xvf libhugetlbfs-"${VERSION}".tar.gz
86 # shellcheck disable=SC2164
87 cd libhugetlbfs-"${VERSION}"
88 make BUILDTYPE=NATIVEONLY
Naresh Kambojuc3bf0812017-02-15 16:42:43 +053089}
90
91libhugetlbfs_run_test() {
Naresh Kambojud7141702016-11-16 16:24:40 +053092 # shellcheck disable=SC2164
93 cd tests
94 # Run tests
95 # Redirect stdout (not stderr)
96 ./run_tests.py -b "${WORD_SIZE}" | tee -a "${RESULT_LOG}"
97 parse_output
Naresh Kambojud7141702016-11-16 16:24:40 +053098}
99
100install() {
101 dist_name
102 # shellcheck disable=SC2154
103 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100104 debian|ubuntu)
Naresh Kambojud7141702016-11-16 16:24:40 +0530105 pkgs="binutils gcc make python sed tar wget"
106 install_deps "${pkgs}" "${SKIP_INSTALL}"
107 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +0100108 fedora|centos)
Naresh Kambojud7141702016-11-16 16:24:40 +0530109 pkgs="binutils gcc glibc-static make python sed tar wget"
110 install_deps "${pkgs}" "${SKIP_INSTALL}"
111 ;;
112 esac
113}
114
115# Test run.
116! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600117create_out_dir "${OUTPUT}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530118# shellcheck disable=SC2164
119cd "${OUTPUT}"
120
121info_msg "About to run libhugetlbfs test..."
122info_msg "Output directory: ${OUTPUT}"
123
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000124if [ -f /proc/config.gz ]
125then
Naresh Kambojud7141702016-11-16 16:24:40 +0530126CONFIG_HUGETLBFS=$(zcat /proc/config.gz | grep "CONFIG_HUGETLBFS=")
127CONFIG_HUGETLB_PAGE=$(zcat /proc/config.gz | grep "CONFIG_HUGETLB_PAGE=")
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000128elif [ -f /boot/config-"$(uname -r)" ]
129then
130KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
131CONFIG_HUGETLBFS=$(grep "CONFIG_HUGETLBFS=" "${KERNEL_CONFIG_FILE}")
132CONFIG_HUGETLB_PAGE=$(grep "CONFIG_HUGETLB_PAGE=" "${KERNEL_CONFIG_FILE}")
133else
134exit_on_skip "libhugetlb-pre-requirements" "Kernel config file not available"
135fi
136
Naresh Kambojud7141702016-11-16 16:24:40 +0530137HUGETLBFS=$(grep hugetlbfs /proc/filesystems | awk '{print $2}')
138
139[ "${CONFIG_HUGETLBFS}" = "CONFIG_HUGETLBFS=y" ] && [ "${CONFIG_HUGETLB_PAGE}" = "CONFIG_HUGETLB_PAGE=y" ] && [ "${HUGETLBFS}" = "hugetlbfs" ]
140exit_on_skip "libhugetlb-pre-requirements" "Kernel config CONFIG_HUGETLBFS=y and CONFIG_HUGETLB_PAGE=y not enabled"
141
142# Install packages
143install
144
Naresh Kambojuc3bf0812017-02-15 16:42:43 +0530145# Setup libhugetlbfs mount point
146libhugetlbfs_setup
147
148if [ -d /usr/lib/libhugetlbfs-"${VERSION}" ]
149then
150 echo "pre built /usr/lib/libhugetlbfs-${VERSION} found on rootfs"
151 # shellcheck disable=SC2164
152 cd /usr/lib/libhugetlbfs-"${VERSION}"
153else
154 # Build libhugetlbfs tests
155 libhugetlbfs_build_test
156fi
157
158# Run libhugetlbfs tests
159libhugetlbfs_run_test
160
161# Unmount libhugetlbfs mount point
162libhugetlbfs_cleanup