55import os
66import time
77
8+ import pytest
9+
810from host_tools .cargo_build import run_seccompiler_bin
911
12+ ITERATIONS = 100
13+
1014
15+ @pytest .mark .nonci
1116def test_startup_time_new_pid_ns (
1217 microvm_factory , guest_kernel_linux_5_10 , rootfs , metrics
1318):
1419 """
1520 Check startup time when jailer is spawned in a new PID namespace.
1621 """
17- for _ in range (10 ):
22+ for _ in range (ITERATIONS ):
1823 microvm = microvm_factory .build (guest_kernel_linux_5_10 , rootfs )
1924 microvm .jailer .new_pid_ns = True
2025 _test_startup_time (microvm , metrics , "new_pid_ns" )
2126
2227
28+ @pytest .mark .nonci
2329def test_startup_time_daemonize (
2430 microvm_factory , guest_kernel_linux_5_10 , rootfs , metrics
2531):
2632 """
2733 Check startup time when jailer detaches Firecracker from the controlling terminal.
2834 """
29- for _ in range (10 ):
35+ for _ in range (ITERATIONS ):
3036 microvm = microvm_factory .build (guest_kernel_linux_5_10 , rootfs )
3137 _test_startup_time (microvm , metrics , "daemonize" )
3238
3339
40+ @pytest .mark .nonci
3441def test_startup_time_custom_seccomp (
3542 microvm_factory , guest_kernel_linux_5_10 , rootfs , metrics
3643):
3744 """
3845 Check the startup time when using custom seccomp filters.
3946 """
40- for _ in range (10 ):
47+ for _ in range (ITERATIONS ):
4148 microvm = microvm_factory .build (guest_kernel_linux_5_10 , rootfs )
4249 _custom_filter_setup (microvm )
4350 _test_startup_time (microvm , metrics , "custom_seccomp" )
4451
4552
4653def _test_startup_time (microvm , metrics , test_suffix : str ):
54+ test_start_time = time .time ()
4755 microvm .spawn ()
4856 microvm .basic_config (vcpu_count = 2 , mem_size_mib = 1024 )
4957 metrics .set_dimensions (
5058 {** microvm .dimensions , "performance_test" : f"test_startup_time_{ test_suffix } " }
5159 )
52- test_start_time = time .time ()
5360 microvm .start ()
54- time . sleep ( 0.4 )
61+ datapoints = microvm . get_all_metrics ( )
5562
56- # The metrics should be at index 1 .
63+ # The metrics should be at index 0 .
5764 # Since metrics are flushed at InstanceStart, the first line will suffice.
58- datapoints = microvm .get_all_metrics ()
5965 test_end_time = time .time ()
6066 fc_metrics = datapoints [0 ]
6167 startup_time_us = fc_metrics ["api_server" ]["process_startup_time_us" ]
@@ -68,20 +74,21 @@ def _test_startup_time(microvm, metrics, test_suffix: str):
6874 )
6975
7076 assert cpu_startup_time_us > 0
71- # Check that startup time is not a huge value
77+ # Check that startup time is not a huge value (overflow)
7278 # This is to catch issues like the ones introduced in PR
7379 # https://github.com/firecracker-microvm/firecracker/pull/4305
7480 test_time_delta_us = (test_end_time - test_start_time ) * 1000 * 1000
7581 assert startup_time_us < test_time_delta_us
7682 assert cpu_startup_time_us < test_time_delta_us
7783
78- metrics .put_metric ("startup_time" , cpu_startup_time_us , unit = "Microseconds" )
84+ metrics .put_metric ("startup_cpu_time" , cpu_startup_time_us , unit = "Microseconds" )
85+ metrics .put_metric ("startup_time" , startup_time_us , unit = "Microseconds" )
7986
8087
8188def _custom_filter_setup (test_microvm ):
8289 bpf_path = os .path .join (test_microvm .path , "bpf.out" )
8390
84- run_seccompiler_bin (bpf_path )
91+ run_seccompiler_bin (bpf_path , binary_dir = test_microvm . fc_binary_path . parent )
8592
8693 test_microvm .create_jailed_resource (bpf_path )
8794 test_microvm .jailer .extra_args .update ({"seccomp-filter" : "bpf.out" })
0 commit comments