xref: /rk3399_rockchip-uboot/test/py/tests/test_gpt.py (revision 135b53be98703ef12b8d891407bd0f72ee7dc30c)
1e2c5d1e4SAlison Chaiken# Copyright (c) 2017 Alison Chaiken
2e2c5d1e4SAlison Chaiken#
3e2c5d1e4SAlison Chaiken# SPDX-License-Identifier: GPL-2.0
4e2c5d1e4SAlison Chaiken
5e2c5d1e4SAlison Chaiken# Test GPT manipulation commands.
6e2c5d1e4SAlison Chaiken
7e2c5d1e4SAlison Chaikenimport os
8e2c5d1e4SAlison Chaikenimport pytest
9e2c5d1e4SAlison Chaikenimport u_boot_utils
10e2c5d1e4SAlison Chaikenimport make_test_disk
11e2c5d1e4SAlison Chaiken
12e2c5d1e4SAlison Chaiken"""
13e2c5d1e4SAlison ChaikenThese tests rely on a 4 MB block device called testdisk.raw
14e2c5d1e4SAlison Chaikenwhich is automatically removed at the end of the tests.
15e2c5d1e4SAlison Chaiken"""
16e2c5d1e4SAlison Chaiken
17e2c5d1e4SAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
18e2c5d1e4SAlison Chaikendef test_gpt_guid(u_boot_console):
19e2c5d1e4SAlison Chaiken    """Test the gpt guid command."""
20e2c5d1e4SAlison Chaiken
21e2c5d1e4SAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
22e2c5d1e4SAlison Chaiken        pytest.skip('gpt command not supported')
23e2c5d1e4SAlison Chaiken    make_test_disk.makeDisk()
24e2c5d1e4SAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
25e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('gpt guid host 0')
26e2c5d1e4SAlison Chaiken    assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
27e2c5d1e4SAlison Chaiken
28e2c5d1e4SAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
29e2c5d1e4SAlison Chaikendef test_gpt_save_guid(u_boot_console):
30e2c5d1e4SAlison Chaiken    """Test the gpt guid command to save GUID into a string."""
31e2c5d1e4SAlison Chaiken
32e2c5d1e4SAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
33e2c5d1e4SAlison Chaiken        pytest.skip('gpt command not supported')
34e2c5d1e4SAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
35e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('gpt guid host 0 newguid')
36e2c5d1e4SAlison Chaiken    output = u_boot_console.run_command('printenv newguid')
37e2c5d1e4SAlison Chaiken    assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
38*135b53beSAlison Chaiken
39*135b53beSAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
40*135b53beSAlison Chaikendef test_gpt_rename_partition(u_boot_console):
41*135b53beSAlison Chaiken    """Test the gpt rename command to write partition names."""
42*135b53beSAlison Chaiken
43*135b53beSAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 'y':
44*135b53beSAlison Chaiken        pytest.skip('gpt rename command not supported')
45*135b53beSAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
46*135b53beSAlison Chaiken    u_boot_console.run_command('gpt rename host 0 1 first')
47*135b53beSAlison Chaiken    output = u_boot_console.run_command('gpt read host 0')
48*135b53beSAlison Chaiken    assert 'name first' in output
49*135b53beSAlison Chaiken    u_boot_console.run_command('gpt rename host 0 2 second')
50*135b53beSAlison Chaiken    output = u_boot_console.run_command('gpt read host 0')
51*135b53beSAlison Chaiken    assert 'name second' in output
52*135b53beSAlison Chaiken
53*135b53beSAlison Chaiken@pytest.mark.buildconfigspec('cmd_gpt')
54*135b53beSAlison Chaikendef test_gpt_swap_partitions(u_boot_console):
55*135b53beSAlison Chaiken    """Test the gpt swap command to exchange two partition names."""
56*135b53beSAlison Chaiken
57*135b53beSAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 'y':
58*135b53beSAlison Chaiken        pytest.skip('gpt rename command not supported')
59*135b53beSAlison Chaiken    if u_boot_console.config.buildconfig.get('config_cmd_part', 'n') != 'y':
60*135b53beSAlison Chaiken        pytest.skip('gpt swap test needs CMD_PART')
61*135b53beSAlison Chaiken    u_boot_console.run_command('host bind 0 testdisk.raw')
62*135b53beSAlison Chaiken    output = u_boot_console.run_command('part list host 0')
63*135b53beSAlison Chaiken    assert '0x000007ff	"first"' in output
64*135b53beSAlison Chaiken    assert '0x000017ff	"second"' in output
65*135b53beSAlison Chaiken    u_boot_console.run_command('gpt swap host 0 first second')
66*135b53beSAlison Chaiken    output = u_boot_console.run_command('part list host 0')
67*135b53beSAlison Chaiken    assert '0x000007ff	"second"' in output
68*135b53beSAlison Chaiken    assert '0x000017ff	"first"' in output
69e2c5d1e4SAlison Chaiken    os.remove('testdisk.raw')
70