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