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