Simon Glass | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # Copyright 2020 Google LLC |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | |
| 5 | import os.path |
| 6 | import pytest |
| 7 | |
Sean Anderson | 8734d6f | 2023-10-14 16:48:05 -0400 | [diff] [blame] | 8 | @pytest.mark.buildconfigspec('spl_unit_test') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 9 | def test_ut_spl_init(ubman): |
Sean Anderson | 8734d6f | 2023-10-14 16:48:05 -0400 | [diff] [blame] | 10 | """Initialize data for ut spl tests.""" |
| 11 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 12 | fn = ubman.config.source_dir + '/spi.bin' |
Sean Anderson | 8734d6f | 2023-10-14 16:48:05 -0400 | [diff] [blame] | 13 | if not os.path.exists(fn): |
| 14 | data = b'\x00' * (2 * 1024 * 1024) |
| 15 | with open(fn, 'wb') as fh: |
| 16 | fh.write(data) |
| 17 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 18 | def test_spl(ubman, ut_spl_subtest): |
Simon Glass | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 19 | """Execute a "ut" subtest. |
| 20 | |
| 21 | The subtests are collected in function generate_ut_subtest() from linker |
| 22 | generated lists by applying a regular expression to the lines of file |
| 23 | spl/u-boot-spl.sym. The list entries are created using the C macro |
| 24 | UNIT_TEST(). |
| 25 | |
| 26 | Strict naming conventions have to be followed to match the regular |
| 27 | expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in |
| 28 | test suite foo that can be executed via command 'ut foo bar' and is |
| 29 | implemented in C function foo_test_bar(). |
| 30 | |
| 31 | Args: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 32 | ubman (ConsoleBase): U-Boot console |
Simon Glass | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 33 | ut_subtest (str): SPL test to be executed (e.g. 'dm platdata_phandle') |
| 34 | """ |
| 35 | try: |
Simon Glass | 3270111 | 2025-02-09 09:07:17 -0700 | [diff] [blame] | 36 | ubman.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]]) |
| 37 | output = ubman.get_spawn_output().replace('\r', '') |
Simon Glass | 1f271dc | 2025-01-20 14:26:01 -0700 | [diff] [blame] | 38 | assert 'failures: 0' in output |
Simon Glass | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 39 | finally: |
| 40 | # Restart afterward in case a non-SPL test is run next. This should not |
| 41 | # happen since SPL tests are run in their own invocation of test.py, but |
| 42 | # the cost of doing this is not too great at present. |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 43 | ubman.restart_uboot() |