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

Dev shell tests with pytest #4062

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nix/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import platform
import pytest

ALL = set(["aarch64", "x86_64"])


def pytest_runtest_setup(item):
supported_platforms = ALL.intersection(mark.name for mark in item.iter_markers())
plat = platform.machine()
if supported_platforms and plat not in supported_platforms:
pytest.skip("platform specific test; not running on {}".format(plat))
2 changes: 1 addition & 1 deletion nix/pyenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let
};
in pkgs.python310.withPackages (ps:
[
ps.pep8
ps.autopep8
ps.pytest
ps.pytest-xdist
ps.pytest-rerunfailures
Expand Down
4 changes: 4 additions & 0 deletions nix/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers =
aarch64: tests that should pass on aarch64
x86_64: tests that should pass on x86_64
4 changes: 2 additions & 2 deletions nix/shell.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
echo nix/shell.sh: Entering a devShell
echo nix/shell.sh: Entering a devShell...checking environment.
export SRC_ROOT=$(pwd)
export PATH=$SRC_ROOT/build/bin:$PATH
pytest -rfs -v ./nix/test_devshell.py

banner()
{
Expand All @@ -9,7 +10,6 @@ banner()
echo "+---------------------------------------------------------+"
}


function clean {
banner "Cleanup ./build"
rm -rf ./build
Expand Down
70 changes: 70 additions & 0 deletions nix/test_devshell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import shutil
import subprocess
import pytest


ALL_LCS = ["openssl-3.0", "openssl-1.1.1",
"openssl-1.0.2", "libressl", "aws-lc"]


def translate_lc(lc: str):
# awslc for S2N_LIBCRYPTO is special.
if "awslc" in lc:
return "aws-lc"
else:
return lc


@pytest.mark.parametrize("lc", [os.getenv("S2N_LIBCRYPTO")])
def test_s2n_libcrypto(lc):
# Validate S2N_LIBCRYPTO is in the CMAKE_INCLUDE_PATH
assert lc is not None
libcrypto = translate_lc(lc)
include_path = os.getenv("CMAKE_INCLUDE_PATH")
assert include_path is not None
assert libcrypto in ALL_LCS
assert libcrypto in include_path


@pytest.mark.parametrize("lc", [os.getenv("S2N_LIBCRYPTO")])
def test_s2n_libcrypto_uniq(lc):
# Make certain we only have the preferred libcrypto in CMAKE_INCLUDE_PATH.
assert lc is not None
libcrypto = translate_lc(lc)
include_path = os.getenv("CMAKE_INCLUDE_PATH")
assert include_path is not None
negative_lc = ALL_LCS
negative_lc.remove(libcrypto)
for library in negative_lc:
assert library not in include_path


@pytest.mark.parametrize("cmd,expected,version", [
("gnutls-serv", "gnutls-serv 3.7", "--version"),
("gnutls-cli", "gnutls-cli 3.7", "--version"),
("openssl", "OpenSSL 1.1.1", "version"),
("java", "Corretto-17", "--version")])
def test_utility_versions(cmd, expected, version):
# Valildate utility is in the path and the correct version.
abspath = shutil.which(cmd)
result = ""
with subprocess.Popen([abspath, version], shell=False, stdout=subprocess.PIPE) as p:
output = p.stdout.readlines()
for line in output:
result += line.decode().strip()
' '.join(result)
assert expected in result


def test_python():
# Validate python _from nix_ is in the PATH.
assert 'nix' in shutil.which('python')


def test_pytest():
# Validate pytest _from nix_ is in the PATH.
assert 'nix' in shutil.which('pytest')

if __name__ == "__main__":
print("Use pytest")