From patchwork Fri May 22 22:32:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 246331 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Fri, 22 May 2020 16:32:39 -0600 Subject: [PATCH 5/6] checkpatch.pl: Request a test when a new command is added In-Reply-To: <20200522223240.187032-1-sjg@chromium.org> References: <20200522223240.187032-1-sjg@chromium.org> Message-ID: <20200522163226.5.I78919f84c7f7563b4926020b3ab7fb9c927bd09b@changeid> This request is made with nearly every new command. Point to some docs on how to do it. Signed-off-by: Simon Glass --- doc/README.commands | 50 +++++++++++++++++++++++++++++++++++++++++++ scripts/checkpatch.pl | 6 ++++++ 2 files changed, 56 insertions(+) diff --git a/doc/README.commands b/doc/README.commands index 716ad227aa1..229f86d8fb2 100644 --- a/doc/README.commands +++ b/doc/README.commands @@ -134,3 +134,53 @@ by writing in u-boot.lds ($(srctree)/board/boardname/u-boot.lds) these .u_boot_list : { KEEP(*(SORT(.u_boot_list*))); } + +Writing tests +------------- + +All new commands should have tests. Tests for existing commands are very +welcome. + +It is fairly easy to write a test for a command. Enable it in sandbox, and +then add code that runs the command and checks the output. + +Here is an example: + +/* Test 'acpi items' command */ +static int dm_test_acpi_cmd_items(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + void *buf; + + buf = malloc(BUF_SIZE); + ut_assertnonnull(buf); + + ctx.current = buf; + ut_assertok(acpi_fill_ssdt(&ctx)); + console_record_reset(); + run_command("acpi items", 0); + ut_assert_nextline("dev 'acpi-test', type 1, size 2"); + ut_assert_nextline("dev 'acpi-test2', type 1, size 2"); + ut_assert_console_end(); + + ctx.current = buf; + ut_assertok(acpi_inject_dsdt(&ctx)); + console_record_reset(); + run_command("acpi items", 0); + ut_assert_nextline("dev 'acpi-test', type 2, size 2"); + ut_assert_nextline("dev 'acpi-test2', type 2, size 2"); + ut_assert_console_end(); + + console_record_reset(); + run_command("acpi items -d", 0); + ut_assert_nextline("dev 'acpi-test', type 2, size 2"); + ut_assert_nextlines_are_dump(2); + ut_assert_nextline("%s", ""); + ut_assert_nextline("dev 'acpi-test2', type 2, size 2"); + ut_assert_nextlines_are_dump(2); + ut_assert_nextline("%s", ""); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_acpi_cmd_items, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e3a2a289aea..22869992e90 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2253,6 +2253,12 @@ sub u_boot_line { WARN("LIVETREE", "Use the livetree API (dev_read_...)\n" . $herecurr); } + + # add tests for new commands + if ($line =~ /^\+.*do_($Ident)\(struct cmd_tbl.*/) { + WARN("CMD_TEST", + "Possible new command - make sure you add a test\n" . $herecurr); + } } sub process {