1import re, os 2from autotest_lib.client.bin import utils, test 3from autotest_lib.client.common_lib import error 4 5class libhugetlbfs(test.test): 6 version = 6 7 8 def initialize(self, dir = None, pages_requested = 20): 9 self.dir = None 10 11 self.job.require_gcc() 12 13 utils.check_kernel_ver("2.6.16") 14 15 # Check huge page number 16 pages_available = 0 17 if os.path.exists('/proc/sys/vm/nr_hugepages'): 18 utils.write_one_line('/proc/sys/vm/nr_hugepages', 19 str(pages_requested)) 20 nr_hugepages = utils.read_one_line('/proc/sys/vm/nr_hugepages') 21 pages_available = int(nr_hugepages) 22 else: 23 raise error.TestNAError('Kernel does not support hugepages') 24 25 if pages_available < pages_requested: 26 raise error.TestError('%d huge pages available, < %d pages requested' % (pages_available, pages_requested)) 27 28 # Check if hugetlbfs has been mounted 29 if not utils.file_contains_pattern('/proc/mounts', 'hugetlbfs'): 30 if not dir: 31 dir = os.path.join(self.tmpdir, 'hugetlbfs') 32 os.makedirs(dir) 33 utils.system('mount -t hugetlbfs none %s' % dir) 34 self.dir = dir 35 36 37 # http://libhugetlbfs.ozlabs.org/releases/libhugetlbfs-2.0.tar.gz 38 def setup(self, tarball = 'libhugetlbfs-2.0.tar.gz'): 39 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) 40 utils.extract_tarball_to_dir(tarball, self.srcdir) 41 os.chdir(self.srcdir) 42 43 utils.system('patch -p1 < ../elflink.patch') 44 # make might fail if there are no proper headers for the 32 bit 45 # version, in that case try only for the 64 bit version 46 try: 47 utils.make() 48 except: 49 utils.make('OBJDIRS=obj64') 50 51 52 def run_once(self): 53 os.chdir(self.srcdir) 54 # make check might fail for 32 bit if the 32 bit compile earlier 55 # had failed. See if it passes for 64 bit in that case. 56 try: 57 utils.make('check') 58 except: 59 utils.make('check OBJDIRS=obj64') 60 61 62 def cleanup(self): 63 if self.dir: 64 utils.system('umount %s' % self.dir) 65