def test_set_idle_state_disable(self): output = io.BytesIO() function = 'avocado.utils.cpu.online_list' state_file = '/sys/devices/system/cpu/cpu0/cpuidle/state1' with unittest.mock.patch(function, return_value=[0, 2]): with unittest.mock.patch('glob.glob', return_value=[state_file]): with unittest.mock.patch('builtins.open', return_value=output): with self.assertRaises(TypeError): cpu.set_idle_state(disable=1)
def test_set_idle_state_withsetstate(self): output = io.BytesIO() with unittest.mock.patch('avocado.utils.cpu.online_list', return_value=[0, 2]): with unittest.mock.patch('glob.glob', return_value=['/sys/devices/system/cpu/cpu0/cpuidle/state1']): with unittest.mock.patch('builtins.open', return_value=output): cpu.set_idle_state(setstate={0: {0: True}, 2: {0: False}}) self.assertEqual(output.getvalue(), b'10')
def test_set_idle_state_withstateno(self): output = io.BytesIO() 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/state2']): with unittest.mock.patch('builtins.open', return_value=output): cpu.set_idle_state(disable=False, state_number='2') self.assertEqual(output.getvalue(), b'0')
def test_set_idle_state_withstateno(self): output = io.BytesIO() 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/state2"], ): with unittest.mock.patch("builtins.open", return_value=output): cpu.set_idle_state(disable=False, state_number="2") self.assertEqual(output.getvalue(), b"0")
def test_set_idle_state_default(self): output = io.BytesIO() 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=output): cpu.set_idle_state() self.assertEqual(output.getvalue(), b"1")
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)