From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>,
Rui Miguel Silva <rui.silva@linaro.org>,
Stefan Roese <sr@denx.de>,
U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH 25/45] test: Support tests which can only be run manually
Date: Mon, 26 Sep 2022 08:56:14 +0200 [thread overview]
Message-ID: <a20d9ca8-77ce-bc3e-87ab-9900cddbd179@gmx.de> (raw)
In-Reply-To: <20220925150248.2524421-26-sjg@chromium.org>
On 9/25/22 17:02, Simon Glass wrote:
> At present we normally write tests either in Python or in C. But most
> Python tests end up doing a lot of checks which would be better done in C.
> Checks done in C are orders of magnitude faster and it is possible to get
> full access to U-Boot's internal workings, rather than just relying on
> the command line.
>
> The model is to have a Python test set up some things and then use C code
> (in a unit test) to check that they were done correctly. But we don't want
> those checks to happen as part of normal test running, since each C unit
> tests is dependent on the associate Python tests, so cannot run without
> it.
>
> To acheive this, add a new UT_TESTF_MANUAL flag to use with the C 'check'
> tests, so that they can be skipped by default when the 'ut' command is
> used. Require that tests have a name ending with '_norun', so that pytest
> knows to skip them.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> arch/sandbox/cpu/spl.c | 2 +-
> doc/develop/tests_writing.rst | 22 ++++++++++++++++++++++
> include/test/test.h | 8 ++++++++
> include/test/ut.h | 4 +++-
> test/cmd_ut.c | 16 +++++++++++++---
> test/dm/test-dm.c | 2 +-
> test/py/conftest.py | 8 +++++++-
> test/test-main.c | 27 ++++++++++++++++++++++++++-
> 8 files changed, 81 insertions(+), 8 deletions(-)
>
> diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
> index 6d4981152bb..2678370481a 100644
> --- a/arch/sandbox/cpu/spl.c
> +++ b/arch/sandbox/cpu/spl.c
> @@ -90,7 +90,7 @@ void spl_board_init(void)
> int ret;
>
> ret = ut_run_list("spl", NULL, tests, count,
> - state->select_unittests, 1);
> + state->select_unittests, 1, false);
> /* continue execution into U-Boot */
> }
> }
> diff --git a/doc/develop/tests_writing.rst b/doc/develop/tests_writing.rst
> index 1ddf7a353a7..d3ffc550300 100644
> --- a/doc/develop/tests_writing.rst
> +++ b/doc/develop/tests_writing.rst
> @@ -74,6 +74,28 @@ NOT rely on running with sandbox, but instead should function correctly on any
> board supported by U-Boot.
>
>
> +Mixing Python and C
> +-------------------
> +
> +The best of both worlds is sometimes to have a Python test set things up and
> +perform some operations, with a 'checker' C unit test doing the checks
> +afterwards. This can be achieved with these steps:
> +
> +- Add the `UT_TESTF_MANUAL` flag to the checker test so that the `ut` command
> + does not run it by default
> +- Add a `_norun` suffix to the name so that pytest knows to skip it too
> +
> +In your Python test use the `-f` flag to the `ut` command to force the checker
> +test to run it, e.g.::
> +
> + # Do the Python part
> + host load ...
> + bootm ...
> +
> + # Run the checker to make sure that everything worked
> + ut -f bootstd vbe_test_fixup_norun
Shouldn't the documentation describes what a test looks like that can
only be run manually?
Best regards
Heinrich
> +
> +
> How slow are Python tests?
> --------------------------
>
> diff --git a/include/test/test.h b/include/test/test.h
> index 011668795b9..1c3ed638d24 100644
> --- a/include/test/test.h
> +++ b/include/test/test.h
> @@ -22,6 +22,7 @@
> * @force_fail_alloc: Force all memory allocs to fail
> * @skip_post_probe: Skip uclass post-probe processing
> * @runs_per_test: Number of times to run each test (typically 1)
> + * @force_run: true to run tests marked with the UT_TESTF_MANUAL flag
> * @fdt_chksum: crc8 of the device tree contents
> * @fdt_copy: Copy of the device tree
> * @fdt_size: Size of the device-tree copy
> @@ -42,6 +43,7 @@ struct unit_test_state {
> int force_fail_alloc;
> int skip_post_probe;
> int runs_per_test;
> + bool force_run;
> uint fdt_chksum;
> void *fdt_copy;
> uint fdt_size;
> @@ -63,6 +65,12 @@ enum {
> /* do extra driver model init and uninit */
> UT_TESTF_DM = BIT(6),
> UT_TESTF_OTHER_FDT = BIT(7), /* read in other device tree */
> + /*
> + * Only run if explicitly requested with 'ut -f <suite> <test>'. The
> + * test name must end in "_norun" so that pytest detects this also,
> + * since it cannot access the flags.
> + */
> + UT_TESTF_MANUAL = BIT(8),
> };
>
> /**
> diff --git a/include/test/ut.h b/include/test/ut.h
> index f7217aa8ac5..e0e618b58c2 100644
> --- a/include/test/ut.h
> +++ b/include/test/ut.h
> @@ -409,9 +409,11 @@ void test_set_state(struct unit_test_state *uts);
> * @select_name: Name of a single test to run (from the list provided). If NULL
> * then all tests are run
> * @runs_per_test: Number of times to run each test (typically 1)
> + * @force_run: Run tests that are marked as manual-only (UT_TESTF_MANUAL)
> * Return: 0 if all tests passed, -1 if any failed
> */
> int ut_run_list(const char *name, const char *prefix, struct unit_test *tests,
> - int count, const char *select_name, int runs_per_test);
> + int count, const char *select_name, int runs_per_test,
> + bool force_run);
>
> #endif
> diff --git a/test/cmd_ut.c b/test/cmd_ut.c
> index 11c219b48ac..3ea692fd31f 100644
> --- a/test/cmd_ut.c
> +++ b/test/cmd_ut.c
> @@ -19,16 +19,26 @@ int cmd_ut_category(const char *name, const char *prefix,
> int argc, char *const argv[])
> {
> int runs_per_text = 1;
> + bool force_run = false;
> int ret;
>
> - if (argc > 1 && !strncmp("-r", argv[1], 2)) {
> - runs_per_text = dectoul(argv[1] + 2, NULL);
> + while (argc > 1 && *argv[1] == '-') {
> + const char *str = argv[1];
> +
> + switch (str[1]) {
> + case 'r':
> + runs_per_text = dectoul(str + 2, NULL);
> + break;
> + case 'f':
> + force_run = true;
> + break;
> + }
> argv++;
> argc++;
> }
>
> ret = ut_run_list(name, prefix, tests, n_ents,
> - argc > 1 ? argv[1] : NULL, runs_per_text);
> + argc > 1 ? argv[1] : NULL, runs_per_text, force_run);
>
> return ret ? CMD_RET_FAILURE : 0;
> }
> diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
> index eb3581333b9..66cc2bc6cce 100644
> --- a/test/dm/test-dm.c
> +++ b/test/dm/test-dm.c
> @@ -36,7 +36,7 @@ static int dm_test_run(const char *test_name, int runs_per_text)
> int ret;
>
> ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name,
> - runs_per_text);
> + runs_per_text, false);
>
> return ret ? CMD_RET_FAILURE : 0;
> }
> diff --git a/test/py/conftest.py b/test/py/conftest.py
> index 304e93164aa..fc9dd3a83f8 100644
> --- a/test/py/conftest.py
> +++ b/test/py/conftest.py
> @@ -289,7 +289,13 @@ def generate_ut_subtest(metafunc, fixture_name, sym_path):
> m = re_ut_test_list.search(l)
> if not m:
> continue
> - vals.append(m.group(1) + ' ' + m.group(2))
> + suite, name = m.groups()
> +
> + # Tests marked with _norun should only be run manually using 'ut -f'
> + if name.endswith('_norun'):
> + continue
> +
> + vals.append(f'{suite} {name}')
>
> ids = ['ut_' + s.replace(' ', '_') for s in vals]
> metafunc.parametrize(fixture_name, vals, ids=ids)
> diff --git a/test/test-main.c b/test/test-main.c
> index 8d1a4c4a818..d5c08625836 100644
> --- a/test/test-main.c
> +++ b/test/test-main.c
> @@ -517,6 +517,30 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
>
> if (!test_matches(prefix, test_name, select_name))
> continue;
> +
> + if (test->flags & UT_TESTF_MANUAL) {
> + int len;
> +
> + /*
> + * manual tests must have a name ending "_norun" as this
> + * is how pytest knows to skip them. See
> + * generate_ut_subtest() for this check.
> + */
> + len = strlen(test_name);
> + if (len < 6 || strcmp(test_name + len - 6, "_norun")) {
> + printf("Test %s is manual so must have a name ending in _norun\n",
> + test_name);
> + uts->fail_count++;
> + return -EBADF;
> + }
> + if (!uts->force_run) {
> + if (select_name) {
> + printf("Test %s skipped as it is manual (use -f to run it)\n",
> + test_name);
> + }
> + continue;
> + }
> + }
> old_fail_count = uts->fail_count;
> for (i = 0; i < uts->runs_per_test; i++)
> ret = ut_run_test_live_flat(uts, test, select_name);
> @@ -538,7 +562,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
>
> int ut_run_list(const char *category, const char *prefix,
> struct unit_test *tests, int count, const char *select_name,
> - int runs_per_test)
> + int runs_per_test, bool force_run)
> {
> struct unit_test_state uts = { .fail_count = 0 };
> bool has_dm_tests = false;
> @@ -572,6 +596,7 @@ int ut_run_list(const char *category, const char *prefix,
> }
> memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size);
> }
> + uts.force_run = force_run;
> ret = ut_run_tests(&uts, prefix, tests, count, select_name);
>
> /* Best efforts only...ignore errors */
next prev parent reply other threads:[~2022-09-26 6:56 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-25 15:02 [PATCH 00/45] vbe: Implement the full firmware flow Simon Glass
2022-09-25 15:02 ` [PATCH 01/45] Rename CONFIG_SYS_TEXT_BASE to CONFIG_TEXT_BASE Simon Glass
2022-09-25 15:02 ` [PATCH 02/45] disk: Drop debug messages in part_efi Simon Glass
2022-09-26 6:11 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 03/45] bloblist: Drop debugging Simon Glass
2022-09-25 15:02 ` [PATCH 04/45] rsa: Avoid warning in padding_pss_verify() Simon Glass
2022-09-26 6:23 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 05/45] spl: Use binman suffix allow symbols of any SPL etype Simon Glass
2022-09-25 15:02 ` [PATCH 06/45] spl: Split up the board_init_r() function Simon Glass
2022-09-25 15:02 ` [PATCH 07/45] spl: Refactor controls for console output Simon Glass
2022-09-29 15:16 ` Tom Rini
2022-09-25 15:02 ` [PATCH 08/45] spl: Add a separate silence option for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 09/45] CI: Install pyelftools for builds Simon Glass
2022-09-26 6:29 ` Heinrich Schuchardt
2022-09-28 10:20 ` Simon Glass
2022-09-29 15:05 ` Tom Rini
2022-09-29 23:55 ` Simon Glass
2022-09-30 12:56 ` Tom Rini
2022-09-30 13:28 ` Simon Glass
2022-09-25 15:02 ` [PATCH 10/45] binman: Allow obtaining a symbol value Simon Glass
2022-09-25 15:02 ` [PATCH 11/45] binman: Split out looking up a symbol into a function Simon Glass
2022-09-25 15:02 ` [PATCH 12/45] binman: Handle writing ELF symbols in the Entry class Simon Glass
2022-09-25 15:02 ` [PATCH 13/45] binman: Support writing symbols into ELF files Simon Glass
2022-09-25 15:02 ` [PATCH 14/45] dm: blk: Add udevice functions Simon Glass
2022-09-26 0:17 ` AKASHI Takahiro
2022-09-28 10:20 ` Simon Glass
2022-09-29 0:51 ` AKASHI Takahiro
2022-09-29 2:35 ` Simon Glass
2022-09-30 1:54 ` AKASHI Takahiro
2022-09-25 15:02 ` [PATCH 15/45] dm: usb: Update the test to cover reading and writing Simon Glass
2022-09-25 15:02 ` [PATCH 16/45] dm: blk: mmc: Tidy up some Makefile rules for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 17/45] dm: mmc: Allow sandbox emulator to build without writes Simon Glass
2022-09-25 15:02 ` [PATCH 18/45] sandbox: Drop message about writing sandbox state Simon Glass
2022-09-26 6:31 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 19/45] sandbox: Generalise SPL booting Simon Glass
2022-09-25 15:02 ` [PATCH 20/45] sandbox: Add a way to specify the sandbox executable Simon Glass
2022-09-26 6:49 ` Heinrich Schuchardt
2022-11-07 23:35 ` Simon Glass
2022-09-25 15:02 ` [PATCH 21/45] bootstd: Add a way to set up a bootflow Simon Glass
2022-09-25 15:02 ` [PATCH 22/45] image: Move comment for fit_conf_find_compat() Simon Glass
2022-09-26 6:54 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 23/45] test: Report skippped tests Simon Glass
2022-09-25 15:02 ` [PATCH 24/45] test: Update tests to use the skip feature Simon Glass
2022-09-25 15:02 ` [PATCH 25/45] test: Support tests which can only be run manually Simon Glass
2022-09-26 6:56 ` Heinrich Schuchardt [this message]
2022-09-28 10:20 ` Simon Glass
2022-09-25 15:02 ` [PATCH 26/45] image: Add the concept of a phase to FIT Simon Glass
2022-09-25 15:02 ` [PATCH 27/45] image: Allow loading a FIT config for a particular phase Simon Glass
2022-09-25 15:02 ` [PATCH 28/45] image: Correct strncpy() warning with image_set_name() Simon Glass
2022-09-25 15:02 ` [PATCH 29/45] vbe: Rename vbe_fixup to vbe_request Simon Glass
2022-09-25 15:02 ` [PATCH 30/45] vbe: Use a warning for a failed requests Simon Glass
2022-09-25 15:02 ` [PATCH 31/45] spl: Allow multiple loaders of the same type Simon Glass
2022-09-30 16:28 ` Tom Rini
2022-09-30 16:37 ` Simon Glass
2022-09-30 16:39 ` Tom Rini
2022-09-30 16:45 ` Simon Glass
2022-09-30 16:50 ` Tom Rini
2022-09-30 16:55 ` Simon Glass
2022-09-25 15:02 ` [PATCH 32/45] sandbox: Support obtaining the next phase from an image Simon Glass
2022-09-25 15:02 ` [PATCH 33/45] vbe: Support selecting operations by SPL phase Simon Glass
2022-09-25 15:02 ` [PATCH 34/45] vbe: Support reading the next SPL phase via VBE Simon Glass
2022-09-25 15:02 ` [PATCH 35/45] vbe: Move OS implementation into a separate file Simon Glass
2022-09-25 15:02 ` [PATCH 36/45] vbe: Drop the U-Boot prefix from the version Simon Glass
2022-09-25 15:02 ` [PATCH 37/45] vbe: Add Kconfig options for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 38/45] vbe: Add info about the VBE device to the fwupd node Simon Glass
2022-09-25 15:02 ` [PATCH 39/45] sandbox: Add a binman image for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 40/45] vbe: Correct pylint warnings in test_vbe Simon Glass
2022-09-25 15:02 ` [PATCH 41/45] vbe: Use a manual test Simon Glass
2022-09-25 15:02 ` [PATCH 42/45] vbe: Record which phases loaded using VBE Simon Glass
2022-09-25 15:02 ` [PATCH 43/45] vbe: Add docs and a test for the VBE command Simon Glass
2022-09-25 15:02 ` [PATCH 44/45] vbe: Add a subcommand to show the VBE state Simon Glass
2022-09-25 15:02 ` [PATCH 45/45] vbe: Add a test for the VBE flow into U-Boot proper Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a20d9ca8-77ce-bc3e-87ab-9900cddbd179@gmx.de \
--to=xypron.glpk@gmx.de \
--cc=rui.silva@linaro.org \
--cc=sjg@chromium.org \
--cc=sr@denx.de \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).