Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5897pxj; Wed, 26 May 2021 14:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvMxgd7OGb/rT6dZnaeJNCFLi/0HRNysUOdmBCbbnVG/gV9MtriVN3kBDl4ZAYiYsyDKXc X-Received: by 2002:a17:907:980c:: with SMTP id ji12mr302050ejc.152.1622064594109; Wed, 26 May 2021 14:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622064594; cv=none; d=google.com; s=arc-20160816; b=GgCotguYhe7zX3Vp5Qj9xItqOB+SXEgVM94uo0lw/mOrpR0oLAxP/hlTrDqTS6ySfk CiaTTdiAt7Wzspre3bfJouph/iHCsbkvgjXW/LIXWBnV9CTtl/bsw5/9VV2Uaty/yh6p mC/W6u40iWFtheThqmYmkePH9LAjRmziUPBOyHusxP5nmHO0/7T6YjEmXug9sBqdntqK zrz//wDrEOjVkAxn4w21W8eWE4go3zuPX23/geEk3ASEqqa+Rm1bA3/yPg4SRrGNFUDw PyXlAvoaG3VvZdW2tLLa+arCat3PcsaO4YWcD7E4wWYRrH6jB2EeGYCn7KQeFtjWw1HL o3pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=NCrgWD9y8dgxTwWaAeztMIx9ZvUPVidLmF2TLjSwzOg=; b=pv3bRVk56ida7683OJu6e7mxrjW1uJPDZWcoaHa7m6fijmL9MrkHE1ygAdfRUpjf2a Q1+TiHK/p2m6QFX8TgqkUe5dR6eKWqLLYea0a1O9bf7+7abZvRUWmrE8JLsNEOk17Cnw Y54/Nopi7ynjWtP7Ba7PcOSlJjgiYVadVwceEn9lalbEcEJJu0yVmWA5neGLMur7SwuO 5biUAixiNMmfmE7Mi6GCOE+7k+4AGITLP+VU2e5Om2QeUbP8tqcBmOJgV2d8K1ZJMMDU uN2TcIL5ubKxoqkazfo1wQEvQG4xqTHj8ETrGr5nXQqwJA71JNsMQRETaaTTrM3RBzYu STaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QslW7nZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k11si48786edi.5.2021.05.26.14.29.30; Wed, 26 May 2021 14:29:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QslW7nZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234193AbhEZV0E (ORCPT + 99 others); Wed, 26 May 2021 17:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234186AbhEZVZz (ORCPT ); Wed, 26 May 2021 17:25:55 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765D9C061761 for ; Wed, 26 May 2021 14:24:22 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id h7-20020ac846c70000b0290231af0e7829so1492113qto.7 for ; Wed, 26 May 2021 14:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NCrgWD9y8dgxTwWaAeztMIx9ZvUPVidLmF2TLjSwzOg=; b=QslW7nZ2jdLCUQI6gauB+dNQdZU7thGetMHlphcJ4qWFxSlzyFs0cyd2icaLOL+cIE NTMAlx4YcSYUoYv0Ab0IJlaKT9+3YNxyXvCHAeL/XEKUqO3qNAVG7qGqsz+Pa+P6ZG23 CBZeDO7hllQZx7dwUBkb4v1HdHi+7wsh7DaBF1in4YYdEx7kCN7YGtl40GWnKj3NeVtI IARdQo13n2lDu9qN5g2LeMJtSbNZGuBB9IuhVVPkSWSokmE5q8KOkcMgGY0wIE942I+U vdw3J7Ep4MwOv3qSV2b1cGaPnU03B3RetgNcnyB52UiA+GytXhhLajuR6aDcgUf9wbHx HB4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NCrgWD9y8dgxTwWaAeztMIx9ZvUPVidLmF2TLjSwzOg=; b=NrGcdi8WgOT7mZ0FbYAUTfg9kD2tdQLSERNl8FghK5AZ0poitauqOKpVK3ol9oiUJI kBeXY/67SIzc8EaPay5on5xyD7kr1Od2zVaIey7j/3wBq29IddsADIJufl563rBiSbHf Dz8JIsxhg7xnx2dy1c6VDRjH0474OlDcMZt2cJGr5xV5gqcEOeaNEH7ccHmHidUort/3 0fxJY+YNPyB9+qFBXhxloEsVF6TtZK81PAtjubbgzE9WDmD6CScwDXGC5koMWeNJB0sf 7+MIDHp/pS0Xu4owyVyMNVyUCPYm857VLmRkx3v6dOXuFpUVIMJlOoRzFQNA9bC8G3pz NOPg== X-Gm-Message-State: AOAM532ucVwF4Xq2ASmbXK7lXy8XxggrWQ+/V0eIat3i67l+oYIOPC+/ GSsqascYZ2Pe4vC3URTc4Pw1B6Hi836t3ZgxzQPunQ== X-Received: from mactruck.svl.corp.google.com ([2620:15c:2cb:201:2a22:5aa3:3643:4ddb]) (user=brendanhiggins job=sendgmr) by 2002:a05:6214:212f:: with SMTP id r15mr390267qvc.11.1622064261597; Wed, 26 May 2021 14:24:21 -0700 (PDT) Date: Wed, 26 May 2021 14:24:07 -0700 In-Reply-To: <20210526212407.2753879-1-brendanhiggins@google.com> Message-Id: <20210526212407.2753879-5-brendanhiggins@google.com> Mime-Version: 1.0 References: <20210526212407.2753879-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH v2 4/4] Documentation: kunit: document support for QEMU in kunit_tool From: Brendan Higgins To: shuah@kernel.org, davidgow@google.com Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, corbet@lwn.net, linux-doc@vger.kernel.org, sboyd@kernel.org, keescook@chromium.org, frowand.list@gmail.com, dlatypov@google.com, Brendan Higgins Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Document QEMU support, what it does, and how to use it in kunit_tool. Signed-off-by: Brendan Higgins --- Changes since last revision: - Finally, I added a new section to the kunit_tool documentation to document the new command line flags I added. --- Documentation/dev-tools/kunit/kunit-tool.rst | 48 +++++++++++++++++++ Documentation/dev-tools/kunit/usage.rst | 50 +++++++++++++++----- 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/Documentation/dev-tools/kunit/kunit-tool.rst b/Documentation/dev-tools/kunit/kunit-tool.rst index 4247b7420e3ba..c7ff9afe407a5 100644 --- a/Documentation/dev-tools/kunit/kunit-tool.rst +++ b/Documentation/dev-tools/kunit/kunit-tool.rst @@ -145,6 +145,54 @@ to run KUnit resource tests, you could use: This uses the standard glob format for wildcards. +Running Tests on QEMU +===================== + +kunit_tool supports running tests on QEMU as well as via UML (as mentioned +elsewhere). The default way of running tests on QEMU requires two flags: + +``--arch`` + Selects a collection of configs (Kconfig as well as QEMU configs + options, etc) that allow KUnit tests to be run on the specified + architecture in a minimal way; this is usually not much slower than + using UML. The architecture argument is the same as the name of the + option passed to the ``ARCH`` variable used by Kbuild. Not all + architectures are currently supported by this flag, but can be handled + by the ``--qemu_config`` discussed later. If ``um`` is passed (or this + this flag is ignored) the tests will run via UML. Non-UML architectures, + e.g. i386, x86_64, arm, um, etc. Non-UML run on QEMU. + +``--cross_compile`` + Specifies the use of a toolchain by Kbuild. The argument passed here is + the same passed to the ``CROSS_COMPILE`` variable used by Kbuild. As a + reminder this will be the prefix for the toolchain binaries such as gcc + for example ``sparc64-linux-gnu-`` if you have the sparc toolchain + installed on your system, or + ``$HOME/toolchains/microblaze/gcc-9.2.0-nolibc/microblaze-linux/bin/microblaze-linux-`` + if you have downloaded the microblaze toolchain from the 0-day website + to a directory in your home directory called ``toolchains``. + +In many cases it is likely that you may want to run an architecture which is +not supported by the ``--arch`` flag, or you may want to just run KUnit tests +on QEMU using a non-default configuration. For this use case, you can write +your own QemuConfig. These QemuConfigs are written in Python. They must have an +import line ``from ..qemu_config import QemuArchParams`` at the top of the file +and the file must contain a variable called ``QEMU_ARCH`` that has an instance +of ``QemuArchParams`` assigned to it. An example can be seen in +``tools/testing/kunit/qemu_configs/x86_64.py``. + +Once you have a QemuConfig you can pass it into kunit_tool using the +``--qemu_config`` flag; when used this flag replaces the ``--arch`` flag. If we +were to do this with the ``x86_64.py`` example from above, the invocation would +look something like this: + +.. code-block:: bash + + ./tools/testing/kunit/kunit.py run \ + --timeout=60 \ + --jobs=12 \ + --qemu_config=./tools/testing/kunit/qemu_configs/x86_64.py + Other Useful Options ==================== diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index 650f99590df57..888c341701da4 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -609,17 +609,45 @@ non-UML architectures: None of these are reasons not to run your KUnit tests on real hardware; they are only things to be aware of when doing so. -The biggest impediment will likely be that certain KUnit features and -infrastructure may not support your target environment. For example, at this -time the KUnit Wrapper (``tools/testing/kunit/kunit.py``) does not work outside -of UML. Unfortunately, there is no way around this. Using UML (or even just a -particular architecture) allows us to make a lot of assumptions that make it -possible to do things which might otherwise be impossible. - -Nevertheless, all core KUnit framework features are fully supported on all -architectures, and using them is straightforward: all you need to do is to take -your kunitconfig, your Kconfig options for the tests you would like to run, and -merge them into whatever config your are using for your platform. That's it! +Currently, the KUnit Wrapper (``tools/testing/kunit/kunit.py``) (aka +kunit_tool) only fully supports running tests inside of UML and QEMU; however, +this is only due to our own time limitations as humans working on KUnit. It is +entirely possible to support other emulators and even actual hardware, but for +now QEMU and UML is what is fully supported within the KUnit Wrapper. Again, to +be clear, this is just the Wrapper. The actualy KUnit tests and the KUnit +library they are written in is fully architecture agnostic and can be used in +virtually any setup, you just won't have the benefit of typing a single command +out of the box and having everything magically work perfectly. + +Again, all core KUnit framework features are fully supported on all +architectures, and using them is straightforward: Most popular architectures +are supported directly in the KUnit Wrapper via QEMU. Currently, supported +architectures on QEMU include: + +* i386 +* x86_64 +* arm +* arm64 +* alpha +* powerpc +* riscv +* s390 +* sparc + +In order to run KUnit tests on one of these architectures via QEMU with the +KUnit wrapper, all you need to do is specify the flags ``--arch`` and +``--cross_compile`` when invoking the KUnit Wrapper. For example, we could run +the default KUnit tests on ARM in the following manner (assuming we have an ARM +toolchain installed): + +.. code-block:: bash + + tools/testing/kunit/kunit.py run --timeout=60 --jobs=12 --arch=arm --cross_compile=arm-linux-gnueabihf- + +Alternatively, if you want to run your tests on real hardware or in some other +emulation environment, all you need to do is to take your kunitconfig, your +Kconfig options for the tests you would like to run, and merge them into +whatever config your are using for your platform. That's it! For example, let's say you have the following kunitconfig: -- 2.31.1.818.g46aad6cb9e-goog