xref: /aosp_15_r20/external/armnn/python/pyarmnn/examples/tests/conftest.py (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1# Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
2# SPDX-License-Identifier: MIT
3
4import os
5import ntpath
6
7import urllib.request
8import zipfile
9import pytest
10
11script_dir = os.path.dirname(__file__)
12
13
14@pytest.fixture(scope="session")
15def test_data_folder():
16    """
17        This fixture returns path to folder with shared test resources among all tests
18    """
19
20    data_dir = os.path.join(script_dir, "testdata")
21    if not os.path.exists(data_dir):
22        os.mkdir(data_dir)
23
24    sys_arch = os.uname().machine
25    if sys_arch == "x86_64":
26        libarmnn_url = "https://github.com/ARM-software/armnn/releases/download/v21.11/ArmNN-linux-x86_64.tar.gz"
27    else:
28        libarmnn_url = "https://github.com/ARM-software/armnn/releases/download/v21.11/ArmNN-linux-aarch64.tar.gz"
29
30
31    files_to_download = ["https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/messi5.jpg",
32                         "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/basketball1.png",
33                         "https://raw.githubusercontent.com/opencv/opencv/4.0.0/samples/data/Megamind.avi",
34                         "https://github.com/ARM-software/ML-zoo/raw/master/models/object_detection/ssd_mobilenet_v1/tflite_uint8/ssd_mobilenet_v1.tflite",
35                         "https://git.mlplatform.org/ml/ethos-u/ml-embedded-evaluation-kit.git/plain/resources/kws/samples/yes.wav",
36                         "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-speech-sdk/master/sampledata/audiofiles/myVoiceIsMyPassportVerifyMe04.wav",
37                         "https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/int8/prediction/1?lite-format=tflite",
38                         "https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/int8/transfer/1?lite-format=tflite",
39                         libarmnn_url
40                         ]
41
42    for file in files_to_download:
43        path, filename = ntpath.split(file)
44        if filename == '1?lite-format=tflite' and 'prediction' in file:
45            filename = 'style_predict.tflite'
46        elif filename == '1?lite-format=tflite' and 'transfer' in file:
47            filename = 'style_transfer.tflite'
48        file_path = os.path.join(data_dir, filename)
49        if not os.path.exists(file_path):
50            print("\nDownloading test file: " + file_path + "\n")
51            urllib.request.urlretrieve(file, file_path)
52
53    path, filename = ntpath.split(libarmnn_url)
54    file_path = os.path.join(data_dir, filename)
55    os.system(f"tar -xvzf {file_path} -C {data_dir} ")
56
57    return data_dir
58