blob: 373a5ba6a078fb57001b5be8195ade1d2c7f3548 [file] [log] [blame]
mbligh9f857922008-06-05 16:19:07 +00001import re, os
mbligh53da18e2009-01-05 21:13:26 +00002from autotest_lib.client.bin import utils, test
3from autotest_lib.client.common_lib import error
mbligh62eaf662006-09-30 15:58:59 +00004
5class libhugetlbfs(test.test):
jadmanskie80d4712008-10-03 16:15:59 +00006 version = 6
mbligh62eaf662006-09-30 15:58:59 +00007
mbligha57e5ab2008-08-27 19:58:08 +00008 def initialize(self, dir = None, pages_requested = 20):
mbligh42519b82009-03-09 21:12:47 +00009 self.dir = None
10
mblighc5ddfd12008-08-04 17:15:00 +000011 self.job.require_gcc()
jadmanskie80d4712008-10-03 16:15:59 +000012
mbligh53da18e2009-01-05 21:13:26 +000013 utils.check_kernel_ver("2.6.16")
mblighf1e7c3f2008-02-14 16:19:12 +000014
jadmanski0afbb632008-06-06 21:10:57 +000015 # 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))
mbligh8b352852008-06-07 01:07:08 +000020 nr_hugepages = utils.read_one_line('/proc/sys/vm/nr_hugepages')
21 pages_available = int(nr_hugepages)
jadmanski0afbb632008-06-06 21:10:57 +000022 else:
23 raise error.TestNAError('Kernel does not support hugepages')
jadmanski153cc8b2008-05-20 19:57:47 +000024
jadmanski0afbb632008-06-06 21:10:57 +000025 if pages_available < pages_requested:
26 raise error.TestError('%d huge pages available, < %d pages requested' % (pages_available, pages_requested))
mblighf1e7c3f2008-02-14 16:19:12 +000027
jadmanski0afbb632008-06-06 21:10:57 +000028 # Check if hugetlbfs has been mounted
mbligh53da18e2009-01-05 21:13:26 +000029 if not utils.file_contains_pattern('/proc/mounts', 'hugetlbfs'):
jadmanski0afbb632008-06-06 21:10:57 +000030 if not dir:
31 dir = os.path.join(self.tmpdir, 'hugetlbfs')
32 os.makedirs(dir)
33 utils.system('mount -t hugetlbfs none %s' % dir)
mbligha57e5ab2008-08-27 19:58:08 +000034 self.dir = dir
mblighf1e7c3f2008-02-14 16:19:12 +000035
mbligha57e5ab2008-08-27 19:58:08 +000036
mbligh4b849522008-09-16 16:29:24 +000037 # http://libhugetlbfs.ozlabs.org/releases/libhugetlbfs-2.0.tar.gz
38 def setup(self, tarball = 'libhugetlbfs-2.0.tar.gz'):
mbligha57e5ab2008-08-27 19:58:08 +000039 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
mbligh53da18e2009-01-05 21:13:26 +000040 utils.extract_tarball_to_dir(tarball, self.srcdir)
jadmanski0afbb632008-06-06 21:10:57 +000041 os.chdir(self.srcdir)
mbligh62eaf662006-09-30 15:58:59 +000042
lmr4b45b7f2010-04-01 02:11:53 +000043 utils.system('patch -p1 < ../elflink.patch')
mbligha57e5ab2008-08-27 19:58:08 +000044 # 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:
Eric Li6f27d4f2010-09-29 10:55:17 -070047 utils.make()
mbligha57e5ab2008-08-27 19:58:08 +000048 except:
Eric Li6f27d4f2010-09-29 10:55:17 -070049 utils.make('OBJDIRS=obj64')
mbligha57e5ab2008-08-27 19:58:08 +000050
51
52 def run_once(self):
53 os.chdir(self.srcdir)
jadmanski0afbb632008-06-06 21:10:57 +000054 # 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:
Eric Li6f27d4f2010-09-29 10:55:17 -070057 utils.make('check')
jadmanski0afbb632008-06-06 21:10:57 +000058 except:
Eric Li6f27d4f2010-09-29 10:55:17 -070059 utils.make('check OBJDIRS=obj64')
mbligh62eaf662006-09-30 15:58:59 +000060
mbligha57e5ab2008-08-27 19:58:08 +000061
62 def cleanup(self):
mbligh42519b82009-03-09 21:12:47 +000063 if self.dir:
64 utils.system('umount %s' % self.dir)