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