test_pstore.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2020, Collabora
  3. # Author: Frédéric Danis <frederic.danis@collabora.com>
  4. import pytest
  5. import u_boot_utils
  6. import os
  7. import tempfile
  8. import shutil
  9. PSTORE_ADDR=0x3000000
  10. PSTORE_LENGTH=0x100000
  11. PSTORE_PANIC1='test/py/tests/test_pstore_data_panic1.hex'
  12. PSTORE_PANIC2='test/py/tests/test_pstore_data_panic2.hex'
  13. PSTORE_CONSOLE='test/py/tests/test_pstore_data_console.hex'
  14. ADDR=0x01000008
  15. def load_pstore(u_boot_console):
  16. """Load PStore records from sample files"""
  17. output = u_boot_console.run_command_list([
  18. 'host load hostfs - 0x%x %s' % (PSTORE_ADDR,
  19. os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC1)),
  20. 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 4096,
  21. os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC2)),
  22. 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 253 * 4096,
  23. os.path.join(u_boot_console.config.source_dir, PSTORE_CONSOLE)),
  24. 'pstore set 0x%x 0x%x' % (PSTORE_ADDR, PSTORE_LENGTH)])
  25. def checkfile(u_boot_console, path, filesize, checksum):
  26. """Check file against MD5 checksum"""
  27. output = u_boot_console.run_command_list([
  28. 'load hostfs - %x %s' % (ADDR, path),
  29. 'printenv filesize'])
  30. assert('filesize=%x' % (filesize) in ''.join(output))
  31. output = u_boot_console.run_command_list([
  32. 'md5sum %x $filesize' % ADDR,
  33. 'setenv filesize'])
  34. assert(checksum in ''.join(output))
  35. @pytest.mark.buildconfigspec('cmd_pstore')
  36. def test_pstore_display_all_records(u_boot_console):
  37. """Test that pstore displays all records."""
  38. u_boot_console.run_command('')
  39. load_pstore(u_boot_console)
  40. response = u_boot_console.run_command('pstore display')
  41. assert('**** Dump' in response)
  42. assert('**** Console' in response)
  43. @pytest.mark.buildconfigspec('cmd_pstore')
  44. def test_pstore_display_one_record(u_boot_console):
  45. """Test that pstore displays only one record."""
  46. u_boot_console.run_command('')
  47. load_pstore(u_boot_console)
  48. response = u_boot_console.run_command('pstore display dump 1')
  49. assert('Panic#2 Part1' in response)
  50. assert('**** Console' not in response)
  51. @pytest.mark.buildconfigspec('cmd_pstore')
  52. def test_pstore_save_records(u_boot_console):
  53. """Test that pstore saves all records."""
  54. outdir = tempfile.mkdtemp()
  55. u_boot_console.run_command('')
  56. load_pstore(u_boot_console)
  57. u_boot_console.run_command('pstore save hostfs - %s' % (outdir))
  58. checkfile(u_boot_console, '%s/dmesg-ramoops-0' % (outdir), 3798, '8059335ab4cfa62c77324c491659c503')
  59. checkfile(u_boot_console, '%s/dmesg-ramoops-1' % (outdir), 4035, '3ff30df3429d81939c75d0070b5187b9')
  60. checkfile(u_boot_console, '%s/console-ramoops-0' % (outdir), 4084, 'bb44de4a9b8ebd9b17ae98003287325b')
  61. shutil.rmtree(outdir)