All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] Re: [PATCH 3/4] mptcp: move crypto test to KUNIT
@ 2020-05-25  8:17 Paolo Abeni
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2020-05-25  8:17 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

On Mon, 2020-05-25 at 09:26 +0200, Davide Caratti wrote:
> On Fri, 2020-05-22 at 12:10 +0200, Paolo Abeni wrote:
> > currently MPTCP uses a custom hook to executed unit test at
> > boot time. Let's use the KUNIT framework instead.
> > Additionally move the relevant code to a separate file and
> > export the function needed by the test when self-tests
> > are build as a module.
> > 
> > Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> > ---
> >  net/mptcp/Kconfig       | 19 +++++++----
> >  net/mptcp/Makefile      |  3 ++
> >  net/mptcp/crypto.c      | 65 ++-----------------------------------
> >  net/mptcp/crypto_test.c | 71 +++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 90 insertions(+), 68 deletions(-)
> >  create mode 100644 net/mptcp/crypto_test.c
> > 
> 
> [...]
> 
> > diff --git a/net/mptcp/crypto_test.c b/net/mptcp/crypto_test.c
> > new file mode 100644
> > index 000000000000..3a7c40f5e8f8
> > --- /dev/null
> > +++ b/net/mptcp/crypto_test.c
> > @@ -0,0 +1,71 @@
> > +#include <kunit/test.h>
> 
> Nit: I think we need a SPDX line here (or non-conventional users of
> checkpatch might see a warning)

Right you are! I'll fix that in the next iteration!

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [MPTCP] Re: [PATCH 3/4] mptcp: move crypto test to KUNIT
@ 2020-05-25  7:26 Davide Caratti
  0 siblings, 0 replies; 2+ messages in thread
From: Davide Caratti @ 2020-05-25  7:26 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 2979 bytes --]

On Fri, 2020-05-22 at 12:10 +0200, Paolo Abeni wrote:
> currently MPTCP uses a custom hook to executed unit test at
> boot time. Let's use the KUNIT framework instead.
> Additionally move the relevant code to a separate file and
> export the function needed by the test when self-tests
> are build as a module.
> 
> Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
> ---
>  net/mptcp/Kconfig       | 19 +++++++----
>  net/mptcp/Makefile      |  3 ++
>  net/mptcp/crypto.c      | 65 ++-----------------------------------
>  net/mptcp/crypto_test.c | 71 +++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 90 insertions(+), 68 deletions(-)
>  create mode 100644 net/mptcp/crypto_test.c
> 

[...]

> diff --git a/net/mptcp/crypto_test.c b/net/mptcp/crypto_test.c
> new file mode 100644
> index 000000000000..3a7c40f5e8f8
> --- /dev/null
> +++ b/net/mptcp/crypto_test.c
> @@ -0,0 +1,71 @@
> +#include <kunit/test.h>

Nit: I think we need a SPDX line here (or non-conventional users of
checkpatch might see a warning)

> +
> +#include "protocol.h"
> +
> +struct test_case {
> +	char *key;
> +	char *msg;
> +	char *result;
> +};
> +
> +/* we can't reuse RFC 4231 test vectors, as we have constraint on the
> + * input and key size, and we truncate the output.
> + */
> +static struct test_case tests[] = {
> +	{
> +		.key = "0b0b0b0b0b0b0b0b",
> +		.msg = "48692054",
> +		.result = "8385e24fb4235ac37556b6b886db106284a1da67",
> +	},
> +	{
> +		.key = "aaaaaaaaaaaaaaaa",
> +		.msg = "dddddddd",
> +		.result = "2c5e219164ff1dca1c4a92318d847bb6b9d44492",
> +	},
> +	{
> +		.key = "0102030405060708",
> +		.msg = "cdcdcdcd",
> +		.result = "e73b9ba9969969cefb04aa0d6df18ec2fcc075b6",
> +	},
> +};
> +
> +static void mptcp_crypto_test_basic(struct kunit *test)
> +{
> +	char hmac[20], hmac_hex[41];
> +	u32 nonce1, nonce2;
> +	u64 key1, key2;
> +	u8 msg[8];
> +	int i, j;
> +
> +	for (i = 0; i < ARRAY_SIZE(tests); ++i) {
> +		/* mptcp hmap will convert to be before computing the hmac */
> +		key1 = be64_to_cpu(*((__be64 *)&tests[i].key[0]));
> +		key2 = be64_to_cpu(*((__be64 *)&tests[i].key[8]));
> +		nonce1 = be32_to_cpu(*((__be32 *)&tests[i].msg[0]));
> +		nonce2 = be32_to_cpu(*((__be32 *)&tests[i].msg[4]));
> +
> +		put_unaligned_be32(nonce1, &msg[0]);
> +		put_unaligned_be32(nonce2, &msg[4]);
> +
> +		mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
> +		for (j = 0; j < 20; ++j)
> +			sprintf(&hmac_hex[j << 1], "%02x", hmac[j] & 0xff);
> +		hmac_hex[40] = 0;
> +
> +		KUNIT_EXPECT_STREQ(test, &hmac_hex[0], tests[i].result);
> +	}
> +}
> +
> +static struct kunit_case mptcp_crypto_test_cases[] = {
> +	KUNIT_CASE(mptcp_crypto_test_basic),
> +	{}
> +};
> +
> +static struct kunit_suite mptcp_crypto_suite = {
> +	.name = "mptcp-crypto",
> +	.test_cases = mptcp_crypto_test_cases,
> +};
> +
> +kunit_test_suite(mptcp_crypto_suite);
> +
> +MODULE_LICENSE("GPL");


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-25  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25  8:17 [MPTCP] Re: [PATCH 3/4] mptcp: move crypto test to KUNIT Paolo Abeni
  -- strict thread matches above, loose matches on Subject: below --
2020-05-25  7:26 Davide Caratti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.