def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) allocator.assign_threads(Workload("a", 2, STATIC)) self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("b", 2, STATIC)) self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.free_threads("b") self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("c", 2, STATIC)) self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.free_threads("a") self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("d", 2, STATIC)) self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))
def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator() workloads = {} workload = get_test_workload("a", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) workload = get_test_workload("b", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) request = AllocateThreadsRequest(cpu, "b", workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads.pop("b") workload = get_test_workload("c", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) request = AllocateThreadsRequest(cpu, "a", workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) workloads.pop("a") workload = get_test_workload("d", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) allocator.assign_threads(request).get_cpu() self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))
def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator() w_a = get_test_workload("a", 2, STATIC) w_b = get_test_workload("b", 2, STATIC) w_c = get_test_workload("c", 2, STATIC) w_d = get_test_workload("d", 2, STATIC) workloads = [w_a] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_a, w_b] request = get_no_usage_threads_request(cpu, workloads) allocator.assign_threads(request).get_cpu() self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_a, w_c] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_c, w_a] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_c, w_d] request = get_no_usage_threads_request(cpu, workloads) allocator.assign_threads(request).get_cpu() self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))