forked from firecracker-microvm/firecracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_boottime.py
107 lines (87 loc) · 3.55 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
# 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 = 160000 if platform.machine() == "x86_64" else 200000
# 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 not present by default."""
_ = _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_boottime_timer):
"""Check boot time of microVM without network."""
test_microvm_with_boottime_timer.jailer.extra_args.update(
{'boot-timer': None}
)
_ = _configure_and_run_vm(test_microvm_with_boottime_timer)
time.sleep(0.4)
boottime_us = _test_microvm_boottime(
test_microvm_with_boottime_timer.log_data)
print("Boot time with no network is: " + str(boottime_us) + " us")
def test_boottime_with_network(
test_microvm_with_boottime_timer,
network_config
):
"""Check boot time of microVM with network."""
test_microvm_with_boottime_timer.jailer.extra_args.update(
{'boot-timer': None}
)
_tap = _configure_and_run_vm(test_microvm_with_boottime_timer, {
"config": network_config, "iface_id": "1"
})
time.sleep(0.4)
boottime_us = _test_microvm_boottime(
test_microvm_with_boottime_timer.log_data)
print("Boot time with network configured is: " + str(boottime_us) + " us")
def test_initrd_boottime(
test_microvm_with_initrd_timer):
"""Check boot time of microVM when using an initrd."""
test_microvm_with_initrd_timer.jailer.extra_args.update(
{'boot-timer': None}
)
_tap = _configure_and_run_vm(test_microvm_with_initrd_timer, initrd=True)
time.sleep(0.8)
boottime_us = _test_microvm_boottime(
test_microvm_with_initrd_timer.log_data,
max_time_us=INITRD_BOOT_TIME_US)
print("Boot time with initrd is: " + str(boottime_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
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