Sean Anderson | 8959992 | 2022-12-12 14:12:08 -0500 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | # Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com> |
| 3 | |
| 4 | import os |
| 5 | import pytest |
| 6 | import 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') |
| 12 | def 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 Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 21 | assert '2' in cons.run_command('source') |
| 22 | assert '1' in cons.run_command('source :') |
Sean Anderson | 8959992 | 2022-12-12 14:12:08 -0500 | [diff] [blame] | 23 | 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 Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 26 | 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 Anderson | 8959992 | 2022-12-12 14:12:08 -0500 | [diff] [blame] | 29 | |
| 30 | cons.run_command('fdt addr $loadaddr') |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 31 | 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 Anderson | 8959992 | 2022-12-12 14:12:08 -0500 | [diff] [blame] | 35 | cons.run_command('fdt rm /images default') |
| 36 | assert 'Fail' in cons.run_command('source || echo Fail') |
Sean Anderson | bcc85b9 | 2022-12-12 14:12:11 -0500 | [diff] [blame] | 37 | assert 'Fail' in cons.run_command('source \\# || echo Fail') |