1#!/usr/bin/env python2 2# 3# Copyright 2014 Google Inc. All Rights Reserved 4"""Unit tests for the Crosperf Benchmark class.""" 5 6from __future__ import print_function 7 8import inspect 9from benchmark import Benchmark 10 11import unittest 12 13 14class BenchmarkTestCase(unittest.TestCase): 15 """Individual tests for the Benchmark class.""" 16 17 def test_benchmark(self): 18 # Test creating a benchmark with all the fields filled out. 19 b1 = Benchmark( 20 'b1_test', # name 21 'octane', # test_name 22 '', # test_args 23 3, # iterations 24 False, # rm_chroot_tmp 25 'record -e cycles', # perf_args 26 'telemetry_Crosperf', # suite 27 True) # show_all_results 28 self.assertTrue(b1.suite, 'telemetry_Crosperf') 29 30 # Test creating a benchmark field with default fields left out. 31 b2 = Benchmark( 32 'b2_test', # name 33 'octane', # test_name 34 '', # test_args 35 3, # iterations 36 False, # rm_chroot_tmp 37 'record -e cycles') # perf_args 38 self.assertEqual(b2.suite, '') 39 self.assertFalse(b2.show_all_results) 40 41 # Test explicitly creating 'suite=Telemetry' and 'show_all_results=False" 42 # and see what happens. 43 b3 = Benchmark( 44 'b3_test', # name 45 'octane', # test_name 46 '', # test_args 47 3, # iterations 48 False, # rm_chroot_tmp 49 'record -e cycles', # perf_args 50 'telemetry', # suite 51 False) # show_all_results 52 self.assertTrue(b3.show_all_results) 53 54 # Check to see if the args to Benchmark have changed since the last time 55 # this test was updated. 56 args_list = [ 57 'self', 'name', 'test_name', 'test_args', 'iterations', 'rm_chroot_tmp', 58 'perf_args', 'suite', 'show_all_results', 'retries', 'run_local' 59 ] 60 arg_spec = inspect.getargspec(Benchmark.__init__) 61 self.assertEqual(len(arg_spec.args), len(args_list)) 62 for arg in args_list: 63 self.assertIn(arg, arg_spec.args) 64 65 66if __name__ == '__main__': 67 unittest.main() 68