def test_remove_pids(self, lib): "Tests remove_pids() method." values = CPqosEventValues(llc=123, mbm_local=456, mbm_total=789, mbm_remote=120, mbm_local_delta=456, mbm_total_delta=789, mbm_remote_delta=120) group_mock = CPqosMonData(values=values) def pqos_mon_remove_pids_mock(num_pids, pids_arr, group_ref): "Mock pqos_mon_remove_pids()." group_ptr = ctypes.cast(group_ref, ctypes.POINTER(CPqosMonData)) group_ptr_addr = ctypes.addressof(group_ptr.contents) mock_addr = ctypes.addressof(group_mock) self.assertEqual(group_ptr_addr, mock_addr) self.assertEqual(num_pids, 4) self.assertEqual(pids_arr[0], 555) self.assertEqual(pids_arr[1], 444) self.assertEqual(pids_arr[2], 321) self.assertEqual(pids_arr[3], 121) return 0 func_mock = MagicMock(side_effect=pqos_mon_remove_pids_mock) lib.pqos_mon_remove_pids = func_mock group_mock.remove_pids([555, 444, 321, 121]) lib.pqos_mon_remove_pids.assert_called_once()
def test_stop(self, lib): "Tests stop() method." values = CPqosEventValues(llc=123, mbm_local=456, mbm_total=789, mbm_remote=120, mbm_local_delta=456, mbm_total_delta=789, mbm_remote_delta=120) group_mock = CPqosMonData(values=values) def pqos_mon_stop_mock(group_ref): "Mock pqos_mon_stop()." group_ptr = ctypes.cast(group_ref, ctypes.POINTER(CPqosMonData)) group_ptr_addr = ctypes.addressof(group_ptr.contents) mock_addr = ctypes.addressof(group_mock) self.assertEqual(group_ptr_addr, mock_addr) return 0 func_mock = MagicMock(side_effect=pqos_mon_stop_mock) lib.pqos_mon_stop = func_mock group_mock.stop() lib.pqos_mon_stop.assert_called_once()
def test_poll(self, lib): "Tests poll() method." values = CPqosEventValues(llc=678, mbm_local=653, mbm_total=721, mbm_remote=68, mbm_local_delta=653, mbm_total_delta=721, mbm_remote_delta=68, ipc=0.98, llc_misses=10, llc_misses_delta=10) event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP group = CPqosMonData(event=event, values=values) values2 = CPqosEventValues(llc=998, mbm_local=653, mbm_total=721, mbm_remote=68, mbm_local_delta=653, mbm_total_delta=721, mbm_remote_delta=68, ipc=0.98, llc_misses=10, llc_misses_delta=10) group_mock2 = CPqosMonData(values=values2) def pqos_mon_poll_mock(groups_arr, num_groups): "Mock pqos_mon_poll()." self.assertEqual(num_groups, 1) ctypes.memmove(groups_arr[0], ctypes.addressof(group_mock2), ctypes.sizeof(group_mock2)) return 0 func_mock = MagicMock(side_effect=pqos_mon_poll_mock) lib.pqos_mon_poll = func_mock mon = PqosMon() mon.poll([group]) lib.pqos_mon_poll.assert_called_once() self.assertEqual(group.values.llc, 998)
def test_start(self, lib): "Tests start() method." values = CPqosEventValues(llc=123, mbm_local=456, mbm_total=789, mbm_remote=120, mbm_local_delta=456, mbm_total_delta=789, mbm_remote_delta=120) group_mock = CPqosMonData(values=values) def pqos_mon_start_mock(num_cores, cores_arr, event, _context, group_ref): "Mock pqos_mon_start()." self.assertEqual(num_cores, 2) self.assertEqual(cores_arr[0], 1) self.assertEqual(cores_arr[1], 3) exp_event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP exp_event |= CPqosMonitor.PQOS_MON_EVENT_LMEM_BW self.assertEqual(event, exp_event) ctypes.memmove(group_ref, ctypes.addressof(group_mock), ctypes.sizeof(group_mock)) return 0 func_mock = MagicMock(side_effect=pqos_mon_start_mock) lib.pqos_mon_start = func_mock mon = PqosMon() group = mon.start([1, 3], ['l3_occup', 'lmem_bw']) lib.pqos_mon_start.assert_called_once() self.assertEqual(group.values.llc, 123) self.assertEqual(group.values.mbm_local, 456)
def test_start_pids(self, lib): "Tests start_pids() method." values = CPqosEventValues(llc=678, mbm_local=653, mbm_total=721, mbm_remote=68, mbm_local_delta=653, mbm_total_delta=721, mbm_remote_delta=68, ipc=0.98, llc_misses=10, llc_misses_delta=10) group_mock = CPqosMonData(values=values) def pqos_mon_start_pids_mock(num_pids, pids_arr, event, _context, group_ref): "Mock pqos_mon_start_pids()." self.assertEqual(num_pids, 2) self.assertEqual(pids_arr[0], 1286) self.assertEqual(pids_arr[1], 2251) exp_event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP exp_event |= CPqosMonitor.PQOS_MON_EVENT_TMEM_BW self.assertEqual(event, exp_event) ctypes.memmove(group_ref, ctypes.addressof(group_mock), ctypes.sizeof(group_mock)) return 0 func_mock = MagicMock(side_effect=pqos_mon_start_pids_mock) lib.pqos_mon_start_pids = func_mock mon = PqosMon() group = mon.start_pids([1286, 2251], ['l3_occup', 'tmem_bw']) lib.pqos_mon_start_pids.assert_called_once() self.assertEqual(group.values.llc, 678) self.assertEqual(group.values.mbm_local, 653) self.assertAlmostEqual(group.values.ipc, 0.98, places=5)