+class GptTestDiskImage(object):
+ """Disk Image used by the GPT tests."""
+
+ def __init__(self, u_boot_console):
+ """Initialize a new GptTestDiskImage object.
+
+ Args:
+ u_boot_console: A U-Boot console.
+
+ Returns:
+ Nothing.
+ """
+
+ filename = 'test_gpt_disk_image.bin'
+ self.path = u_boot_console.config.persistent_data_dir + '/' + filename
+
+ if os.path.exists(self.path):
+ u_boot_console.log.action('Disk image file ' + self.path +
+ ' already exists')
+ else:
+ u_boot_console.log.action('Generating ' + self.path)
+ fd = os.open(self.path, os.O_RDWR | os.O_CREAT)
+ os.ftruncate(fd, 4194304)
+ os.close(fd)
+ sgdisk = '/sbin/sgdisk'
+ cmd = (sgdisk, '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe',
+ self.path)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ cmd = (sgdisk, '--new=1:2048:2560', self.path)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ cmd = (sgdisk, '--new=2:4096:4608', self.path)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ cmd = (sgdisk, '-l', self.path)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+
+gtdi = None
+@pytest.fixture(scope='function')
+def state_disk_image(u_boot_console):
+ """pytest fixture to provide a GptTestDiskImage object to tests.
+ This is function-scoped because it uses u_boot_console, which is also
+ function-scoped. However, we don't need to actually do any function-scope
+ work, so this simply returns the same object over and over each time."""
+
+ global gtdi
+ if not gtdi:
+ gtdi = GptTestDiskImage(u_boot_console)
+ return gtdi
+
+@pytest.mark.boardspec('sandbox')