Stephen Warren | 1cd85f5 | 2016-02-08 14:44:16 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 1cd85f5 | 2016-02-08 14:44:16 -0700 | [diff] [blame] | 3 | |
| 4 | import os.path |
| 5 | import pytest |
| 6 | |
| 7 | @pytest.mark.buildconfigspec('ut_dm') |
| 8 | def test_ut_dm_init(u_boot_console): |
| 9 | """Initialize data for ut dm tests.""" |
| 10 | |
| 11 | fn = u_boot_console.config.source_dir + '/testflash.bin' |
| 12 | if not os.path.exists(fn): |
Tom Rini | 8060209 | 2019-10-24 11:59:22 -0400 | [diff] [blame] | 13 | data = b'this is a test' |
| 14 | data += b'\x00' * ((4 * 1024 * 1024) - len(data)) |
Stephen Warren | 1cd85f5 | 2016-02-08 14:44:16 -0700 | [diff] [blame] | 15 | with open(fn, 'wb') as fh: |
| 16 | fh.write(data) |
| 17 | |
| 18 | fn = u_boot_console.config.source_dir + '/spi.bin' |
| 19 | if not os.path.exists(fn): |
Tom Rini | 8060209 | 2019-10-24 11:59:22 -0400 | [diff] [blame] | 20 | data = b'\x00' * (2 * 1024 * 1024) |
Stephen Warren | 1cd85f5 | 2016-02-08 14:44:16 -0700 | [diff] [blame] | 21 | with open(fn, 'wb') as fh: |
| 22 | fh.write(data) |
| 23 | |
| 24 | def test_ut(u_boot_console, ut_subtest): |
Heinrich Schuchardt | d0ba026 | 2020-05-06 18:26:07 +0200 | [diff] [blame] | 25 | """Execute a "ut" subtest. |
| 26 | |
| 27 | The subtests are collected in function generate_ut_subtest() from linker |
| 28 | generated lists by applying a regular expression to the lines of file |
| 29 | u-boot.sym. The list entries are created using the C macro UNIT_TEST(). |
| 30 | |
| 31 | Strict naming conventions have to be followed to match the regular |
| 32 | expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in |
| 33 | test suite foo that can be executed via command 'ut foo bar' and is |
| 34 | implemented in C function foo_test_bar(). |
| 35 | |
| 36 | Args: |
| 37 | u_boot_console (ConsoleBase): U-Boot console |
| 38 | ut_subtest (str): test to be executed via command ut, e.g 'foo bar' to |
| 39 | execute command 'ut foo bar' |
| 40 | """ |
Stephen Warren | 1cd85f5 | 2016-02-08 14:44:16 -0700 | [diff] [blame] | 41 | |
| 42 | output = u_boot_console.run_command('ut ' + ut_subtest) |
| 43 | assert output.endswith('Failures: 0') |