2
2
# SPDX-License-Identifier: Apache-2.0
3
3
"""Test that the process startup time up to socket bind is within spec."""
4
4
5
+ # pylint: disable=redefined-outer-name
6
+
5
7
import json
6
8
import os
7
9
import platform
8
10
import time
9
11
12
+ import pytest
13
+
10
14
import host_tools .logging as log_tools
15
+ from framework .properties import global_props
11
16
from host_tools .cargo_build import run_seccompiler_bin
12
17
18
+ # The maximum acceptable startup time in CPU us.
13
19
MAX_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 )
16
38
39
+ return record_startup_time
17
40
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 ):
19
43
"""
20
44
Check startup time when jailer is spawned in a new PID namespace.
21
45
@@ -24,29 +48,28 @@ def test_startup_time_new_pid_ns(test_microvm_with_api, record_property):
24
48
microvm = test_microvm_with_api
25
49
microvm .bin_cloner_path = None
26
50
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 ))
28
52
29
53
30
- def test_startup_time_daemonize (test_microvm_with_api , record_property ):
54
+ def test_startup_time_daemonize (test_microvm_with_api , startup_time ):
31
55
"""
32
56
Check startup time when jailer detaches Firecracker from the controlling terminal.
33
57
34
58
@type: performance
35
59
"""
36
60
microvm = test_microvm_with_api
37
- record_property ( "startup_time_daemonize_μs" , _test_startup_time (microvm ))
61
+ startup_time ( _test_startup_time (microvm ))
38
62
39
63
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 ):
41
65
"""
42
66
Check the startup time when using custom seccomp filters.
43
67
44
68
@type: performance
45
69
"""
46
70
microvm = test_microvm_with_api
47
-
48
71
_custom_filter_setup (microvm )
49
- record_property ( "startup_time_custom_seccomp_μs" , _test_startup_time (microvm ))
72
+ startup_time ( _test_startup_time (microvm ))
50
73
51
74
52
75
def _test_startup_time (microvm ):
@@ -79,11 +102,9 @@ def _test_startup_time(microvm):
79
102
)
80
103
)
81
104
82
- max_startup_time = MAX_STARTUP_TIME_CPU_US [platform .machine ()]
83
105
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
87
108
88
109
89
110
def _custom_filter_setup (test_microvm ):
0 commit comments