• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2from __future__ import absolute_import
3from __future__ import division
4from __future__ import print_function
5import unittest
6import common
7from autotest_lib.client.bin import kernel_versions
8from six.moves import range
9
10
11class kernel_versions_test(unittest.TestCase):
12
13    def increases(self, kernels):
14        for i in range(len(kernels)-1):
15            k1 = kernels[i]
16            k2 = kernels[i+1]
17            ek1 = kernel_versions.version_encode(k1)
18            ek2 = kernel_versions.version_encode(k2)
19            self.assertTrue(ek1 < ek2,
20                    '%s (-> %s)  should sort <  %s (-> %s)'
21                    % (k1, ek1, k2, ek2) )
22
23
24    def test_version_encode(self):
25        series1 = [
26                '2.6',
27                '2.6.0',
28                '2.6.1-rc1',
29                '2.6.1-rc1_fix',
30                '2.6.1-rc1_patch',
31                '2.6.1-rc9',
32                '2.6.1-rc9-mm1',
33                '2.6.1-rc9-mm2',
34                '2.6.1-rc10',
35                '2.6.1-rc98',
36                '2.6.1',
37                '2.6.1_patch',
38                '2.6.9',
39                '2.6.10',
40                '2.6.99',
41                '2.7',
42                '2.9.99',
43                '2.10.0',
44                '99.99.99',
45                'UNKNOWN',
46                ]
47        self.increases(series1)
48        self.increases(['pathX'+k for k in series1])
49        series2 = [
50                '2.6.18-smp-220',
51                '2.6.18-smp-220.0',
52                '2.6.18-smp-220.1_rc1',
53                '2.6.18-smp-220.1_rc1_fix',
54                '2.6.18-smp-220.1_rc1_patch',
55                '2.6.18-smp-220.1_rc9',
56                '2.6.18-smp-220.1_rc9_mm1',
57                '2.6.18-smp-220.1_rc9_mm2',
58                '2.6.18-smp-220.1_rc10',
59                '2.6.18-smp-220.1_rc98',
60                '2.6.18-smp-220.1',
61                '2.6.18-smp-220.1_patch',
62                '2.6.18-smp-220.9',
63                '2.6.18-smp-220.10',
64                '2.6.18-smp-220.99',
65                '2.6.18-smp-221',
66                'UNKNOWN',
67                ]
68        self.increases(series2)
69        self.increases(['pathX'+k for k in series2])
70
71
72    releases    = ['2.6.1'      , '2.6.18-smp-220.0'   ]
73    candidates  = ['2.6.1-rc1'  , '2.6.18-smp-220.0_rc1']
74    experiments = ['2.6.1-patch', '2.6.1-rc1_patch', '2.6.18-smp-220.0_patch',
75                   'UNKNOWN']
76
77    def test_is_released_kernel(self):
78        for v in self.releases:
79            self.assertTrue(kernel_versions.is_released_kernel(v))
80        for v in self.candidates + self.experiments:
81            self.assertFalse(kernel_versions.is_released_kernel(v))
82
83
84    def test_is_release_candidate(self):
85        for v in self.releases + self.candidates:
86            self.assertTrue(kernel_versions.is_release_candidate(v))
87        for v in self.experiments:
88            self.assertFalse(kernel_versions.is_release_candidate(v))
89
90
91if  __name__ == "__main__":
92    unittest.main()
93