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