From: Shuah Khan <skhan@linuxfoundation.org>
To: Shengyu Li <shengyu.li.evgeny@gmail.com>,
shuah@kernel.org,
Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
Jason Gunthorpe <jgg@nvidia.com>,
Joao Martins <joao.m.martins@oracle.com>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
luto@amacapital.net, wad@chromium.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v2] selftests/harness: Prevent infinite loop due to Assert in FIXTURE_TEARDOWN
Date: Thu, 4 Apr 2024 10:47:50 -0600 [thread overview]
Message-ID: <8fd67aab-21ed-4aec-bea4-42171b6d0523@linuxfoundation.org> (raw)
In-Reply-To: <20240326211315.12201-1-shengyu.li.evgeny@gmail.com>
On 3/26/24 15:13, Shengyu Li wrote:
> This patch addresses an issue in the selftests/harness where an
> assertion within FIXTURE_TEARDOWN could trigger an infinite loop.
> The problem arises because the teardown procedure is meant to
> execute once, but the presence of failing assertions (ASSERT_EQ(0, 1))
> leads to repeated attempts to execute teardown due to
> the long jump mechanism used by the harness for handling assertions.
>
> To resolve this, the patch ensures that the teardown process
> runs only once, regardless of assertion outcomes, preventing
> the infinite loop and allowing tests to fail.
>
> A simple test demo(test.c):
> #include "kselftest_harness.h"
>
> FIXTURE(f)
> {
> int fd;
> };
>
> FIXTURE_SETUP(f)
> {
> self->fd = 0;
> }
>
> FIXTURE_TEARDOWN(f)
> {
> TH_LOG("TEARDOWN");
> ASSERT_EQ(0, 1);
> self->fd = -1;
> }
>
> TEST_F(f, open_close)
> {
> ASSERT_NE(self->fd, 1);
> }
>
> TEST_HARNESS_MAIN
>
> will always output the following output due to a dead loop until timeout:
> # test.c:15:open_close:TEARDOWN
> # test.c:16:open_close:Expected 0 (0) == 1 (1)
> # test.c:15:open_close:TEARDOWN
> # test.c:16:open_close:Expected 0 (0) == 1 (1)
> ...
>
> But here's what we should and expect to get:
> TAP version 13
> 1..1
> # Starting 1 tests from 2 test cases.
> # RUN f.open_close ...
> # test.c:15:open_close:TEARDOWN
> # test.c:16:open_close:Expected 0 (0) == 1 (1)
> # open_close: Test terminated by assertion
> # FAIL f.open_close
> not ok 1 f.open_close
> # FAILED: 0 / 1 tests passed.
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>
> also this is related to the issue mentioned in this patch
> https://patchwork.kernel.org/project/linux-kselftest/patch/e2ba3f8c-80e6-477d-9cea-1c9af820e0ed@alu.unizg.hr/
>
Adding people who participated in the above thread discussion.
Please try this patch out to see if this fixes the problem
with iommu test.
>
>
> Signed-off-by: Shengyu Li <shengyu.li.evgeny@gmail.com>
Than you for finding and fixing this. Applied now to linux-kselftes fixes
branch for the next rc.
thanks,
-- Shuah
next prev parent reply other threads:[~2024-04-04 16:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 22:43 [PATCH] selftests/harness: Prevent infinite loop due to Assert in FIXTURE_TEARDOWN Shengyu Li
2024-03-24 21:44 ` Shengyu Li
2024-03-26 21:13 ` [PATCH v2] " Shengyu Li
2024-04-04 16:47 ` Shuah Khan [this message]
2024-03-26 19:28 ` [PATCH] " Shuah Khan
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=8fd67aab-21ed-4aec-bea4-42171b6d0523@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mirsad.todorovac@alu.unizg.hr \
--cc=shengyu.li.evgeny@gmail.com \
--cc=shuah@kernel.org \
--cc=wad@chromium.org \
/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