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') |
| 9 | def test_ut_spl_init(u_boot_console): |
| 10 | """Initialize data for ut spl tests.""" |
| 11 | |
| 12 | fn = u_boot_console.config.source_dir + '/spi.bin' |
| 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 | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 18 | def test_spl(u_boot_console, ut_spl_subtest): |
| 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: |
| 32 | u_boot_console (ConsoleBase): U-Boot console |
| 33 | ut_subtest (str): SPL test to be executed (e.g. 'dm platdata_phandle') |
| 34 | """ |
| 35 | try: |
| 36 | cons = u_boot_console |
Simon Glass | 8c921ac | 2020-10-25 20:38:34 -0600 | [diff] [blame] | 37 | cons.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]]) |
Simon Glass | ed298be | 2020-10-25 20:38:31 -0600 | [diff] [blame] | 38 | output = cons.get_spawn_output().replace('\r', '') |
| 39 | assert 'Failures: 0' in output |
| 40 | finally: |
| 41 | # Restart afterward in case a non-SPL test is run next. This should not |
| 42 | # happen since SPL tests are run in their own invocation of test.py, but |
| 43 | # the cost of doing this is not too great at present. |
| 44 | u_boot_console.restart_uboot() |