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 <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-05-24 12:51:32 +02:00
parent 046eb86091
commit 430768f38b

View File

@ -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()