diff --git a/nix/conftest.py b/nix/conftest.py new file mode 100644 index 00000000000..6cc5d68de42 --- /dev/null +++ b/nix/conftest.py @@ -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)) diff --git a/nix/pyenv.nix b/nix/pyenv.nix index cfe9d46e258..15f43e041fd 100644 --- a/nix/pyenv.nix +++ b/nix/pyenv.nix @@ -35,7 +35,7 @@ let }; in pkgs.python310.withPackages (ps: [ - ps.pep8 + ps.autopep8 ps.pytest ps.pytest-xdist ps.pytest-rerunfailures diff --git a/nix/pytest.ini b/nix/pytest.ini new file mode 100644 index 00000000000..1394e7d6a8d --- /dev/null +++ b/nix/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + aarch64: tests that should pass on aarch64 + x86_64: tests that should pass on x86_64 diff --git a/nix/shell.sh b/nix/shell.sh index 198afb6df30..278ffd62333 100644 --- a/nix/shell.sh +++ b/nix/shell.sh @@ -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() { @@ -9,7 +10,6 @@ banner() echo "+---------------------------------------------------------+" } - function clean { banner "Cleanup ./build" rm -rf ./build diff --git a/nix/test_devshell.py b/nix/test_devshell.py new file mode 100755 index 00000000000..e410e782298 --- /dev/null +++ b/nix/test_devshell.py @@ -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")