blob: 3206350c6744da3542f3ba76c3c8c95ec9cea903 [file] [log] [blame]
mblighb62f7242009-07-29 14:34:30 +00001#!/usr/bin/python
2# Copyright 2009 Google Inc. Released under the GPL v2
3
4import unittest
5
6import common
7from autotest_lib.mirror import trigger
8from autotest_lib.client.common_lib.test_utils import mock
9
10
11class 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):
mblighb8f5b702009-11-06 03:09:03 +000021 tests = object()
mblighb62f7242009-07-29 14:34:30 +000022 configs = object()
23
mblighb8f5b702009-11-06 03:09:03 +000024 info = trigger.map_action.machine_info(tests, configs)
25 self.assertEquals(tests, info.tests)
mblighb62f7242009-07-29 14:34:30 +000026 self.assertEquals(configs, info.kernel_configs)
27
28
mblighb8f5b702009-11-06 03:09:03 +000029 @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
mblighb62f7242009-07-29 14:34:30 +000036 def test_job_grouping(self):
mblighb8f5b702009-11-06 03:09:03 +000037 tests_map = {
mblighb62f7242009-07-29 14:34:30 +000038 'mach1': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000039 ('test1', 'test2'), {'2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000040 'mach2': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000041 ('test3',), {'2.6.10': 'config2', '2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000042 'mach3': trigger.map_action.machine_info(
mblighb8f5b702009-11-06 03:09:03 +000043 ('test2', 'test3'), {'2.6.20': 'config1'}),
mblighb62f7242009-07-29 14:34:30 +000044 }
mblighb8f5b702009-11-06 03:09:03 +000045 action = trigger.map_action(tests_map, 'jobname %s')
mblighb62f7242009-07-29 14:34:30 +000046
47 self.god.stub_function(action, '_generate_control')
48 self.god.stub_function(action, '_schedule_job')
49
mblighb8f5b702009-11-06 03:09:03 +000050 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'])
mblighb62f7242009-07-29 14:34:30 +000055
mblighb8f5b702009-11-06 03:09:03 +000056 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'])
mblighb62f7242009-07-29 14:34:30 +000061
mblighb8f5b702009-11-06 03:09:03 +000062 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'])
mblighb62f7242009-07-29 14:34:30 +000066
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
88if __name__ == "__main__":
89 unittest.main()