Esempio n. 1
0
    def test_init(self, lib):
        """
        Tests if the pointer to CPU information object given
        to PQoS library APIs is the same returned from pqos_cap_get() API during
        an initialization of PqosCpuInfo.
        """

        builder = PqosCpuInfoMockBuilder()
        p_cpu = builder.build()

        def pqos_cap_get_mock(_cap_ref, cpu_ref):
            "Mock pqos_cap_get()."

            ctypes.memmove(cpu_ref, ctypes.addressof(p_cpu),
                           ctypes.sizeof(p_cpu))
            return 0

        def pqos_socketid_m(cpu_ref, _core, _socket_ref):
            "Mock pqos_cpu_get_socketid()."

            cpu_ref_addr = ctypes.addressof(cpu_ref.contents)
            p_cpu_addr = ctypes.addressof(p_cpu.contents)
            self.assertEqual(cpu_ref_addr, p_cpu_addr)
            return 1

        lib.pqos_cap_get = MagicMock(side_effect=pqos_cap_get_mock)
        lib.pqos_cpu_get_socketid = MagicMock(side_effect=pqos_socketid_m,
                                              __name__=u'pqos_cpu_get_socketid')

        pqos_cpu = PqosCpuInfo()

        with self.assertRaises(PqosError):
            pqos_cpu.get_socketid(0)

        lib.pqos_cpu_get_socketid.assert_called_once()
        lib.pqos_cap_get.assert_called_once()
Esempio n. 2
0
    def test_init(self, lib):
        """
        Tests if the pointer to CPU information object given
        to PQoS library APIs is the same returned from pqos_cap_get() API during
        an initialization of PqosCpuInfo.
        """

        builder = PqosCpuInfoMockBuilder()
        p_cpu = builder.build()

        def pqos_cap_get_mock(_cap_ref, cpu_ref):
            "Mock pqos_cap_get()."

            ctypes.memmove(cpu_ref, ctypes.addressof(p_cpu),
                           ctypes.sizeof(p_cpu))
            return 0

        def pqos_socketid_m(cpu_ref, _core, _socket_ref):
            "Mock pqos_cpu_get_socketid()."

            cpu_ref_addr = ctypes.addressof(cpu_ref.contents)
            p_cpu_addr = ctypes.addressof(p_cpu.contents)
            self.assertEqual(cpu_ref_addr, p_cpu_addr)
            return 1

        lib.pqos_cap_get = MagicMock(side_effect=pqos_cap_get_mock)
        lib.pqos_cpu_get_socketid = MagicMock(side_effect=pqos_socketid_m,
                                              __name__=u'pqos_cpu_get_socketid')

        pqos_cpu = PqosCpuInfo()

        with self.assertRaises(PqosError):
            pqos_cpu.get_socketid(0)

        lib.pqos_cpu_get_socketid.assert_called_once()
        lib.pqos_cap_get.assert_called_once()
Esempio n. 3
0
    def test_get_socketid(self, lib):
        "Tests get_socketid() method."

        def pqos_get_socketid_m(_p_cpu, core, socket_ref):
            "Mock pqos_cpu_get_socketid()."

            self.assertEqual(core, 3)
            ctypes_ref_set_int(socket_ref, 4)
            return 0

        lib.pqos_cap_get = MagicMock(return_value=0)
        lib.pqos_cpu_get_socketid = MagicMock(side_effect=pqos_get_socketid_m,
                                              __name__=u'pqos_cpu_get_socketid')

        cpu = PqosCpuInfo()
        socket = cpu.get_socketid(3)

        self.assertEqual(socket, 4)

        lib.pqos_cpu_get_socketid.assert_called_once()
Esempio n. 4
0
    def test_get_socketid(self, lib):
        "Tests get_socketid() method."

        def pqos_get_socketid_m(_p_cpu, core, socket_ref):
            "Mock pqos_cpu_get_socketid()."

            self.assertEqual(core, 3)
            ctypes_ref_set_int(socket_ref, 4)
            return 0

        lib.pqos_cap_get = MagicMock(return_value=0)
        lib.pqos_cpu_get_socketid = MagicMock(side_effect=pqos_get_socketid_m,
                                              __name__=u'pqos_cpu_get_socketid')

        cpu = PqosCpuInfo()
        socket = cpu.get_socketid(3)

        self.assertEqual(socket, 4)

        lib.pqos_cpu_get_socketid.assert_called_once()