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