Home | History | Annotate | Download | only in platform_KernelVersionByBoard
      1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging
      6 import os
      7 
      8 from autotest_lib.client.bin import test
      9 from autotest_lib.client.bin import utils
     10 from autotest_lib.client.common_lib import error
     11 
     12 
     13 _EXPECTED_FILE = 'expected'
     14 
     15 
     16 class platform_KernelVersionByBoard(test.test):
     17     """ Compare kernel version of a build to expected value. """
     18 
     19     version = 1
     20 
     21     def _expected_kernel(self, board):
     22         """ Return expected kernel version number from file.
     23 
     24         @return: string of expected kernel version (e.g. '3.4')
     25         """
     26         with open(os.path.join(self.bindir, _EXPECTED_FILE)) as file_handle:
     27             for line in file_handle:
     28                 file_board, expected = line.split()
     29                 if board == file_board:
     30                     logging.info('Expected Kernel Version for %s: %s', board,
     31                                  expected)
     32                     return expected.strip()
     33 
     34         actual = self._actual_kernel(board)
     35         raise error.TestError('Could not find expected kernel version for '
     36                               '%s.  Should it be added?  Actual is %s.'
     37                               % (board, actual))
     38 
     39     def _actual_kernel(self, board):
     40         """ Return actual kernel version number from device.
     41 
     42         @returns: string of actual kernel version (e.g. '3.8.11')
     43         """
     44         return utils.system_output('uname -r')
     45 
     46     def run_once(self):
     47         """ Compare expected and actual kernel versions. """
     48         board = utils.get_current_board()
     49         actual = self._actual_kernel(board)
     50         expected = self._expected_kernel(board)
     51         if not actual.startswith(expected):
     52             raise error.TestFail('%s: Expected kernel version %s; Found %s'
     53                                  % (board, expected, actual))
     54 
     55