Skip to content

Commit

Permalink
tests/qtest/npcm7xx_rng-test: dump random data on failure
Browse files Browse the repository at this point in the history
Dump the collected random data after a randomness test failure.

Note that this relies on the test having called
g_test_set_nonfatal_assertions() so we don't abort immediately on the
assertion failure.

Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: minor commit message tweak]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
hskinnemoen authored and pm215 committed Dec 10, 2020
1 parent ce3adff commit 1af979b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/qtest/npcm7xx_rng-test.c
Expand Up @@ -20,6 +20,7 @@

#include "libqtest-single.h"
#include "qemu/bitops.h"
#include "qemu-common.h"

#define RNG_BASE_ADDR 0xf000b000

Expand All @@ -36,6 +37,13 @@
/* Number of bits to collect for randomness tests. */
#define TEST_INPUT_BITS (128)

static void dump_buf_if_failed(const uint8_t *buf, size_t size)
{
if (g_test_failed()) {
qemu_hexdump(stderr, "", buf, size);
}
}

static void rng_writeb(unsigned int offset, uint8_t value)
{
writeb(RNG_BASE_ADDR + offset, value);
Expand Down Expand Up @@ -188,6 +196,7 @@ static void test_continuous_monobit(void)
}

g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
dump_buf_if_failed(buf, sizeof(buf));
}

/*
Expand All @@ -209,6 +218,7 @@ static void test_continuous_runs(void)
}

g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
dump_buf_if_failed(buf.c, sizeof(buf));
}

/*
Expand All @@ -230,6 +240,7 @@ static void test_first_byte_monobit(void)
}

g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
dump_buf_if_failed(buf, sizeof(buf));
}

/*
Expand All @@ -254,6 +265,7 @@ static void test_first_byte_runs(void)
}

g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
dump_buf_if_failed(buf.c, sizeof(buf));
}

int main(int argc, char **argv)
Expand Down

0 comments on commit 1af979b

Please sign in to comment.