xref: /aosp_15_r20/external/armnn/python/pyarmnn/conftest.py (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1*89c4ff92SAndroid Build Coastguard Worker# Copyright © 2020 Arm Ltd. All rights reserved.
2*89c4ff92SAndroid Build Coastguard Worker# SPDX-License-Identifier: MIT
3*89c4ff92SAndroid Build Coastguard Workerimport os
4*89c4ff92SAndroid Build Coastguard Workerimport platform
5*89c4ff92SAndroid Build Coastguard Worker
6*89c4ff92SAndroid Build Coastguard Workerimport pytest
7*89c4ff92SAndroid Build Coastguard Worker
8*89c4ff92SAndroid Build Coastguard WorkerARCHITECTURES = set("x86_64 aarch64".split())
9*89c4ff92SAndroid Build Coastguard Worker
10*89c4ff92SAndroid Build Coastguard Worker
11*89c4ff92SAndroid Build Coastguard Worker@pytest.fixture(scope="module")
12*89c4ff92SAndroid Build Coastguard Workerdef data_folder_per_test(request):
13*89c4ff92SAndroid Build Coastguard Worker    """
14*89c4ff92SAndroid Build Coastguard Worker        This fixture returns path to folder with test resources (one per test module)
15*89c4ff92SAndroid Build Coastguard Worker    """
16*89c4ff92SAndroid Build Coastguard Worker
17*89c4ff92SAndroid Build Coastguard Worker    basedir, script = request.fspath.dirname, request.fspath.basename
18*89c4ff92SAndroid Build Coastguard Worker    return str(os.path.join(basedir, "testdata", os.path.splitext(script)[0]))
19*89c4ff92SAndroid Build Coastguard Worker
20*89c4ff92SAndroid Build Coastguard Worker
21*89c4ff92SAndroid Build Coastguard Worker@pytest.fixture(scope="module")
22*89c4ff92SAndroid Build Coastguard Workerdef shared_data_folder(request):
23*89c4ff92SAndroid Build Coastguard Worker    """
24*89c4ff92SAndroid Build Coastguard Worker        This fixture returns path to folder with shared test resources among all tests
25*89c4ff92SAndroid Build Coastguard Worker    """
26*89c4ff92SAndroid Build Coastguard Worker
27*89c4ff92SAndroid Build Coastguard Worker    return str(os.path.join(request.fspath.dirname, "testdata", "shared"))
28*89c4ff92SAndroid Build Coastguard Worker
29*89c4ff92SAndroid Build Coastguard Worker
30*89c4ff92SAndroid Build Coastguard Worker@pytest.fixture(scope="function")
31*89c4ff92SAndroid Build Coastguard Workerdef tmpdir(tmpdir):
32*89c4ff92SAndroid Build Coastguard Worker    """
33*89c4ff92SAndroid Build Coastguard Worker        This fixture returns path to temp folder. Fixture was added for py35 compatibility
34*89c4ff92SAndroid Build Coastguard Worker    """
35*89c4ff92SAndroid Build Coastguard Worker
36*89c4ff92SAndroid Build Coastguard Worker    return str(tmpdir)
37*89c4ff92SAndroid Build Coastguard Worker
38*89c4ff92SAndroid Build Coastguard Worker
39*89c4ff92SAndroid Build Coastguard Workerdef pytest_runtest_setup(item):
40*89c4ff92SAndroid Build Coastguard Worker    supported_architectures = ARCHITECTURES.intersection(mark.name for mark in item.iter_markers())
41*89c4ff92SAndroid Build Coastguard Worker    arch = platform.machine()
42*89c4ff92SAndroid Build Coastguard Worker    if supported_architectures and arch not in supported_architectures:
43*89c4ff92SAndroid Build Coastguard Worker        pytest.skip("cannot run on platform {}".format(arch))
44*89c4ff92SAndroid Build Coastguard Worker
45*89c4ff92SAndroid Build Coastguard Worker
46*89c4ff92SAndroid Build Coastguard Workerdef pytest_configure(config):
47*89c4ff92SAndroid Build Coastguard Worker    config.addinivalue_line(
48*89c4ff92SAndroid Build Coastguard Worker        "markers", "aarch64: mark test to run only on aarch64"
49*89c4ff92SAndroid Build Coastguard Worker    )
50*89c4ff92SAndroid Build Coastguard Worker    config.addinivalue_line(
51*89c4ff92SAndroid Build Coastguard Worker        "markers", "x86_64: mark test to run only on x86_64"
52*89c4ff92SAndroid Build Coastguard Worker    )