1 #!/usr/bin/env python2 2 # 3 # Copyright 2017 The Chromium OS Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 """Unittest for crosperf.""" 7 8 from __future__ import print_function 9 10 import unittest 11 12 import settings_factory 13 14 15 class BenchmarkSettingsTest(unittest.TestCase): 16 """Class to test benchmark settings.""" 17 18 def test_init(self): 19 res = settings_factory.BenchmarkSettings('b_settings') 20 self.assertIsNotNone(res) 21 self.assertEqual(len(res.fields), 6) 22 self.assertEqual(res.GetField('test_name'), '') 23 self.assertEqual(res.GetField('test_args'), '') 24 self.assertEqual(res.GetField('iterations'), 0) 25 self.assertEqual(res.GetField('suite'), '') 26 27 28 class LabelSettingsTest(unittest.TestCase): 29 """Class to test label settings.""" 30 31 def test_init(self): 32 res = settings_factory.LabelSettings('l_settings') 33 self.assertIsNotNone(res) 34 self.assertEqual(len(res.fields), 9) 35 self.assertEqual(res.GetField('chromeos_image'), '') 36 self.assertEqual(res.GetField('autotest_path'), '') 37 self.assertEqual(res.GetField('chromeos_root'), '') 38 self.assertEqual(res.GetField('remote'), None) 39 self.assertEqual(res.GetField('image_args'), '') 40 self.assertEqual(res.GetField('cache_dir'), '') 41 self.assertEqual(res.GetField('chrome_src'), '') 42 self.assertEqual(res.GetField('build'), '') 43 44 45 class GlobalSettingsTest(unittest.TestCase): 46 """Class to test global settings.""" 47 48 def test_init(self): 49 res = settings_factory.GlobalSettings('g_settings') 50 self.assertIsNotNone(res) 51 self.assertEqual(len(res.fields), 25) 52 self.assertEqual(res.GetField('name'), '') 53 self.assertEqual(res.GetField('board'), '') 54 self.assertEqual(res.GetField('remote'), None) 55 self.assertEqual(res.GetField('rerun_if_failed'), False) 56 self.assertEqual(res.GetField('rm_chroot_tmp'), False) 57 self.assertEqual(res.GetField('email'), None) 58 self.assertEqual(res.GetField('rerun'), False) 59 self.assertEqual(res.GetField('same_specs'), True) 60 self.assertEqual(res.GetField('same_machine'), False) 61 self.assertEqual(res.GetField('iterations'), 0) 62 self.assertEqual(res.GetField('chromeos_root'), '') 63 self.assertEqual(res.GetField('logging_level'), 'average') 64 self.assertEqual(res.GetField('acquire_timeout'), 0) 65 self.assertEqual(res.GetField('perf_args'), '') 66 self.assertEqual(res.GetField('cache_dir'), '') 67 self.assertEqual(res.GetField('cache_only'), False) 68 self.assertEqual(res.GetField('no_email'), False) 69 self.assertEqual(res.GetField('show_all_results'), False) 70 self.assertEqual(res.GetField('share_cache'), '') 71 self.assertEqual(res.GetField('results_dir'), '') 72 self.assertEqual(res.GetField('chrome_src'), '') 73 74 75 class SettingsFactoryTest(unittest.TestCase): 76 """Class to test SettingsFactory.""" 77 78 def test_get_settings(self): 79 self.assertRaises(Exception, settings_factory.SettingsFactory.GetSettings, 80 'global', 'bad_type') 81 82 l_settings = settings_factory.SettingsFactory().GetSettings( 83 'label', 'label') 84 self.assertIsInstance(l_settings, settings_factory.LabelSettings) 85 self.assertEqual(len(l_settings.fields), 9) 86 87 b_settings = settings_factory.SettingsFactory().GetSettings( 88 'benchmark', 'benchmark') 89 self.assertIsInstance(b_settings, settings_factory.BenchmarkSettings) 90 self.assertEqual(len(b_settings.fields), 6) 91 92 g_settings = settings_factory.SettingsFactory().GetSettings( 93 'global', 'global') 94 self.assertIsInstance(g_settings, settings_factory.GlobalSettings) 95 self.assertEqual(len(g_settings.fields), 25) 96 97 98 if __name__ == '__main__': 99 unittest.main() 100