1import os, shutil, re 2from autotest_lib.client.bin import test, utils 3from autotest_lib.client.common_lib import error 4 5 6class systemtap(test.test): 7 """ 8 This autotest module runs the systemtap test suite. 9 10 @author Anton Blanchard <anton@au.ibm.com> 11 """ 12 13 version = 1 14 def initialize(self, local=False): 15 self.job.require_gcc() 16 17 self.systemtap_dir = '' 18 if local == False: 19 self.systemtap_dir = os.path.join(self.autodir, 20 'deps/systemtap/systemtap') 21 22 def setup(self, local=False, tarball_systemtap='systemtap-0.9.5.tar.gz', tarball_elfutils='elfutils-0.140.tar.bz2'): 23 depdir = os.path.join(self.autodir, 'deps/systemtap') 24 tarball_systemtap = utils.unmap_url(depdir, tarball_systemtap, self.tmpdir) 25 tarball_elfutils = utils.unmap_url(depdir, tarball_elfutils, self.tmpdir) 26 srcdir = os.path.join(depdir, 'src') 27 utils.extract_tarball_to_dir(tarball_systemtap, srcdir) 28 elfdir = os.path.join(srcdir, 'elfutils') 29 utils.extract_tarball_to_dir(tarball_elfutils, elfdir) 30 31 self.job.setup_dep(['dejagnu']) 32 if local == False: 33 self.job.setup_dep(['systemtap']) 34 35 # Try grabbing the systemtap tarball out of the deps directory 36 depdir = os.path.join(self.autodir, 'deps/systemtap') 37 if os.path.exists(os.path.join(depdir, tarball_systemtap)): 38 tarball = utils.unmap_url(depdir, tarball_systemtap, self.tmpdir) 39 else: 40 tarball = utils.unmap_url(self.bindir, tarball_systemtap, self.tmpdir) 41 utils.extract_tarball_to_dir(tarball_systemtap, self.srcdir) 42 43 testsuite = os.path.join(self.srcdir, 'testsuite') 44 os.chdir(testsuite) 45 46 utils.configure() 47 utils.make() 48 49 # Run a simple systemtap script to make sure systemtap and the 50 # kernel debuginfo packages are correctly installed 51 script = "PATH=%s/bin:$PATH stap -c /bin/true -e 'probe syscall.read { exit() }'" % self.systemtap_dir 52 try: 53 utils.system(script) 54 except: 55 raise error.TestError('simple systemtap test failed, kernel debuginfo package may be missing: %s' % script) 56 57 58 def run_once(self): 59 testsuite = os.path.join(self.srcdir, 'testsuite') 60 os.chdir(testsuite) 61 62 dejagnu_dir = os.path.join(self.autodir, 'deps/dejagnu/dejagnu') 63 64 utils.system('PATH=%s/bin:%s/bin:$PATH make installcheck' % 65 (self.systemtap_dir, dejagnu_dir)) 66 67 # After we are done with this iteration, we move the log files to 68 # the results dir 69 sum = os.path.join(testsuite, 'systemtap.sum') 70 log = os.path.join(testsuite, 'systemtap.log') 71 72 if self.iteration: 73 logfile = 'systemtap.log.%d' % self.iteration 74 sumfile = 'systemtap.sum.%d' % self.iteration 75 else: 76 logfile = 'systemtap.log.profile' 77 sumfile = 'systemtap.sum.profile' 78 79 self.logfile = os.path.join(self.resultsdir, logfile) 80 self.sumfile = os.path.join(self.resultsdir, sumfile) 81 82 shutil.move(log, self.logfile) 83 shutil.move(sum, self.sumfile) 84 85 86 def postprocess_iteration(self): 87 os.chdir(self.resultsdir) 88 89 r = re.compile("# of (.*)\t(\d+)") 90 91 f = open(self.sumfile, 'r') 92 keyval = {} 93 for line in f: 94 result = r.match(line) 95 if result: 96 key = result.group(1) 97 key = key.strip().replace(' ', '_') 98 value = result.group(2) 99 keyval[key] = value 100 f.close() 101 102 self.write_perf_keyval(keyval) 103