1010
1111from framework .properties import global_props
1212
13- # The maximum acceptable boot time in us.
14- # It is a bit bigger than the default 150_000 because
15- # we have ftrace enabled in the guest kernels.
16- MAX_BOOT_TIME_US = 170000
17-
1813# Regex for obtaining boot time from some string.
1914TIMESTAMP_LOG_REGEX = r"Guest-boot-time\s+\=\s+(\d+)\s+us"
2015
3227}
3328
3429
35- @pytest .fixture
36- def fast_microvm (microvm_factory , guest_kernel_linux_4_14 , rootfs_rw ):
37- """The microvm defined for the boottime SLA
38-
39- Guest kernel 4.14
40- Rootfs: Ubuntu 22.04 ext4
41-
42- Using ext4 seems to result in a faster boot than with squashfs. Probably
43- because we have to spend CPU time decompressing and extracting into memory.
44- """
45- return microvm_factory .build (kernel = guest_kernel_linux_4_14 , rootfs = rootfs_rw )
46-
47-
48- def test_no_boottime (uvm_plain ):
49- """
50- Check that boot timer device is not present by default.
51- """
52- vm = uvm_plain
53- _configure_and_run_vm (vm )
54- # microvm.start() ensures that the vm is in Running mode,
55- # so there is no need to sleep and wait for log message.
56- timestamps = re .findall (TIMESTAMP_LOG_REGEX , uvm_plain .log_data )
57- assert not timestamps
58-
59-
60- def test_boottime_no_network (fast_microvm , record_property , metrics ):
61- """
62- Check boot time of microVM without a network device.
63- """
64-
65- vm = fast_microvm
66- vm .jailer .extra_args .update ({"boot-timer" : None })
67- _configure_and_run_vm (vm )
68- boottime_us = _get_microvm_boottime (vm )
69- print (f"Boot time with no network is: { boottime_us } us" )
70- record_property ("boottime_no_network" , f"{ boottime_us } us < { MAX_BOOT_TIME_US } us" )
71- metrics .set_dimensions (DIMENSIONS )
72- metrics .put_metric ("boot_time" , boottime_us , unit = "Microseconds" )
73- assert (
74- boottime_us < MAX_BOOT_TIME_US
75- ), f"boot time { boottime_us } cannot be greater than: { MAX_BOOT_TIME_US } us"
76-
77-
78- def test_boottime_with_network (fast_microvm , record_property , metrics ):
79- """Check boot time of microVM with a network device."""
80- vm = fast_microvm
81- vm .jailer .extra_args .update ({"boot-timer" : None })
82- _configure_and_run_vm (vm , network = True )
83- boottime_us = _get_microvm_boottime (vm )
84- print (f"Boot time with network configured is: { boottime_us } us" )
85- record_property (
86- "boottime_with_network" , f"{ boottime_us } us < { MAX_BOOT_TIME_US } us"
87- )
88- metrics .set_dimensions (DIMENSIONS )
89- metrics .put_metric ("boot_time_with_net" , boottime_us , unit = "Microseconds" )
90- assert (
91- boottime_us < MAX_BOOT_TIME_US
92- ), f"boot time { boottime_us } cannot be greater than: { MAX_BOOT_TIME_US } us"
93-
94-
95- def test_initrd_boottime (uvm_with_initrd , record_property , metrics ):
96- """
97- Check boot time of microVM when using an initrd.
98- """
99- vm = uvm_with_initrd
100- vm .jailer .extra_args .update ({"boot-timer" : None })
101- _configure_and_run_vm (vm , initrd = True )
102- boottime_us = _get_microvm_boottime (vm )
103- print (f"Boot time with initrd is: { boottime_us } us" )
104- record_property ("boottime_initrd" , f"{ boottime_us } us" )
105- metrics .set_dimensions (DIMENSIONS )
106- metrics .put_metric ("boot_time_with_initrd" , boottime_us , unit = "Microseconds" )
107-
108-
10930def _get_microvm_boottime (vm ):
11031 """Auxiliary function for asserting the expected boot time."""
11132 boot_time_us = None
@@ -129,28 +50,6 @@ def _get_microvm_boottime(vm):
12950 return boot_time_us
13051
13152
132- def _configure_and_run_vm (microvm , network = False , initrd = False ):
133- """Auxiliary function for preparing microvm before measuring boottime."""
134- microvm .spawn ()
135-
136- # Machine configuration specified in the SLA.
137- config = {
138- "vcpu_count" : 1 ,
139- "mem_size_mib" : 128 ,
140- "boot_args" : DEFAULT_BOOT_ARGS + " init=/usr/local/bin/init" ,
141- "enable_entropy_device" : True ,
142- }
143- if initrd :
144- config ["add_root_device" ] = False
145- config ["use_initrd" ] = True
146-
147- microvm .basic_config (** config )
148- if network :
149- microvm .add_net_iface ()
150- microvm .start ()
151- microvm .pin_threads (0 )
152-
153-
15453def find_events (log_data ):
15554 """
15655 Parse events in the Firecracker logs
0 commit comments