Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 668E0C07E9D for ; Mon, 26 Sep 2022 06:56:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 845AD84D67; Mon, 26 Sep 2022 08:56:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="buaamA5w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 18B9B84D6B; Mon, 26 Sep 2022 08:56:19 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 088B4811C5 for ; Mon, 26 Sep 2022 08:56:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1664175374; bh=GO1YHMXys41ccbqevlBM9XMQcCxZ3dVgY5aHYAN+7qY=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=buaamA5w5mVBFOkKZ5ziHR7O5eyJcqav6MkYIE53b1zxtTnvL8NsQfSDZd3+wVZUc Kyp1cfJuCVcNBChp5MvqEYUxJR8fhrMCP6dZK3f1srAXlP+6If3fqDQt4LMXadaZp0 GBeoUCsPaJYLhEAXs4uce6IXKQ74DMiOI5MRxoSM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MybGh-1pSCh92M6X-00yvzr; Mon, 26 Sep 2022 08:56:14 +0200 Message-ID: Date: Mon, 26 Sep 2022 08:56:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH 25/45] test: Support tests which can only be run manually Content-Language: en-US To: Simon Glass Cc: Tom Rini , Rui Miguel Silva , Stefan Roese , U-Boot Mailing List References: <20220925150248.2524421-1-sjg@chromium.org> <20220925150248.2524421-26-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20220925150248.2524421-26-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:y0BYqE9Huk0MkpQITVTBlos7EclxW2LhnqLtMJg/hHWCECC1/Il zQPIlwCZKHQvyI/P22FLOKzw8ASg2t5phU7s16cFl08W9vFTpUlvmxtodEKrVrr2lUAzKhe Q7wXgg+6qBShs/A6PMu9IVaQSZ7Zn9N1813UPSjVSMu+l+VuTfaVuhP/kyev+KnU1ZTIv6j yGP/W9gnaOlA2GiEmo53Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:zqhJiKZYWXk=:4NmodAVVOyj/L+OLp6L3WQ YjdclLKQpePrqTxHmgfRtctSWuDbNY6oYVgr821ccrg6rkKRqa39yD3HGyzpWN4WnUMKYQCfr yPdUrL8PQHFsucbfXJT1VTv67bBEwOeYJMertR9ZujAbLsErM1BWFCrl35O7cqFARchUKrBtp jZqh4zDqTWwxyzMFezVidHRhlWgK2iKkORr/mhaztcSdxBs5P0jfPZt7q13HkK1kYto9mJVVr tf+zqh+3G0dT58QqTklx8o6fft56XUmJ0uGwQ1syuPHR7Q6lKgI47giONayQRUHfCI9+6ZiqE 55dVUk34k6DnOBzvMIQVQym6dGjgqk2zWIvjdEQSMsPRCCTkpF7//grVt/LI1ve3EqPwTN77R SSH40T9yWP8vp5v+a01i+MJ3ZwIOzcJuNcrO8fW14OBkhVioIMNbjo64MNy3xbkfD6KgPJfqZ TiRlphqlYNdaELbHt31+XmcxESBpmNvbt1zAO2EDzGc7lRuVYTrKS8z54oE/62cKPqSm/Bsjg iCjYGgYvawhu4ZRkDCc1/nyLNCTCksl7Vk28CMAXdJfHRgDpiZi79TMx6x+MBOeBH0pKDGvmd RAG59KZ1VxKHm6t+CHBcTNGSuQgfOJbhsJ8QeM0e5MFyCkQ8hTxQVdFlwI7PZQwzTOKnRWElG KP1ghtFmH5AloiGUw6Ow2XGjKr5sOgE7xTgbuDeikFNXFgwmEmaLmhULRmOzzoEM+4oc8UdgN ZpAwKWl0q7ROpISrWl4StwRBBJ3MTCQ/BbttQ92Goy0fP6YSe5K48Vbo3Fo5R91RTusW3oe99 eMcg6L9UcBcQPhnz4Q/bCONw56y/B8VAxzDiILi1PkLmO2CceBbO+CQtY3//M9t5qF2+8i2g6 h6MUv9TJ2cC1g+XlbPyhgouSnzPdHJrCaXcfgEe9P4TAf3WkvqeogwWzoASwAiD90Izhj02LJ N9QPGpkDx9kCMPGc8ODakOjVGu8lIL7J/Q3mgXKJqquIfY/+dLsUoPsinoSQ8vbmRM/5tcFiZ YLevev5uk6qg2c0m3KO8tvAWg2PIH5xlVX/pFNg6VrqIG4/aTRq4tcfr3xTn+ydNpEinC3E17 +qmWCZTIoxPflKibCTSJLmm6+4y/sZZ6qRl1GdcdaXmnHnVjYpeHxvaPFGGYbaBXbUJF/wk7V B0fsgkoXda74bcjJHBEdj483vB X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 ge= t > 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 cod= e > (in a unit test) to check that they were done correctly. But we don't wa= nt > 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 pytes= t > knows to skip them. > > Signed-off-by: Simon Glass > --- > > 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 =3D 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.r= st > 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 u= p 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` c= ommand > + 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 =3D BIT(6), > UT_TESTF_OTHER_FDT =3D BIT(7), /* read in other device tree */ > + /* > + * Only run if explicitly requested with 'ut -f '. The > + * test name must end in "_norun" so that pytest detects this also, > + * since it cannot access the flags. > + */ > + UT_TESTF_MANUAL =3D 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_MANUA= L) > * 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 *pr= efix, > int argc, char *const argv[]) > { > int runs_per_text =3D 1; > + bool force_run =3D false; > int ret; > > - if (argc > 1 && !strncmp("-r", argv[1], 2)) { > - runs_per_text =3D dectoul(argv[1] + 2, NULL); > + while (argc > 1 && *argv[1] =3D=3D '-') { > + const char *str =3D argv[1]; > + > + switch (str[1]) { > + case 'r': > + runs_per_text =3D dectoul(str + 2, NULL); > + break; > + case 'f': > + force_run =3D true; > + break; > + } > argv++; > argc++; > } > > ret =3D 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 =3D ut_run_list("driver model", "dm_test_", tests, n_ents, test_n= ame, > - 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 =3D re_ut_test_list.search(l) > if not m: > continue > - vals.append(m.group(1) + ' ' + m.group(2)) > + suite, name =3D m.groups() > + > + # Tests marked with _norun should only be run manually using 'u= t -f' > + if name.endswith('_norun'): > + continue > + > + vals.append(f'{suite} {name}') > > ids =3D ['ut_' + s.replace(' ', '_') for s in vals] > metafunc.parametrize(fixture_name, vals, ids=3Dids) > 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 =3D 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 =3D uts->fail_count; > for (i =3D 0; i < uts->runs_per_test; i++) > ret =3D 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 =3D { .fail_count =3D 0 }; > bool has_dm_tests =3D false; > @@ -572,6 +596,7 @@ int ut_run_list(const char *category, const char *pr= efix, > } > memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size); > } > + uts.force_run =3D force_run; > ret =3D ut_run_tests(&uts, prefix, tests, count, select_name); > > /* Best efforts only...ignore errors */