1# SPDX-License-Identifier: GPL-2.0 2# (C) Copyright 2023, Advanced Micro Devices, Inc. 3 4""" 5Test the bootstage command. 6 7It is used for checking the boot progress and timing by printing the bootstage 8report, stashes the data into memory and unstashes the data from memory. 9 10Note: This test relies on boardenv_* containing configuration values to define 11the data size, memory address, and bootstage magic address (defined in 12common/bootstage.c). Without this, bootstage stash and unstash tests will be 13automatically skipped. 14 15For example: 16 17.. code-block:: python 18 19 env__bootstage_cmd_file = { 20 'addr': 0x200000, 21 'size': 0x1000, 22 'bootstage_magic_addr': 0xb00757a3, 23 } 24""" 25 26import pytest 27 28@pytest.mark.buildconfigspec('bootstage') 29@pytest.mark.buildconfigspec('cmd_bootstage') 30def test_bootstage_report(ubman): 31 """Test the bootstage report subcommand 32 33 This will run the 'bootstage report' subcommand and ensure that we are 34 reporting: 35 36 - A timer summary in microseconds 37 - The accumulated time 38 - That at least the phrase 'dm_r' is in the output 39 40 Note that the time values are not checked. 41 """ 42 output = ubman.run_command('bootstage report') 43 assert 'Timer summary in microseconds' in output 44 assert 'Accumulated time:' in output 45 assert 'dm_r' in output 46 47@pytest.mark.buildconfigspec('bootstage') 48@pytest.mark.buildconfigspec('cmd_bootstage') 49@pytest.mark.buildconfigspec('bootstage_stash') 50def test_bootstage_stash_and_unstash(ubman): 51 """Test the bootstage stash and unstash subcommands 52 53 After checking that we have configured an environment file to use, we will 54 use the stash subcommand to save information. Then we will use the md 55 command to verify the contents in memory. Finally we confirm the unstash 56 subcommand runs successfully. 57 """ 58 f = ubman.config.env.get('env__bootstage_cmd_file', None) 59 if not f: 60 pytest.skip('No bootstage environment file is defined') 61 62 addr = f.get('addr') 63 size = f.get('size') 64 bootstage_magic = f.get('bootstage_magic_addr') 65 expected_text = 'dm_r' 66 67 ubman.run_command('bootstage stash %x %x' % (addr, size)) 68 output = ubman.run_command('echo $?') 69 assert output.endswith('0') 70 71 output = ubman.run_command('md %x 100' % addr) 72 73 # Check BOOTSTAGE_MAGIC address at 4th byte address 74 assert '0x' + output.split('\n')[0].split()[4] == hex(bootstage_magic) 75 76 # Check expected string in last column of output 77 output_last_col = ''.join([i.split()[-1] for i in output.split('\n')]) 78 assert expected_text in output_last_col 79 80 # Check that unstash works as expected 81 ubman.run_command('bootstage unstash %x %x' % (addr, size)) 82 output = ubman.run_command('echo $?') 83 assert output.endswith('0') 84