]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: dm: virtio_rng: Update virtio-rng test
authorKavin Gunasekara <kavin.gunasekara@arm.com>
Mon, 9 Mar 2026 16:55:04 +0000 (16:55 +0000)
committerTom Rini <trini@konsulko.com>
Wed, 25 Mar 2026 20:32:38 +0000 (14:32 -0600)
The virtio-rng test to verify effective handling of oversized return
buffers checks that an (undocumented) error is raised, instead of the
real concern, which is the surrounding buffer integrity following a rng
function call.
Update the test to check that the other contents of a buffer remain
unchanged instead of looking for an error code.

Signed-off-by: Kavin Gunasekara <kavin.gunasekara@arm.com>
Signed-off-by: Meet Patel <meet.patel2@arm.com>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
test/dm/virtio_rng.c

index e404b08484e559767a04538c2677b914c0aa3f6d..5fd56ade5861d588bcf517c3db151479dfe6405e 100644 (file)
@@ -19,12 +19,19 @@ struct virtio_rng_priv {
        struct virtqueue *rng_vq;
 };
 
+#define BUFFER_SIZE 16
+#define CANARY "CANARYCANARYCANARYCANARY"
+
 /* Test the virtio-rng driver validates the used size */
 static int dm_test_virtio_rng_check_len(struct unit_test_state *uts)
 {
        struct udevice *bus, *dev;
        struct virtio_rng_priv *priv;
-       u8 buffer[16];
+       u8 buffer[BUFFER_SIZE + sizeof(CANARY)];
+
+       /* write known data to buffer */
+       memset(buffer, 0xaa, BUFFER_SIZE);
+       memcpy(buffer + BUFFER_SIZE, CANARY, sizeof(CANARY));
 
        /* check probe success */
        ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
@@ -44,7 +51,10 @@ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts)
        priv->rng_vq->vring.used->ring[0].len = U32_MAX;
 
        /* check the driver gracefully handles the error */
-       ut_asserteq(-EIO, dm_rng_read(dev, buffer, sizeof(buffer)));
+       dm_rng_read(dev, buffer, BUFFER_SIZE);
+
+       /* check for the canary bytes behind the real buffer */
+       ut_asserteq_mem(buffer + BUFFER_SIZE, CANARY, sizeof(CANARY));
 
        return 0;
 }