Skip to contentSkip to conversation

crypto: testmgr: allow building a copy as loadable module for testing.

PATCH In review Michal Suchanek 2 participants 2 messages Dec 19, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: testmgr: allow building a copy as loadable module for testing.

There is no way to just run the tests built into testmgr. Also it is rarely possible to build testmgr modular due to KConfig dependencies.

Add a module that does not provide infrastructure, just runs testmgr tests.

---
 crypto/Kconfig            |   8 ++
 crypto/Makefile           |   3 +
 crypto/alg_test_desc.h    | 219 ++++++++++++++++++++++++++++++++++++++
 crypto/algboss.c          |   2 +
 crypto/algboss_runtests.c |  38 +++++++
 crypto/testmgr.c          |  71 +-----------
 crypto/testmgr.h          | 146 +------------------------
 crypto/testmgr_runtests.c |   1 +
 8 files changed, 277 insertions(+), 211 deletions(-)
 create mode 100644 crypto/alg_test_desc.h
 create mode 100644 crypto/algboss_runtests.c
 create mode 120000 crypto/testmgr_runtests.c
crypto/Kconfig +8 -0
index 5575d48473bd..956379b24c74 100644
@@ -119,6 +119,14 @@ config CRYPTO_MANAGER
 	  Create default cryptographic template instantiations such as
 	  cbc(aes).
 
+config CRYPTO_MANAGER_RUNTESTS
+	tristate "Cryptographic algorithm manager: test module"
+	depends on CRYPTO_MANAGER2 && !CRYPTO_MANAGER_DISABLE_TESTS
+	default m
+	help
+	  Build a module that runs the tests from cryptographic algorithm
+	  manager when loaded.
+
 config CRYPTO_MANAGER2
 	def_tristate CRYPTO_MANAGER || (CRYPTO_MANAGER!=n && CRYPTO_ALGAPI=y)
 	select CRYPTO_AEAD2
crypto/Makefile +3 -0
index 4ca12b6044f7..c296b27da29e 100644
@@ -47,6 +47,9 @@ crypto_acompress-y += scompress.o
 obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o
 
 cryptomgr-y := algboss.o testmgr.o
+cryptomgr_runtests-y := testmgr_runtests.o algboss_runtests.o
+
+obj-$(CONFIG_CRYPTO_MANAGER_RUNTESTS) += cryptomgr_runtests.o
 
 obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
 obj-$(CONFIG_CRYPTO_USER) += crypto_user.o
crypto/alg_test_desc.h new file +219 -0

219 lines not on this page · raw message

crypto/algboss.c +2 -0
index a62149d6c839..be37c78c7833 100644
@@ -300,5 +300,7 @@ static void __exit cryptomgr_exit(void)
 arch_initcall(cryptomgr_init);
 module_exit(cryptomgr_exit);
 
+EXPORT_SYMBOL_GPL(alg_test);
+
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Crypto Algorithm Manager");
crypto/algboss_runtests.c new file +38 -0
new file mode 100644
index 000000000000..7aa3459cc4fc
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/module.h>
+#include "alg_test_desc.h"
+
+static int __init testmgr_runtests_init(void)
+{
+	int i;
+	int ret = 0;
+
+	for (i = 0; i < nr_alg_test_descs; i++) {
+		const char *alg = alg_test_descs[i].alg;
+		int rc;
+
+		pr_info("Testing %s ...", alg);
+		rc = alg_test_descs[i].test(alg_test_descs + i, alg, 0, 0);
+		switch (rc) {
+		case 0:
+			pr_info("PASSED\n");
+			break;
+		case -2:
+			pr_info("SKIPPED\n");
+			break;
+
+		default:
+			ret = rc;
+			pr_err("%s FAILED(%i)\n", alg, rc);
+		}
+	}
+	return ret;
+}
+
+static void __exit testmgr_runtests_exit(void) {}
+
+module_init(testmgr_runtests_init);
+module_exit(testmgr_runtests_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Crypto Algorithm Manager Test Module");
crypto/testmgr.c +5 -66

98 lines not on this page · raw message

crypto/testmgr.h +1 -145

155 lines not on this page · raw message

crypto/testmgr_runtests.c new file +1 -0
new file mode 120000
index 000000000000..e2a85037239d
@@ -0,0 +1 @@
+testmgr.c
\ No newline at end of file
Signature · 1 line
2.23.0
#1 lore raw
Quoted 7 lines · Michal Suchanek

There is no way to just run the tests built into testmgr. Also it is rarely possible to build testmgr modular due to KConfig dependencies.

Add a module that does not provide infrastructure, just runs testmgr tests.

Why does this need to be a kernel module? Since the self-tests are already run at algorithm registration time, it's already possible to use AF_ALG or crypto_user to allocate all algorithms which have self-tests.

- Eric