blob: 7da089e6480831ecb7c34c544a426fd57d65cfc0 [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
David Pursellf1d16a62015-03-25 13:31:04 -07002# Copyright 2015 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Unit tests for the flash module."""
7
8from __future__ import print_function
9
David Pursellf1d16a62015-03-25 13:31:04 -070010import os
11
Mike Frysinger6db648e2018-07-24 19:57:58 -040012import mock
13
David Pursellf1d16a62015-03-25 13:31:04 -070014from chromite.cli import flash
Sanika Kulkarnia8c4e3a2019-09-20 16:47:25 -070015from chromite.lib import auto_updater_transfer
David Pursellf1d16a62015-03-25 13:31:04 -070016from chromite.lib import commandline
17from chromite.lib import cros_build_lib
Ralph Nathan9b997232015-05-15 13:13:12 -070018from chromite.lib import cros_logging as logging
David Pursellf1d16a62015-03-25 13:31:04 -070019from chromite.lib import cros_test_lib
20from chromite.lib import dev_server_wrapper
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -070021from chromite.lib import osutils
David Pursellf1d16a62015-03-25 13:31:04 -070022from chromite.lib import partial_mock
23from chromite.lib import remote_access
Mike Frysingerdda695b2019-11-23 20:58:59 -050024from chromite.lib import remote_access_unittest
David Pursellf1d16a62015-03-25 13:31:04 -070025
Amin Hassanic0f06fa2019-01-28 15:24:47 -080026from chromite.lib.paygen import paygen_payload_lib
27from chromite.lib.paygen import paygen_stateful_payload_lib
28
David Pursellf1d16a62015-03-25 13:31:04 -070029
30class RemoteDeviceUpdaterMock(partial_mock.PartialCmdMock):
31 """Mock out RemoteDeviceUpdater."""
Amin Hassani9800d432019-07-24 14:23:39 -070032 TARGET = 'chromite.lib.auto_updater.ChromiumOSUpdater'
xixuane851dfb2016-05-02 18:02:37 -070033 ATTRS = ('UpdateStateful', 'UpdateRootfs', 'SetupRootfsUpdate',
Sanika Kulkarni00b9d682019-11-26 09:43:20 -080034 'RebootAndVerify', 'PreparePayloadPropsFile')
David Pursellf1d16a62015-03-25 13:31:04 -070035
36 def __init__(self):
37 partial_mock.PartialCmdMock.__init__(self)
38
39 def UpdateStateful(self, _inst, *_args, **_kwargs):
40 """Mock out UpdateStateful."""
41
42 def UpdateRootfs(self, _inst, *_args, **_kwargs):
43 """Mock out UpdateRootfs."""
44
45 def SetupRootfsUpdate(self, _inst, *_args, **_kwargs):
46 """Mock out SetupRootfsUpdate."""
47
xixuane851dfb2016-05-02 18:02:37 -070048 def RebootAndVerify(self, _inst, *_args, **_kwargs):
49 """Mock out RebootAndVerify."""
David Pursellf1d16a62015-03-25 13:31:04 -070050
Sanika Kulkarni00b9d682019-11-26 09:43:20 -080051 def PreparePayloadPropsFile(self, _inst, *_args, **_kwargs):
52 """Mock out PreparePayloadPropsFile."""
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +020053
Mike Frysingerdda695b2019-11-23 20:58:59 -050054class RemoteAccessMock(remote_access_unittest.RemoteShMock):
55 """Mock out RemoteAccess."""
56
57 ATTRS = ('RemoteSh', 'Rsync', 'Scp')
58
59 def Rsync(self, *_args, **_kwargs):
60 return cros_build_lib.CommandResult(returncode=0)
61
62 def Scp(self, *_args, **_kwargs):
63 return cros_build_lib.CommandResult(returncode=0)
64
65
David Pursellf1d16a62015-03-25 13:31:04 -070066class RemoteDeviceUpdaterTest(cros_test_lib.MockTempDirTestCase):
67 """Test the flow of flash.Flash() with RemoteDeviceUpdater."""
68
69 IMAGE = '/path/to/image'
70 DEVICE = commandline.Device(scheme=commandline.DEVICE_SCHEME_SSH,
Mike Frysingerb5a297f2019-11-23 21:17:41 -050071 hostname=remote_access.TEST_IP)
David Pursellf1d16a62015-03-25 13:31:04 -070072
73 def setUp(self):
74 """Patches objects."""
75 self.updater_mock = self.StartPatcher(RemoteDeviceUpdaterMock())
76 self.PatchObject(dev_server_wrapper, 'GenerateXbuddyRequest',
77 return_value='xbuddy/local/latest')
David Pursellf1d16a62015-03-25 13:31:04 -070078 self.PatchObject(dev_server_wrapper, 'GetImagePathWithXbuddy',
Gilad Arnolde62ec902015-04-24 14:41:02 -070079 return_value=('taco-paladin/R36/chromiumos_test_image.bin',
80 'remote/taco-paladin/R36/test'))
Amin Hassanic0f06fa2019-01-28 15:24:47 -080081 self.PatchObject(paygen_payload_lib, 'GenerateUpdatePayload')
82 self.PatchObject(paygen_stateful_payload_lib, 'GenerateStatefulPayload')
David Pursellf1d16a62015-03-25 13:31:04 -070083 self.PatchObject(remote_access, 'CHECK_INTERVAL', new=0)
Mike Frysingerdda695b2019-11-23 20:58:59 -050084 self.PatchObject(remote_access.ChromiumOSDevice, 'Pingable',
85 return_value=True)
86 m = self.StartPatcher(RemoteAccessMock())
87 m.AddCmdResult(['cat', '/etc/lsb-release'],
88 stdout='CHROMEOS_RELEASE_BOARD=board')
89 m.SetDefaultCmdResult()
David Pursellf1d16a62015-03-25 13:31:04 -070090
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -080091 def _ExistsMock(self, path, ret=True):
92 """Mock function for os.path.exists.
93
94 os.path.exists is used a lot; we only want to mock it for devserver/static,
95 and actually check if the file exists in all other cases (using os.access).
96
97 Args:
98 path: path to check.
99 ret: return value of mock.
100
101 Returns:
102 ret for paths under devserver/static, and the expected value of
103 os.path.exists otherwise.
104 """
105 if path.startswith(flash.DEVSERVER_STATIC_DIR):
106 return ret
107 return os.access(path, os.F_OK)
108
David Pursellf1d16a62015-03-25 13:31:04 -0700109 def testUpdateAll(self):
110 """Tests that update methods are called correctly."""
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800111 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Bertrand SIMONNETb34a98b2015-04-22 14:30:04 -0700112 flash.Flash(self.DEVICE, self.IMAGE)
113 self.assertTrue(self.updater_mock.patched['UpdateStateful'].called)
114 self.assertTrue(self.updater_mock.patched['UpdateRootfs'].called)
David Pursellf1d16a62015-03-25 13:31:04 -0700115
116 def testUpdateStateful(self):
117 """Tests that update methods are called correctly."""
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800118 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Bertrand SIMONNETb34a98b2015-04-22 14:30:04 -0700119 flash.Flash(self.DEVICE, self.IMAGE, rootfs_update=False)
120 self.assertTrue(self.updater_mock.patched['UpdateStateful'].called)
121 self.assertFalse(self.updater_mock.patched['UpdateRootfs'].called)
David Pursellf1d16a62015-03-25 13:31:04 -0700122
123 def testUpdateRootfs(self):
124 """Tests that update methods are called correctly."""
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800125 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Bertrand SIMONNETb34a98b2015-04-22 14:30:04 -0700126 flash.Flash(self.DEVICE, self.IMAGE, stateful_update=False)
127 self.assertFalse(self.updater_mock.patched['UpdateStateful'].called)
128 self.assertTrue(self.updater_mock.patched['UpdateRootfs'].called)
David Pursellf1d16a62015-03-25 13:31:04 -0700129
130 def testMissingPayloads(self):
131 """Tests we raise FlashError when payloads are missing."""
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800132 with mock.patch('os.path.exists',
133 side_effect=lambda p: self._ExistsMock(p, ret=False)):
Sanika Kulkarnia8c4e3a2019-09-20 16:47:25 -0700134 self.assertRaises(auto_updater_transfer.ChromiumOSTransferError,
135 flash.Flash, self.DEVICE, self.IMAGE)
David Pursellf1d16a62015-03-25 13:31:04 -0700136
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200137 def testFullPayload(self):
138 """Tests that we download full_payload and stateful using xBuddy."""
139 with mock.patch.object(
140 dev_server_wrapper,
141 'GetImagePathWithXbuddy',
142 return_value=('translated/xbuddy/path',
143 'resolved/xbuddy/path')) as mock_xbuddy:
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800144 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200145 flash.Flash(self.DEVICE, self.IMAGE)
146
147 # Call to download full_payload and stateful. No other calls.
148 mock_xbuddy.assert_has_calls(
149 [mock.call('/path/to/image/full_payload', mock.ANY,
Achuith Bhandarkar12f43c72019-11-21 16:44:24 -0800150 static_dir=flash.DEVSERVER_STATIC_DIR, silent=True),
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200151 mock.call('/path/to/image/stateful', mock.ANY,
Achuith Bhandarkar12f43c72019-11-21 16:44:24 -0800152 static_dir=flash.DEVSERVER_STATIC_DIR, silent=True)])
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200153 self.assertEqual(mock_xbuddy.call_count, 2)
154
155 def testTestImage(self):
156 """Tests that we download the test image when the full payload fails."""
157 with mock.patch.object(
158 dev_server_wrapper,
159 'GetImagePathWithXbuddy',
160 side_effect=(dev_server_wrapper.ImagePathError,
161 ('translated/xbuddy/path',
162 'resolved/xbuddy/path'))) as mock_xbuddy:
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800163 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200164 flash.Flash(self.DEVICE, self.IMAGE)
165
166 # Call to download full_payload and image. No other calls.
167 mock_xbuddy.assert_has_calls(
168 [mock.call('/path/to/image/full_payload', mock.ANY,
Achuith Bhandarkar12f43c72019-11-21 16:44:24 -0800169 static_dir=flash.DEVSERVER_STATIC_DIR, silent=True),
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200170 mock.call('/path/to/image', mock.ANY,
171 static_dir=flash.DEVSERVER_STATIC_DIR)])
172 self.assertEqual(mock_xbuddy.call_count, 2)
173
David Pursellf1d16a62015-03-25 13:31:04 -0700174
175class USBImagerMock(partial_mock.PartialCmdMock):
176 """Mock out USBImager."""
177 TARGET = 'chromite.cli.flash.USBImager'
178 ATTRS = ('CopyImageToDevice', 'InstallImageToDevice',
179 'ChooseRemovableDevice', 'ListAllRemovableDevices',
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700180 'GetRemovableDeviceDescription')
David Pursellf1d16a62015-03-25 13:31:04 -0700181 VALID_IMAGE = True
182
183 def __init__(self):
184 partial_mock.PartialCmdMock.__init__(self)
185
186 def CopyImageToDevice(self, _inst, *_args, **_kwargs):
187 """Mock out CopyImageToDevice."""
188
189 def InstallImageToDevice(self, _inst, *_args, **_kwargs):
190 """Mock out InstallImageToDevice."""
191
192 def ChooseRemovableDevice(self, _inst, *_args, **_kwargs):
193 """Mock out ChooseRemovableDevice."""
194
195 def ListAllRemovableDevices(self, _inst, *_args, **_kwargs):
196 """Mock out ListAllRemovableDevices."""
197 return ['foo', 'taco', 'milk']
198
199 def GetRemovableDeviceDescription(self, _inst, *_args, **_kwargs):
200 """Mock out GetRemovableDeviceDescription."""
201
David Pursellf1d16a62015-03-25 13:31:04 -0700202
203class USBImagerTest(cros_test_lib.MockTempDirTestCase):
204 """Test the flow of flash.Flash() with USBImager."""
205 IMAGE = '/path/to/image'
206
207 def Device(self, path):
208 """Create a USB device for passing to flash.Flash()."""
209 return commandline.Device(scheme=commandline.DEVICE_SCHEME_USB,
210 path=path)
211
212 def setUp(self):
213 """Patches objects."""
214 self.usb_mock = USBImagerMock()
215 self.imager_mock = self.StartPatcher(self.usb_mock)
216 self.PatchObject(dev_server_wrapper, 'GenerateXbuddyRequest',
217 return_value='xbuddy/local/latest')
David Pursellf1d16a62015-03-25 13:31:04 -0700218 self.PatchObject(dev_server_wrapper, 'GetImagePathWithXbuddy',
Gilad Arnolde62ec902015-04-24 14:41:02 -0700219 return_value=('taco-paladin/R36/chromiumos_test_image.bin',
220 'remote/taco-paladin/R36/test'))
David Pursellf1d16a62015-03-25 13:31:04 -0700221 self.PatchObject(os.path, 'exists', return_value=True)
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700222 self.isgpt_mock = self.PatchObject(flash, '_IsFilePathGPTDiskImage',
223 return_value=True)
David Pursellf1d16a62015-03-25 13:31:04 -0700224
225 def testLocalImagePathCopy(self):
226 """Tests that imaging methods are called correctly."""
227 with mock.patch('os.path.isfile', return_value=True):
228 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
229 self.assertTrue(self.imager_mock.patched['CopyImageToDevice'].called)
230
231 def testLocalImagePathInstall(self):
232 """Tests that imaging methods are called correctly."""
233 with mock.patch('os.path.isfile', return_value=True):
234 flash.Flash(self.Device('/dev/foo'), self.IMAGE, board='taco',
235 install=True)
236 self.assertTrue(self.imager_mock.patched['InstallImageToDevice'].called)
237
238 def testLocalBadImagePath(self):
239 """Tests that using an image not having the magic bytes has prompt."""
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700240 self.isgpt_mock.return_value = False
David Pursellf1d16a62015-03-25 13:31:04 -0700241 with mock.patch('os.path.isfile', return_value=True):
242 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
243 mock_prompt.return_value = False
244 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
245 self.assertTrue(mock_prompt.called)
246
247 def testNonLocalImagePath(self):
248 """Tests that we try to get the image path using xbuddy."""
249 with mock.patch.object(
250 dev_server_wrapper,
251 'GetImagePathWithXbuddy',
Gilad Arnolde62ec902015-04-24 14:41:02 -0700252 return_value=('translated/xbuddy/path',
253 'resolved/xbuddy/path')) as mock_xbuddy:
David Pursellf1d16a62015-03-25 13:31:04 -0700254 with mock.patch('os.path.isfile', return_value=False):
255 with mock.patch('os.path.isdir', return_value=False):
256 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
257 self.assertTrue(mock_xbuddy.called)
258
259 def testConfirmNonRemovableDevice(self):
260 """Tests that we ask user to confirm if the device is not removable."""
261 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
262 flash.Flash(self.Device('/dev/dummy'), self.IMAGE)
263 self.assertTrue(mock_prompt.called)
264
265 def testSkipPromptNonRemovableDevice(self):
266 """Tests that we skip the prompt for non-removable with --yes."""
267 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
268 flash.Flash(self.Device('/dev/dummy'), self.IMAGE, yes=True)
269 self.assertFalse(mock_prompt.called)
270
271 def testChooseRemovableDevice(self):
272 """Tests that we ask user to choose a device if none is given."""
273 flash.Flash(self.Device(''), self.IMAGE)
274 self.assertTrue(self.imager_mock.patched['ChooseRemovableDevice'].called)
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700275
276
Benjamin Gordon121a2aa2018-05-04 16:24:45 -0600277class UsbImagerOperationTest(cros_test_lib.RunCommandTestCase):
Ralph Nathan9b997232015-05-15 13:13:12 -0700278 """Tests for flash.UsbImagerOperation."""
279 # pylint: disable=protected-access
280
281 def setUp(self):
282 self.PatchObject(flash.UsbImagerOperation, '__init__', return_value=None)
283
284 def testUsbImagerOperationCalled(self):
285 """Test that flash.UsbImagerOperation is called when log level <= NOTICE."""
286 expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
Frank Huang8e626432019-06-24 19:51:08 +0800287 'oflag=direct', 'conv=fdatasync']
Ralph Nathan9b997232015-05-15 13:13:12 -0700288 usb_imager = flash.USBImager('dummy_device', 'board', 'foo')
289 run_mock = self.PatchObject(flash.UsbImagerOperation, 'Run')
290 self.PatchObject(logging.Logger, 'getEffectiveLevel',
291 return_value=logging.NOTICE)
292 usb_imager.CopyImageToDevice('foo', 'bar')
293
294 # Check that flash.UsbImagerOperation.Run() is called correctly.
Mike Frysinger45602c72019-09-22 02:15:11 -0400295 run_mock.assert_called_with(cros_build_lib.sudo_run, expected_cmd,
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400296 debug_level=logging.NOTICE, encoding='utf-8',
297 update_period=0.5)
Ralph Nathan9b997232015-05-15 13:13:12 -0700298
299 def testSudoRunCommandCalled(self):
Mike Frysinger45602c72019-09-22 02:15:11 -0400300 """Test that sudo_run is called when log level > NOTICE."""
Ralph Nathan9b997232015-05-15 13:13:12 -0700301 expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
Frank Huang8e626432019-06-24 19:51:08 +0800302 'oflag=direct', 'conv=fdatasync']
Ralph Nathan9b997232015-05-15 13:13:12 -0700303 usb_imager = flash.USBImager('dummy_device', 'board', 'foo')
Mike Frysinger45602c72019-09-22 02:15:11 -0400304 run_mock = self.PatchObject(cros_build_lib, 'sudo_run')
Ralph Nathan9b997232015-05-15 13:13:12 -0700305 self.PatchObject(logging.Logger, 'getEffectiveLevel',
306 return_value=logging.WARNING)
307 usb_imager.CopyImageToDevice('foo', 'bar')
308
Mike Frysinger45602c72019-09-22 02:15:11 -0400309 # Check that sudo_run() is called correctly.
Ralph Nathan9b997232015-05-15 13:13:12 -0700310 run_mock.assert_any_call(expected_cmd, debug_level=logging.NOTICE,
311 print_cmd=False)
312
313 def testPingDD(self):
314 """Test that UsbImagerOperation._PingDD() sends the correct signal."""
315 expected_cmd = ['kill', '-USR1', '5']
Mike Frysinger45602c72019-09-22 02:15:11 -0400316 run_mock = self.PatchObject(cros_build_lib, 'sudo_run')
Ralph Nathan9b997232015-05-15 13:13:12 -0700317 op = flash.UsbImagerOperation('foo')
318 op._PingDD(5)
319
Mike Frysinger45602c72019-09-22 02:15:11 -0400320 # Check that sudo_run was called correctly.
Ralph Nathan9b997232015-05-15 13:13:12 -0700321 run_mock.assert_called_with(expected_cmd, print_cmd=False)
322
323 def testGetDDPidFound(self):
324 """Check that the expected pid is returned for _GetDDPid()."""
325 expected_pid = 5
326 op = flash.UsbImagerOperation('foo')
327 self.PatchObject(osutils, 'IsChildProcess', return_value=True)
328 self.rc.AddCmdResult(partial_mock.Ignore(),
329 output='%d\n10\n' % expected_pid)
330
331 pid = op._GetDDPid()
332
333 # Check that the correct pid was returned.
334 self.assertEqual(pid, expected_pid)
335
336 def testGetDDPidNotFound(self):
337 """Check that -1 is returned for _GetDDPid() if the pids aren't valid."""
338 expected_pid = -1
339 op = flash.UsbImagerOperation('foo')
340 self.PatchObject(osutils, 'IsChildProcess', return_value=False)
341 self.rc.AddCmdResult(partial_mock.Ignore(), output='5\n10\n')
342
343 pid = op._GetDDPid()
344
345 # Check that the correct pid was returned.
346 self.assertEqual(pid, expected_pid)
347
348
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700349class FlashUtilTest(cros_test_lib.MockTempDirTestCase):
350 """Tests the helpers from cli.flash."""
351
352 def testChooseImage(self):
353 """Tests that we can detect a GPT image."""
354 # pylint: disable=protected-access
355
356 with self.PatchObject(flash, '_IsFilePathGPTDiskImage', return_value=True):
357 # No images defined. Choosing the image should raise an error.
358 with self.assertRaises(ValueError):
359 flash._ChooseImageFromDirectory(self.tempdir)
360
361 file_a = os.path.join(self.tempdir, 'a')
362 osutils.Touch(file_a)
363 # Only one image available, it should be selected automatically.
364 self.assertEqual(file_a, flash._ChooseImageFromDirectory(self.tempdir))
365
366 osutils.Touch(os.path.join(self.tempdir, 'b'))
367 file_c = os.path.join(self.tempdir, 'c')
368 osutils.Touch(file_c)
369 osutils.Touch(os.path.join(self.tempdir, 'd'))
370
371 # Multiple images available, we should ask the user to select the right
372 # image.
373 with self.PatchObject(cros_build_lib, 'GetChoice', return_value=2):
374 self.assertEqual(file_c, flash._ChooseImageFromDirectory(self.tempdir))
Mike Frysinger32759e42016-12-21 18:40:16 -0500375
376 def testIsFilePathGPTDiskImage(self):
377 """Tests the GPT image probing."""
378 # pylint: disable=protected-access
379
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400380 INVALID_PMBR = b' ' * 0x200
381 INVALID_GPT = b' ' * 0x200
382 VALID_PMBR = (b' ' * 0x1fe) + b'\x55\xaa'
383 VALID_GPT = b'EFI PART' + (b' ' * 0x1f8)
Mike Frysinger32759e42016-12-21 18:40:16 -0500384 TESTCASES = (
385 (False, False, INVALID_PMBR + INVALID_GPT),
386 (False, False, VALID_PMBR + INVALID_GPT),
387 (False, True, INVALID_PMBR + VALID_GPT),
388 (True, True, VALID_PMBR + VALID_GPT),
389 )
390
391 img = os.path.join(self.tempdir, 'img.bin')
392 for exp_pmbr_t, exp_pmbr_f, data in TESTCASES:
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400393 osutils.WriteFile(img, data, mode='wb')
Mike Frysinger32759e42016-12-21 18:40:16 -0500394 self.assertEqual(
395 flash._IsFilePathGPTDiskImage(img, require_pmbr=True), exp_pmbr_t)
396 self.assertEqual(
397 flash._IsFilePathGPTDiskImage(img, require_pmbr=False), exp_pmbr_f)