blob: ad09407a9226b22fa1769ede7f24ee5ff0baff95 [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"
12
13WORD_SIZE="64"
14VERSION="2.20"
15
16usage() {
17 echo "Usage: $0 [-b <4|64>] [-s <true>] [-v <libhugetlbfs-version>]" 1>&2
18 exit 1
19}
20
21while getopts "b:s:v:" o; do
22 case "$o" in
23 b) WORD_SIZE="${OPTARG}" ;;
24 s) SKIP_INSTALL="${OPTARG}" ;;
25 v) VERSION="${OPTARG}" ;;
26 *) usage ;;
27 esac
28done
29
30parse_output() {
31 # Parse each type of results
32 egrep "*:.*PASS" "${RESULT_LOG}" | tee -a "${TEST_PASS_LOG}"
33 sed -i -e 's/ (inconclusive)//g' "${TEST_PASS_LOG}"
34 sed -i -e 's/(//g' "${TEST_PASS_LOG}"
35 sed -i -e 's/)://g' "${TEST_PASS_LOG}"
36 sed -i -e 's/://g' "${TEST_PASS_LOG}"
37 awk '{for (i=1; i<NF-1; i++) printf $i "-"; print $i " " $NF}' "${TEST_PASS_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
38
39 egrep "*:.*FAIL" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_FAIL_LOG}"
40 sed -i -e 's/ (inconclusive)//g' "${TEST_FAIL_LOG}"
41 sed -i -e 's/(//g' "${TEST_FAIL_LOG}"
42 sed -i -e 's/)//g' "${TEST_FAIL_LOG}"
43 sed -i -e 's/://g' "${TEST_FAIL_LOG}"
44 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "FAIL"}' "${TEST_FAIL_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
45
46 egrep "*:.*SKIP" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
47 egrep "*:.*Bad configuration" "${RESULT_LOG}" | cut -d: -f 1-2 2>&1 | tee -a "${TEST_SKIP_LOG}"
48 sed -i -e 's/ (inconclusive)//g' "${TEST_SKIP_LOG}"
49 sed -i -e 's/(//g' "${TEST_SKIP_LOG}"
50 sed -i -e 's/)//g' "${TEST_SKIP_LOG}"
51 sed -i -e 's/://g' "${TEST_SKIP_LOG}"
52 awk '{for (i=1; i<NF; i++) printf $i "-"; print $i " " "SKIP"}' "${TEST_SKIP_LOG}" 2>&1 | tee -a "${RESULT_FILE}"
53}
54
55libhugetlbfs_build_test() {
56 mount_point="/mnt/hugetlb/"
57 # Allocate hugepages
58 echo 200 > /proc/sys/vm/nr_hugepages
59 umount "${mount_point}" > /dev/null 2>&1 || true
60 mkdir -p "${mount_point}"
61 mount -t hugetlbfs hugetlbfs "${mount_point}"
62
63 # shellcheck disable=SC2140
64 # Upstream tree
65# wget https://github.com/libhugetlbfs/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
66 #TODO
67 # Private tree with CentOS build fix
68 # When patch is upstream remove private tree and enable upstream tree
69 wget https://github.com/nareshkamboju/libhugetlbfs/releases/download/"${VERSION}"/libhugetlbfs-"${VERSION}".tar.gz
70 tar -xvf libhugetlbfs-"${VERSION}".tar.gz
71 # shellcheck disable=SC2164
72 cd libhugetlbfs-"${VERSION}"
73 make BUILDTYPE=NATIVEONLY
74 # shellcheck disable=SC2164
75 cd tests
76 # Run tests
77 # Redirect stdout (not stderr)
78 ./run_tests.py -b "${WORD_SIZE}" | tee -a "${RESULT_LOG}"
79 parse_output
80 umount "${mount_point}" > /dev/null 2>&1 || true
81}
82
83install() {
84 dist_name
85 # shellcheck disable=SC2154
86 case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010087 debian|ubuntu)
Naresh Kambojud7141702016-11-16 16:24:40 +053088 pkgs="binutils gcc make python sed tar wget"
89 install_deps "${pkgs}" "${SKIP_INSTALL}"
90 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010091 fedora|centos)
Naresh Kambojud7141702016-11-16 16:24:40 +053092 pkgs="binutils gcc glibc-static make python sed tar wget"
93 install_deps "${pkgs}" "${SKIP_INSTALL}"
94 ;;
95 esac
96}
97
98# Test run.
99! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -0600100create_out_dir "${OUTPUT}"
Naresh Kambojud7141702016-11-16 16:24:40 +0530101# shellcheck disable=SC2164
102cd "${OUTPUT}"
103
104info_msg "About to run libhugetlbfs test..."
105info_msg "Output directory: ${OUTPUT}"
106
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000107if [ -f /proc/config.gz ]
108then
Naresh Kambojud7141702016-11-16 16:24:40 +0530109CONFIG_HUGETLBFS=$(zcat /proc/config.gz | grep "CONFIG_HUGETLBFS=")
110CONFIG_HUGETLB_PAGE=$(zcat /proc/config.gz | grep "CONFIG_HUGETLB_PAGE=")
Milosz Wasilewski236749e2016-12-05 14:49:30 +0000111elif [ -f /boot/config-"$(uname -r)" ]
112then
113KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
114CONFIG_HUGETLBFS=$(grep "CONFIG_HUGETLBFS=" "${KERNEL_CONFIG_FILE}")
115CONFIG_HUGETLB_PAGE=$(grep "CONFIG_HUGETLB_PAGE=" "${KERNEL_CONFIG_FILE}")
116else
117exit_on_skip "libhugetlb-pre-requirements" "Kernel config file not available"
118fi
119
Naresh Kambojud7141702016-11-16 16:24:40 +0530120HUGETLBFS=$(grep hugetlbfs /proc/filesystems | awk '{print $2}')
121
122[ "${CONFIG_HUGETLBFS}" = "CONFIG_HUGETLBFS=y" ] && [ "${CONFIG_HUGETLB_PAGE}" = "CONFIG_HUGETLB_PAGE=y" ] && [ "${HUGETLBFS}" = "hugetlbfs" ]
123exit_on_skip "libhugetlb-pre-requirements" "Kernel config CONFIG_HUGETLBFS=y and CONFIG_HUGETLB_PAGE=y not enabled"
124
125# Install packages
126install
127
128# Build libhugetlbfs and run tests
129libhugetlbfs_build_test