Coverage for jumpstarter_driver_flashers/driver_test.py: 100%

61 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-05 20:29 +0000

1import os 

2import tempfile 

3 

4import pytest 

5from jumpstarter_driver_power.driver import MockPower 

6from jumpstarter_driver_pyserial.driver import PySerial 

7 

8from .driver import BaseFlasher 

9from jumpstarter.common.exceptions import ConfigurationError 

10from jumpstarter.common.utils import serve 

11 

12 

13@pytest.fixture(scope="session") 

14def temp_dirs(): 

15 with tempfile.TemporaryDirectory() as temp_dir: 

16 cache = os.path.join(temp_dir, "cache") 

17 http = os.path.join(temp_dir, "http") 

18 tftp = os.path.join(temp_dir, "tftp") 

19 os.mkdir(cache) 

20 os.mkdir(http) 

21 os.mkdir(tftp) 

22 yield cache, http, tftp 

23 

24 

25@pytest.fixture(scope="session") # session to retain cache over time 

26def complete_flasher(temp_dirs): 

27 cache, http, tftp = temp_dirs 

28 yield BaseFlasher( 

29 cache_dir=cache, 

30 http_dir=http, 

31 tftp_dir=tftp, 

32 children={ 

33 "serial": PySerial(url="loop://"), 

34 "power": MockPower(), 

35 }, 

36 ) 

37 

38 

39def test_missing_serial(temp_dirs): 

40 cache, http, tftp = temp_dirs 

41 with pytest.raises(ConfigurationError): 

42 BaseFlasher(cache_dir=cache, http_dir=http, tftp_dir=tftp, children={"power": MockPower()}) 

43 

44 

45def test_missing_power(temp_dirs): 

46 cache, http, tftp = temp_dirs 

47 with pytest.raises(ConfigurationError): 

48 BaseFlasher(cache_dir=cache, http_dir=http, tftp_dir=tftp, children={"serial": PySerial(url="loop://")}) 

49 

50 

51def test_drivers_flashers_setup_flasher_bundle(complete_flasher): 

52 with serve(complete_flasher) as client: 

53 client.call("setup_flasher_bundle") 

54 dtb = client.call("get_dtb_filename") 

55 kernel = client.call("get_kernel_filename") 

56 initram = client.call("get_initram_filename") 

57 assert client.tftp.storage.read_bytes(kernel) == b"\x00" * 1024 

58 assert client.tftp.storage.read_bytes(initram) == b"\x00" * 1024 * 2 

59 assert client.tftp.storage.read_bytes(dtb) == b"\x00" * 1024 * 3 

60 

61 

62def test_drivers_flashers_manifest(complete_flasher): 

63 with serve(complete_flasher) as client: 

64 assert client.manifest.spec.kernel.file == "data/kernel" 

65 

66 

67def test_drivers_flashers_dtb_switching(complete_flasher): 

68 with serve(complete_flasher) as client: 

69 assert client.call("get_dtb_filename") == "test-dtb.dtb" 

70 client.call("use_dtb_variant", "alternate") 

71 assert client.call("get_dtb_filename") == "alternate.dtb" 

72 client.call("use_dtb_variant", "test-dtb") 

73 assert client.call("get_dtb_filename") == "test-dtb.dtb" 

74 # verify dtb variant switching to nonexisting 

75 with pytest.raises(ValueError): 

76 client.call("use_dtb_variant", "noexists") 

77 

78 

79def test_drivers_flashers_filenames(complete_flasher): 

80 with serve(complete_flasher) as client: 

81 assert client.call("get_dtb_filename") == "test-dtb.dtb" 

82 assert client.call("get_kernel_filename") == "kernel" 

83 assert client.call("get_initram_filename") == "initramfs" 

84 

85 

86def test_drivers_flashers_addresses(complete_flasher): 

87 with serve(complete_flasher) as client: 

88 assert client.call("get_kernel_address") == "0x82000000" 

89 assert client.call("get_initram_address") == "0x83000000" 

90 assert client.call("get_dtb_address") == "0x84000000"