summaryrefslogtreecommitdiff
path: root/client/tests/dacapo/dacapo.py
blob: 38bb71182134bfaeafe89a9082948e05e9807617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Dacapo test suite wrapper
#
# This benchmark suite is intended as a tool for Java benchmarking by the 
# programming language, memory management and computer architecture communities.
# It consists of a set of open source, real world applications with non-trivial 
# memory loads. The suite is the culmination of over five years work at eight 
# institutions, as part of the DaCapo research project, which was funded by a 
# National Science Foundation ITR Grant, CCR-0085792.
#
import os
from autotest_lib.client.bin import autotest_utils, package, test
from autotest_lib.client.bin.test_config import config_loader
from autotest_lib.client.common_lib import utils


class dacapo(test.test):
	version = 1

	def set_java_environment(self, jvm, java_root):
		'''\
		Setup java environment variables (path and classpath in order to
		execute a specific jvm specified by the java_root variable. 
		java_root - Base of the java vm installation
		'''
		# Sun has changed the directory layout for java 6
		# (now there's no jre directory). Let's work around this...
		if jvm == 'sun16':
			self.java_home = java_root
		else:
			self.java_home = os.path.join(java_root, 'jre')
		self.java_bin = os.path.join(self.java_home, 'bin')
		self.java_lib =  os.path.join(self.java_home, 'lib')
		os.environ['JAVA_ROOT'] = java_root
		os.environ['JAVA_HOME'] = self.java_home
		os.environ['JRE_HOME'] = self.java_home
		os.environ['CLASSPATH'] = self.java_lib
		os.environ['JAVA_BINDIR'] = self.java_bin
		os.environ['PATH'] = self.java_bin + ':' + os.environ['PATH']


	def execute(self, test = 'antlr', config = './dacapo.cfg', jvm = 'ibm14-ppc64'):
		# Load the test configuration. If needed, use autotest tmpdir to write
		# files.
		my_config = config_loader(config, self.tmpdir)
		# Directory where we will cache the dacapo jar file
		# and the jvm package files
		self.cachedir = os.path.join(self.bindir, 'cache')
		if not os.path.isdir(self.cachedir):
			os.makedirs(self.cachedir)

		# Get dacapo jar URL
		# (It's possible to override the default URL that points to the 
		# sourceforge repository)
		if my_config.get('dacapo', 'override_default_url') == 'no':
			self.dacapo_url = my_config.get('dacapo', 'tarball_url')
		else:
			self.dacapo_url = my_config.get('dacapo', 'tarball_url_alt')
		if not self.dacapo_url:
			raise error.TestError('Could not read dacapo URL from conf file')
		# We can cache the dacapo package file if we take some
		# precautions (checking md5 sum of the downloaded file)
		self.dacapo_md5 = my_config.get('dacapo', 'package_md5')
		if not self.dacapo_md5:
			e_msg = 'Could not read dacapo package md5sum from conf file'
			raise error.TestError(e_msg)
		self.dacapo_pkg = \
		autotest_utils.unmap_url_cache(self.cachedir, self.dacapo_url,
		                               self.dacapo_md5)

		# Get jvm package URL
		self.jvm_pkg_url = my_config.get(jvm, 'jvm_pkg_url')
		if not self.jvm_pkg_url:
			raise error.TestError('Could not read java vm URL from conf file')
		# Let's cache the jvm package as well
		self.jvm_pkg_md5 = my_config.get(jvm, 'package_md5')
		if not self.jvm_pkg_md5:
			raise error.TestError('Could not read java package_md5 from conf file')
		self.jvm_pkg = \
		autotest_utils.unmap_url_cache(self.cachedir, self.jvm_pkg_url,
		                               self.jvm_pkg_md5)

		# Install the jvm pakage
		package.install(self.jvm_pkg)

		# Basic Java environment variables setup
		self.java_root = my_config.get(jvm, 'java_root')
		if not self.java_root:
			raise error.TestError('Could not read java root dir from conf file')
		self.set_java_environment(jvm, self.java_root)

		# If use_global is set to 'yes', then we want to use the global
		# setting instead of per test settings
		if my_config.get('global', 'use_global') == 'yes':
			self.iterations = my_config.get('global', 'iterations')
			self.workload = my_config.get('global', 'workload')
		else:
			self.iterations = my_config.get(test, 'iterations')
			self.workload = my_config.get(test, 'workload')

		self.verbose = '-v '
		self.workload = '-s %s ' % self.workload
		self.iterations = '-n %s ' % self.iterations
		self.scratch = '-scratch %s ' % os.path.join(self.resultsdir, test)
		# Compose the arguments string
		self.args = self.verbose + self.workload + self.scratch \
		+ self.iterations + test
		# Execute the actual test
		try:
			utils.system('java -jar %s %s' % (self.dacapo_pkg, self.args))
		except:
			e_msg = \
			'Test %s has failed, command line options "%s"' % (test, self.args)
			raise error.TestError(e_msg)