Reduce dependencies with monsoon controller am: ecc6a352b4 am: a881e009f0 am: acb31d5596
Original change: https://android-review.googlesource.com/c/platform/tools/test/connectivity/+/1443289
Change-Id: I7befe53362f90989672b7105ee2d16119e27c294
diff --git a/acts/framework/acts/test_utils/power/PowerBaseTest.py b/acts/framework/acts/test_utils/power/PowerBaseTest.py
index 93b8c44..32d7301 100644
--- a/acts/framework/acts/test_utils/power/PowerBaseTest.py
+++ b/acts/framework/acts/test_utils/power/PowerBaseTest.py
@@ -75,6 +75,7 @@
self.img_name = ''
self.dut = None
self.power_logger = PowerMetricLogger.for_test_case()
+ self.power_monitor = None
@property
def final_test(self):
@@ -100,6 +101,19 @@
def display_name_test_case(self, name):
self._display_name_test_case = name
+ def initialize_power_monitor(self):
+ """ Initializes the power monitor object.
+
+ Raises an exception if there are no controllers available.
+ """
+ if hasattr(self, 'monsoons'):
+ self.power_monitor = power_monitor_lib.PowerMonitorMonsoonFacade(
+ self.monsoons[0])
+ self.monsoons[0].set_max_current(8.0)
+ self.monsoons[0].set_voltage(self.mon_voltage)
+ else:
+ raise RuntimeError('No power monitors available.')
+
def setup_class(self):
self.log = logging.getLogger()
@@ -132,13 +146,9 @@
self.dut = self.android_devices[0]
self.mon_data_path = os.path.join(self.log_path, 'Monsoon')
os.makedirs(self.mon_data_path, exist_ok=True)
- self.mon = self.monsoons[0]
- self.mon.set_max_current(8.0)
- self.mon.set_voltage(self.mon_voltage)
# Initialize the power monitor object that will be used to measure
- self.power_monitor = power_monitor_lib.PowerMonitorMonsoonFacade(
- self.monsoons[0])
+ self.initialize_power_monitor()
# Unpack the thresholds file or fail class setup if it can't be found
for file in self.custom_files:
@@ -206,7 +216,7 @@
"""
self.log.info('Tearing down the test case')
- self.mon.usb('on')
+ self.power_monitor.connect_usb()
self.power_logger.set_avg_power(self.power_result.metric_value)
self.power_logger.set_avg_current(self.avg_current)
self.power_logger.set_voltage(self.mon_voltage)
@@ -251,8 +261,8 @@
"""
self.log.info('Tearing down the test class')
- if hasattr(self, 'monsoons'):
- self.monsoons[0].usb('on')
+ if self.power_monitor:
+ self.power_monitor.connect_usb()
def on_fail(self, test_name, begin_time):
self.power_logger.set_pass_fail_status('FAIL')
@@ -391,8 +401,7 @@
Returns:
mon_info: Dictionary with the monsoon packet config
"""
- mon_info = ObjNew(dut=self.mon,
- freq=self.mon_freq,
+ mon_info = ObjNew(freq=self.mon_freq,
duration=self.mon_duration,
offset=self.mon_offset,
data_path=self.mon_data_path)
diff --git a/acts/framework/acts/test_utils/power/PowerGnssBaseTest.py b/acts/framework/acts/test_utils/power/PowerGnssBaseTest.py
index 99f150f..d4e4c3b 100644
--- a/acts/framework/acts/test_utils/power/PowerGnssBaseTest.py
+++ b/acts/framework/acts/test_utils/power/PowerGnssBaseTest.py
@@ -134,10 +134,10 @@
self.dut.adb.shell(RESET_BATTERY_STATS)
time.sleep(1)
for _ in range(LOGTIME_RETRY_COUNT):
- self.mon_info.dut.usb(PassthroughStates.OFF)
+ self.monsoons[0].usb(PassthroughStates.OFF)
if not ad.is_connected():
time.sleep(sleeptime)
- self.mon_info.dut.usb(PassthroughStates.ON)
+ self.monsoons[0].usb(PassthroughStates.ON)
break
else:
self.log.error('Test failed after maximum retry')
@@ -162,15 +162,13 @@
True/False
"""
try:
- self.mon.reconnect_monsoon()
- time.sleep(2)
- self.mon.usb('on')
+ self.power_monitor.connect_usb()
logging.info('Monsoon recovered from unexpected error')
time.sleep(2)
return True
except MonsoonError:
try:
- self.log.info(self.mon_info.dut._mon.ser.in_waiting)
+ self.log.info(self.monsoons[0]._mon.ser.in_waiting)
except AttributeError:
# This attribute does not exist for HVPMs.
pass