blob: 484073990397fa027bbea5792c57b72626bdc091 [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')
Simon Glassddba5202025-02-09 09:07:14 -07009def test_ut_spl_init(ubman):
Sean Anderson8734d6f2023-10-14 16:48:05 -040010 """Initialize data for ut spl tests."""
11
Simon Glassddba5202025-02-09 09:07:14 -070012 fn = ubman.config.source_dir + '/spi.bin'
Sean Anderson8734d6f2023-10-14 16:48:05 -040013 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 Glassddba5202025-02-09 09:07:14 -070018def test_spl(ubman, ut_spl_subtest):
Simon Glassed298be2020-10-25 20:38:31 -060019 """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 Glassddba5202025-02-09 09:07:14 -070032 ubman (ConsoleBase): U-Boot console
Simon Glassed298be2020-10-25 20:38:31 -060033 ut_subtest (str): SPL test to be executed (e.g. 'dm platdata_phandle')
34 """
35 try:
Simon Glass32701112025-02-09 09:07:17 -070036 ubman.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
37 output = ubman.get_spawn_output().replace('\r', '')
Simon Glass1f271dc2025-01-20 14:26:01 -070038 assert 'failures: 0' in output
Simon Glassed298be2020-10-25 20:38:31 -060039 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 Glassddba5202025-02-09 09:07:14 -070043 ubman.restart_uboot()