1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{5,6,7} )
8 inherit multilib toolchain-funcs python-any-r1
10 DESCRIPTION="easy hugepage access"
11 HOMEPAGE="https://github.com/libhugetlbfs/libhugetlbfs"
12 SRC_URI="https://github.com/libhugetlbfs/libhugetlbfs/archive/${PV}.tar.gz -> ${P}.tar.gz"
16 KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~s390 ~x86"
17 IUSE="static-libs test"
18 RESTRICT="!test? ( test )"
20 DEPEND="test? ( ${PYTHON_DEPS} )"
23 "${FILESDIR}"/${PN}-2.6-fixup-testsuite.patch
29 -e '/^PREFIX/s:/local::' \
30 -e '1iBUILDTYPE = NATIVEONLY' \
32 -e '/gzip.*MANDIR/d' \
33 -e "/^LIB\(32\)/s:=.*:= $(get_libdir):" \
34 -e '/^CC\(32\|64\)/s:=.*:= $(CC):' \
35 -e 's@^\(ARCH\) ?=@\1 =@' \
36 Makefile || die "sed failed"
37 if [ "$(get_libdir)" == "lib64" ]; then
39 -e "/^LIB\(32\)/s:=.*:= lib32:" \
43 # Tarballs from github don't have the version set.
44 # https://github.com/libhugetlbfs/libhugetlbfs/issues/7
45 [[ -f version ]] || echo "${PV}" > version
50 emake CC="$(tc-getCC)" libs tools
55 use static-libs || rm -f "${ED}"/usr/$(get_libdir)/*.a
58 src_test_alloc_one() {
64 --pool-pages-max ${pagesize}:${sign}${pagecount} \
67 --pool-pages-min ${pagesize}:${sign}${pagecount}
71 # die is NOT allowed in this src_test block after the marked point, so that we
72 # can clean up memory allocation. You'll leak at LEAST 64MiB per run otherwise.
74 [[ $UID -eq 0 ]] || die "Need FEATURES=-userpriv to run this testsuite"
75 einfo "Building testsuite"
78 local hugeadm='obj/hugeadm'
81 # the testcases need 64MiB per pagesize.
82 local MIN_HUGEPAGE_RAM=$((64*1024*1024))
84 einfo "Planning allocation"
85 local PAGESIZES="$(${hugeadm} --page-sizes-all)"
87 # Need to do this before we can create the mountpoints.
88 local pagesize pagecount
89 for pagesize in ${PAGESIZES} ; do
90 # The kernel depends on the location :-(
91 mkdir -p /var/lib/hugetlbfs/pagesize-${pagesize}
92 addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
94 addwrite /proc/sys/vm/
95 addwrite /proc/sys/kernel/shmall
96 addwrite /proc/sys/kernel/shmmax
97 addwrite /proc/sys/kernel/shmmni
99 einfo "Checking HugeTLB mountpoints"
100 ${hugeadm} --create-mounts || die "Failed to set up hugetlb mountpoints."
102 # -----------------------------------------------------
103 # --------- die is unsafe after this point. -----------
104 # -----------------------------------------------------
106 einfo "Starting allocation"
107 for pagesize in ${PAGESIZES} ; do
108 pagecount=$((${MIN_HUGEPAGE_RAM}/${pagesize}))
109 einfo " ${pagecount} @ ${pagesize}"
110 addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
111 src_test_alloc_one "${hugeadm}" "+" "${pagesize}" "${pagecount}"
113 if [[ ${rc} -eq 0 ]]; then
114 allocated="${allocated} ${pagesize}:${pagecount}"
116 eerror "Failed to add ${pagecount} pages of size ${pagesize}"
120 einfo "Allocation status"
121 ${hugeadm} --pool-list
123 if [[ -n "${allocated}" ]]; then
124 # All our allocations worked, so time to run.
125 einfo "Starting tests"
126 cd "${S}"/tests || die
127 local TESTOPTS="-t func"
130 TESTOPTS="${TESTOPTS} -b 64"
133 TESTOPTS="${TESTOPTS} -b 32"
136 # This needs a bit of work to give a nice exit code still.
137 ./run_tests.py ${TESTOPTS}
140 eerror "Failed to make HugeTLB allocations."
144 einfo "Cleaning up memory"
146 # Cleanup memory allocation
147 for alloc in ${allocated} ; do
148 pagesize="${alloc/:*}"
149 pagecount="${alloc/*:}"
150 einfo " ${pagecount} @ ${pagesize}"
151 src_test_alloc_one "$hugeadm" "-" "${pagesize}" "${pagecount}"
154 # ---------------------------------------------------------
155 # --------- die is safe again after this point. -----------
156 # ---------------------------------------------------------