def wait_for_active_stream_count(expected_count): """Waits for the expected number of active streams. @param expected_count: expected count of active streams. """ utils.poll_for_condition( lambda: cras_utils.get_active_stream_count() == expected_count, exception=error.TestError( 'Timeout waiting active stream count to become "%d",' 'current value is "%d"' % (expected_count, cras_utils.get_active_stream_count())))
def wait_for_active_stream_count(self, expected_count): utils.poll_for_condition( lambda: cras_utils.get_active_stream_count() == expected_count, exception=error.TestError( 'Timeout waiting active stream count to become %d' % expected_count), timeout=1, sleep_interval=0.05)
def verify_active_streams(self): """Verifies test active audio streams with cras active streams.""" cras_stream_count = cras_utils.get_active_stream_count() if self._active_stream_count != cras_stream_count: cras_crash_reports = self.collect_cras_crash() new_reports = list( set(cras_crash_reports) - set(self._existing_cras_reports)) error_msg = ('Active stream count: %d is not matching with ' 'cras active stream count: %d. ' 'Number of cras crashes %d : %s' % (self._active_stream_count, cras_stream_count, len(new_reports), new_reports)) raise error.TestError(error_msg)
def wait_for_active_stream_count(self, expected_count): """ Waits for there to be the expected number of audio streams. @param expected_count: Number of audio streams to wait for. @raises error.TestError: if there is a timeout before the there is the desired number of audio streams. """ utils.poll_for_condition( lambda: cras_utils.get_active_stream_count() == expected_count, exception=error.TestError( 'Timeout waiting active stream count to become %d' % expected_count))
def run_once(self): # Check for existing cras crashes which might occur during UI bring up. # TODO: (rohitbm) check if we need to reboot the DUT before the test # start to verify cras crashes during boot. existing_crash_reports = self.collect_cras_crash() if len(existing_crash_reports) == 0: self._check['crashes_on_boot'] = True # Capturing cras pid before startig the test. cras_pid_1 = utils.get_oldest_pid_by_name('/usr/bin/cras') with chrome.Chrome(init_network_controller=True) as self._cr: # Push the 1st stream self.push_new_stream(self._cr.browser.tabs.New()) # Capturing cras pid before opening a new set of audio streams. cras_pid_2 = utils.get_oldest_pid_by_name('/usr/bin/cras') # Push the 2nd stream self.push_new_stream(self._cr.browser.tabs.New()) # Let's play audio for sometime to ensure that # long playback is good. time.sleep(10) total_tests = 2 active_streams = cras_utils.get_active_stream_count() logging.debug( 'Number of active streams after opening all tabs: %d.', active_streams) if active_streams >= total_tests: self._check['stream_activation'] = True # Capturing cras pid after opening all audio/video streams. cras_pid_3 = utils.get_oldest_pid_by_name('/usr/bin/cras') # Close all open audio streams. while total_tests > 0: self._cr.browser.tabs[total_tests].Close() total_tests -= 1 time.sleep(1) active_streams = cras_utils.get_active_stream_count() logging.debug( 'Number of active streams after closing all tabs: %d.', active_streams) # Capturing cras pid after closing all audio/stream streams. cras_pid_4 = utils.get_oldest_pid_by_name('/usr/bin/cras') if cras_pid_1 == cras_pid_2 == cras_pid_3 == cras_pid_4: self._check['cras_status'] = True new_crash_reports = self.collect_cras_crash() new_reports = list( set(new_crash_reports) - set(existing_crash_reports)) if len(new_reports) == 0: self._check['crashes_at_end'] = True err_msg = '' if self._check.values().count(False) > 0: if not self._check['crashes_on_boot']: err_msg = ('1. Found cras crashes on boot: %s.\n' % existing_crash_reports) if not self._check['stream_activation']: err_msg += ('2. CRAS stream count is not matching with ' 'number of streams.\n') if not self._check['cras_status']: err_msg += ('CRAS PID changed during the test. CRAS might be ' 'crashing while adding/removing streams.\n') if not self._check['crashes_at_end']: err_msg += ('Found cras crashes at the end of the test : %s.' % new_reports) raise error.TestError(err_msg)
def run_once(self): boards_to_skip = ['x86-mario'] dut_board = utils.get_current_board() if dut_board in boards_to_skip: logging.info("Skipping test run on this board.") return # Check for existing cras crashes which might occur during UI bring up. # TODO: (rohitbm) check if we need to reboot the DUT before the test # start to verify cras crashes during boot. existing_crash_reports = self.collect_cras_crash() if len(existing_crash_reports) == 0: self._check['crashes_on_boot'] = True # Capturing cras pid before startig the test. cras_pid_1 = utils.get_oldest_pid_by_name('/usr/bin/cras') with chrome.Chrome(init_network_controller=True) as self._cr: try: # This will be used on Chrome PFQ since it's using a more recent # version of Chrome. crbug.com/537655. self._cr.browser.platform.SetHTTPServerDirectories(self.bindir) except: # This will be used on ChromeOS CQ since Chrome hasn't uprev'ed # yet. crbug.com/538140. self._cr.browser.SetHTTPServerDirectories(self.bindir) for test_file in self._audio: url = _DOWNLOAD_BASE + 'audio_test/' + test_file self.push_new_stream(self._cr.browser.tabs.New(), url) # Capturing cras pid before opening a new set of audio streams. cras_pid_2 = utils.get_oldest_pid_by_name('/usr/bin/cras') for test_file in self._video: url = _DOWNLOAD_BASE + 'traffic/' + test_file self.push_new_stream(self._cr.browser.tabs.New(), url) # Let's play audio for sometime to ensure that # long playback is good. time.sleep(10) total_tests = len(self._audio) + len(self._video) active_streams = cras_utils.get_active_stream_count() logging.debug( 'Number of active streams after opening all tabs: %d.', active_streams) if active_streams >= total_tests: self._check['stream_activation'] = True # Capturing cras pid after opening all audio/video streams. cras_pid_3 = utils.get_oldest_pid_by_name('/usr/bin/cras') # Close all open audio streams. while total_tests > 0: self._cr.browser.tabs[total_tests].Close() total_tests -= 1 time.sleep(1) active_streams = cras_utils.get_active_stream_count() logging.debug( 'Number of active streams after closing all tabs: %d.', active_streams) # Capturing cras pid after closing all audio/stream streams. cras_pid_4 = utils.get_oldest_pid_by_name('/usr/bin/cras') if cras_pid_1 == cras_pid_2 == cras_pid_3 == cras_pid_4: self._check['cras_status'] = True new_crash_reports = self.collect_cras_crash() new_reports = list( set(new_crash_reports) - set(existing_crash_reports)) if len(new_reports) == 0: self._check['crashes_at_end'] = True err_msg = '' if self._check.values().count(False) > 0: if not self._check['crashes_on_boot']: err_msg = ('1. Found cras crashes on boot: %s.\n' % existing_crash_reports) if not self._check['stream_activation']: err_msg += ('2. CRAS stream count is not matching with ' 'number of streams.\n') if not self._check['cras_status']: err_msg += ('CRAS PID changed during the test. CRAS might be ' 'crashing while adding/removing streams.\n') if not self._check['crashes_at_end']: err_msg += ('Found cras crashes at the end of the test : %s.' % new_reports) raise error.TestError(err_msg)
def wait_for_active_stream_count(expected_count): utils.poll_for_condition( lambda: cras_utils.get_active_stream_count() == expected_count, exception=error.TestError( 'Timeout waiting active stream count to become %d' % expected_count))