예제 #1
0
    def test_get_emptiest_package(self):
        t0 = Thread(0)
        t1 = Thread(1)
        t2 = Thread(2)
        t3 = Thread(3)
        t4 = Thread(4)
        t5 = Thread(5)
        t6 = Thread(6)
        t7 = Thread(7)

        p0 = Package(0, [Core(0, [t0, t4]), Core(1, [t1, t5])])
        p1 = Package(1, [Core(0, [t2, t6]), Core(1, [t3, t7])])

        cpu = Cpu([p0, p1])

        # The first package should be the emptiest
        self.assertEqual(p0, cpu.get_emptiest_package())

        # The second package should be the emptiest after we claim a thread on the first
        t5.claim(uuid.uuid4())
        self.assertEqual(p1, cpu.get_emptiest_package())

        # The first package should be the emptiest again, after we release the claimed thread
        t5.clear()
        self.assertEqual(p0, cpu.get_emptiest_package())

        # The first package should be emptiest when we claim a thread on the second
        t3.claim(uuid.uuid4())
        self.assertEqual(p0, cpu.get_emptiest_package())

        # When an equal number of threads are claimed on both packages, the first should be returned
        t4.claim(uuid.uuid4())
        self.assertEqual(p0, cpu.get_emptiest_package())
예제 #2
0
    def test_claim(self):
        workload_id = uuid.uuid4()

        t = Thread(42)
        self.assertEqual(0, len(t.get_workload_ids()))

        t.claim(workload_id)
        self.assertEqual(1, len(t.get_workload_ids()))
        self.assertEqual(workload_id, t.get_workload_ids()[0])

        t.clear()
        self.assertEqual(0, len(t.get_workload_ids()))
예제 #3
0
    def test_clear_multiple_claims(self):
        workload_id_a = "a"
        workload_id_b = "b"
        t = Thread(42)

        t.claim(workload_id_a)
        t.claim(workload_id_b)
        self.assertTrue(t.is_claimed())
        self.assertEqual(2, len(t.get_workload_ids()))

        t.clear()
        self.assertFalse(t.is_claimed())
        self.assertEqual(0, len(t.get_workload_ids()))
예제 #4
0
    def test_get_empty_threads(self):
        t0 = Thread(0)
        t1 = Thread(1)
        t2 = Thread(2)
        t3 = Thread(3)

        c0 = Core(0, [t0, t2])
        c1 = Core(1, [t1, t3])

        p = Package(1, [c0, c1])
        self.assertEqual([t0, t2, t1, t3], p.get_empty_threads())

        t1.claim(uuid.uuid4())
        self.assertEqual([t0, t2, t3], p.get_empty_threads())

        t1.clear()
        self.assertEqual([t0, t2, t1, t3], p.get_empty_threads())