|
| 1 | +# Copyright (c) 2019 ARM Limited |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import pytest |
| 18 | +import os |
| 19 | +from tools.notifier.mock import MockNotifier |
| 20 | +from tools.resources import Resources, FileType |
| 21 | +from tools.psa import find_secure_image |
| 22 | + |
| 23 | + |
| 24 | +def test_find_secure_image(): |
| 25 | + mock_notifier = MockNotifier() |
| 26 | + mock_resources = Resources(mock_notifier) |
| 27 | + ns_image_path = os.path.join('BUILD', 'TARGET_NS', 'app.bin') |
| 28 | + ns_test_path = os.path.join('BUILD', 'TARGET_NS', 'test.bin') |
| 29 | + config_s_image_name = 'target_config.bin' |
| 30 | + default_bin = os.path.join('prebuilt', config_s_image_name) |
| 31 | + test_bin = os.path.join('prebuilt', 'test.bin') |
| 32 | + |
| 33 | + with pytest.raises(Exception, match='ns_image_path and configured_s_image_path are mandatory'): |
| 34 | + find_secure_image(mock_notifier, mock_resources, None, None, FileType.BIN) |
| 35 | + find_secure_image(mock_notifier, mock_resources, ns_image_path, None, FileType.BIN) |
| 36 | + find_secure_image(mock_notifier, mock_resources, None, config_s_image_name, FileType.BIN) |
| 37 | + |
| 38 | + with pytest.raises(Exception, match='image_type must be of type BIN or HEX'): |
| 39 | + find_secure_image(mock_notifier, mock_resources, ns_image_path, config_s_image_name, None) |
| 40 | + find_secure_image(mock_notifier, mock_resources, ns_image_path, config_s_image_name, FileType.C_SRC) |
| 41 | + |
| 42 | + with pytest.raises(Exception, match='No image files found for this target'): |
| 43 | + find_secure_image(mock_notifier, mock_resources, ns_image_path, config_s_image_name, FileType.BIN) |
| 44 | + |
| 45 | + dummy_bin = os.path.join('path', 'to', 'dummy.bin') |
| 46 | + mock_resources.add_file_ref(FileType.BIN, dummy_bin, dummy_bin) |
| 47 | + |
| 48 | + with pytest.raises(Exception, match='Required secure image not found'): |
| 49 | + find_secure_image(mock_notifier, mock_resources, ns_image_path, config_s_image_name, FileType.BIN) |
| 50 | + |
| 51 | + mock_resources.add_file_ref(FileType.BIN, default_bin, default_bin) |
| 52 | + mock_resources.add_file_ref(FileType.BIN, test_bin, test_bin) |
| 53 | + secure_image = find_secure_image(mock_notifier, mock_resources, ns_image_path, config_s_image_name, FileType.BIN) |
| 54 | + assert secure_image == default_bin |
| 55 | + |
| 56 | + secure_image = find_secure_image(mock_notifier, mock_resources, ns_test_path, config_s_image_name, FileType.BIN) |
| 57 | + assert secure_image == test_bin |
0 commit comments