libhugetlbfs-2.19.ebuild 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="4"
  4. inherit eutils multilib toolchain-funcs
  5. DESCRIPTION="easy hugepage access"
  6. HOMEPAGE="https://github.com/libhugetlbfs/libhugetlbfs"
  7. SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"
  8. # Switch to github tarball w/next release.
  9. #SRC_URI="https://github.com/libhugetlbfs/libhugetlbfs/archive/${PV}.tar.gz -> ${P}.tar.gz"
  10. LICENSE="GPL-2"
  11. SLOT="0"
  12. KEYWORDS="~amd64 ~ppc64 ~x86"
  13. IUSE="static-libs"
  14. src_prepare() {
  15. epatch "${FILESDIR}"/${PN}-2.9-build.patch #332517
  16. epatch "${FILESDIR}"/${PN}-2.6-noexec-stack.patch
  17. epatch "${FILESDIR}"/${PN}-2.6-fixup-testsuite.patch
  18. sed -i \
  19. -e '/^PREFIX/s:/local::' \
  20. -e '1iBUILDTYPE = NATIVEONLY' \
  21. -e '1iV = 1' \
  22. -e "/^LIB\(32\)/s:=.*:= $(get_libdir):" \
  23. -e '/^CC\(32\|64\)/s:=.*:= $(CC):' \
  24. Makefile
  25. if [ "$(get_libdir)" == "lib64" ]; then
  26. sed -i \
  27. -e "/^LIB\(32\)/s:=.*:= lib32:" \
  28. Makefile
  29. fi
  30. }
  31. src_compile() {
  32. tc-export AR
  33. emake CC="$(tc-getCC)" libs tools
  34. }
  35. src_install() {
  36. default
  37. use static-libs || rm -f "${D}"/usr/$(get_libdir)/*.a
  38. rm "${D}"/usr/bin/oprofile* || die
  39. }
  40. src_test_alloc_one() {
  41. hugeadm="$1"
  42. sign="$2"
  43. pagesize="$3"
  44. pagecount="$4"
  45. ${hugeadm} \
  46. --pool-pages-max ${pagesize}:${sign}${pagecount} \
  47. && \
  48. ${hugeadm} \
  49. --pool-pages-min ${pagesize}:${sign}${pagecount}
  50. return $?
  51. }
  52. # die is NOT allowed in this src_test block after the marked point, so that we
  53. # can clean up memory allocation. You'll leak at LEAST 64MiB per run otherwise.
  54. src_test() {
  55. [[ $UID -eq 0 ]] || die "Need FEATURES=-userpriv to run this testsuite"
  56. einfo "Building testsuite"
  57. emake -j1 tests || die "Failed to build tests"
  58. hugeadm='obj/hugeadm'
  59. allocated=''
  60. rc=0
  61. # the testcases need 64MiB per pagesize.
  62. MIN_HUGEPAGE_RAM=$((64*1024*1024))
  63. einfo "Planning allocation"
  64. PAGESIZES="$(${hugeadm} --page-sizes-all)"
  65. # Need to do this before we can create the mountpoints.
  66. for pagesize in ${PAGESIZES} ; do
  67. # The kernel depends on the location :-(
  68. mkdir -p /var/lib/hugetlbfs/pagesize-${pagesize}
  69. addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
  70. done
  71. addwrite /proc/sys/vm/
  72. addwrite /proc/sys/kernel/shmall
  73. addwrite /proc/sys/kernel/shmmax
  74. addwrite /proc/sys/kernel/shmmni
  75. einfo "Checking HugeTLB mountpoints"
  76. ${hugeadm} --create-mounts || die "Failed to set up hugetlb mountpoints."
  77. # -----------------------------------------------------
  78. # --------- die is unsafe after this point. -----------
  79. # -----------------------------------------------------
  80. einfo "Starting allocation"
  81. for pagesize in ${PAGESIZES} ; do
  82. pagecount=$((${MIN_HUGEPAGE_RAM}/${pagesize}))
  83. einfo " ${pagecount} @ ${pagesize}"
  84. addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
  85. src_test_alloc_one "$hugeadm" "+" "${pagesize}" "${pagecount}"
  86. rc=$?
  87. if [[ $rc -eq 0 ]]; then
  88. allocated="${allocated} ${pagesize}:${pagecount}"
  89. else
  90. eerror "Failed to add ${pagecount} pages of size ${pagesize}"
  91. fi
  92. done
  93. einfo "Allocation status"
  94. ${hugeadm} --pool-list
  95. if [[ -n "${allocated}" ]]; then
  96. # All our allocations worked, so time to run.
  97. einfo "Starting tests"
  98. cd "${S}"/tests
  99. TESTOPTS="-t func"
  100. case $ARCH in
  101. amd64|ppc64)
  102. TESTOPTS="${TESTOPTS} -b 64"
  103. ;;
  104. x86)
  105. TESTOPTS="${TESTOPTS} -b 32"
  106. ;;
  107. esac
  108. # This needs a bit of work to give a nice exit code still.
  109. ./run_tests.py ${TESTOPTS}
  110. rc=$?
  111. else
  112. eerror "Failed to make HugeTLB allocations."
  113. rc=1
  114. fi
  115. einfo "Cleaning up memory"
  116. cd "${S}"
  117. # Cleanup memory allocation
  118. for alloc in ${allocated} ; do
  119. pagesize="${alloc/:*}"
  120. pagecount="${alloc/*:}"
  121. einfo " ${pagecount} @ ${pagesize}"
  122. src_test_alloc_one "$hugeadm" "-" "${pagesize}" "${pagecount}"
  123. done
  124. # ---------------------------------------------------------
  125. # --------- die is safe again after this point. -----------
  126. # ---------------------------------------------------------
  127. return $rc
  128. }