From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFDD5C433EF for ; Thu, 31 Mar 2022 10:13:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C626184233; Thu, 31 Mar 2022 12:12:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="UT0prFNO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BC69E841F2; Thu, 31 Mar 2022 12:10:33 +0200 (CEST) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 54E7A84209 for ; Thu, 31 Mar 2022 12:10:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3DX5FYgYKBjgUmWoffaiiafY.Wigo-Viinfcmnm.XYhr.XY@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id m185-20020a1c26c2000000b0038c9e1197f6so4441617wmm.4 for ; Thu, 31 Mar 2022 03:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=x9OAJzNUDRD0AElVk2QJygC1PbJQ9eXAbjdyrYPB+sk=; b=UT0prFNOh169yVIkFQc76WqTXbeYz3oNETu5d+abZvcGAsafhnk0TnoAhm7bSZVpaX AUbjCYllF2lW8oDfPi29zPwgpt8rBKZYQiQvqwBRd+1uKVjFH2oKD+q10eFVlxoEI9qC B65yHI/F1g5jdxvRQvbDu7glLMzwK0ogHN5Plg9Mc0aXjn2WsVpONoMvBlvTwW+0uEQj JU3/cg0Iw7tsoK2UKP//nrqToZ0MwZorGpyleLls6ISsqmDzb38xMwbGqazEkRne84XP a03QjwvaLwITqihHrFv5k3B7EuR0Y/BvFVvbdOrnVTpXvT8aVeMfIFq8Imohub4Qrhct CtyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=x9OAJzNUDRD0AElVk2QJygC1PbJQ9eXAbjdyrYPB+sk=; b=qxnWJ3DChe7ALULnk84nq9QFv+1HJYT/g3DNzUZh/WPI9SG+Am34jvOokIRTHyRt+0 h0FqclTIaFnIO2OycS/TkufX32TLFKqnkhJbWrJrKvdc/VbcFlj5l2gO5uTp8Ynw14Js mZeEIF07QJSv0KAsRk0oyrkKpU918KG6iTKpKr2k9J4dkxkPQVmvMwUyd23Fr6KJaBYP 3F2FQ/tMh/ISU6o1x9uY56bUVu9s1inLLC8OJ1BNWl1GWti6QFG5Grljz5vi5cBSuKEM B0tufvX4jjqLGWzha+4ZkCVRANk28Pi8nbuyOloInXffNkrHhi05mcyyiP55E4O6uGcX iHwA== X-Gm-Message-State: AOAM530pLHD2lQrmWJFMGcYLklFkzVjcWk0kQ16a3WlPfVVNQF0ygHEN b6+v/g6d2RX5lqGSS+DgblsjUSD5MLZB3sCoisawBJ1WwVM0Vt0vy3pP9X2lnkpQK2WjUgN2ukd cpAQUDH+vjbNdCk5VdHSDSgvVZdy+h+yMC09HOpggsok7VsDivzYsyYY0YFk= X-Google-Smtp-Source: ABdhPJy5WlrfHKIoaJdBvzJuQKw91xdPDov384vbZxZbWjXk0UvSrCXv3Hyi/Cc2Xt9SroyF/X38gWBkfXM= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:15d4:b0:38e:3eff:4a0c with SMTP id v20-20020a05600c15d400b0038e3eff4a0cmr4099084wmf.90.1648721421776; Thu, 31 Mar 2022 03:10:21 -0700 (PDT) Date: Thu, 31 Mar 2022 10:09:49 +0000 In-Reply-To: <20220331100949.3637425-1-ascull@google.com> Message-Id: <20220331100949.3637425-12-ascull@google.com> Mime-Version: 1.0 References: <20220331100949.3637425-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 11/11] RFC: test: dm: virtio: Test virtio-rng with faked device From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, adelva@google.com, keirf@google.com, ptosi@google.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean When looking into possibilities for testing virtio drivers I was trying to simulate the device's responses in the virtqueue. It required a hack to get access to the virtqueue by accessing the driver's private data and only allows pre-programmed buffer returns but no dynamic responses, data or descriptor modifications. This is an example of a regression test for the virtio-rng fix in the previous patch. Signed-off-by: Andrew Scull --- test/dm/virtio.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/dm/virtio.c b/test/dm/virtio.c index 7139c31ab5..85791e3f58 100644 --- a/test/dm/virtio.c +++ b/test/dm/virtio.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -211,3 +212,38 @@ static int dm_test_virtio_ring(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_virtio_ring, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +struct virtio_rng_priv { + struct virtqueue *rng_vq; +}; + +/* Test the virtio-rng driver validates the used size */ +static int dm_test_virtio_rng(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + struct virtio_rng_priv *priv; + u8 buffer[16]; + + /* check probe success */ + ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertnonnull(bus); + + /* check the child virtio-rng device is bound */ + ut_assertok(device_find_first_child(bus, &dev)); + ut_assertnonnull(dev); + + /* probe the virtio-rng driver */ + ut_assertok(device_probe(dev)); + + /* simulate the device returning the buffer with too much data */ + priv = dev_get_priv(dev); + priv->rng_vq->vring.used->idx = 1; + priv->rng_vq->vring.used->ring[0].id = 0; + 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))); + + return 0; +} +DM_TEST(dm_test_virtio_rng, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- 2.35.1.1094.g7c7d902a7c-goog