1
1
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0
3
- """Tests that check if the release binary sizes fall within expected size."""
3
+ """Tests that check if the release binary sizes fall within expected size.
4
+
5
+ This is not representative of the actual memory overhead of Firecracker.
6
+
7
+ A more representative test is file:../performance/test_memory_overhead.py
8
+ """
4
9
5
- import os
6
10
import platform
7
11
8
12
import pytest
9
13
10
14
import host_tools .cargo_build as host
11
15
12
16
MACHINE = platform .machine ()
13
- """ Platform definition used to select the correct size target"""
14
-
15
- SIZES_DICT = {
16
- "x86_64" : {
17
- "FC_BINARY_SIZE_TARGET" : 3063120 ,
18
- "JAILER_BINARY_SIZE_TARGET" : 1080088 ,
19
- },
20
- "aarch64" : {
21
- "FC_BINARY_SIZE_TARGET" : 2441008 ,
22
- "JAILER_BINARY_SIZE_TARGET" : 1040928 ,
23
- },
24
- }
25
-
26
- FC_BINARY_SIZE_TARGET = SIZES_DICT [MACHINE ]["FC_BINARY_SIZE_TARGET" ]
27
- """Firecracker target binary size in bytes"""
28
-
29
- JAILER_BINARY_SIZE_TARGET = SIZES_DICT [MACHINE ]["JAILER_BINARY_SIZE_TARGET" ]
30
- """Jailer target binary size in bytes"""
31
-
32
- BINARY_SIZE_TOLERANCE = 0.05
33
- """Tolerance of 5% allowed for binary size"""
34
17
35
18
36
19
@pytest .mark .timeout (500 )
37
20
def test_firecracker_binary_size (record_property , metrics ):
38
21
"""
39
22
Test if the size of the firecracker binary is within expected ranges.
40
23
"""
41
- fc_binary , _ = host .get_firecracker_binaries ()
42
-
43
- result = check_binary_size (
44
- "firecracker" ,
45
- fc_binary ,
46
- FC_BINARY_SIZE_TARGET ,
47
- BINARY_SIZE_TOLERANCE ,
48
- )
49
-
50
- record_property (
51
- "firecracker_binary_size" ,
52
- f"{ result } B ({ FC_BINARY_SIZE_TARGET } B ±{ BINARY_SIZE_TOLERANCE :.0%} )" ,
53
- )
24
+ fc_binary = host .get_binary ("firecracker" )
25
+ result = fc_binary .stat ().st_size
26
+ record_property ("firecracker_binary_size" , f"{ result } B" )
54
27
metrics .set_dimensions ({"cpu_arch" : MACHINE })
55
28
metrics .put_metric ("firecracker_binary_size" , result , unit = "Bytes" )
56
29
@@ -60,51 +33,8 @@ def test_jailer_binary_size(record_property, metrics):
60
33
"""
61
34
Test if the size of the jailer binary is within expected ranges.
62
35
"""
63
- _ , jailer_binary = host .get_firecracker_binaries ()
64
-
65
- result = check_binary_size (
66
- "jailer" ,
67
- jailer_binary ,
68
- JAILER_BINARY_SIZE_TARGET ,
69
- BINARY_SIZE_TOLERANCE ,
70
- )
71
-
72
- record_property (
73
- "jailer_binary_size" ,
74
- f"{ result } B ({ JAILER_BINARY_SIZE_TARGET } B ±{ BINARY_SIZE_TOLERANCE :.0%} )" ,
75
- )
36
+ jailer_binary = host .get_binary ("jailer" )
37
+ result = jailer_binary .stat ().st_size
38
+ record_property ("jailer_binary_size" , f"{ result } B" )
76
39
metrics .set_dimensions ({"cpu_arch" : MACHINE })
77
40
metrics .put_metric ("jailer_binary_size" , result , unit = "Bytes" )
78
-
79
-
80
- def check_binary_size (name , binary_path , size_target , tolerance ):
81
- """Check if the specified binary falls within the expected range."""
82
- # Get the size of the release binary.
83
- binary_size = os .path .getsize (binary_path )
84
-
85
- # Get the name of the variable that needs updating.
86
- namespace = globals ()
87
- size_target_name = [name for name in namespace if namespace [name ] is size_target ][0 ]
88
-
89
- # Compute concrete binary size difference.
90
- delta_size = size_target - binary_size
91
-
92
- binary_low_msg = (
93
- "Current {} binary size of {} bytes is below the target"
94
- " of {} bytes with {} bytes.\n "
95
- "Update the {} threshold" .format (
96
- name , binary_size , size_target , delta_size , size_target_name
97
- )
98
- )
99
-
100
- assert binary_size > size_target * (1 - tolerance ), binary_low_msg
101
-
102
- binary_high_msg = (
103
- "Current {} binary size of {} bytes is above the target"
104
- " of {} bytes with {} bytes.\n " .format (
105
- name , binary_size , size_target , - delta_size
106
- )
107
- )
108
-
109
- assert binary_size < size_target * (1 + tolerance ), binary_high_msg
110
- return binary_size
0 commit comments