mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Stepan Ionichev <sozdayvek@gmail.com>
Cc: akpm@linux-foundation.org, gregkh@linuxfoundation.org,
	brendan.higgins@linux.dev, david@davidgow.net,
	raemoar63@gmail.com, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/uuid_kunit: add tests for the four random UUID/GUID generators
Date: Fri, 15 May 2026 13:51:29 +0300	[thread overview]
Message-ID: <agb6sZH_YezBNTSs@ashevche-desk.local> (raw)
In-Reply-To: <20260514172241.28006-1-sozdayvek@gmail.com>

On Thu, May 14, 2026 at 10:22:41PM +0500, Stepan Ionichev wrote:
> uuid_kunit currently exercises only guid_parse() and uuid_parse() (plus
> their invalid-input paths). The four random generators exported from
> lib/uuid.c -- generate_random_uuid(), generate_random_guid(),
> uuid_gen() and guid_gen() -- have no direct kunit coverage.
> 
> Random output cannot be compared against a fixed expected value, but
> RFC 4122 section 4.4 specifies two invariants that any version-4
> random UUID/GUID must satisfy:
> 
>   - version 4 in the high nibble of the version byte
>     (byte 6 in the wire uuid_t layout, byte 7 in the byte-swapped
>     guid_t layout);
>   - variant DCE 1.1 (binary 10x) in the high bits of byte 8.
> 
> Add four test cases that invoke each generator several times and
> verify these bit patterns hold. The same checks catch a regression
> in either the mask/OR sequence in the generators or the layout
> constants. Run the loop a handful of times to cover the small but
> non-zero chance that an unmasked random byte happens to satisfy
> the version/variant pattern by accident on a single call.

Test cases are always good, although here I'm not sure we are so picky about
following this RFC. Whatever, feel free to add
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

...

> +static void uuid_test_uuid_gen(struct kunit *test)
> +{
> +	unsigned int i;
> +	uuid_t u;

> +	for (i = 0; i < 8; i++) {

Can be

	for (unsigned int i = 0; i < 8; i++) {

> +		uuid_gen(&u);
> +		KUNIT_EXPECT_EQ(test, u.b[6] & 0xf0, 0x40);
> +		KUNIT_EXPECT_EQ(test, u.b[8] & 0xc0, 0x80);
> +	}
> +}

Same for the rest.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-05-15 10:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-14 17:22 Stepan Ionichev
2026-05-15 10:51 ` Andy Shevchenko [this message]
2026-05-16 12:09 ` [PATCH v2] " Stepan Ionichev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=agb6sZH_YezBNTSs@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=david@davidgow.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=raemoar63@gmail.com \
    --cc=sozdayvek@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®