1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
3
4import os
5import pytest
6import utils
7
8@pytest.mark.boardspec('sandbox')
9@pytest.mark.buildconfigspec('cmd_echo')
10@pytest.mark.buildconfigspec('cmd_source')
11@pytest.mark.buildconfigspec('fit')
12def test_source(ubman):
13    # Compile our test script image
14    mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
15    its = os.path.join(ubman.config.source_dir, 'test/py/tests/source.its')
16    fit = os.path.join(ubman.config.build_dir, 'source.itb')
17    utils.run_and_log(ubman, (mkimage, '-f', its, fit))
18    ubman.run_command(f'host load hostfs - $loadaddr {fit}')
19
20    assert '2' in ubman.run_command('source')
21    assert '1' in ubman.run_command('source :')
22    assert '1' in ubman.run_command('source :script-1')
23    assert '2' in ubman.run_command('source :script-2')
24    assert 'Fail' in ubman.run_command('source :not-a-script || echo Fail')
25    assert '2' in ubman.run_command('source \\#')
26    assert '1' in ubman.run_command('source \\#conf-1')
27    assert '2' in ubman.run_command('source \\#conf-2')
28
29    ubman.run_command('fdt addr $loadaddr')
30    ubman.run_command('fdt rm /configurations default')
31    assert '1' in ubman.run_command('source')
32    assert 'Fail' in ubman.run_command('source \\# || echo Fail')
33
34    ubman.run_command('fdt rm /images default')
35    assert 'Fail' in ubman.run_command('source || echo Fail')
36    assert 'Fail' in ubman.run_command('source \\# || echo Fail')
37