From 430768f38b76fd983d003cc6db40c95e7ce8ea0c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 24 May 2023 12:51:32 +0200 Subject: [PATCH] Skip crypto test if RLIMIT_MEMLOCK is too low On systems where the max locked memory (a.k.a., RLIMIT_MEMLOCK) is too low, the crypto test fails with "Cannot allocate memory". Distros such as Debian and Ubuntu run the test-suite as part of the build process. This results in failed builds if the build machine itself does not have a sufficiently high value for RLIMIT_MEMLOCK. That said, the resulting builds would run perfectly fine when installed on machines that meet the requirements. On supported systems, we now check if the RLIMIT_MEMLOCK is high enough and skip the crypto test if it is not. Signed-off-by: Olivier Gayot --- kitty_tests/crypto.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kitty_tests/crypto.py b/kitty_tests/crypto.py index 5f4501cac..c4d24e1d8 100644 --- a/kitty_tests/crypto.py +++ b/kitty_tests/crypto.py @@ -3,12 +3,27 @@ import os +import unittest from . import BaseTest +def is_rlimit_memlock_too_low() -> bool: + ''' On supported systems, return true if the MEMLOCK limit is too low to + run the crypto test. ''' + try: + import resource + except ModuleNotFoundError: + return False + + memlock_limit, _ = resource.getrlimit(resource.RLIMIT_MEMLOCK) + pagesize = resource.getpagesize() + return memlock_limit <= pagesize + + class TestCrypto(BaseTest): + @unittest.skipIf(is_rlimit_memlock_too_low(), 'RLIMIT_MEMLOCK is too low') def test_elliptic_curve_data_exchange(self): from kitty.fast_data_types import AES256GCMDecrypt, AES256GCMEncrypt, CryptoError, EllipticCurveKey alice = EllipticCurveKey()