Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tests/integration_tests/performance/test_versioned_serialization_benchmark.py
1958 views
1
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""A test that ensures that all unit tests pass at integration time."""
4
5
import platform
6
import os
7
import logging
8
import json
9
import shutil
10
11
import pytest
12
import framework.utils as utils
13
import host_tools.proc as proc
14
from framework.defs import FC_WORKSPACE_DIR
15
16
BENCHMARK_DIRECTORY = "{}/src/vmm".format(FC_WORKSPACE_DIR)
17
18
PROC_MODEL = proc.proc_type()
19
20
NSEC_IN_MSEC = 1000000
21
22
BASELINES = {
23
"Intel": {
24
"serialize": {
25
"no-crc": {
26
"target": 0.146, # milliseconds
27
"delta": 0.025 # milliseconds
28
},
29
"crc": {
30
"target": 0.213, # milliseconds
31
"delta": 0.025 # milliseconds
32
}
33
},
34
"deserialize": {
35
"no-crc": {
36
"target": 0.034, # milliseconds
37
"delta": 0.015 # milliseconds
38
},
39
"crc": {
40
"target": 0.042, # milliseconds
41
"delta": 0.015 # milliseconds
42
}
43
}
44
},
45
"AMD": {
46
"serialize": {
47
"no-crc": {
48
"target": 0.096, # milliseconds
49
"delta": 0.025 # milliseconds
50
},
51
"crc": {
52
"target": 0.122, # milliseconds
53
"delta": 0.025 # milliseconds
54
}
55
},
56
"deserialize": {
57
"no-crc": {
58
"target": 0.034, # milliseconds
59
"delta": 0.015 # milliseconds
60
},
61
"crc": {
62
"target": 0.042, # milliseconds
63
"delta": 0.015 # milliseconds
64
}
65
}
66
},
67
"ARM": {
68
"serialize": {
69
"no-crc": {
70
"target": 0.096, # milliseconds
71
"delta": 0.025 # milliseconds
72
},
73
"crc": {
74
"target": 0.186, # milliseconds
75
"delta": 0.025 # milliseconds
76
}
77
},
78
"deserialize": {
79
"no-crc": {
80
"target": 0.034, # milliseconds
81
"delta": 0.015 # milliseconds
82
},
83
"crc": {
84
"target": 0.042, # milliseconds
85
"delta": 0.015 # milliseconds
86
}
87
}
88
}
89
}
90
91
92
def _check_statistics(directory, mean):
93
proc_model = [item for item in BASELINES if item in PROC_MODEL]
94
assert len(proc_model) == 1, "Could not get processor model!"
95
96
if "deserialize" in directory.lower():
97
bench = "deserialize"
98
else:
99
bench = "serialize"
100
101
if "crc" in directory.lower():
102
attribute = "crc"
103
else:
104
attribute = "no-crc"
105
106
measure = BASELINES[proc_model[0]][bench][attribute]
107
low = measure["target"] - measure["delta"]
108
high = measure["target"] + measure["delta"]
109
assert low <= mean <= high, "Benchmark result {} has changed!" \
110
.format(directory)
111
112
113
@pytest.mark.skipif(
114
platform.machine() != "x86_64",
115
reason="Not supported yet."
116
)
117
def test_serialization_benchmark():
118
"""Benchmark test for MicrovmState serialization/deserialization."""
119
logger = logging.getLogger("serialization_benchmark")
120
121
# Move into the benchmark directory
122
os.chdir(BENCHMARK_DIRECTORY)
123
124
# Run benchmark test
125
cmd = 'cargo bench'
126
result = utils.run_cmd_sync(cmd)
127
assert result.returncode == 0
128
129
# Parse each Criterion benchmark from the result folder and
130
# check the results against a baseline
131
results_dir = os.path.join(FC_WORKSPACE_DIR, "build/vmm_benchmark")
132
for directory in os.listdir(results_dir):
133
# Ignore the 'report' directory as it is of no use to us
134
if directory == "report":
135
continue
136
137
logger.info("Benchmark: %s", directory)
138
139
# Retrieve the 'estimates.json' file content
140
json_file = os.path.join(
141
results_dir,
142
"{}/{}".format(directory, "base/estimates.json"))
143
with open(json_file, "r") as read_file:
144
estimates = json.load(read_file)
145
146
# Save the Mean measurement(nanoseconds) and transform it(milliseconds)
147
mean = estimates['mean']['point_estimate'] / NSEC_IN_MSEC
148
logger.info("Mean: %f", mean)
149
150
_check_statistics(directory, mean)
151
152
# Cleanup the Target directory
153
shutil.rmtree(results_dir)
154
155