22# SPDX-License-Identifier: Apache-2.0
33"""Test that the process startup time up to socket bind is within spec."""
44
5+ # pylint: disable=redefined-outer-name
6+
57import json
68import os
79import platform
810import time
911
12+ import pytest
13+
1014import host_tools .logging as log_tools
15+ from framework .properties import global_props
1116from host_tools .cargo_build import run_seccompiler_bin
1217
18+ # The maximum acceptable startup time in CPU us.
1319MAX_STARTUP_TIME_CPU_US = {"x86_64" : 5500 , "aarch64" : 3800 }
14- """ The maximum acceptable startup time in CPU us. """
15- # TODO: Keep a `current` startup time in S3 and validate we don't regress
20+ MAX_STARTUP_TIME = MAX_STARTUP_TIME_CPU_US [platform .machine ()]
21+
22+
23+ @pytest .fixture
24+ def startup_time (metrics , record_property ):
25+ """Fixture to capture the startup time"""
26+ metrics .set_dimensions (
27+ {
28+ "instance" : global_props .instance ,
29+ "cpu_model" : global_props .cpu_model ,
30+ "host_kernel" : "linux-" + global_props .host_linux_version ,
31+ }
32+ )
33+
34+ def record_startup_time (startup_time ):
35+ metrics .put_metric ("startup_time" , startup_time , unit = "Microseconds" )
36+ record_property ("startup_time_μs" , startup_time )
37+ record_property ("startup_max_threshold_μs" , MAX_STARTUP_TIME )
1638
39+ return record_startup_time
1740
18- def test_startup_time_new_pid_ns (test_microvm_with_api , record_property ):
41+
42+ def test_startup_time_new_pid_ns (test_microvm_with_api , startup_time ):
1943 """
2044 Check startup time when jailer is spawned in a new PID namespace.
2145
@@ -24,29 +48,28 @@ def test_startup_time_new_pid_ns(test_microvm_with_api, record_property):
2448 microvm = test_microvm_with_api
2549 microvm .bin_cloner_path = None
2650 microvm .jailer .new_pid_ns = True
27- record_property ( "startup_time_new_pid_μs" , _test_startup_time (microvm ))
51+ startup_time ( _test_startup_time (microvm ))
2852
2953
30- def test_startup_time_daemonize (test_microvm_with_api , record_property ):
54+ def test_startup_time_daemonize (test_microvm_with_api , startup_time ):
3155 """
3256 Check startup time when jailer detaches Firecracker from the controlling terminal.
3357
3458 @type: performance
3559 """
3660 microvm = test_microvm_with_api
37- record_property ( "startup_time_daemonize_μs" , _test_startup_time (microvm ))
61+ startup_time ( _test_startup_time (microvm ))
3862
3963
40- def test_startup_time_custom_seccomp (test_microvm_with_api , record_property ):
64+ def test_startup_time_custom_seccomp (test_microvm_with_api , startup_time ):
4165 """
4266 Check the startup time when using custom seccomp filters.
4367
4468 @type: performance
4569 """
4670 microvm = test_microvm_with_api
47-
4871 _custom_filter_setup (microvm )
49- record_property ( "startup_time_custom_seccomp_μs" , _test_startup_time (microvm ))
72+ startup_time ( _test_startup_time (microvm ))
5073
5174
5275def _test_startup_time (microvm ):
@@ -79,11 +102,9 @@ def _test_startup_time(microvm):
79102 )
80103 )
81104
82- max_startup_time = MAX_STARTUP_TIME_CPU_US [platform .machine ()]
83105 assert cpu_startup_time_us > 0
84- assert cpu_startup_time_us <= max_startup_time
85-
86- return f"{ cpu_startup_time_us } us" , f"<= { max_startup_time } us"
106+ assert cpu_startup_time_us <= MAX_STARTUP_TIME
107+ return cpu_startup_time_us
87108
88109
89110def _custom_filter_setup (test_microvm ):
0 commit comments