Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tests/integration_tests/performance/test_boottime.py
1958 views
1
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""Tests that ensure the boot time to init process is within spec."""
4
5
import re
6
import time
7
import platform
8
9
# The maximum acceptable boot time in us.
10
MAX_BOOT_TIME_US = 150000
11
# NOTE: for aarch64 most of the boot time is spent by the kernel to unpack the
12
# initramfs in RAM. This time is influenced by the size and the compression
13
# method of the used initrd image.
14
INITRD_BOOT_TIME_US = 180000 if platform.machine() == "x86_64" else 200000
15
# TODO: Keep a `current` boot time in S3 and validate we don't regress
16
# Regex for obtaining boot time from some string.
17
TIMESTAMP_LOG_REGEX = r'Guest-boot-time\s+\=\s+(\d+)\s+us'
18
19
20
def test_no_boottime(test_microvm_with_api):
21
"""Check that boot timer device not present by default."""
22
_ = _configure_and_run_vm(test_microvm_with_api)
23
time.sleep(0.4)
24
timestamps = re.findall(TIMESTAMP_LOG_REGEX,
25
test_microvm_with_api.log_data)
26
assert not timestamps
27
28
29
def test_boottime_no_network(test_microvm_with_boottime):
30
"""Check boot time of microVM without network."""
31
vm = test_microvm_with_boottime
32
vm.jailer.extra_args.update(
33
{'boot-timer': None}
34
)
35
_ = _configure_and_run_vm(vm)
36
time.sleep(0.4)
37
boottime_us = _test_microvm_boottime(
38
vm.log_data)
39
print("Boot time with no network is: " + str(boottime_us) + " us")
40
41
42
def test_boottime_with_network(
43
test_microvm_with_boottime,
44
network_config
45
):
46
"""Check boot time of microVM with network."""
47
vm = test_microvm_with_boottime
48
vm.jailer.extra_args.update(
49
{'boot-timer': None}
50
)
51
_tap = _configure_and_run_vm(vm, {
52
"config": network_config, "iface_id": "1"
53
})
54
time.sleep(0.4)
55
boottime_us = _test_microvm_boottime(
56
vm.log_data)
57
print("Boot time with network configured is: " + str(boottime_us) + " us")
58
59
60
def test_initrd_boottime(
61
test_microvm_with_initrd):
62
"""Check boot time of microVM when using an initrd."""
63
vm = test_microvm_with_initrd
64
vm.jailer.extra_args.update(
65
{'boot-timer': None}
66
)
67
_tap = _configure_and_run_vm(vm, initrd=True)
68
time.sleep(0.8)
69
boottime_us = _test_microvm_boottime(
70
vm.log_data,
71
max_time_us=INITRD_BOOT_TIME_US)
72
print("Boot time with initrd is: " + str(boottime_us) + " us")
73
74
75
def _test_microvm_boottime(log_fifo_data, max_time_us=MAX_BOOT_TIME_US):
76
"""Auxiliary function for asserting the expected boot time."""
77
boot_time_us = 0
78
timestamps = re.findall(TIMESTAMP_LOG_REGEX, log_fifo_data)
79
if timestamps:
80
boot_time_us = int(timestamps[0])
81
82
assert boot_time_us > 0
83
assert boot_time_us < max_time_us
84
return boot_time_us
85
86
87
def _configure_and_run_vm(microvm, network_info=None, initrd=False):
88
"""Auxiliary function for preparing microvm before measuring boottime."""
89
microvm.spawn()
90
91
# Machine configuration specified in the SLA.
92
config = {
93
'vcpu_count': 1,
94
'mem_size_mib': 128
95
}
96
97
if initrd:
98
config['add_root_device'] = False
99
config['use_initrd'] = True
100
101
microvm.basic_config(**config)
102
103
if network_info:
104
_tap, _, _ = microvm.ssh_network_config(
105
network_info["config"],
106
network_info["iface_id"]
107
)
108
109
microvm.start()
110
return _tap if network_info else None
111
112