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