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