Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format files by black inside integration_tests/build #3292

Merged
merged 1 commit into from Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 37 additions & 22 deletions tests/integration_tests/build/test_binary_size.py
Expand Up @@ -23,7 +23,7 @@
"JAILER_BINARY_SIZE_TARGET": 851152,
"FC_BINARY_SIZE_LIMIT": 2438511,
"JAILER_BINARY_SIZE_LIMIT": 893709,
}
},
}

FC_BINARY_SIZE_TARGET = SIZES_DICT[MACHINE]["FC_BINARY_SIZE_TARGET"]
Expand Down Expand Up @@ -51,11 +51,18 @@ def test_firecracker_binary_size():
"""
fc_binary, _ = host.get_firecracker_binaries()

result = check_binary_size("firecracker", fc_binary, FC_BINARY_SIZE_TARGET,
BINARY_SIZE_TOLERANCE, FC_BINARY_SIZE_LIMIT)
result = check_binary_size(
"firecracker",
fc_binary,
FC_BINARY_SIZE_TARGET,
BINARY_SIZE_TOLERANCE,
FC_BINARY_SIZE_LIMIT,
)

return f"{result} B", \
f"{FC_BINARY_SIZE_TARGET} +/- {BINARY_SIZE_TOLERANCE * 100}% B"
return (
f"{result} B",
f"{FC_BINARY_SIZE_TARGET} +/- {BINARY_SIZE_TOLERANCE * 100}% B",
)


@pytest.mark.timeout(500)
Expand All @@ -67,12 +74,18 @@ def test_jailer_binary_size():
"""
_, jailer_binary = host.get_firecracker_binaries()

result = check_binary_size("jailer", jailer_binary,
JAILER_BINARY_SIZE_TARGET,
BINARY_SIZE_TOLERANCE, JAILER_BINARY_SIZE_LIMIT)
result = check_binary_size(
"jailer",
jailer_binary,
JAILER_BINARY_SIZE_TARGET,
BINARY_SIZE_TOLERANCE,
JAILER_BINARY_SIZE_LIMIT,
)

return f"{result} B", \
f"{JAILER_BINARY_SIZE_TARGET} +/- {BINARY_SIZE_TOLERANCE * 100}% B"
return (
f"{result} B",
f"{JAILER_BINARY_SIZE_TARGET} +/- {BINARY_SIZE_TOLERANCE * 100}% B",
)


def check_binary_size(name, binary_path, size_target, tolerance, limit):
Expand All @@ -82,33 +95,35 @@ def check_binary_size(name, binary_path, size_target, tolerance, limit):

# Get the name of the variable that needs updating.
namespace = globals()
size_target_name = [name for name in namespace if namespace[name]
is size_target][0]
size_target_name = [name for name in namespace if namespace[name] is size_target][0]

# Compute concrete binary size difference.
delta_size = size_target - binary_size

binary_low_msg = (
'Current {} binary size of {} bytes is below the target'
' of {} bytes with {} bytes.\n'
'Update the {} threshold'
.format(name, binary_size, size_target, delta_size, size_target_name)
"Current {} binary size of {} bytes is below the target"
" of {} bytes with {} bytes.\n"
"Update the {} threshold".format(
name, binary_size, size_target, delta_size, size_target_name
)
)

assert binary_size > size_target * (1 - tolerance), binary_low_msg

binary_high_msg = (
'Current {} binary size of {} bytes is above the target'
' of {} bytes with {} bytes.\n'
.format(name, binary_size, size_target, -delta_size)
"Current {} binary size of {} bytes is above the target"
" of {} bytes with {} bytes.\n".format(
name, binary_size, size_target, -delta_size
)
)

assert binary_size < size_target * (1 + tolerance), binary_high_msg

binary_limit_msg = (
'Current {} binary size of {} bytes is above the limit'
' of {} bytes with {} bytes.\n'
.format(name, binary_size, limit, binary_size - limit)
"Current {} binary size of {} bytes is above the limit"
" of {} bytes with {} bytes.\n".format(
name, binary_size, limit, binary_size - limit
)
)

assert binary_size < limit, binary_limit_msg
Expand Down
31 changes: 13 additions & 18 deletions tests/integration_tests/build/test_dependencies.py
Expand Up @@ -17,25 +17,18 @@ def test_licenses():
@type: build
"""
toml_file = os.path.normpath(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'../../../Cargo.toml')
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../Cargo.toml")
)
utils.run_cmd('cargo deny --manifest-path {} check licenses'.
format(toml_file))
utils.run_cmd("cargo deny --manifest-path {} check licenses".format(toml_file))


@pytest.mark.parametrize(
"dep_file",
["framework/dependencies.txt"]
)
@pytest.mark.parametrize("dep_file", ["framework/dependencies.txt"])
def test_num_dependencies(dep_file):
"""Enforce minimal dependency check.

@type: build
"""
_, stdout, _ = utils.run_cmd('cargo tree --prefix none -e no-dev '
'--workspace')
_, stdout, _ = utils.run_cmd("cargo tree --prefix none -e no-dev " "--workspace")
deps = stdout.splitlines()

current_deps = set()
Expand All @@ -54,16 +47,18 @@ def test_num_dependencies(dep_file):
# with open(dep_file, "w", encoding='utf-8') as prev_deps:
# pprint(sorted(current_deps), stream=prev_deps)

with open(dep_file, encoding='utf-8') as prev_deps:
with open(dep_file, encoding="utf-8") as prev_deps:
prev_deps = ast.literal_eval(prev_deps.read())
if len(current_deps) > len(prev_deps):
difference = current_deps - set(prev_deps)
msg = "The number of build dependencies has increased." \
" Is this expected? New dependencies {}".\
format(list(difference))
msg = (
"The number of build dependencies has increased."
" Is this expected? New dependencies {}".format(list(difference))
)
assert False, msg
elif len(current_deps) != len(prev_deps):
msg = "The build dependencies have changed." \
" Use the code above to modify the {} file.". \
format(dep_file)
msg = (
"The build dependencies have changed."
" Use the code above to modify the {} file.".format(dep_file)
)
assert False, msg
5 changes: 1 addition & 4 deletions tests/integration_tests/build/test_unittests.py
Expand Up @@ -20,7 +20,4 @@ def test_unittests(test_fc_session_root_path):
"""
extra_args = "--release --target {} ".format(TARGET)

host.cargo_test(
test_fc_session_root_path,
extra_args=extra_args
)
host.cargo_test(test_fc_session_root_path, extra_args=extra_args)
5 changes: 5 additions & 0 deletions tests/pyproject.toml
@@ -0,0 +1,5 @@
[tool.black]
# By default config black will ignore `build` directory
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#command-line-options
# This project has `build` directory, so override default config here
exclude = "/(\\.direnv|\\.eggs|\\.git|\\.hg|\\.mypy_cache|\\.nox|\\.tox|\\.venv|venv|\\.svn|\\.ipynb_checkpoints|_build|buck-out|dist|__pypackages__)/"