From patchwork Mon Oct 28 14:02:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 1185439 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 471xHJ32Vtz9s7T for ; Tue, 29 Oct 2019 01:02:16 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 958C320484; Mon, 28 Oct 2019 14:02:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w15xDJ6FkduC; Mon, 28 Oct 2019 14:02:12 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 2B10B20420; Mon, 28 Oct 2019 14:02:12 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 68C2D1BF3A1 for ; Mon, 28 Oct 2019 14:02:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 65C2386F5C for ; Mon, 28 Oct 2019 14:02:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CD+y5bhe0LC8 for ; Mon, 28 Oct 2019 14:02:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ch3vs04.rockwellcollins.com (smtpimr.rockwellcollins.com [205.175.226.52]) by hemlock.osuosl.org (Postfix) with ESMTPS id CDFC9864B8 for ; Mon, 28 Oct 2019 14:02:08 +0000 (UTC) IronPort-SDR: ojKhCqmr8fijlbND3TNoAUl6zbyHlCjgfMb94MuuYW2zhxZ2fxt8qMQd7l39xsbrBtHYBKY0ur Mp6eq27Htky5DlzkUCrD868JB/BslI2QMuClXu6GjyC5nzbi022a9nfxc40cQ4cnZS5nJ6VKb+ XXpH1VG1EeJ3g0wPGTUFblaT3jChqRNyfYOV2gVsBrSs9AfRC7hj08LKnb7uV61jkkoQNgSSbZ XSr+4kIuuInhC4nNjT0wcA3ixZm4mn816H1eT0Gpgt6DQv7kjq2lHsm+mmMwcrcrIxfbJBCKSq BvE= Received: from ofwch3n02.rockwellcollins.com (HELO dtulimr01.rockwellcollins.com) ([205.175.226.14]) by ch3vs04.rockwellcollins.com with ESMTP; 28 Oct 2019 09:02:08 -0500 X-Received: from bacon.rockwellcollins.com (unknown [192.168.6.146]) by dtulimr01.rockwellcollins.com (Postfix) with ESMTP id 789546071C; Mon, 28 Oct 2019 09:02:07 -0500 (CDT) From: Matt Weber To: buildroot@buildroot.org Date: Mon, 28 Oct 2019 09:02:06 -0500 Message-Id: <20191028140206.15590-1-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 2.18.0 Subject: [Buildroot] [PATCH] docs/manual: run-tests run-time test framework X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ricardo Martincoski MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds a new manual section that captures an overview of the run-tests tool, how to manually run a test and where to find the test case script. A brief set of steps is included to go through how to add a new test case and suggestions on how to test/debug. Cc: Ricardo Martincoski Signed-off-by: Matthew Weber --- docs/manual/contribute.txt | 118 +++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/docs/manual/contribute.txt b/docs/manual/contribute.txt index f339ca50b8..0aa6a345c5 100644 --- a/docs/manual/contribute.txt +++ b/docs/manual/contribute.txt @@ -487,3 +487,121 @@ preserve Unix-style line terminators when downloading raw pastes. Following pastebin services are known to work correctly: - https://gist.github.com/ - http://code.bulix.org/ + +=== Contributing run-time tests + +Buildroot includes a run-time testing framework called run-tests built +upon python scripting and QEMU runtime execution. + +* Builds a well defined configuration +* Boots it under QEMU +* Runs some test to verify that a given feature is working + +These tests are hooked into the Gitlab CI's build and testing +infrastructure. To see the current job status, visit +https://gitlab.com/buildroot.org/buildroot/-/jobs. + +Within the Buildroot repository, the testing framework is organized at the +top level in +support/testing/+ by folders of +conf+, +infra+ and +tests+. +All the test cases live under the +test+ folder and are organized by +boot+, ++core+, +download+, +fs+, +init+, +package+, +toolchain+, and +utils+. + +The Gitlab CI job's execute the +support/testing/run-tests+ tool. For a +current set of tool options see the help description by executing the tool +with '-h'. Some common options include setting the download folder, the +output folder, keeping build output, and for multiple test cases, you +can set the JLEVEL for each. + +Here is an example walk through of running a test case. + +* For a first step, lets see what all the test case options are. The test +cases can be listed by executing +support/testing/run-tests -l+. These tests +can all be ran individually during test development from the console. Both +one at a time and selectively as a group of a subset of tests. + +--------------------- +$ support/testing/run-tests -l +List of tests +test_run (tests.utils.test_check_package.TestCheckPackage) +Test the various ways the script can be called in a simple top to ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainBuildrootMusl) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainBuildrootuClibc) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainCCache) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainCtngMusl) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainLinaroArm) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv4) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv5) ... ok +test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv7) ... ok +[snip] +test_run (tests.init.test_systemd.TestInitSystemSystemdRoFull) ... ok +test_run (tests.init.test_systemd.TestInitSystemSystemdRoIfupdown) ... ok +test_run (tests.init.test_systemd.TestInitSystemSystemdRoNetworkd) ... ok +test_run (tests.init.test_systemd.TestInitSystemSystemdRwFull) ... ok +test_run (tests.init.test_systemd.TestInitSystemSystemdRwIfupdown) ... ok +test_run (tests.init.test_systemd.TestInitSystemSystemdRwNetworkd) ... ok +test_run (tests.init.test_busybox.TestInitSystemBusyboxRo) ... ok +test_run (tests.init.test_busybox.TestInitSystemBusyboxRoNet) ... ok +test_run (tests.init.test_busybox.TestInitSystemBusyboxRw) ... ok +test_run (tests.init.test_busybox.TestInitSystemBusyboxRwNet) ... ok + +Ran 157 tests in 0.021s + +OK +--------------------- + +* Next let's use the Busybox Init system test case with a read/write rootfs ++tests.init.test_busybox.TestInitSystemBusyboxRw+ as our example test case. +* A minimal set of command line arguments when debugging a test case would +include '-d' which points to your dl folder, '-o' to an output folder, and +'-k' to keep any output on both pass/fail. With those options, the test will +retain logging and build artifacts providing status of the build and +execution of the test case. + +--------------------- +$ support/testing/run-tests -d dl -o output_folder -k tests.init.test_busybox.TestInitSystemBusyboxRw +15:03:26 TestInitSystemBusyboxRw Starting +15:03:28 TestInitSystemBusyboxRw Building +15:08:18 TestInitSystemBusyboxRw Building done +15:08:27 TestInitSystemBusyboxRw Cleaning up +. +Ran 1 test in 301.140s + +OK +--------------------- + +* For the case of a successful build, the +output_folder+ would contain a + folder with the Buildroot build, build log and run-time log. If +the build failed, the console output would show the stage at which it failed +(setup / build / run). Depending on the failure stage, the build/run logs +and/or Buildroot build artifacts can be inspected and instrumented. If the +QEMU instance needs to be launched for additional testing, the first few +lines of the run-time log capture it and it would allow some incremental +testing without re-running +support/testing/run-tests+. + +--------------------- +$ ls output_folder/ +TestInitSystemBusyboxRw/ +TestInitSystemBusyboxRw-build.log +TestInitSystemBusyboxRw-run.log +--------------------- + +* The source file used to implement this example test is found under ++support/testing/tests/init/test_busybox.py+. This file outlines the +minimal defconfig that creates the build, QEMU configuration to launch +the built images and the test case assertions. + +The best way to get familiar with how to create a test case is to look at a +few of the basic file system +support/testing/tests/fs/+ and init ++support/testing/tests/init/+ test scripts. Those tests give good examples +of a basic build and build with run type of tests. There are other more +advanced cases that use things like nested +br2-external+ folders to provide +skeletons and additional packages. Beyond creating the test script, there +are a couple additional steps that should be taken once you have your initial +test case script. The first is to add yourself in the +DEVELOPERS+ file to +be the maintainer of that test case. The second is to update the Gitlab CI +yml by executing +make .gitlab-ci.yml+. + +To test an existing or new test case within Gitlab CI, there is a method of +invoking a specific test by creating a Buildroot fork in Gitlab under your +account and then follow the instructions outlined in +https://git.busybox.net/buildroot/commit/?id=12904c03a7ccbf0c04c5b1f7e3302916c6f37f50.