def testEqual(self): """Test that equal instances are equal.""" arg = '2 v1 u1 f1 1,0 1 t1 a1, v2 u2 f2 2,3 4 t2 a2,5 6 t3 a3' dc = kernel_cmdline.DmConfig(arg) self.assertEqual(dc, kernel_cmdline.DmConfig(arg)) self.assertTrue(dc == kernel_cmdline.DmConfig(arg)) # Also verify that != is False. self.assertFalse(dc != kernel_cmdline.DmConfig(arg))
def testNotEqual(self): """Test that unequal instances are unequal.""" # Start with duplicated instances, and change fields to verify that all the # fields matter. arg = '2 v1 u1 f1 1,0 1 t1 a1, v2 u2 f2 2,3 4 t2 a2,5 6 t3 a3' dc1 = kernel_cmdline.DmConfig(arg) self.assertNotEqual(dc1, '') dc2 = kernel_cmdline.DmConfig(arg) dc2.num_devices = 1 self.assertNotEqual(dc1, dc2) dc3 = kernel_cmdline.DmConfig(arg) dc3.devices = [] self.assertNotEqual(dc1, dc3)
def testFormats(self): """Verify that DmConfig recreates its input string.""" device_data = [['vboot uuid ro 1', '0 1 verity arg1 arg2'], [ 'vblah uuid2 ro 2', '100 9 stripe larg1=val1', '200 10 stripe larg2=val2' ], ['vroot uuid3 ro 1', '99 3 linear larg1 larg2']] dm_arg = ', '.join(','.join(x for x in data) for data in device_data) dm_config_val = '%d %s' % (len(device_data), dm_arg) dc = kernel_cmdline.DmConfig(dm_config_val) self.assertEqual(dm_config_val, dc.Format())
def testIgnoresQuotes(self): """Verify that DmConfig works with quoted string.""" device_data = [['vboot uuid ro 1', '0 1 verity arg1 arg2'], [ 'vblah uuid2 ro 2', '100 9 stripe larg1=val1', '200 10 stripe larg2=val2' ], ['vroot uuid3 ro 1', '99 3 linear larg1 larg2']] dm_arg = ', '.join(','.join(x for x in data) for data in device_data) devices = [kernel_cmdline.DmDevice(x) for x in device_data] dc = kernel_cmdline.DmConfig('"%d %s"' % (len(device_data), dm_arg)) self.assertEqual(len(device_data), dc.num_devices) self.assertEqual(devices, list(dc.devices.values()))
def testParses(self): """Verify that DmConfig correctly parses the config from DmDevice.""" device_data = [['vboot uuid ro 1', '0 1 verity arg1 arg2'], [ 'vblah uuid2 ro 2', '100 9 stripe larg1=val1', '200 10 stripe larg2=val2' ], ['vroot uuid3 ro 1', '99 3 linear larg1 larg2']] dm_arg = ', '.join(','.join(x for x in data) for data in device_data) devices = [kernel_cmdline.DmDevice(x) for x in device_data] dc = kernel_cmdline.DmConfig('%d %s' % (len(device_data), dm_arg)) self.assertEqual(len(device_data), dc.num_devices) self.assertEqual(devices, list(dc.devices.values()))
def __init__(self, image, kern_cmdline, calc_dm_args=None, calc_conf=None): self.image = image self.kern_cmdline = kern_cmdline self._file = tempfile.NamedTemporaryFile(delete=False) if not calc_dm_args: calc_dm_args = '1 vroot none ro 1,0 800 verity alg=sha1' self.calculated_dm_config = kernel_cmdline.DmConfig(calc_dm_args) if calc_conf: self.calculated_kernel_cmdline = calc_conf else: self.calculated_kernel_cmdline = 'CALCULATED KERNEL CONFIG' self.hashtree_filename = self._file.name
def testSimple(self): """Test the simple case for CalculateRootfsHash.""" self.rc.AddCmdResult(partial_mock.In('verity'), output=SAMPLE_VERITY_OUTPUT) rootfs_hash = imagefile.CalculateRootfsHash( self.image, kernel_cmdline.CommandLine(SAMPLE_KERNEL_CONFIG)) expected_rc = [ mock.call([ 'sudo', '--', 'verity', 'mode=create', 'alg=sha1', 'payload=/dev/loop9999p3', 'payload_blocks=486400', 'hashtree=%s' % rootfs_hash.hashtree_filename, 'salt=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' 'bbbbbbbbbbbbbbb' ], capture_output=True, print_cmd=False, encoding='utf-8') ] self.assertEqual(expected_rc, self.rc.call_args_list) self.assertEqual( kernel_cmdline.DmConfig( '1 vroot none ro 1,0 3891200 verity ' 'payload=PARTUUID=%U/PARTNROFF=1 hashtree=PARTUUID=%U/PARTNROFF=1 ' 'hashstart=3891200 alg=sha1 ' 'root_hexdigest=9999999999999999999999999999999999999999 salt=bbbbb' 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'), rootfs_hash.calculated_dm_config) self.assertEqual( 'console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 ' 'root=/dev/dm-0 rootwait ro dm_verity.error_behavior=3 ' 'dm_verity.max_bios=-1 dm_verity.dev_wait=1 dm="1 vroot none ro ' '1,0 3891200 verity payload=PARTUUID=%U/PARTNROFF=1 ' 'hashtree=PARTUUID=%U/PARTNROFF=1 hashstart=3891200 alg=sha1 ' 'root_hexdigest=9999999999999999999999999999999999999999 ' 'salt=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' 'bbbb" noinitrd cros_debug vt.global_cursor_default=0 kern_guid=%U ' 'add_efi_memmap boot=local noresume noswap i915.modeset=1 ' 'tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapic ' 'disablevmx=off', rootfs_hash.calculated_kernel_cmdline.Format())
def testSetDmConfig(self): """Test that SetDmConfig sets the dm= parameter.""" cmd = kernel_cmdline.CommandLine('a -- b') cmd.SetDmConfig(kernel_cmdline.DmConfig(DM)) self.assertEqual(kernel_cmdline.KernelArg('dm', DM), cmd.kern_args[1])
def testGetDmConfig(self): """Test that GetDmConfig returns the DmConfig we expect.""" cmd = kernel_cmdline.CommandLine(CMDLINE) dm = kernel_cmdline.DmConfig(DM) self.assertEqual(dm, cmd.GetDmConfig())