blob: 746163d1e83b065e441d20c998fc732553a8e22b [file] [log] [blame]
mblighb8a14e32006-05-06 00:17:35 +00001import test, pickle
mblighf4c35322006-03-13 01:01:10 +00002from autotest_utils import *
mbligh0662b152007-06-20 13:03:19 +00003import re
4
apw7a0d5782006-04-21 14:21:17 +00005class kernbench(test.test):
mbligh96aee2a2006-05-03 16:28:26 +00006 version = 1
7
mblighb8a14e32006-05-06 00:17:35 +00008 def setup(self):
apw7d5477a2007-03-13 16:24:12 +00009 #
10 # If we have a local copy of the 2.6.14 tarball use that
11 # else let the kernel object use the defined mirrors
12 # to obtain it.
13 #
mbligh4f6243c2006-08-29 06:15:15 +000014 # http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.tar.bz2
apw7d5477a2007-03-13 16:24:12 +000015 #
mbligh14bb0aa2007-06-04 23:19:53 +000016 # On ia64, we default to 2.6.20, as it can't compile 2.6.14.
17
18 if get_current_kernel_arch() == 'ia64':
19 default_ver = '2.6.20'
20 else:
21 default_ver = '2.6.14'
apw7d5477a2007-03-13 16:24:12 +000022 tarball = None
23 for dir in (self.bindir, '/usr/local/src'):
mbligh14bb0aa2007-06-04 23:19:53 +000024 tar = 'linux-%s.tar.bz2' % default_ver
25 path = os.path.join(dir, tar)
apw7d5477a2007-03-13 16:24:12 +000026 if os.path.exists(path):
27 tarball = path
28 break
29 if not tarball:
mbligh14bb0aa2007-06-04 23:19:53 +000030 tarball = default_ver
apw7d5477a2007-03-13 16:24:12 +000031
mbligh931ee5e2006-12-07 19:34:10 +000032 kernel = self.job.kernel(tarball, self.tmpdir, self.srcdir)
apwc30cbd32006-12-05 12:16:24 +000033 kernel.config(defconfig=True)
mblighb8a14e32006-05-06 00:17:35 +000034 # have to save this off, as we might use it in another run
35 kernel.pickle_dump(self.srcdir + '/.pickle')
mblighf4c35322006-03-13 01:01:10 +000036
37
mbligh82641862006-04-23 06:21:36 +000038 def execute(self, iterations = 1, threads = 2 * count_cpus()):
mblighb8a14e32006-05-06 00:17:35 +000039 kernel = pickle.load(open(self.srcdir + '/.pickle', 'r'))
mbligh931ee5e2006-12-07 19:34:10 +000040 kernel.job = self.job
mbligh82641862006-04-23 06:21:36 +000041 print "kernbench x %d: %d threads" % (iterations, threads)
42
mblighb8a14e32006-05-06 00:17:35 +000043 kernel.build_timed(threads) # warmup run
mbligh9f5113d2007-06-25 23:41:10 +000044 profilers = self.job.profilers
45 if not profilers.only():
46 for i in range(iterations):
47 logfile = self.resultsdir+'/time.%d' % i
48 kernel.build_timed(threads, logfile)
mblighf4c35322006-03-13 01:01:10 +000049
mbligh72905562006-05-25 01:30:49 +000050 # Do a profiling run if necessary
mbligh72905562006-05-25 01:30:49 +000051 if profilers.present():
52 profilers.start(self)
53 logfile = self.resultsdir+'/time.profile'
54 kernel.build_timed(threads, logfile)
55 profilers.stop(self)
56 profilers.report(self)
57
mblighb8a14e32006-05-06 00:17:35 +000058 kernel.clean() # Don't leave litter lying around
59 os.chdir(self.resultsdir)
mbligh39aa03c2006-11-25 23:11:22 +000060 system("grep -h elapsed time.* > time")
mbligh0662b152007-06-20 13:03:19 +000061
62 self.__format_results(open('time').read())
63
64
65 def __format_results(self, results):
66 out = open('keyval', 'w')
mbligh32bcff32007-07-25 16:37:32 +000067 for result in extract_all_time_results(results):
mbligh0662b152007-06-20 13:03:19 +000068 print >> out, "user=%s\nsystem=%s\nelapsed=%s\n" % result
69 out.close()