def test_allocations_generate_metrics(tasks_allocations, expected_metrics): """Check that proper allocations metrics are generated. """ containers = {task('/t1'): container('/t1'), task('/t2'): container('/t2'), } platform_mock.rdt_information.rdt_mb_control_enabled = True allocations_values = TasksAllocationsValues.create( True, tasks_allocations, containers, platform_mock) allocations_values.validate() metrics_got = allocations_values.generate_metrics() assert metrics_got == expected_metrics
def test_convert_invalid_task_allocations(tasks_allocations, expected_error): """After allocations are converted, check that for improper input values proper validation exception with appropriate message is raised.""" containers = {task('/t1'): container('/t1'), task('/t2'): container('/t2'), task('/t3'): container('/t3'), } with pytest.raises(InvalidAllocations, match=expected_error): got_allocations_values = TasksAllocationsValues.create( True, tasks_allocations, containers, platform_mock) got_allocations_values.validate()
def test_unique_rdt_allocations(tasks_allocations, expected_resgroup_reallocation_count): """Checks if allocation of resctrl group is performed only once if more than one task_allocations has RDTAllocation with the same name. In other words, check if unnecessary reallocation of resctrl group does not take place. The goal is achieved by checking how many times Container.write_schemata is called with allocate_rdt=True.""" containers = {task('/t1'): container('/t1', resgroup_name='', with_config=True), task('/t2'): container('/t2', resgroup_name='', with_config=True)} allocations_values = TasksAllocationsValues.create( True, tasks_allocations, containers, platform_mock) allocations_values.validate() with patch('wca.resctrl.ResGroup.write_schemata') as mock, \ patch('wca.cgroups.Cgroup._write'), patch('wca.cgroups.Cgroup._read'): allocations_values.perform_allocations() assert mock.call_count == expected_resgroup_reallocation_count