blob: 70e07503ad3bc76ddff2cff29a396d78e344e4ee [file] [log] [blame]
Frédéric Danis4aacee12020-03-20 10:59:23 +01001# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2020, Collabora
3# Author: Frédéric Danis <frederic.danis@collabora.com>
4
5import pytest
Simon Glassfb916372025-02-09 09:07:15 -07006import utils
Frédéric Danis4aacee12020-03-20 10:59:23 +01007import 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
Simon Glassddba5202025-02-09 09:07:14 -070018def load_pstore(ubman):
Frédéric Danis4aacee12020-03-20 10:59:23 +010019 """Load PStore records from sample files"""
20
Simon Glassddba5202025-02-09 09:07:14 -070021 output = ubman.run_command_list([
Frédéric Danis4aacee12020-03-20 10:59:23 +010022 'host load hostfs - 0x%x %s' % (PSTORE_ADDR,
Simon Glassddba5202025-02-09 09:07:14 -070023 os.path.join(ubman.config.source_dir, PSTORE_PANIC1)),
Frédéric Danis4aacee12020-03-20 10:59:23 +010024 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 4096,
Simon Glassddba5202025-02-09 09:07:14 -070025 os.path.join(ubman.config.source_dir, PSTORE_PANIC2)),
Frédéric Danis4aacee12020-03-20 10:59:23 +010026 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 253 * 4096,
Simon Glassddba5202025-02-09 09:07:14 -070027 os.path.join(ubman.config.source_dir, PSTORE_CONSOLE)),
Frédéric Danis4aacee12020-03-20 10:59:23 +010028 'pstore set 0x%x 0x%x' % (PSTORE_ADDR, PSTORE_LENGTH)])
29
Simon Glassddba5202025-02-09 09:07:14 -070030def checkfile(ubman, path, filesize, checksum):
Frédéric Danis4aacee12020-03-20 10:59:23 +010031 """Check file against MD5 checksum"""
32
Simon Glassddba5202025-02-09 09:07:14 -070033 output = ubman.run_command_list([
Frédéric Danis4aacee12020-03-20 10:59:23 +010034 'load hostfs - %x %s' % (ADDR, path),
35 'printenv filesize'])
36 assert('filesize=%x' % (filesize) in ''.join(output))
37
Simon Glassddba5202025-02-09 09:07:14 -070038 output = ubman.run_command_list([
Frédéric Danis4aacee12020-03-20 10:59:23 +010039 'md5sum %x $filesize' % ADDR,
40 'setenv filesize'])
41 assert(checksum in ''.join(output))
42
43@pytest.mark.buildconfigspec('cmd_pstore')
Simon Glassddba5202025-02-09 09:07:14 -070044def test_pstore_display_all_records(ubman):
Frédéric Danis4aacee12020-03-20 10:59:23 +010045 """Test that pstore displays all records."""
46
Simon Glassddba5202025-02-09 09:07:14 -070047 ubman.run_command('')
48 load_pstore(ubman)
49 response = ubman.run_command('pstore display')
Frédéric Danis4aacee12020-03-20 10:59:23 +010050 assert('**** Dump' in response)
51 assert('**** Console' in response)
52
53@pytest.mark.buildconfigspec('cmd_pstore')
Simon Glassddba5202025-02-09 09:07:14 -070054def test_pstore_display_one_record(ubman):
Frédéric Danis4aacee12020-03-20 10:59:23 +010055 """Test that pstore displays only one record."""
56
Simon Glassddba5202025-02-09 09:07:14 -070057 ubman.run_command('')
58 load_pstore(ubman)
59 response = ubman.run_command('pstore display dump 1')
Frédéric Danis4aacee12020-03-20 10:59:23 +010060 assert('Panic#2 Part1' in response)
61 assert('**** Console' not in response)
62
63@pytest.mark.buildconfigspec('cmd_pstore')
Simon Glassddba5202025-02-09 09:07:14 -070064def test_pstore_save_records(ubman):
Frédéric Danis4aacee12020-03-20 10:59:23 +010065 """Test that pstore saves all records."""
66
67 outdir = tempfile.mkdtemp()
68
Simon Glassddba5202025-02-09 09:07:14 -070069 ubman.run_command('')
70 load_pstore(ubman)
71 ubman.run_command('pstore save hostfs - %s' % (outdir))
Frédéric Danis4aacee12020-03-20 10:59:23 +010072
Simon Glassddba5202025-02-09 09:07:14 -070073 checkfile(ubman, '%s/dmesg-ramoops-0' % (outdir), 3798, '8059335ab4cfa62c77324c491659c503')
74 checkfile(ubman, '%s/dmesg-ramoops-1' % (outdir), 4035, '3ff30df3429d81939c75d0070b5187b9')
75 checkfile(ubman, '%s/console-ramoops-0' % (outdir), 4084, 'bb44de4a9b8ebd9b17ae98003287325b')
Frédéric Danis4aacee12020-03-20 10:59:23 +010076
77 shutil.rmtree(outdir)