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