[libvirt] [PATCH v5 1/6] tests: Add mock for virRandomBytes

Peter Krempa pkrempa at redhat.com
Fri May 20 12:32:17 UTC 2016


On Thu, May 19, 2016 at 16:29:00 -0400, John Ferlan wrote:
> Create a mock for virRandomBytes to generate a not so random value.
> This should be usable by other tests that need a not so random number
> to be generated by including the virrandommock at preload.
> 
> The "random number" generated is based upon the size of the expected
> stream of bytes being returned where each byte in the result gets
> the index of the array - hence a 4 byte array returns 0x00010203.
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  tests/Makefile.am     | 12 +++++++
>  tests/virrandommock.c | 39 +++++++++++++++++++++++
>  tests/virrandomtest.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 137 insertions(+)
>  create mode 100644 tests/virrandommock.c
>  create mode 100644 tests/virrandomtest.c

[...]

> diff --git a/tests/virrandomtest.c b/tests/virrandomtest.c
> new file mode 100644
> index 0000000..f76911f
> --- /dev/null
> +++ b/tests/virrandomtest.c
> @@ -0,0 +1,86 @@

[...]

> +
> +    for (i = 0; i < datalen; i++) {
> +        if (data[i] != i) {
> +            fprintf(stderr,
> +                    "virRandomBytes data[%zu]='%x' not in seqence\n"

This is a very amusing test :). Also this is basically meta-testing
since it's testing that the tests test correctly.

> +                    i, data[i]);
> +            goto cleanup;

ACK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160520/83345668/attachment-0001.sig>


More information about the libvir-list mailing list