From: Peter Maydell <peter.maydell@linaro.org>
To: Tong Ho <tong.ho@amd.com>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
alistair@alistair23.me, edgar.iglesias@gmail.com,
frasse.iglesias@gmail.com
Subject: Re: [PATCH v3 3/3] tests/qtest: Introduce tests for AMD/Xilinx Versal TRNG device
Date: Tue, 17 Oct 2023 14:47:25 +0100 [thread overview]
Message-ID: <CAFEAcA-s61X-YAc6Fx27HWAdoGEWt3C9dRa-ncNUaMb5RPwxYw@mail.gmail.com> (raw)
In-Reply-To: <20231004142746.350225-4-tong.ho@amd.com>
On Wed, 4 Oct 2023 at 15:27, Tong Ho <tong.ho@amd.com> wrote:
>
> Signed-off-by: Tong Ho <tong.ho@amd.com>
> ---
> tests/qtest/meson.build | 2 +-
> tests/qtest/xlnx-versal-trng-test.c | 490 ++++++++++++++++++++++++++++
> 2 files changed, 491 insertions(+), 1 deletion(-)
> create mode 100644 tests/qtest/xlnx-versal-trng-test.c
>
> +static void trng_test_autogen(void)
> +{
> + const size_t cnt = 512 / 32;
> + uint32_t rng[cnt], prng[cnt];
> + size_t n;
> +
> + trng_reset();
> +
> + /* PRNG run #1 */
> + trng_reseed(prng_seed);
> + trng_generate(true);
> +
> + n = trng_collect(prng, cnt);
> + if (n != cnt) {
> + FAILED("PRNG_1 Auto-gen test failed: expected = %u, got = %u",
> + (unsigned)cnt, (unsigned)n);
> + }
> +
> + /* TRNG, should not match PRNG */
> + trng_reseed(NULL);
> + trng_generate(true);
> +
> + n = trng_collect(rng, cnt);
> + if (n != cnt) {
> + FAILED("TRNG Auto-gen test failed: expected = %u, got = %u",
> + (unsigned)cnt, (unsigned)n);
> + }
> +
> + if (!memcmp(rng, prng, sizeof(rng))) {
> + FAILED("TRNG test failed: matching PRNG");
> + }
Why can't the TRNG output ever match the PRNG output ?
It's random numbers, so you might get (un)lucky.
This sort of check results in flaky CI, because very very
occasionally the RNG will give you output that results in
a test failure.
> +
> + /* PRNG #2: should matches run #1 */
> + trng_reseed(prng_seed);
> + trng_generate(true);
> +
> + n = trng_collect(rng, cnt);
> + if (n != cnt) {
> + FAILED("PRNG_2 Auto-gen test failed: expected = %u, got = %u",
> + (unsigned)cnt, (unsigned)n);
> + }
> +
> + if (memcmp(rng, prng, sizeof(rng))) {
> + FAILED("PRNG_2 Auto-gen test failed: does not match PRNG_1");
> + }
> +}
> +
thanks
-- PMM
prev parent reply other threads:[~2023-10-17 13:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 14:27 [PATCH v3 0/3] AMD/Xilinx Versal TRNG support Tong Ho
2023-10-04 14:27 ` [PATCH v3 1/3] hw/misc: Introduce AMD/Xilix Versal TRNG device Tong Ho
2023-10-17 14:10 ` Peter Maydell
2023-10-04 14:27 ` [PATCH v3 2/3] hw/arm: xlnx-versal-virt: Add AMD/Xilinx " Tong Ho
2023-10-04 19:11 ` Francisco Iglesias
2023-10-04 14:27 ` [PATCH v3 3/3] tests/qtest: Introduce tests for AMD/Xilinx Versal " Tong Ho
2023-10-04 19:08 ` Francisco Iglesias
2023-10-17 13:47 ` Peter Maydell [this message]
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=CAFEAcA-s61X-YAc6Fx27HWAdoGEWt3C9dRa-ncNUaMb5RPwxYw@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=alistair@alistair23.me \
--cc=edgar.iglesias@gmail.com \
--cc=frasse.iglesias@gmail.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=tong.ho@amd.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;
as well as URLs for NNTP newsgroup(s).