1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for the backend registry module."""
from __future__ import annotations
from functools import partial
import pytest
from mlia.backend.config import BackendType
from mlia.backend.config import System
from mlia.backend.registry import registry
from mlia.core.common import AdviceCategory
@pytest.mark.parametrize(
("backend", "advices", "systems", "type_"),
(
(
"ArmNNTFLiteDelegate",
[AdviceCategory.OPERATORS],
None,
BackendType.BUILTIN,
),
(
"Corstone-300",
[AdviceCategory.PERFORMANCE, AdviceCategory.OPTIMIZATION],
[System.LINUX_AMD64],
BackendType.CUSTOM,
),
(
"Corstone-310",
[AdviceCategory.PERFORMANCE, AdviceCategory.OPTIMIZATION],
[System.LINUX_AMD64],
BackendType.CUSTOM,
),
(
"TOSA-Checker",
[AdviceCategory.OPERATORS],
[System.LINUX_AMD64],
BackendType.WHEEL,
),
(
"Vela",
[
AdviceCategory.OPERATORS,
AdviceCategory.PERFORMANCE,
AdviceCategory.OPTIMIZATION,
],
[
System.LINUX_AMD64,
System.LINUX_AARCH64,
System.WINDOWS_AMD64,
System.WINDOWS_AARCH64,
],
BackendType.BUILTIN,
),
),
)
def test_backend_registry(
backend: str,
advices: list[AdviceCategory],
systems: list[System] | None,
type_: BackendType,
) -> None:
"""Test the backend registry."""
sorted_by_name = partial(sorted, key=lambda x: x.name)
assert backend in registry.items
cfg = registry.items[backend]
assert sorted_by_name(advices) == sorted_by_name(
cfg.supported_advice
), f"Advices differs: {advices} != {cfg.supported_advice}"
if systems is None:
assert cfg.supported_systems is None
else:
assert cfg.supported_systems is not None
assert sorted_by_name(systems) == sorted_by_name(
cfg.supported_systems
), f"Supported systems differs: {advices} != {cfg.supported_advice}"
assert cfg.type == type_
|