From patchwork Mon Oct 15 09:21:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 984051 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q1pI1awp"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42YYKC526gz9s5c for ; Mon, 15 Oct 2018 20:38:23 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5AFD8C21CB1; Mon, 15 Oct 2018 09:34:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5ED0AC21F6A; Mon, 15 Oct 2018 09:17:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E9E84C21E75; Mon, 15 Oct 2018 09:17:15 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 1DA5EC21ECE for ; Mon, 15 Oct 2018 09:17:09 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id c10-v6so8877464pgq.4 for ; Mon, 15 Oct 2018 02:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+XtTlQsYCnYpliLMruBXk/7t5Wb/AHsASl2HUnaXTvc=; b=Q1pI1awp3pBEKjWv+niMruiG3C0PnT0k/4kQihNVRVdwrf0T9xCDU32Bmf9vVHu0Bg J1xfVnSJRn1lJksD449tzw82zz79uRSVGjmeXfp6GvtBmqr1/IJ/B9ybAOeUO9IjYGkO ZlDtByDwiFcWvz+9Br/90Dh7wm+X/FiBBoWx6eX7hVFMsYA46/n4H0XYeSU8IQGdY7HL CmA5dsqm5bKoqfftolLWHuMSvR1dSvVPa3u3jcP/NmIHG2gGIuF29VS0zKK+0p+HeCHc 6x7/XX02WZ883yELOnzKFSTeuAnD633BODBWRVShWFOE9/vdJmCX2lqmAhWcWct8uTg8 1O0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+XtTlQsYCnYpliLMruBXk/7t5Wb/AHsASl2HUnaXTvc=; b=tYs52pV+PY/LiSzpuQh0rO7BacC1lX/4/tVIZGEwNPc97F600H9+MzjbejIpuKXr5E nSF7p4Ns+/tsh/trxZe3Pf8MeIHmYfrIa0c21fnioBHq78RYoWL593L/M0N+N7x/oJFC gt972uvhCnOJNTpuqBarwMGugKMlYE2VL3jEbGgIHcBbGnf68TLBtc4in2+dT/bikeT2 TzLJ0WYrgUNsCiiIYGBmzxSV+KRswPmZXMOKlUbp8jmronQ+66UALYuTHYsLZS5dQn2s BsduIcEcMZAgKBW1ehHbZ8/RdZ1JR/hSe3xrf0sz1Kp3sqGLMGQeC14kB6wSvbjArVyR eaag== X-Gm-Message-State: ABuFfojaQxxEIkdupCcRKAMOfRj4VvyEZK8qiDwah6yH+f7qas77WD/Q tOVq6Y9tJrjHuQhTXEr+PIg= X-Google-Smtp-Source: ACcGV60dHMW7HK4vUYQaOP/4vJJxPdjsmemwg/Sf3VqKGMMQTkTFxms6PkeOEeMAX8/LHfKxQaifwA== X-Received: by 2002:a63:7b09:: with SMTP id w9-v6mr15396314pgc.385.1539595027704; Mon, 15 Oct 2018 02:17:07 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-156-139.windriver.com. [147.11.156.139]) by smtp.gmail.com with ESMTPSA id a11-v6sm10798256pgw.54.2018.10.15.02.17.06 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Oct 2018 02:17:06 -0700 (PDT) From: Bin Meng To: Simon Glass , U-Boot Mailing List Date: Mon, 15 Oct 2018 02:21:26 -0700 Message-Id: <1539595287-31378-31-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1539595287-31378-1-git-send-email-bmeng.cn@gmail.com> References: <1539595287-31378-1-git-send-email-bmeng.cn@gmail.com> Subject: [U-Boot] [PATCH v3 30/31] test: dm: virtio: Add test cases for virtio uclass X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Now that we have a sandbox virtio transport driver, add some test cases to test virtio uclass driver. Signed-off-by: Bin Meng Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- Changes in v3: - Exclude VIRTIO_BLK in sandbox_noblk_defconfig build Changes in v2: - new patch to add test cases for virtio uclass arch/Kconfig | 5 ++ arch/sandbox/dts/test.dts | 8 +++ configs/sandbox_noblk_defconfig | 1 + test/dm/Makefile | 1 + test/dm/virtio.c | 122 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 test/dm/virtio.c diff --git a/arch/Kconfig b/arch/Kconfig index e822a0b..9fdd2f7 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -110,6 +110,11 @@ config SANDBOX imply LIBAVB imply CMD_AVB imply UDP_FUNCTION_FASTBOOT + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_SANDBOX + imply VIRTIO_BLK + imply VIRTIO_NET config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index c52f5a9..47e0646 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -715,6 +715,14 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + sandbox_virtio1 { + compatible = "sandbox,virtio1"; + }; + + sandbox_virtio2 { + compatible = "sandbox,virtio2"; + }; }; #include "sandbox_pmic.dtsi" diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig index 93b2240..e71e2d3 100644 --- a/configs/sandbox_noblk_defconfig +++ b/configs/sandbox_noblk_defconfig @@ -171,6 +171,7 @@ CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y CONFIG_VIDEO_SANDBOX_SDL=y CONFIG_OSD=y CONFIG_SANDBOX_OSD=y +# CONFIG_VIRTIO_BLK is not set CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y CONFIG_CMD_DHRYSTONE=y diff --git a/test/dm/Makefile b/test/dm/Makefile index b490cf2..213e0fd 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -53,4 +53,5 @@ obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_TEE) += tee.o +obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o endif diff --git a/test/dm/virtio.c b/test/dm/virtio.c new file mode 100644 index 0000000..4b317d2 --- /dev/null +++ b/test/dm/virtio.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Bin Meng + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Basic test of the virtio uclass */ +static int dm_test_virtio_base(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + u8 status; + + /* check probe success */ + ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + + /* check the child virtio-blk device is bound */ + ut_assertok(device_find_first_child(bus, &dev)); + ut_assertok(strcmp(dev->name, "virtio-blk#0")); + + /* check driver status */ + ut_assertok(virtio_get_status(dev, &status)); + ut_asserteq(VIRTIO_CONFIG_S_ACKNOWLEDGE, status); + + return 0; +} +DM_TEST(dm_test_virtio_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test all of the virtio uclass ops */ +static int dm_test_virtio_all_ops(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + struct virtio_dev_priv *uc_priv; + uint offset = 0, len = 0, nvqs = 1; + void *buffer = NULL; + u8 status; + u32 counter; + u64 features; + struct virtqueue *vqs[2]; + + /* check probe success */ + ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + + /* check the child virtio-blk device is bound */ + ut_assertok(device_find_first_child(bus, &dev)); + + /* + * fake the virtio device probe by filling in uc_priv->vdev + * which is used by virtio_find_vqs/virtio_del_vqs. + */ + uc_priv = dev_get_uclass_priv(bus); + uc_priv->vdev = dev; + + /* test virtio_xxx APIs */ + ut_assertok(virtio_get_config(dev, offset, buffer, len)); + ut_assertok(virtio_set_config(dev, offset, buffer, len)); + ut_asserteq(-ENOSYS, virtio_generation(dev, &counter)); + ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK)); + ut_assertok(virtio_get_status(dev, &status)); + ut_asserteq(VIRTIO_CONFIG_S_DRIVER_OK, status); + ut_assertok(virtio_reset(dev)); + ut_assertok(virtio_get_status(dev, &status)); + ut_asserteq(0, status); + ut_assertok(virtio_get_features(dev, &features)); + ut_asserteq(VIRTIO_F_VERSION_1, features); + ut_assertok(virtio_set_features(dev)); + ut_assertok(virtio_find_vqs(dev, nvqs, vqs)); + ut_assertok(virtio_del_vqs(dev)); + ut_assertok(virtio_notify(dev, vqs[0])); + + return 0; +} +DM_TEST(dm_test_virtio_all_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test of the virtio driver that does not have required driver ops */ +static int dm_test_virtio_missing_ops(struct unit_test_state *uts) +{ + struct udevice *bus; + + /* find the virtio device */ + ut_assertok(uclass_find_device(UCLASS_VIRTIO, 1, &bus)); + + /* + * Probe the device should fail with error -ENOENT. + * See ops check in virtio_uclass_pre_probe(). + */ + ut_asserteq(-ENOENT, device_probe(bus)); + + return 0; +} +DM_TEST(dm_test_virtio_missing_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test removal of virtio device driver */ +static int dm_test_virtio_remove(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + + /* check probe success */ + ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + + /* check the child virtio-blk device is bound */ + ut_assertok(device_find_first_child(bus, &dev)); + + /* set driver status to VIRTIO_CONFIG_S_DRIVER_OK */ + ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK)); + + /* check the device can be successfully removed */ + dev->flags |= DM_FLAG_ACTIVATED; + ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL)); + + return 0; +} +DM_TEST(dm_test_virtio_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);