Path: blob/main/tests/integration_tests/performance/test_versioned_serialization_benchmark.py
1958 views
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.1# SPDX-License-Identifier: Apache-2.02"""A test that ensures that all unit tests pass at integration time."""34import platform5import os6import logging7import json8import shutil910import pytest11import framework.utils as utils12import host_tools.proc as proc13from framework.defs import FC_WORKSPACE_DIR1415BENCHMARK_DIRECTORY = "{}/src/vmm".format(FC_WORKSPACE_DIR)1617PROC_MODEL = proc.proc_type()1819NSEC_IN_MSEC = 10000002021BASELINES = {22"Intel": {23"serialize": {24"no-crc": {25"target": 0.146, # milliseconds26"delta": 0.025 # milliseconds27},28"crc": {29"target": 0.213, # milliseconds30"delta": 0.025 # milliseconds31}32},33"deserialize": {34"no-crc": {35"target": 0.034, # milliseconds36"delta": 0.015 # milliseconds37},38"crc": {39"target": 0.042, # milliseconds40"delta": 0.015 # milliseconds41}42}43},44"AMD": {45"serialize": {46"no-crc": {47"target": 0.096, # milliseconds48"delta": 0.025 # milliseconds49},50"crc": {51"target": 0.122, # milliseconds52"delta": 0.025 # milliseconds53}54},55"deserialize": {56"no-crc": {57"target": 0.034, # milliseconds58"delta": 0.015 # milliseconds59},60"crc": {61"target": 0.042, # milliseconds62"delta": 0.015 # milliseconds63}64}65},66"ARM": {67"serialize": {68"no-crc": {69"target": 0.096, # milliseconds70"delta": 0.025 # milliseconds71},72"crc": {73"target": 0.186, # milliseconds74"delta": 0.025 # milliseconds75}76},77"deserialize": {78"no-crc": {79"target": 0.034, # milliseconds80"delta": 0.015 # milliseconds81},82"crc": {83"target": 0.042, # milliseconds84"delta": 0.015 # milliseconds85}86}87}88}899091def _check_statistics(directory, mean):92proc_model = [item for item in BASELINES if item in PROC_MODEL]93assert len(proc_model) == 1, "Could not get processor model!"9495if "deserialize" in directory.lower():96bench = "deserialize"97else:98bench = "serialize"99100if "crc" in directory.lower():101attribute = "crc"102else:103attribute = "no-crc"104105measure = BASELINES[proc_model[0]][bench][attribute]106low = measure["target"] - measure["delta"]107high = measure["target"] + measure["delta"]108assert low <= mean <= high, "Benchmark result {} has changed!" \109.format(directory)110111112@pytest.mark.skipif(113platform.machine() != "x86_64",114reason="Not supported yet."115)116def test_serialization_benchmark():117"""Benchmark test for MicrovmState serialization/deserialization."""118logger = logging.getLogger("serialization_benchmark")119120# Move into the benchmark directory121os.chdir(BENCHMARK_DIRECTORY)122123# Run benchmark test124cmd = 'cargo bench'125result = utils.run_cmd_sync(cmd)126assert result.returncode == 0127128# Parse each Criterion benchmark from the result folder and129# check the results against a baseline130results_dir = os.path.join(FC_WORKSPACE_DIR, "build/vmm_benchmark")131for directory in os.listdir(results_dir):132# Ignore the 'report' directory as it is of no use to us133if directory == "report":134continue135136logger.info("Benchmark: %s", directory)137138# Retrieve the 'estimates.json' file content139json_file = os.path.join(140results_dir,141"{}/{}".format(directory, "base/estimates.json"))142with open(json_file, "r") as read_file:143estimates = json.load(read_file)144145# Save the Mean measurement(nanoseconds) and transform it(milliseconds)146mean = estimates['mean']['point_estimate'] / NSEC_IN_MSEC147logger.info("Mean: %f", mean)148149_check_statistics(directory, mean)150151# Cleanup the Target directory152shutil.rmtree(results_dir)153154155