blob: 42e4c4342b23c4fc7c5b3b3897e70fb8f3f6058f [file] [log] [blame]
Simon Glassed298be2020-10-25 20:38:31 -06001# SPDX-License-Identifier: GPL-2.0
2# Copyright 2020 Google LLC
3# Written by Simon Glass <sjg@chromium.org>
4
5import os.path
6import pytest
7
Sean Anderson8734d6f2023-10-14 16:48:05 -04008@pytest.mark.buildconfigspec('spl_unit_test')
9def 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 Glassed298be2020-10-25 20:38:31 -060018def 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 Glass8c921ac2020-10-25 20:38:34 -060037 cons.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
Simon Glassed298be2020-10-25 20:38:31 -060038 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()