Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # shellcheck disable=SC1091 |
| 4 | . ../../lib/sh-test-lib |
| 5 | |
| 6 | OUTPUT="$(pwd)/output" |
| 7 | RESULT_FILE="${OUTPUT}/result.txt" |
| 8 | RESULT_LOG="${OUTPUT}/result_log.txt" |
| 9 | TEST_PASS_LOG="${OUTPUT}/test_pass_log.txt" |
| 10 | TEST_FAIL_LOG="${OUTPUT}/test_fail_log.txt" |
| 11 | TEST_SKIP_LOG="${OUTPUT}/test_skip_log.txt" |
| 12 | |
| 13 | WORD_SIZE="64" |
| 14 | VERSION="2.20" |
| 15 | |
| 16 | usage() { |
| 17 | echo "Usage: $0 [-b <4|64>] [-s <true>] [-v <libhugetlbfs-version>]" 1>&2 |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | while 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 |
| 28 | done |
| 29 | |
| 30 | parse_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 | |
| 55 | libhugetlbfs_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 | |
| 83 | install() { |
| 84 | dist_name |
| 85 | # shellcheck disable=SC2154 |
| 86 | case "${dist}" in |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame] | 87 | debian|ubuntu) |
Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 88 | pkgs="binutils gcc make python sed tar wget" |
| 89 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
| 90 | ;; |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame] | 91 | fedora|centos) |
Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 92 | 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íaz | 6f49a1b | 2017-02-15 18:56:15 -0600 | [diff] [blame] | 100 | create_out_dir "${OUTPUT}" |
Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 101 | # shellcheck disable=SC2164 |
| 102 | cd "${OUTPUT}" |
| 103 | |
| 104 | info_msg "About to run libhugetlbfs test..." |
| 105 | info_msg "Output directory: ${OUTPUT}" |
| 106 | |
Milosz Wasilewski | 236749e | 2016-12-05 14:49:30 +0000 | [diff] [blame] | 107 | if [ -f /proc/config.gz ] |
| 108 | then |
Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 109 | CONFIG_HUGETLBFS=$(zcat /proc/config.gz | grep "CONFIG_HUGETLBFS=") |
| 110 | CONFIG_HUGETLB_PAGE=$(zcat /proc/config.gz | grep "CONFIG_HUGETLB_PAGE=") |
Milosz Wasilewski | 236749e | 2016-12-05 14:49:30 +0000 | [diff] [blame] | 111 | elif [ -f /boot/config-"$(uname -r)" ] |
| 112 | then |
| 113 | KERNEL_CONFIG_FILE="/boot/config-$(uname -r)" |
| 114 | CONFIG_HUGETLBFS=$(grep "CONFIG_HUGETLBFS=" "${KERNEL_CONFIG_FILE}") |
| 115 | CONFIG_HUGETLB_PAGE=$(grep "CONFIG_HUGETLB_PAGE=" "${KERNEL_CONFIG_FILE}") |
| 116 | else |
| 117 | exit_on_skip "libhugetlb-pre-requirements" "Kernel config file not available" |
| 118 | fi |
| 119 | |
Naresh Kamboju | d714170 | 2016-11-16 16:24:40 +0530 | [diff] [blame] | 120 | HUGETLBFS=$(grep hugetlbfs /proc/filesystems | awk '{print $2}') |
| 121 | |
| 122 | [ "${CONFIG_HUGETLBFS}" = "CONFIG_HUGETLBFS=y" ] && [ "${CONFIG_HUGETLB_PAGE}" = "CONFIG_HUGETLB_PAGE=y" ] && [ "${HUGETLBFS}" = "hugetlbfs" ] |
| 123 | exit_on_skip "libhugetlb-pre-requirements" "Kernel config CONFIG_HUGETLBFS=y and CONFIG_HUGETLB_PAGE=y not enabled" |
| 124 | |
| 125 | # Install packages |
| 126 | install |
| 127 | |
| 128 | # Build libhugetlbfs and run tests |
| 129 | libhugetlbfs_build_test |