blob: bbc311df6d11f7b391c37216441a3025f292682f [file] [log] [blame]
Sean Anderson89599922022-12-12 14:12:08 -05001# SPDX-License-Identifier: GPL-2.0+
2# Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
3
4import os
5import pytest
6import u_boot_utils as util
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(u_boot_console):
13 # Compile our test script image
14 cons = u_boot_console
15 mkimage = os.path.join(cons.config.build_dir, 'tools/mkimage')
16 its = os.path.join(cons.config.source_dir, 'test/py/tests/source.its')
17 fit = os.path.join(cons.config.build_dir, 'source.itb')
18 util.run_and_log(cons, (mkimage, '-f', its, fit))
19 cons.run_command(f'host load hostfs - $loadaddr {fit}')
20
Sean Andersonbcc85b92022-12-12 14:12:11 -050021 assert '2' in cons.run_command('source')
22 assert '1' in cons.run_command('source :')
Sean Anderson89599922022-12-12 14:12:08 -050023 assert '1' in cons.run_command('source :script-1')
24 assert '2' in cons.run_command('source :script-2')
25 assert 'Fail' in cons.run_command('source :not-a-script || echo Fail')
Sean Andersonbcc85b92022-12-12 14:12:11 -050026 assert '2' in cons.run_command('source \\#')
27 assert '1' in cons.run_command('source \\#conf-1')
28 assert '2' in cons.run_command('source \\#conf-2')
Sean Anderson89599922022-12-12 14:12:08 -050029
30 cons.run_command('fdt addr $loadaddr')
Sean Andersonbcc85b92022-12-12 14:12:11 -050031 cons.run_command('fdt rm /configurations default')
32 assert '1' in cons.run_command('source')
33 assert 'Fail' in cons.run_command('source \\# || echo Fail')
34
Sean Anderson89599922022-12-12 14:12:08 -050035 cons.run_command('fdt rm /images default')
36 assert 'Fail' in cons.run_command('source || echo Fail')
Sean Andersonbcc85b92022-12-12 14:12:11 -050037 assert 'Fail' in cons.run_command('source \\# || echo Fail')