Home | History | Annotate | Download | only in platform_AesThroughput
      1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging, os, re
      6 
      7 from autotest_lib.client.bin import test
      8 from autotest_lib.client.bin import utils as bin_utils
      9 from autotest_lib.client.common_lib import error, utils
     10 
     11 class platform_AesThroughput(test.test):
     12     version = 1
     13 
     14 
     15     def setup(self):
     16         self.results = {'bytes_per_sec_ideal_min' : 20 * 1024 * 1024}
     17 
     18 
     19     def run_once(self):
     20         num_cpus = bin_utils.count_cpus()
     21         logging.debug('Running using all cpus: %d' % num_cpus)
     22         results = self.openssl_speed('aes-256-cbc', '-multi %d' % num_cpus)
     23         parsed = self.parse_results(results)
     24         self.update_stats(parsed)
     25         self.export_stats()
     26 
     27 
     28     def openssl_speed(self, cipher, options=''):
     29         cmd = 'openssl speed %s -mr %s' % (cipher, options)
     30         return utils.system_output(cmd, retain_output=True)
     31 
     32 
     33     def parse_results(self, results, name=''):
     34         # Split the results into lines.
     35         # We really only want the final line for our purposes.
     36         type, times = results.split("\n")[-1].split(' ')
     37         # +F:num:aes-256 cbc -> aes_256_cbc
     38         type = re.sub('[- ]', '_', type.split(':')[-1])
     39         # cbc:time:time:time:... -> time, time, ...
     40         times = times.split(':')[1:]
     41 
     42         # Build the key names
     43         if len(name) > 0:
     44           name = name + '_'
     45         key_prefix = 'bytes_per_sec_' + name + type + '_blocksz_'
     46         keys = ['16_bytes', '64_bytes', '256_bytes', '1024_bytes', '8192_bytes']
     47         keys = [key_prefix+k for k in keys]
     48 
     49         if len(times) > len(keys):
     50             logging.debug(results)
     51             raise error.TestFail('openssl output format parsing failed')
     52         return dict(zip(keys, times))
     53 
     54 
     55     def update_stats(self, keyvals):
     56         self.results.update(keyvals)
     57 
     58 
     59     def export_stats(self):
     60         self.write_perf_keyval(self.results)
     61