| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright 2009 Google Inc. Released under the GPL v2 |
| 3 | |
| 4 | import unittest |
| 5 | |
| 6 | import common |
| 7 | from autotest_lib.mirror import trigger |
| 8 | from autotest_lib.client.common_lib.test_utils import mock |
| 9 | |
| 10 | |
| 11 | class map_action_unittest(unittest.TestCase): |
| 12 | def setUp(self): |
| 13 | self.god = mock.mock_god() |
| 14 | |
| 15 | |
| 16 | def tearDown(self): |
| 17 | pass |
| 18 | |
| 19 | |
| 20 | def test_machine_info_api(self): |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 21 | tests = object() |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 22 | configs = object() |
| 23 | |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 24 | info = trigger.map_action.machine_info(tests, configs) |
| 25 | self.assertEquals(tests, info.tests) |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 26 | self.assertEquals(configs, info.kernel_configs) |
| 27 | |
| 28 | |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 29 | @staticmethod |
| 30 | def _make_control_dict(contents, is_server=False, synch_count=1, |
| 31 | dependencies=()): |
| 32 | return dict(control_file=contents, is_server=is_server, |
| 33 | synch_count=synch_count, dependencies=dependencies) |
| 34 | |
| 35 | |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 36 | def test_job_grouping(self): |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 37 | tests_map = { |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 38 | 'mach1': trigger.map_action.machine_info( |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 39 | ('test1', 'test2'), {'2.6.20': 'config1'}), |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 40 | 'mach2': trigger.map_action.machine_info( |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 41 | ('test3',), {'2.6.10': 'config2', '2.6.20': 'config1'}), |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 42 | 'mach3': trigger.map_action.machine_info( |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 43 | ('test2', 'test3'), {'2.6.20': 'config1'}), |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 44 | } |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 45 | action = trigger.map_action(tests_map, 'jobname %s') |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 46 | |
| 47 | self.god.stub_function(action, '_generate_control') |
| 48 | self.god.stub_function(action, '_schedule_job') |
| 49 | |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 50 | control2 = self._make_control_dict('control contents2') |
| 51 | (action._generate_control.expect_call('test2', '2.6.21', 'config1') |
| 52 | .and_return(control2)) |
| 53 | action._schedule_job.expect_call('jobname 2.6.21', control2, |
| 54 | ['mach1', 'mach3']) |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 55 | |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 56 | control3 = self._make_control_dict('control contents3') |
| 57 | (action._generate_control.expect_call('test3', '2.6.21', 'config1') |
| 58 | .and_return(control3)) |
| 59 | action._schedule_job.expect_call('jobname 2.6.21', control3, |
| 60 | ['mach2', 'mach3']) |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 61 | |
| mbligh | b8f5b70 | 2009-11-06 03:09:03 +0000 | [diff] [blame] | 62 | control1 = self._make_control_dict('control contents1') |
| 63 | (action._generate_control.expect_call('test1', '2.6.21', 'config1') |
| 64 | .and_return(control1)) |
| 65 | action._schedule_job.expect_call('jobname 2.6.21', control1, ['mach1']) |
| mbligh | b62f724 | 2009-07-29 14:34:30 +0000 | [diff] [blame] | 66 | |
| 67 | action(['2.6.21']) |
| 68 | self.god.check_playback() |
| 69 | |
| 70 | |
| 71 | def test_kver_cmp(self): |
| 72 | def check_cmp(ver1, ver2): |
| 73 | # function to make sure "cmp" invariants are followed |
| 74 | cmp_func = trigger.map_action._kver_cmp |
| 75 | if ver1 != ver2: |
| 76 | self.assertEquals(cmp_func(ver1, ver2), -1) |
| 77 | self.assertEquals(cmp_func(ver2, ver1), 1) |
| 78 | else: |
| 79 | self.assertEquals(cmp_func(ver1, ver2), 0) |
| 80 | self.assertEquals(cmp_func(ver2, ver1), 0) |
| 81 | |
| 82 | check_cmp('2.6.20', '2.6.20') |
| 83 | check_cmp('2.6.20', '2.6.21') |
| 84 | check_cmp('2.6.20', '2.6.21-rc2') |
| 85 | check_cmp('2.6.20-rc2-git2', '2.6.20-rc2') |
| 86 | |
| 87 | |
| 88 | if __name__ == "__main__": |
| 89 | unittest.main() |