def test_get(self, lib): "Tests get() method." # pylint: disable=invalid-name def pqos_l2ca_get_mock(socket, cos_num, num_ca_ref, l2cas): "Mock pqos_l2ca_get()." self.assertEqual(socket, 1) self.assertEqual(cos_num, 2) cos_c = CPqosL2Ca(class_id=0, u=CPqosL2CaMask(ways_mask=0x01ff)) cos2_c = CPqosL2Ca(class_id=1, u=CPqosL2CaMask(ways_mask=0x007f)) cos_arr_c = ctypes_build_array([cos_c, cos2_c]) ctypes.memmove(l2cas, cos_arr_c, ctypes.sizeof(cos_arr_c)) ctypes_ref_set_int(num_ca_ref, len(cos_arr_c)) return 0 lib.pqos_l2ca_get = MagicMock(side_effect=pqos_l2ca_get_mock) l2ca = PqosCatL2() with patch('pqos.l2ca.PqosCap') as PqosCapMock: PqosCapMock.return_value.get_l2ca_cos_num.return_value = 2 coses = l2ca.get(1) lib.pqos_l2ca_get.assert_called_once() self.assertEqual(len(coses), 2) self.assertEqual(coses[0].class_id, 0) self.assertEqual(coses[0].mask, 0x01ff) self.assertEqual(coses[1].class_id, 1) self.assertEqual(coses[1].mask, 0x007f)
def test_get_min_cbm_bits(self, lib): "Tests get_min_cbm_bits() method." def pqos_l2ca_get_min_cbm_bits_mock(min_cbm_bits_ref): "Mock pqos_l2ca_get_min_cbm_bits()." ctypes_ref_set_int(min_cbm_bits_ref, 2) return 0 func_mock = MagicMock(side_effect=pqos_l2ca_get_min_cbm_bits_mock) lib.pqos_l2ca_get_min_cbm_bits = func_mock l2ca = PqosCatL2() min_bits = l2ca.get_min_cbm_bits() self.assertEqual(min_bits, 2)
def set_allocation_class(l2_ids, class_id, mask): """ Sets up allocation classes of service on selected CPU sockets Parameters: l2_ids: a list of L2 IDs class_id: class of service ID mask: COS bitmask """ l2ca = PqosCatL2() cos = l2ca.COS(class_id, mask) for l2_id in l2_ids: try: l2ca.set(l2_id, [cos]) except: print("Setting up cache allocation class of service failed!")
def print_allocation_config(l2_ids): """ Prints allocation configuration. Parameters: l2_ids: a list of L2 IDs """ l2ca = PqosCatL2() for l2_id in l2_ids: try: coses = l2ca.get(l2_id) print("L2CA COS definitions for L2 ID %u:" % l2_id) for cos in coses: cos_params = (cos.class_id, cos.mask) print(" L2CA COS%u => MASK 0x%x" % cos_params) except: print("Error") raise
def test_set(self, lib): "Tests set() method." def pqos_l2ca_set_mock(socket, num_ca, l2_ca_arr): "Mock pqos_l2ca_set()." self.assertEqual(socket, 0) self.assertEqual(num_ca, 1) cos = l2_ca_arr[0] self.assertEqual(cos.class_id, 1) self.assertEqual(cos.cdp, 1) self.assertEqual(cos.u.s.data_mask, 0x1f) self.assertEqual(cos.u.s.code_mask, 0x0f) return 0 lib.pqos_l2ca_set = MagicMock(side_effect=pqos_l2ca_set_mock) l2ca = PqosCatL2() cos = l2ca.COS(1, data_mask=u'0x1f', code_mask=0x0f) l2ca.set(0, [cos]) lib.pqos_l2ca_set.assert_called_once()
def test_cos_no_masks(self): "Tests PqosCatL2.COS class construction when no masks are given." with self.assertRaises(ValueError): PqosCatL2.COS(1)