Path: blob/main/tests/integration_tests/performance/test_boottime.py
1958 views
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.1# SPDX-License-Identifier: Apache-2.02"""Tests that ensure the boot time to init process is within spec."""34import re5import time6import platform78# The maximum acceptable boot time in us.9MAX_BOOT_TIME_US = 15000010# NOTE: for aarch64 most of the boot time is spent by the kernel to unpack the11# initramfs in RAM. This time is influenced by the size and the compression12# method of the used initrd image.13INITRD_BOOT_TIME_US = 180000 if platform.machine() == "x86_64" else 20000014# TODO: Keep a `current` boot time in S3 and validate we don't regress15# Regex for obtaining boot time from some string.16TIMESTAMP_LOG_REGEX = r'Guest-boot-time\s+\=\s+(\d+)\s+us'171819def test_no_boottime(test_microvm_with_api):20"""Check that boot timer device not present by default."""21_ = _configure_and_run_vm(test_microvm_with_api)22time.sleep(0.4)23timestamps = re.findall(TIMESTAMP_LOG_REGEX,24test_microvm_with_api.log_data)25assert not timestamps262728def test_boottime_no_network(test_microvm_with_boottime):29"""Check boot time of microVM without network."""30vm = test_microvm_with_boottime31vm.jailer.extra_args.update(32{'boot-timer': None}33)34_ = _configure_and_run_vm(vm)35time.sleep(0.4)36boottime_us = _test_microvm_boottime(37vm.log_data)38print("Boot time with no network is: " + str(boottime_us) + " us")394041def test_boottime_with_network(42test_microvm_with_boottime,43network_config44):45"""Check boot time of microVM with network."""46vm = test_microvm_with_boottime47vm.jailer.extra_args.update(48{'boot-timer': None}49)50_tap = _configure_and_run_vm(vm, {51"config": network_config, "iface_id": "1"52})53time.sleep(0.4)54boottime_us = _test_microvm_boottime(55vm.log_data)56print("Boot time with network configured is: " + str(boottime_us) + " us")575859def test_initrd_boottime(60test_microvm_with_initrd):61"""Check boot time of microVM when using an initrd."""62vm = test_microvm_with_initrd63vm.jailer.extra_args.update(64{'boot-timer': None}65)66_tap = _configure_and_run_vm(vm, initrd=True)67time.sleep(0.8)68boottime_us = _test_microvm_boottime(69vm.log_data,70max_time_us=INITRD_BOOT_TIME_US)71print("Boot time with initrd is: " + str(boottime_us) + " us")727374def _test_microvm_boottime(log_fifo_data, max_time_us=MAX_BOOT_TIME_US):75"""Auxiliary function for asserting the expected boot time."""76boot_time_us = 077timestamps = re.findall(TIMESTAMP_LOG_REGEX, log_fifo_data)78if timestamps:79boot_time_us = int(timestamps[0])8081assert boot_time_us > 082assert boot_time_us < max_time_us83return boot_time_us848586def _configure_and_run_vm(microvm, network_info=None, initrd=False):87"""Auxiliary function for preparing microvm before measuring boottime."""88microvm.spawn()8990# Machine configuration specified in the SLA.91config = {92'vcpu_count': 1,93'mem_size_mib': 12894}9596if initrd:97config['add_root_device'] = False98config['use_initrd'] = True99100microvm.basic_config(**config)101102if network_info:103_tap, _, _ = microvm.ssh_network_config(104network_info["config"],105network_info["iface_id"]106)107108microvm.start()109return _tap if network_info else None110111112