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