Ejemplo n.º 1
0
    def test_only_one_linker_script(self):
        """
        Verify that when multiple linker scripts are added to a resource object,
        only the last one added is used.
        """
        resources = Resources(MockNotifier())
        linker_scripts = [
            "first_linker_script.sct", "second_linker_script.sct"
        ]
        for linker_script in linker_scripts:
            resources.add_file_ref(FileType.LD_SCRIPT, linker_script,
                                   linker_script)

        assert (len(resources.get_file_refs(FileType.LD_SCRIPT)) == 1)
        assert (resources.get_file_refs(
            FileType.LD_SCRIPT)[-1].name == linker_scripts[-1])
        assert (resources.get_file_refs(
            FileType.LD_SCRIPT)[-1].path == linker_scripts[-1])
Ejemplo n.º 2
0
def test_find_secure_image():
    mock_notifier = MockNotifier()
    mock_resources = Resources(mock_notifier)
    ns_image_path = os.path.join('BUILD', 'TARGET_NS', 'app.bin')
    ns_test_path = os.path.join('BUILD', 'TARGET_NS', 'test.bin')
    config_s_image_name = 'target_config.bin'
    default_bin = os.path.join('prebuilt', config_s_image_name)
    test_bin = os.path.join('prebuilt', 'test.bin')

    with pytest.raises(
            Exception,
            match='ns_image_path and configured_s_image_path are mandatory'):
        find_secure_image(mock_notifier, mock_resources, None, None,
                          FileType.BIN)
        find_secure_image(mock_notifier, mock_resources, ns_image_path, None,
                          FileType.BIN)
        find_secure_image(mock_notifier, mock_resources, None,
                          config_s_image_name, FileType.BIN)

    with pytest.raises(Exception,
                       match='image_type must be of type BIN or HEX'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, None)
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.C_SRC)

    with pytest.raises(Exception,
                       match='No image files found for this target'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.BIN)

    dummy_bin = os.path.join('path', 'to', 'dummy.bin')
    mock_resources.add_file_ref(FileType.BIN, dummy_bin, dummy_bin)

    with pytest.raises(Exception, match='Required secure image not found'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.BIN)

    mock_resources.add_file_ref(FileType.BIN, default_bin, default_bin)
    mock_resources.add_file_ref(FileType.BIN, test_bin, test_bin)
    secure_image = find_secure_image(mock_notifier, mock_resources,
                                     ns_image_path, config_s_image_name,
                                     FileType.BIN)
    assert secure_image == default_bin

    secure_image = find_secure_image(mock_notifier, mock_resources,
                                     ns_test_path, config_s_image_name,
                                     FileType.BIN)
    assert secure_image == test_bin