def test_get_idle_state_on(self): retval = {0: {0: True}} with unittest.mock.patch('avocado.utils.cpu.online_list', return_value=[0]): with unittest.mock.patch('glob.glob', return_value=['/sys/devices/system/cpu/cpu0/cpuidle/state1']): with unittest.mock.patch('builtins.open', return_value=io.BytesIO(b'1')): self.assertEqual(cpu.get_idle_state(), retval)
def test_get_idle_state_on(self): retval = {0: {0: True}} with unittest.mock.patch("avocado.utils.cpu.online_list", return_value=[0]): with unittest.mock.patch( "glob.glob", return_value=["/sys/devices/system/cpu/cpu0/cpuidle/state1"], ): with unittest.mock.patch( "builtins.open", return_value=io.BytesIO(b"1") ): self.assertEqual(cpu.get_idle_state(), retval)
def host_stress_event(self, event): """ Host Stress events :param event: event name """ for itr in range(self.host_iterations): if "cpu_freq_governor" in event: cpu.set_freq_governor() if hasattr( cpu, 'set_freq_governor') else cpu.set_cpufreq_governor() LOG.debug( "Current governor: %s", cpu.get_freq_governor() if hasattr(cpu, 'get_freq_governor') else cpu.get_cpufreq_governor()) time.sleep(self.event_sleep_time) elif "cpu_idle" in event: idlestate = cpu.get_idle_state() if hasattr( cpu, 'get_idle_state') else cpu.get_cpuidle_state() cpu.set_idle_state() if hasattr( cpu, 'set_idle_state') else cpu.set_cpuidle_state() time.sleep(self.event_sleep_time) cpu.set_idle_state(setstate=idlestate) if hasattr( cpu, 'set_idle_state') else cpu.set_cpuidle_state( setstate=idlestate) time.sleep(self.event_sleep_time) elif "cpuoffline" in event: online_count = cpu.online_count() if hasattr( cpu, 'online_count') else cpu.online_cpus_count() processor = self.host_cpu_list[random.randint( 0, online_count - 1)] cpu.offline(processor) time.sleep(self.event_sleep_time) cpu.online(processor) else: raise NotImplementedError time.sleep(self.itr_sleep_time)