xref: /rk3399_rockchip-uboot/test/py/tests/test_gpt.py (revision e2c5d1e4e7230a53c9703120cc8bbe11e74f7f0b)
1*e2c5d1e4SAlison Chaiken# Copyright (c) 2017 Alison Chaiken
2*e2c5d1e4SAlison Chaiken#
3*e2c5d1e4SAlison Chaiken# SPDX-License-Identifier: GPL-2.0
4*e2c5d1e4SAlison Chaiken
5*e2c5d1e4SAlison Chaiken# Test GPT manipulation commands.
6*e2c5d1e4SAlison Chaiken
7*e2c5d1e4SAlison Chaikenimport os
8*e2c5d1e4SAlison Chaikenimport pytest
9*e2c5d1e4SAlison Chaikenimport u_boot_utils
10*e2c5d1e4SAlison Chaikenimport make_test_disk
11*e2c5d1e4SAlison Chaiken
12*e2c5d1e4SAlison Chaiken"""
13*e2c5d1e4SAlison ChaikenThese tests rely on a 4 MB block device called testdisk.raw
14*e2c5d1e4SAlison Chaikenwhich is automatically removed at the end of the tests.
15*e2c5d1e4SAlison Chaiken"""
16*e2c5d1e4SAlison Chaiken
17*e2c5d1e4SAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
18*e2c5d1e4SAlison Chaikendef test_gpt_guid(u_boot_console):
19*e2c5d1e4SAlison Chaiken    """Test the gpt guid command."""
20*e2c5d1e4SAlison Chaiken
21*e2c5d1e4SAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
22*e2c5d1e4SAlison Chaiken        pytest.skip('gpt command not supported')
23*e2c5d1e4SAlison Chaiken    make_test_disk.makeDisk()
24*e2c5d1e4SAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
25*e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('gpt guid host 0')
26*e2c5d1e4SAlison Chaiken    assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
27*e2c5d1e4SAlison Chaiken
28*e2c5d1e4SAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
29*e2c5d1e4SAlison Chaikendef test_gpt_save_guid(u_boot_console):
30*e2c5d1e4SAlison Chaiken    """Test the gpt guid command to save GUID into a string."""
31*e2c5d1e4SAlison Chaiken
32*e2c5d1e4SAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
33*e2c5d1e4SAlison Chaiken        pytest.skip('gpt command not supported')
34*e2c5d1e4SAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
35*e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('gpt guid host 0 newguid')
36*e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('printenv newguid')
37*e2c5d1e4SAlison Chaiken    assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
38*e2c5d1e4SAlison Chaiken    os.remove('testdisk.raw')
39