def check_kernel_ver(ver): kernel_ver = utils.system_output('uname -r') kv_tmp = re.split(r'[-]', kernel_ver)[0:3] # In compare_versions, if v1 < v2, return value == -1 if utils.compare_versions(kv_tmp[0], ver) == -1: raise error.TestError("Kernel too old (%s). Kernel > %s is needed." % (kernel_ver, ver))
def get_omaha_upgrade(omaha_map, board, version): """Get the later of a build in `omaha_map` or `version`. Read the Omaha version for `board` from `omaha_map`, and compare it to `version`. Return whichever version is more recent. N.B. `board` is the name of a board as known to the AFE. Board names as known to Omaha are different; see `get_omaha_version_map()`, above. This function is responsible for translating names as necessary. @param omaha_map Mapping of Omaha board names to preferred builds. @param board Name of the board to look up, as known to the AFE. @param version Minimum version to be accepted. @return Returns a Chrome OS version string in standard form R##-####.#.#. Will return `None` if `version` is `None` and no Omaha entry is found. """ omaha_version = omaha_map.get(board.replace('_', '-')) if version is None: return omaha_version if omaha_version is not None: if utils.compare_versions(version, omaha_version) < 0: return omaha_version return version
def _get_upgrade_versions(afe_versions, omaha_versions, boards): """Get the new stable versions to which we should update. The new versions are returned as a tuple of a dictionary mapping board names to versions, plus a new default board setting. The new default is determined as the most commonly used version across the given boards. The new dictionary will have a mapping for every board in `boards`. That mapping will be taken from `afe_versions`, unless the board has a mapping in `omaha_versions` _and_ the omaha version is more recent than the AFE version. @param afe_versions The current board->version mappings in the AFE. @param omaha_versions The current board->version mappings from Omaha for the Beta channel. @param boards Set of boards to be upgraded. @return Tuple of (mapping, default) where mapping is a dictionary mapping boards to versions, and default is a version string. """ upgrade_versions = {} version_counts = {} afe_default = afe_versions[_DEFAULT_BOARD] for board in boards: version = afe_versions.get(board, afe_default) omaha_version = omaha_versions.get(board.replace('_', '-')) if (omaha_version is not None and utils.compare_versions(version, omaha_version) < 0): version = omaha_version upgrade_versions[board] = version version_counts.setdefault(version, 0) version_counts[version] += 1 return (upgrade_versions, max(version_counts.items(), key=lambda x: x[1])[0])
def verify_graphics_psr(self): """ On systems which support PSR, check that we can get into PSR; idle before doing so, and retry every second for 20 seconds.""" logging.info('Running verify_graphics_psr') if utils.get_cpu_soc_family() != 'x86_64': return '' tries = 0 found = False param_path = self.get_valid_path(PSR_PATHS) if not param_path: logging.warning("PSR_PATHS not found.") return '' kernel_version = utils.get_kernel_version()[0:4].rstrip(".") logging.info('Kernel version: %s', kernel_version) # First check if PSR is enabled on the device so # we can watch for the active values with open(param_path, 'r') as psr_info_file: match = None for line in psr_info_file: match = re.search(r'Enabled: yes', line) if match: logging.info('PSR enabled') break if not match: logging.warning('PSR not enabled') return '' while not found and tries < 20: time.sleep(1) with open(param_path, 'r') as psr_info_file: for line in psr_info_file: # Kernels 4.4 and up if common_utils.compare_versions(kernel_version, '4.4') != -1: match = re.search(r'PSR status: .* \[SRDENT', line) if match: found = True logging.info('Found active with kernel >= 4.4') break # 3.18 kernel elif kernel_version == '3.18': match = re.search(r'Performance_Counter: 0', line) if match: found = True logging.info('Found active with 3.18 kernel') break # Older kernels (up to 3.14) else: match = re.search(r'Performance_Counter: ([\d])+', line) if match and int(match.group(1)) > 0: found = True logging.info('Found active with kernel <= 3.14') break tries += 1 if not found: return self.handle_error('Did not see PSR activity. ', param_path) return ''
def _update_build(afe, report_log, arguments): """Update the stable_test_versions table. This calls the `set_stable_version` RPC call to set the stable test version selected by this run of the command. The version is selected from three possible versions: * The stable test version currently in the AFE database. * The version Omaha is currently serving as the Beta channel build. * The version supplied by the user. The actual version selected will be whichever of these three is the most up-to-date version. This function will log information about the available versions prior to selection. @param afe AFE object for RPC calls. @param report_log File-like object for logging report output. @param arguments Command line arguments with options. @return Returns the version selected. """ version_map = afe.get_stable_version_map(afe.CROS_IMAGE_TYPE) afe_version = version_map.get_version(arguments.board) omaha_version = _get_omaha_build(arguments.board) report_log.write('AFE version is %s.\n' % afe_version) report_log.write('Omaha version is %s.\n' % omaha_version) if (omaha_version is not None and utils.compare_versions(afe_version, omaha_version) < 0): version = omaha_version else: version = afe_version if arguments.build: if utils.compare_versions(arguments.build, version) >= 0: version = arguments.build else: report_log.write('Selected version %s is too old.\n' % (arguments.build,)) if version != afe_version and not arguments.nostable: version_map.set_version(arguments.board, version) return version
def test_mix_symbols(self): self.assertEqual(utils.compare_versions('k-320.1', 'k-320.3'), -1) self.assertEqual(utils.compare_versions('k-231.5', 'k-231.1'), 1) self.assertEqual(utils.compare_versions('k-231.1', 'k-231.1'), 0) self.assertEqual(utils.compare_versions('k.320-1', 'k.320-3'), -1) self.assertEqual(utils.compare_versions('k.231-5', 'k.231-1'), 1) self.assertEqual(utils.compare_versions('k.231-1', 'k.231-1'), 0)
def test_unequal_len(self): self.assertEqual(utils.compare_versions('1.3', '1.3.4'), -1) self.assertEqual(utils.compare_versions('1.3.1', '1.3'), 1)
def test_dash_delimited(self): self.assertEqual(utils.compare_versions('1-2-3', '1-5-1'), -1) self.assertEqual(utils.compare_versions('1-2-1', '1-1-1'), 1) self.assertEqual(utils.compare_versions('1-2-4', '1-2-4'), 0)
def test_alphabets(self): self.assertEqual(utils.compare_versions('m.l.b', 'n.b.a'), -1) self.assertEqual(utils.compare_versions('n.b.a', 'm.l.b'), 1) self.assertEqual(utils.compare_versions('abc.e', 'abc.e'), 0)
def test_zerofill(self): self.assertEqual(utils.compare_versions('1.7', '1.10'), -1) self.assertEqual(utils.compare_versions('1.222', '1.3'), 1) self.assertEqual(utils.compare_versions('1.03', '1.3'), 0)
def is_supported_kernel_version(version): """ Check if given kernel version is newer than unsupported version.""" return utils.compare_versions(version, UNSUPPORTED_KERNEL) == 1
def check_glibc_ver(ver): glibc_ver = commands.getoutput('ldd --version').splitlines()[0] glibc_ver = re.search(r'(\d+\.\d+(\.\d+)?)', glibc_ver).group() if utils.compare_versions(glibc_ver, ver) == -1: raise error.TestError("Glibc too old (%s). Glibc >= %s is needed." % (glibc_ver, ver))