Skip to content

Commit a4ce78f

Browse files
committed
Add tests for fastboot_flash_recovery function
1 parent 9a85672 commit a4ce78f

File tree

1 file changed

+227
-1
lines changed

1 file changed

+227
-1
lines changed

tests/test_tooling.py

Lines changed: 227 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from openandroidinstaller.tooling import run_command
1717

18-
from openandroidinstaller.tooling import adb_reboot
18+
from openandroidinstaller.tooling import adb_reboot, fastboot_flash_recovery
1919
from openandroidinstaller.tooling import search_device
2020

2121

@@ -214,3 +214,229 @@ def test_run_command_unknown_tool():
214214
assert False, "Exception not raised"
215215
except Exception as e:
216216
assert str(e) == "Unknown tool unknown_tool. Use adb, fastboot or heimdall."
217+
218+
219+
def test_fastboot_flash_recovery_success(fp):
220+
"""Test if flashing custom recovery with fastboot works fine."""
221+
222+
def callback_function_with_kwargs(process, return_code):
223+
process.returncode = return_code
224+
225+
return_code = 0
226+
227+
with fp.context() as nested_process:
228+
nested_process.register(
229+
[
230+
"test/path/to/tools/fastboot",
231+
"flash",
232+
"recovery",
233+
"custom_recovery.img",
234+
],
235+
stdout=bytes.fromhex("00"),
236+
callback=callback_function_with_kwargs,
237+
callback_kwargs={"return_code": return_code},
238+
)
239+
for line in fastboot_flash_recovery(
240+
bin_path=Path("test/path/to/tools"),
241+
recovery="custom_recovery.img",
242+
is_ab=True,
243+
):
244+
print(line)
245+
assert line
246+
247+
248+
def test_fastboot_flash_recovery_failure(fp):
249+
"""Test if a failure in flashing custom recovery with fastboot is handled properly."""
250+
251+
def callback_function_with_kwargs(process, return_code):
252+
process.returncode = return_code
253+
254+
return_code = 1
255+
256+
with fp.context() as nested_process:
257+
nested_process.register(
258+
[
259+
"test/path/to/tools/fastboot",
260+
"flash",
261+
"recovery",
262+
"custom_recovery.img",
263+
],
264+
stdout=[
265+
bytes("error: no devices/emulators found", encoding="utf-8"),
266+
],
267+
callback=callback_function_with_kwargs,
268+
callback_kwargs={"return_code": return_code},
269+
)
270+
for line in fastboot_flash_recovery(
271+
bin_path=Path("test/path/to/tools"),
272+
recovery="custom_recovery.img",
273+
is_ab=True,
274+
):
275+
print(line)
276+
assert not line
277+
278+
279+
def test_fastboot_flash_recovery_with_additional_partitions_success(fp):
280+
"""Test if flashing custom recovery with additional partitions using fastboot works fine."""
281+
282+
def callback_function_with_kwargs(process, return_code):
283+
process.returncode = return_code
284+
285+
return_code = 0
286+
287+
with fp.context() as nested_process:
288+
nested_process.register(
289+
[
290+
"test/path/to/tools/fastboot",
291+
"flash",
292+
"dtbo",
293+
"dtbo.img",
294+
],
295+
stdout=bytes.fromhex("00"),
296+
callback=callback_function_with_kwargs,
297+
callback_kwargs={"return_code": return_code},
298+
)
299+
nested_process.register(
300+
[
301+
"test/path/to/tools/fastboot",
302+
"--disable-verity",
303+
"--disable-verification",
304+
"flash",
305+
"vbmeta",
306+
"vbmeta.img",
307+
],
308+
stdout=bytes.fromhex("00"),
309+
callback=callback_function_with_kwargs,
310+
callback_kwargs={"return_code": return_code},
311+
)
312+
nested_process.register(
313+
[
314+
"test/path/to/tools/fastboot",
315+
"wipe-super",
316+
"super_empty.img",
317+
],
318+
stdout=bytes.fromhex("00"),
319+
callback=callback_function_with_kwargs,
320+
callback_kwargs={"return_code": return_code},
321+
)
322+
nested_process.register(
323+
[
324+
"test/path/to/tools/fastboot",
325+
"flash",
326+
"vendor_boot",
327+
"vendor_boot.img",
328+
],
329+
stdout=bytes.fromhex("00"),
330+
callback=callback_function_with_kwargs,
331+
callback_kwargs={"return_code": return_code},
332+
)
333+
nested_process.register(
334+
[
335+
"test/path/to/tools/fastboot",
336+
"flash",
337+
"recovery",
338+
"custom_recovery.img",
339+
],
340+
stdout=bytes.fromhex("00"),
341+
callback=callback_function_with_kwargs,
342+
callback_kwargs={"return_code": return_code},
343+
)
344+
for line in fastboot_flash_recovery(
345+
bin_path=Path("test/path/to/tools"),
346+
recovery="custom_recovery.img",
347+
is_ab=True,
348+
vendor_boot="vendor_boot.img",
349+
dtbo="dtbo.img",
350+
vbmeta="vbmeta.img",
351+
super_empty="super_empty.img",
352+
):
353+
print(line)
354+
assert line
355+
356+
357+
def test_fastboot_flash_recovery_with_additional_partitions_failure(fp):
358+
"""Test if a failure in flashing custom recovery with additional partitions using fastboot is handled properly."""
359+
360+
def callback_function_with_kwargs(process, return_code):
361+
process.returncode = return_code
362+
363+
return_code = 1
364+
365+
with fp.context() as nested_process:
366+
nested_process.register(
367+
[
368+
"test/path/to/tools/fastboot",
369+
"flash",
370+
"dtbo",
371+
"dtbo.img",
372+
],
373+
stdout=[
374+
bytes("error: no devices/emulators found", encoding="utf-8"),
375+
],
376+
callback=callback_function_with_kwargs,
377+
callback_kwargs={"return_code": return_code},
378+
)
379+
nested_process.register(
380+
[
381+
"test/path/to/tools/fastboot",
382+
"--disable-verity",
383+
"--disable-verification",
384+
"flash",
385+
"vbmeta",
386+
"vbmeta.img",
387+
],
388+
stdout=[
389+
bytes("error: no devices/emulators found", encoding="utf-8"),
390+
],
391+
callback=callback_function_with_kwargs,
392+
callback_kwargs={"return_code": return_code},
393+
)
394+
nested_process.register(
395+
[
396+
"test/path/to/tools/fastboot",
397+
"wipe-super",
398+
"super_empty.img",
399+
],
400+
stdout=[
401+
bytes("error: no devices/emulators found", encoding="utf-8"),
402+
],
403+
callback=callback_function_with_kwargs,
404+
callback_kwargs={"return_code": return_code},
405+
)
406+
nested_process.register(
407+
[
408+
"test/path/to/tools/fastboot",
409+
"flash",
410+
"vendor_boot",
411+
"vendor_boot.img",
412+
],
413+
stdout=[
414+
bytes("error: no devices/emulators found", encoding="utf-8"),
415+
],
416+
callback=callback_function_with_kwargs,
417+
callback_kwargs={"return_code": return_code},
418+
)
419+
nested_process.register(
420+
[
421+
"test/path/to/tools/fastboot",
422+
"flash",
423+
"recovery",
424+
"custom_recovery.img",
425+
],
426+
stdout=[
427+
bytes("error: no devices/emulators found", encoding="utf-8"),
428+
],
429+
callback=callback_function_with_kwargs,
430+
callback_kwargs={"return_code": return_code},
431+
)
432+
for line in fastboot_flash_recovery(
433+
bin_path=Path("test/path/to/tools"),
434+
recovery="custom_recovery.img",
435+
is_ab=True,
436+
vendor_boot="vendor_boot.img",
437+
dtbo="dtbo.img",
438+
vbmeta="vbmeta.img",
439+
super_empty="super_empty.img",
440+
):
441+
print(line)
442+
assert not line

0 commit comments

Comments
 (0)