blob: 3ecffb6fed7b9b4a30f42ddb3ed9ebbfe04bfdeb [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
Mike Frysinger3f087aa2020-03-20 06:03:16 -040011import sys
David Pursellf1d16a62015-03-25 13:31:04 -070012
Mike Frysinger6db648e2018-07-24 19:57:58 -040013import mock
14
David Pursellf1d16a62015-03-25 13:31:04 -070015from chromite.cli import flash
Sanika Kulkarnia8c4e3a2019-09-20 16:47:25 -070016from chromite.lib import auto_updater_transfer
David Pursellf1d16a62015-03-25 13:31:04 -070017from chromite.lib import commandline
18from chromite.lib import cros_build_lib
Ralph Nathan9b997232015-05-15 13:13:12 -070019from chromite.lib import cros_logging as logging
David Pursellf1d16a62015-03-25 13:31:04 -070020from chromite.lib import cros_test_lib
21from chromite.lib import dev_server_wrapper
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -070022from chromite.lib import osutils
David Pursellf1d16a62015-03-25 13:31:04 -070023from chromite.lib import partial_mock
24from chromite.lib import remote_access
Mike Frysingerdda695b2019-11-23 20:58:59 -050025from chromite.lib import remote_access_unittest
David Pursellf1d16a62015-03-25 13:31:04 -070026
Amin Hassanic0f06fa2019-01-28 15:24:47 -080027from chromite.lib.paygen import paygen_payload_lib
28from chromite.lib.paygen import paygen_stateful_payload_lib
29
David Pursellf1d16a62015-03-25 13:31:04 -070030
Mike Frysinger3f087aa2020-03-20 06:03:16 -040031assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
32
33
David Pursellf1d16a62015-03-25 13:31:04 -070034class RemoteDeviceUpdaterMock(partial_mock.PartialCmdMock):
35 """Mock out RemoteDeviceUpdater."""
Amin Hassani9800d432019-07-24 14:23:39 -070036 TARGET = 'chromite.lib.auto_updater.ChromiumOSUpdater'
xixuane851dfb2016-05-02 18:02:37 -070037 ATTRS = ('UpdateStateful', 'UpdateRootfs', 'SetupRootfsUpdate',
Amin Hassani3e87ce12020-10-22 10:39:36 -070038 'RebootAndVerify')
David Pursellf1d16a62015-03-25 13:31:04 -070039
40 def __init__(self):
41 partial_mock.PartialCmdMock.__init__(self)
42
43 def UpdateStateful(self, _inst, *_args, **_kwargs):
44 """Mock out UpdateStateful."""
45
46 def UpdateRootfs(self, _inst, *_args, **_kwargs):
47 """Mock out UpdateRootfs."""
48
49 def SetupRootfsUpdate(self, _inst, *_args, **_kwargs):
50 """Mock out SetupRootfsUpdate."""
51
xixuane851dfb2016-05-02 18:02:37 -070052 def RebootAndVerify(self, _inst, *_args, **_kwargs):
53 """Mock out RebootAndVerify."""
David Pursellf1d16a62015-03-25 13:31:04 -070054
Sanika Kulkarnie3b177b2019-11-26 14:42:48 -080055
Mike Frysingerdda695b2019-11-23 20:58:59 -050056class RemoteAccessMock(remote_access_unittest.RemoteShMock):
57 """Mock out RemoteAccess."""
58
59 ATTRS = ('RemoteSh', 'Rsync', 'Scp')
60
61 def Rsync(self, *_args, **_kwargs):
62 return cros_build_lib.CommandResult(returncode=0)
63
64 def Scp(self, *_args, **_kwargs):
65 return cros_build_lib.CommandResult(returncode=0)
66
67
David Pursellf1d16a62015-03-25 13:31:04 -070068class RemoteDeviceUpdaterTest(cros_test_lib.MockTempDirTestCase):
69 """Test the flow of flash.Flash() with RemoteDeviceUpdater."""
70
71 IMAGE = '/path/to/image'
72 DEVICE = commandline.Device(scheme=commandline.DEVICE_SCHEME_SSH,
Mike Frysingerb5a297f2019-11-23 21:17:41 -050073 hostname=remote_access.TEST_IP)
David Pursellf1d16a62015-03-25 13:31:04 -070074
75 def setUp(self):
76 """Patches objects."""
77 self.updater_mock = self.StartPatcher(RemoteDeviceUpdaterMock())
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 """
Achuith Bhandarkareda9b222020-05-02 10:36:16 +0000105 if path.startswith(dev_server_wrapper.DEFAULT_STATIC_DIR):
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800106 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(
Achuith Bhandarkareda9b222020-05-02 10:36:16 +0000149 [mock.call('/path/to/image/full_payload', 'board', None, silent=True),
150 mock.call('/path/to/image/stateful', 'board', None, silent=True)])
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200151 self.assertEqual(mock_xbuddy.call_count, 2)
152
153 def testTestImage(self):
154 """Tests that we download the test image when the full payload fails."""
155 with mock.patch.object(
156 dev_server_wrapper,
157 'GetImagePathWithXbuddy',
158 side_effect=(dev_server_wrapper.ImagePathError,
159 ('translated/xbuddy/path',
160 'resolved/xbuddy/path'))) as mock_xbuddy:
Achuith Bhandarkar1f54a212019-12-09 12:08:35 -0800161 with mock.patch('os.path.exists', side_effect=self._ExistsMock):
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200162 flash.Flash(self.DEVICE, self.IMAGE)
163
164 # Call to download full_payload and image. No other calls.
165 mock_xbuddy.assert_has_calls(
Achuith Bhandarkareda9b222020-05-02 10:36:16 +0000166 [mock.call('/path/to/image/full_payload', 'board', None, silent=True),
167 mock.call('/path/to/image', 'board', None)])
Achuith Bhandarkar4d4275f2019-10-01 17:07:23 +0200168 self.assertEqual(mock_xbuddy.call_count, 2)
169
David Pursellf1d16a62015-03-25 13:31:04 -0700170
171class USBImagerMock(partial_mock.PartialCmdMock):
172 """Mock out USBImager."""
173 TARGET = 'chromite.cli.flash.USBImager'
174 ATTRS = ('CopyImageToDevice', 'InstallImageToDevice',
175 'ChooseRemovableDevice', 'ListAllRemovableDevices',
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700176 'GetRemovableDeviceDescription')
David Pursellf1d16a62015-03-25 13:31:04 -0700177 VALID_IMAGE = True
178
179 def __init__(self):
180 partial_mock.PartialCmdMock.__init__(self)
181
182 def CopyImageToDevice(self, _inst, *_args, **_kwargs):
183 """Mock out CopyImageToDevice."""
184
185 def InstallImageToDevice(self, _inst, *_args, **_kwargs):
186 """Mock out InstallImageToDevice."""
187
188 def ChooseRemovableDevice(self, _inst, *_args, **_kwargs):
189 """Mock out ChooseRemovableDevice."""
190
191 def ListAllRemovableDevices(self, _inst, *_args, **_kwargs):
192 """Mock out ListAllRemovableDevices."""
193 return ['foo', 'taco', 'milk']
194
195 def GetRemovableDeviceDescription(self, _inst, *_args, **_kwargs):
196 """Mock out GetRemovableDeviceDescription."""
197
David Pursellf1d16a62015-03-25 13:31:04 -0700198
199class USBImagerTest(cros_test_lib.MockTempDirTestCase):
200 """Test the flow of flash.Flash() with USBImager."""
201 IMAGE = '/path/to/image'
202
203 def Device(self, path):
204 """Create a USB device for passing to flash.Flash()."""
205 return commandline.Device(scheme=commandline.DEVICE_SCHEME_USB,
206 path=path)
207
208 def setUp(self):
209 """Patches objects."""
210 self.usb_mock = USBImagerMock()
211 self.imager_mock = self.StartPatcher(self.usb_mock)
David Pursellf1d16a62015-03-25 13:31:04 -0700212 self.PatchObject(dev_server_wrapper, 'GetImagePathWithXbuddy',
Gilad Arnolde62ec902015-04-24 14:41:02 -0700213 return_value=('taco-paladin/R36/chromiumos_test_image.bin',
214 'remote/taco-paladin/R36/test'))
David Pursellf1d16a62015-03-25 13:31:04 -0700215 self.PatchObject(os.path, 'exists', return_value=True)
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700216 self.isgpt_mock = self.PatchObject(flash, '_IsFilePathGPTDiskImage',
217 return_value=True)
David Pursellf1d16a62015-03-25 13:31:04 -0700218
219 def testLocalImagePathCopy(self):
220 """Tests that imaging methods are called correctly."""
221 with mock.patch('os.path.isfile', return_value=True):
222 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
223 self.assertTrue(self.imager_mock.patched['CopyImageToDevice'].called)
224
225 def testLocalImagePathInstall(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, board='taco',
229 install=True)
230 self.assertTrue(self.imager_mock.patched['InstallImageToDevice'].called)
231
232 def testLocalBadImagePath(self):
233 """Tests that using an image not having the magic bytes has prompt."""
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700234 self.isgpt_mock.return_value = False
David Pursellf1d16a62015-03-25 13:31:04 -0700235 with mock.patch('os.path.isfile', return_value=True):
236 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
237 mock_prompt.return_value = False
238 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
239 self.assertTrue(mock_prompt.called)
240
241 def testNonLocalImagePath(self):
242 """Tests that we try to get the image path using xbuddy."""
243 with mock.patch.object(
244 dev_server_wrapper,
245 'GetImagePathWithXbuddy',
Gilad Arnolde62ec902015-04-24 14:41:02 -0700246 return_value=('translated/xbuddy/path',
247 'resolved/xbuddy/path')) as mock_xbuddy:
David Pursellf1d16a62015-03-25 13:31:04 -0700248 with mock.patch('os.path.isfile', return_value=False):
249 with mock.patch('os.path.isdir', return_value=False):
250 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
251 self.assertTrue(mock_xbuddy.called)
252
253 def testConfirmNonRemovableDevice(self):
254 """Tests that we ask user to confirm if the device is not removable."""
255 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
256 flash.Flash(self.Device('/dev/dummy'), self.IMAGE)
257 self.assertTrue(mock_prompt.called)
258
259 def testSkipPromptNonRemovableDevice(self):
260 """Tests that we skip the prompt for non-removable with --yes."""
261 with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
262 flash.Flash(self.Device('/dev/dummy'), self.IMAGE, yes=True)
263 self.assertFalse(mock_prompt.called)
264
265 def testChooseRemovableDevice(self):
266 """Tests that we ask user to choose a device if none is given."""
267 flash.Flash(self.Device(''), self.IMAGE)
268 self.assertTrue(self.imager_mock.patched['ChooseRemovableDevice'].called)
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700269
270
Benjamin Gordon121a2aa2018-05-04 16:24:45 -0600271class UsbImagerOperationTest(cros_test_lib.RunCommandTestCase):
Ralph Nathan9b997232015-05-15 13:13:12 -0700272 """Tests for flash.UsbImagerOperation."""
273 # pylint: disable=protected-access
274
275 def setUp(self):
276 self.PatchObject(flash.UsbImagerOperation, '__init__', return_value=None)
277
278 def testUsbImagerOperationCalled(self):
279 """Test that flash.UsbImagerOperation is called when log level <= NOTICE."""
280 expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
Frank Huang8e626432019-06-24 19:51:08 +0800281 'oflag=direct', 'conv=fdatasync']
Achuith Bhandarkaree1336f2020-04-18 11:44:09 +0000282 usb_imager = flash.USBImager('dummy_device', 'board', 'foo', 'latest')
Ralph Nathan9b997232015-05-15 13:13:12 -0700283 run_mock = self.PatchObject(flash.UsbImagerOperation, 'Run')
284 self.PatchObject(logging.Logger, 'getEffectiveLevel',
285 return_value=logging.NOTICE)
286 usb_imager.CopyImageToDevice('foo', 'bar')
287
288 # Check that flash.UsbImagerOperation.Run() is called correctly.
Mike Frysinger45602c72019-09-22 02:15:11 -0400289 run_mock.assert_called_with(cros_build_lib.sudo_run, expected_cmd,
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400290 debug_level=logging.NOTICE, encoding='utf-8',
291 update_period=0.5)
Ralph Nathan9b997232015-05-15 13:13:12 -0700292
293 def testSudoRunCommandCalled(self):
Mike Frysinger45602c72019-09-22 02:15:11 -0400294 """Test that sudo_run is called when log level > NOTICE."""
Ralph Nathan9b997232015-05-15 13:13:12 -0700295 expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
Frank Huang8e626432019-06-24 19:51:08 +0800296 'oflag=direct', 'conv=fdatasync']
Achuith Bhandarkaree1336f2020-04-18 11:44:09 +0000297 usb_imager = flash.USBImager('dummy_device', 'board', 'foo', 'latest')
Mike Frysinger45602c72019-09-22 02:15:11 -0400298 run_mock = self.PatchObject(cros_build_lib, 'sudo_run')
Ralph Nathan9b997232015-05-15 13:13:12 -0700299 self.PatchObject(logging.Logger, 'getEffectiveLevel',
300 return_value=logging.WARNING)
301 usb_imager.CopyImageToDevice('foo', 'bar')
302
Mike Frysinger45602c72019-09-22 02:15:11 -0400303 # Check that sudo_run() is called correctly.
Ralph Nathan9b997232015-05-15 13:13:12 -0700304 run_mock.assert_any_call(expected_cmd, debug_level=logging.NOTICE,
305 print_cmd=False)
306
307 def testPingDD(self):
308 """Test that UsbImagerOperation._PingDD() sends the correct signal."""
309 expected_cmd = ['kill', '-USR1', '5']
Mike Frysinger45602c72019-09-22 02:15:11 -0400310 run_mock = self.PatchObject(cros_build_lib, 'sudo_run')
Ralph Nathan9b997232015-05-15 13:13:12 -0700311 op = flash.UsbImagerOperation('foo')
312 op._PingDD(5)
313
Mike Frysinger45602c72019-09-22 02:15:11 -0400314 # Check that sudo_run was called correctly.
Ralph Nathan9b997232015-05-15 13:13:12 -0700315 run_mock.assert_called_with(expected_cmd, print_cmd=False)
316
317 def testGetDDPidFound(self):
318 """Check that the expected pid is returned for _GetDDPid()."""
319 expected_pid = 5
320 op = flash.UsbImagerOperation('foo')
321 self.PatchObject(osutils, 'IsChildProcess', return_value=True)
322 self.rc.AddCmdResult(partial_mock.Ignore(),
323 output='%d\n10\n' % expected_pid)
324
325 pid = op._GetDDPid()
326
327 # Check that the correct pid was returned.
328 self.assertEqual(pid, expected_pid)
329
330 def testGetDDPidNotFound(self):
331 """Check that -1 is returned for _GetDDPid() if the pids aren't valid."""
332 expected_pid = -1
333 op = flash.UsbImagerOperation('foo')
334 self.PatchObject(osutils, 'IsChildProcess', return_value=False)
335 self.rc.AddCmdResult(partial_mock.Ignore(), output='5\n10\n')
336
337 pid = op._GetDDPid()
338
339 # Check that the correct pid was returned.
340 self.assertEqual(pid, expected_pid)
341
342
Bertrand SIMONNET56f773d2015-05-04 14:02:39 -0700343class FlashUtilTest(cros_test_lib.MockTempDirTestCase):
344 """Tests the helpers from cli.flash."""
345
346 def testChooseImage(self):
347 """Tests that we can detect a GPT image."""
348 # pylint: disable=protected-access
349
350 with self.PatchObject(flash, '_IsFilePathGPTDiskImage', return_value=True):
351 # No images defined. Choosing the image should raise an error.
352 with self.assertRaises(ValueError):
353 flash._ChooseImageFromDirectory(self.tempdir)
354
355 file_a = os.path.join(self.tempdir, 'a')
356 osutils.Touch(file_a)
357 # Only one image available, it should be selected automatically.
358 self.assertEqual(file_a, flash._ChooseImageFromDirectory(self.tempdir))
359
360 osutils.Touch(os.path.join(self.tempdir, 'b'))
361 file_c = os.path.join(self.tempdir, 'c')
362 osutils.Touch(file_c)
363 osutils.Touch(os.path.join(self.tempdir, 'd'))
364
365 # Multiple images available, we should ask the user to select the right
366 # image.
367 with self.PatchObject(cros_build_lib, 'GetChoice', return_value=2):
368 self.assertEqual(file_c, flash._ChooseImageFromDirectory(self.tempdir))
Mike Frysinger32759e42016-12-21 18:40:16 -0500369
370 def testIsFilePathGPTDiskImage(self):
371 """Tests the GPT image probing."""
372 # pylint: disable=protected-access
373
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400374 INVALID_PMBR = b' ' * 0x200
375 INVALID_GPT = b' ' * 0x200
376 VALID_PMBR = (b' ' * 0x1fe) + b'\x55\xaa'
377 VALID_GPT = b'EFI PART' + (b' ' * 0x1f8)
Mike Frysinger32759e42016-12-21 18:40:16 -0500378 TESTCASES = (
379 (False, False, INVALID_PMBR + INVALID_GPT),
380 (False, False, VALID_PMBR + INVALID_GPT),
381 (False, True, INVALID_PMBR + VALID_GPT),
382 (True, True, VALID_PMBR + VALID_GPT),
383 )
384
385 img = os.path.join(self.tempdir, 'img.bin')
386 for exp_pmbr_t, exp_pmbr_f, data in TESTCASES:
Mike Frysinger3d5de8f2019-10-23 00:48:39 -0400387 osutils.WriteFile(img, data, mode='wb')
Mike Frysinger32759e42016-12-21 18:40:16 -0500388 self.assertEqual(
389 flash._IsFilePathGPTDiskImage(img, require_pmbr=True), exp_pmbr_t)
390 self.assertEqual(
391 flash._IsFilePathGPTDiskImage(img, require_pmbr=False), exp_pmbr_f)