test_ut.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. import os.path
  4. import pytest
  5. @pytest.mark.buildconfigspec('ut_dm')
  6. def test_ut_dm_init(u_boot_console):
  7. """Initialize data for ut dm tests."""
  8. fn = u_boot_console.config.source_dir + '/testflash.bin'
  9. if not os.path.exists(fn):
  10. data = b'this is a test'
  11. data += b'\x00' * ((4 * 1024 * 1024) - len(data))
  12. with open(fn, 'wb') as fh:
  13. fh.write(data)
  14. fn = u_boot_console.config.source_dir + '/spi.bin'
  15. if not os.path.exists(fn):
  16. data = b'\x00' * (2 * 1024 * 1024)
  17. with open(fn, 'wb') as fh:
  18. fh.write(data)
  19. def test_ut(u_boot_console, ut_subtest):
  20. """Execute a "ut" subtest.
  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. u-boot.sym. The list entries are created using the C macro UNIT_TEST().
  24. Strict naming conventions have to be followed to match the regular
  25. expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in
  26. test suite foo that can be executed via command 'ut foo bar' and is
  27. implemented in C function foo_test_bar().
  28. Args:
  29. u_boot_console (ConsoleBase): U-Boot console
  30. ut_subtest (str): test to be executed via command ut, e.g 'foo bar' to
  31. execute command 'ut foo bar'
  32. """
  33. output = u_boot_console.run_command('ut ' + ut_subtest)
  34. assert output.endswith('Failures: 0')