def test_get_l2ids(self, lib): "Tests get_l2ids() method." l2ids_mock = [ctypes.c_uint(l2id) for l2id in [7, 2, 3, 5]] l2ids_arr = ctypes_build_array(l2ids_mock) def pqos_cpu_get_l2ids_m(_p_cpu, count_ref): "Mock pqos_cpu_get_l2ids()." ctypes_ref_set_int(count_ref, len(l2ids_arr)) return ctypes.cast(l2ids_arr, ctypes.POINTER(ctypes.c_uint)) lib.pqos_cap_get = MagicMock(return_value=0) lib.pqos_cpu_get_l2ids = MagicMock(side_effect=pqos_cpu_get_l2ids_m) cpu = PqosCpuInfo() with patch('pqos.cpuinfo.free_memory'): l2ids = cpu.get_l2ids() self.assertEqual(len(l2ids), 4) self.assertEqual(l2ids[0], 7) self.assertEqual(l2ids[1], 2) self.assertEqual(l2ids[2], 3) self.assertEqual(l2ids[3], 5)
def test_get_l2ids(self, lib): "Tests get_l2ids() method." l2ids_mock = [ctypes.c_uint(l2id) for l2id in [7, 2, 3, 5]] l2ids_arr = ctypes_build_array(l2ids_mock) def pqos_cpu_get_l2ids_m(_p_cpu, count_ref): "Mock pqos_cpu_get_l2ids()." ctypes_ref_set_int(count_ref, len(l2ids_arr)) return ctypes.cast(l2ids_arr, ctypes.POINTER(ctypes.c_uint)) lib.pqos_cap_get = MagicMock(return_value=0) lib.pqos_cpu_get_l2ids = MagicMock(side_effect=pqos_cpu_get_l2ids_m) cpu = PqosCpuInfo() with patch('pqos.cpuinfo.free_memory'): l2ids = cpu.get_l2ids() self.assertEqual(len(l2ids), 4) self.assertEqual(l2ids[0], 7) self.assertEqual(l2ids[1], 2) self.assertEqual(l2ids[2], 3) self.assertEqual(l2ids[3], 5)
def main(): args = parse_args() try: with PqosContextManager(args.interface): cpu = PqosCpuInfo() l2_ids = cpu.get_l2ids() set_allocation_class(l2_ids, args.class_id, args.mask) print_allocation_config(l2_ids) except: print("Error!") raise