1 # Copyright 2014 The Chromium 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 os 6 import unittest 7 8 from telemetry.core.platform.power_monitor import android_dumpsys_power_monitor 9 from telemetry.core.util import GetUnittestDataDir 10 11 12 class DS2784PowerMonitorMonitorTest(unittest.TestCase): 13 def testEnergyComsumption(self): 14 package = 'com.google.android.apps.chrome' 15 dumpsys_output = os.path.join(GetUnittestDataDir(), 'batterystats_v7.csv') 16 with open(dumpsys_output, 'r') as output: 17 results = ( 18 android_dumpsys_power_monitor.DumpsysPowerMonitor.ParseSamplingOutput( 19 package, output)) 20 self.assertEqual(results['identifier'], 'dumpsys') 21 self.assertAlmostEqual(results['energy_consumption_mwh'], 2.924) 22 23 # Older version of the OS do not have the data. 24 def testNoData(self): 25 package = 'com.android.chrome' 26 dumpsys_output = os.path.join(GetUnittestDataDir(), 27 'batterystats_v7_no_data.csv') 28 with open(dumpsys_output, 'r') as output: 29 results = ( 30 android_dumpsys_power_monitor.DumpsysPowerMonitor.ParseSamplingOutput( 31 package, output)) 32 self.assertEqual(results['identifier'], 'dumpsys') 33 self.assertEqual(results['energy_consumption_mwh'], 0) 34 35 if __name__ == '__main__': 36 unittest.main() 37