Re: [PATCH] unit: Skip tests that rely on PKCS#8 when parser is missing

Marcel Holtmann <[email protected]> Fri, 13 Feb 2026 21:50:45 +0100
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
Hi Bastien,

> Check whether the kernel has the pkcs8_key_parser module loaded =
(whether
> built-in or external), and allow tests that rely on it to fail.
>=20
> This makes it possible to run the test suite successfully even on
> systems where we might not be able to load modules if they're missing.
> ---
> unit/test-pem.c | 137 +++++++++++++++++++++++++++++++-----------------
> 1 file changed, 88 insertions(+), 49 deletions(-)
>=20
> diff --git a/unit/test-pem.c b/unit/test-pem.c
> index 7ee0597ed172..4ff62ea06d7a 100644
> --- a/unit/test-pem.c
> +++ b/unit/test-pem.c
> @@ -10,6 +10,7 @@
> #endif
>=20
> #include <assert.h>
> +#include <sys/stat.h>
>=20
> #include <ell/ell.h>
>=20
> @@ -136,6 +137,18 @@ static const struct pem_from_data_test =
single_line_cert_chain =3D {
> "-----END CERTIFICATE-----\n",
> };
>=20
> +static bool pkcs8_key_parser_loaded(void)
> +{
> + struct stat s;
> +
> + /* Despite the path, this directory exists whether the module
> + * is external or built-in. */
> + if (stat ("/sys/module/pkcs8_key_parser", &s) !=3D 0)
> + return false;
> +
> + return S_ISDIR (s.st_mode);
> +}
> +

hmm, you just looked at a unit test that I have not converted.

If you look at test-cipher.c for example, you see that I have added =
precheck capability to determine if a test case can be run or not.

static bool aead_cipher_precheck(const void *data)
{
	const struct aead_test_vector *tv =3D data;
	return l_aead_cipher_is_supported(tv->type);
}

> static void destroy_cert(void *cert)
> {
> l_cert_free(cert);
> @@ -384,6 +397,11 @@ static void test_load_file(const void *data)
>=20
> int main(int argc, char *argv[])
> {
> + int flags =3D 0;
> +
> + if (!pkcs8_key_parser_loaded())
> + flags =3D L_TEST_FLAG_ALLOW_FAILURE;
> +
> l_test_init(&argc, &argv);
>=20
> l_test_add("pem/invalid header/test 1", test_pem, &invalid_header1);
> @@ -394,7 +412,7 @@ int main(int argc, char *argv[])
> l_test_add("pem/empty label", test_pem, &empty_label);
> l_test_add("pem/cert chain from data", test_chain_from_data,
> &single_line_cert_chain);
> - l_test_add("pem/private key from data", test_priv_key_from_data, =
NULL);
> + l_test_add_func("pem/private key from data", =
test_priv_key_from_data, flags);

And then I used a macro for the add test case statement

#define add_aead_test(name, data) l_test_add_data_func_precheck(name, =
data, \
						test_aead, =
aead_cipher_precheck, 0);

After that it becomes an easy line in the main() function.

add_aead_test("RFC3610 - Packet Vector #1", &rfc3610_ccm_1);

This makes it clean and easy to change in the future if I want to =
upgrade the test framework.

And I think the unit/test-eapol.c from iwd has some of this done, but =
might could also use a better PKCS#8 support check.

Regards

Marcel