Home | History | Annotate | Download | only in dacapo
      1 import os, re, logging, shutil
      2 from autotest_lib.client.bin import utils, package, test
      3 from autotest_lib.client.bin.test_config import config_loader
      4 from autotest_lib.client.common_lib import error
      5 
      6 
      7 class dacapo(test.test):
      8     """
      9     This autotest module runs the dacapo benchmark suite.
     10 
     11     This benchmark suite is intended as a tool for Java benchmarking by the
     12     programming language, memory management and computer architecture
     13     communities. It consists of a set of open source, real world applications
     14     with non-trivial memory loads. The suite is the culmination of over five
     15     years work at eight institutions, as part of the DaCapo research project,
     16     which was funded by a National Science Foundation ITR Grant, CCR-0085792.
     17 
     18     @author: Lucas Meneghel Rodrigues (lucasmr (at] br.ibm.com)
     19     @see: http://dacapobench.org/
     20     """
     21     version = 2
     22 
     23     def set_java_environment(self, jvm, java_root):
     24         """
     25         Setup java environment variables (path and classpath in order to
     26         execute a specific jvm specified by the java_root variable.
     27         java_root - Base of the java vm installation
     28         """
     29         if jvm.startswith('ibm'):
     30             java_home = os.path.join(java_root, 'jre')
     31         else:
     32             java_home = java_root
     33         java_bin = os.path.join(java_home, 'bin')
     34         java_lib =  os.path.join(java_home, 'lib')
     35         os.environ['JAVA_ROOT'] = java_root
     36         os.environ['JAVA_HOME'] = java_home
     37         os.environ['JRE_HOME'] = java_home
     38         os.environ['CLASSPATH'] = java_lib
     39         os.environ['JAVA_BINDIR'] = java_bin
     40         os.environ['PATH'] = java_bin + ':' + os.environ['PATH']
     41 
     42 
     43     def run_once(self, test='antlr', config='./dacapo.cfg', jvm='default'):
     44         cfg = config_loader(cfg=config, tmpdir=self.tmpdir, raise_errors=True)
     45         self.test = test
     46         cachedir = os.path.join(self.bindir, 'cache')
     47         if not os.path.isdir(cachedir):
     48             os.makedirs(cachedir)
     49 
     50         dacapo_url = cfg.get('dacapo', 'tarball_url')
     51         dacapo_md5 = cfg.get('dacapo', 'package_md5')
     52         dacapo_pkg = utils.unmap_url_cache(cachedir, dacapo_url, dacapo_md5)
     53 
     54         if not jvm == 'default':
     55             # Get the jvm package
     56             jvm_pkg_url = cfg.get(jvm, 'jvm_pkg_url')
     57             jvm_pkg_md5 = cfg.get(jvm, 'package_md5')
     58             jvm_pkg = utils.unmap_url_cache(cachedir, jvm_pkg_url, jvm_pkg_md5)
     59             # Install it
     60             package.install(jvm_pkg)
     61             # Basic Java environment variables setup
     62             java_root = cfg.get(jvm, 'java_root')
     63             self.set_java_environment(jvm, java_root)
     64 
     65         if cfg.get('global', 'use_global') == 'yes':
     66             iterations = cfg.get('global', 'iterations')
     67             workload = cfg.get('global', 'workload')
     68         else:
     69             iterations = cfg.get(test, 'iterations')
     70             workload = cfg.get(test, 'workload')
     71 
     72         verbose = '-v '
     73         workload = '-s %s ' % workload
     74         iterations = '-n %s ' % iterations
     75         self.scratch = os.path.join(self.resultsdir, test)
     76         scratch = '--scratch-directory %s ' % self.scratch
     77         args = verbose + workload + scratch + iterations + test
     78 
     79         self.raw_result_file = os.path.join(self.resultsdir,
     80                                             'raw_output_%s' % self.iteration)
     81         raw_result = open(self.raw_result_file, 'w')
     82 
     83         logging.info('Running dacapo benchmark %s', test)
     84         try:
     85             cmd = 'java -jar %s %s' % (dacapo_pkg, args)
     86             results = utils.run(command=cmd, stdout_tee=raw_result,
     87                                 stderr_tee=raw_result)
     88             self.results = results.stderr
     89             raw_result.close()
     90         except error.CmdError, e:
     91             raise error.TestError('Dacapo benchmark %s has failed: %s' %
     92                                   (test, e))
     93 
     94 
     95     def postprocess_iteration(self):
     96         result_line = self.results.splitlines()[-1]
     97         time_regexp = re.compile('PASSED in (\d+) ms')
     98         matches = time_regexp.findall(result_line)
     99         if len(matches) == 1:
    100             keylist = {}
    101             logging.info('Benchmark %s completed in %s ms', self.test,
    102                          matches[0])
    103             keylist[self.test] = int(matches[0])
    104             self.write_perf_keyval(keylist)
    105             # Remove scratch directory
    106             shutil.rmtree(self.scratch)
    107         else:
    108             logging.error('Problems executing benchmark %s, not recording '
    109                           'results on the perf keyval', self.test)
    110