Skip to content

Commit

Permalink
[Telemetry] Consider linux distribution number is 0 when it cannot be…
Browse files Browse the repository at this point in the history
… parsed

On some linux distributions, the DISTRIB_RELEASE field of
/etc/lsb-release cannot be parsed as a float. In that case, consider it
will be 0

R=
BUG=393022

Review URL: https://codereview.chromium.org/381293003

Cr-Commit-Position: refs/heads/master@{#291481}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291481 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Aug 22, 2014
1 parent 9cfb9ff commit bc0b4d2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tools/telemetry/telemetry/core/platform/linux_platform_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def GetOSVersionName(self):

codename = None
version = None
with open('/etc/lsb-release') as f:
for line in f.readlines():
key, _, value = line.partition('=')
if key == 'DISTRIB_CODENAME':
codename = value.strip()
elif key == 'DISTRIB_RELEASE':
for line in self._GetFileContents('/etc/lsb-release').splitlines():
key, _, value = line.partition('=')
if key == 'DISTRIB_CODENAME':
codename = value.strip()
elif key == 'DISTRIB_RELEASE':
try:
version = float(value)
if codename and version:
break
except ValueError:
version = 0
if codename and version:
break
return platform_backend.OSVersion(codename, version)

def CanFlushIndividualFilesFromSystemCache(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import unittest

from telemetry import decorators
from telemetry.core import util
from telemetry.core.platform import linux_platform_backend

class TestBackend(
linux_platform_backend.LinuxPlatformBackend):

def __init__(self):
super(TestBackend, self).__init__()
self._mock_files = {}

def SetMockFile(self, filename, output):
self._mock_files[filename] = output

def _GetFileContents(self, filename):
return self._mock_files[filename]

def StartRawDisplayFrameRateMeasurement(self):
raise NotImplementedError()

def StopRawDisplayFrameRateMeasurement(self):
raise NotImplementedError()

def GetRawDisplayFrameRateMeasurements(self):
raise NotImplementedError()

def IsThermallyThrottled(self):
raise NotImplementedError()

def HasBeenThermallyThrottled(self):
raise NotImplementedError()

def GetSystemCommitCharge(self):
raise NotImplementedError()

def StopVideoCapture(self):
raise NotImplementedError()

def StartVideoCapture(self, min_bitrate_mbps):
raise NotImplementedError()

def GetSystemTotalPhysicalMemory(self):
raise NotImplementedError()


class LinuxPlatformBackendTest(unittest.TestCase):
@decorators.Enabled('linux')
def testGetOSVersionNameSaucy(self):
backend = TestBackend()
path = os.path.join(util.GetUnittestDataDir(), 'ubuntu-saucy-lsb-release')
with open(path) as f:
backend.SetMockFile('/etc/lsb-release', f.read())

self.assertEqual(backend.GetOSVersionName(), 'saucy')

@decorators.Enabled('linux')
def testGetOSVersionNameArch(self):
backend = TestBackend()
path = os.path.join(util.GetUnittestDataDir(), 'arch-lsb-release')
with open(path) as f:
backend.SetMockFile('/etc/lsb-release', f.read())

# a distribution may not have a codename or a release number. We just check
# that GetOSVersionName doesn't raise an exception
backend.GetOSVersionName()
4 changes: 4 additions & 0 deletions tools/telemetry/unittest_data/arch-lsb-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LSB_VERSION=1.4
DISTRIB_ID=Arch
DISTRIB_RELEASE=rolling
DISTRIB_DESCRIPTION="Arch Linux"
4 changes: 4 additions & 0 deletions tools/telemetry/unittest_data/ubuntu-saucy-lsb-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=13.10
DISTRIB_CODENAME=saucy
DISTRIB_DESCRIPTION="Ubuntu 13.10"

0 comments on commit bc0b4d2

Please sign in to comment.