All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] NFC: nci: Extend virtual NCI deinit test
@ 2022-11-15  9:59 Dmitry Vyukov
  2022-11-17 12:47 ` Paolo Abeni
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Vyukov @ 2022-11-15  9:59 UTC (permalink / raw)
  To: bongsu.jeon, krzysztof.kozlowski, netdev
  Cc: syzkaller, Dmitry Vyukov, Jakub Kicinski

Extend the test to check the scenario when NCI core tries to send data
to already closed device to ensure that nothing bad happens.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
---
 tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c
index 162c41e9bcae8..272958a4ad102 100644
--- a/tools/testing/selftests/nci/nci_dev.c
+++ b/tools/testing/selftests/nci/nci_dev.c
@@ -888,6 +888,16 @@ TEST_F(NCI, deinit)
 			   &msg);
 	ASSERT_EQ(rc, 0);
 	EXPECT_EQ(get_dev_enable_state(&msg), 0);
+
+	// Test that operations that normally send packets to the driver
+	// don't cause issues when the device is already closed.
+	// Note: the send of NFC_CMD_DEV_UP itself still succeeds it's just
+	// that the device won't actually be up.
+	close(self->virtual_nci_fd);
+	self->virtual_nci_fd = -1;
+	rc = send_cmd_with_idx(self->sd, self->fid, self->pid,
+			       NFC_CMD_DEV_UP, self->dev_idex);
+	EXPECT_EQ(rc, 0);
 }
 
 TEST_HARNESS_MAIN

base-commit: f12ed9c04804eec4f1819097a0fd0b4800adac2f
prerequisite-patch-id: 214c5357c652cee65ee803d0f45f4b15cfcc9861
-- 
2.38.1.431.g37b22c650d-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] NFC: nci: Extend virtual NCI deinit test
  2022-11-15  9:59 [PATCH net-next] NFC: nci: Extend virtual NCI deinit test Dmitry Vyukov
@ 2022-11-17 12:47 ` Paolo Abeni
  2022-11-17 13:47   ` Dmitry Vyukov
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2022-11-17 12:47 UTC (permalink / raw)
  To: Dmitry Vyukov, bongsu.jeon, krzysztof.kozlowski, netdev
  Cc: syzkaller, Jakub Kicinski

On Tue, 2022-11-15 at 10:59 +0100, Dmitry Vyukov wrote:
> Extend the test to check the scenario when NCI core tries to send data
> to already closed device to ensure that nothing bad happens.
> 
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: netdev@vger.kernel.org
> ---
>  tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c
> index 162c41e9bcae8..272958a4ad102 100644
> --- a/tools/testing/selftests/nci/nci_dev.c
> +++ b/tools/testing/selftests/nci/nci_dev.c
> @@ -888,6 +888,16 @@ TEST_F(NCI, deinit)
>  			   &msg);
>  	ASSERT_EQ(rc, 0);
>  	EXPECT_EQ(get_dev_enable_state(&msg), 0);
> +
> +	// Test that operations that normally send packets to the driver
> +	// don't cause issues when the device is already closed.
> +	// Note: the send of NFC_CMD_DEV_UP itself still succeeds it's just
> +	// that the device won't actually be up.
> +	close(self->virtual_nci_fd);
> +	self->virtual_nci_fd = -1;

I think you need to handle correctly negative value of virtual_nci_fd
in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on
pthread_join() - read() operation will fail in virtual_deinit*()

Cheers,

Paolo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] NFC: nci: Extend virtual NCI deinit test
  2022-11-17 12:47 ` Paolo Abeni
@ 2022-11-17 13:47   ` Dmitry Vyukov
  2022-11-17 14:58     ` Paolo Abeni
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Vyukov @ 2022-11-17 13:47 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: bongsu.jeon, krzysztof.kozlowski, netdev, syzkaller, Jakub Kicinski

On Thu, 17 Nov 2022 at 13:47, Paolo Abeni <pabeni@redhat.com> wrote:
>
> On Tue, 2022-11-15 at 10:59 +0100, Dmitry Vyukov wrote:
> > Extend the test to check the scenario when NCI core tries to send data
> > to already closed device to ensure that nothing bad happens.
> >
> > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> > Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
> > Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > Cc: Jakub Kicinski <kuba@kernel.org>
> > Cc: netdev@vger.kernel.org
> > ---
> >  tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c
> > index 162c41e9bcae8..272958a4ad102 100644
> > --- a/tools/testing/selftests/nci/nci_dev.c
> > +++ b/tools/testing/selftests/nci/nci_dev.c
> > @@ -888,6 +888,16 @@ TEST_F(NCI, deinit)
> >                          &msg);
> >       ASSERT_EQ(rc, 0);
> >       EXPECT_EQ(get_dev_enable_state(&msg), 0);
> > +
> > +     // Test that operations that normally send packets to the driver
> > +     // don't cause issues when the device is already closed.
> > +     // Note: the send of NFC_CMD_DEV_UP itself still succeeds it's just
> > +     // that the device won't actually be up.
> > +     close(self->virtual_nci_fd);
> > +     self->virtual_nci_fd = -1;
>
> I think you need to handle correctly negative value of virtual_nci_fd
> in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on
> pthread_join() - read() operation will fail in virtual_deinit*()

Hi Paolo,

In this test we also set self->open_state = 0. This will make
FIXTURE_TEARDOWN(NCI) skip all of the deinit code. It will still do
close(self->virtual_nci_fd) w/o checking the return value. So it will
be close(-1), which will return an error, but we won't check it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] NFC: nci: Extend virtual NCI deinit test
  2022-11-17 13:47   ` Dmitry Vyukov
@ 2022-11-17 14:58     ` Paolo Abeni
  2022-11-17 16:29       ` Dmitry Vyukov
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2022-11-17 14:58 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: bongsu.jeon, krzysztof.kozlowski, netdev, syzkaller, Jakub Kicinski

On Thu, 2022-11-17 at 14:47 +0100, Dmitry Vyukov wrote:
> On Thu, 17 Nov 2022 at 13:47, Paolo Abeni <pabeni@redhat.com> wrote:
> > 
> > On Tue, 2022-11-15 at 10:59 +0100, Dmitry Vyukov wrote:
> > > Extend the test to check the scenario when NCI core tries to send data
> > > to already closed device to ensure that nothing bad happens.
> > > 
> > > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> > > Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
> > > Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > Cc: Jakub Kicinski <kuba@kernel.org>
> > > Cc: netdev@vger.kernel.org
> > > ---
> > >  tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++
> > >  1 file changed, 10 insertions(+)
> > > 
> > > diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c
> > > index 162c41e9bcae8..272958a4ad102 100644
> > > --- a/tools/testing/selftests/nci/nci_dev.c
> > > +++ b/tools/testing/selftests/nci/nci_dev.c
> > > @@ -888,6 +888,16 @@ TEST_F(NCI, deinit)
> > >                          &msg);
> > >       ASSERT_EQ(rc, 0);
> > >       EXPECT_EQ(get_dev_enable_state(&msg), 0);
> > > +
> > > +     // Test that operations that normally send packets to the driver
> > > +     // don't cause issues when the device is already closed.
> > > +     // Note: the send of NFC_CMD_DEV_UP itself still succeeds it's just
> > > +     // that the device won't actually be up.
> > > +     close(self->virtual_nci_fd);
> > > +     self->virtual_nci_fd = -1;
> > 
> > I think you need to handle correctly negative value of virtual_nci_fd
> > in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on
> > pthread_join() - read() operation will fail in virtual_deinit*()
> 
> Hi Paolo,
> 
> In this test we also set self->open_state = 0. This will make
> FIXTURE_TEARDOWN(NCI) skip all of the deinit code. It will still do
> close(self->virtual_nci_fd) w/o checking the return value. So it will
> be close(-1), which will return an error, but we won't check it.

Thanks for the pointer. The code looks indeed correct.

And sorry for the late nit picking, but I guess it's better to avoid
the '//' comment marker and use instead the multi-line ones.

Thanks!

Paolo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] NFC: nci: Extend virtual NCI deinit test
  2022-11-17 14:58     ` Paolo Abeni
@ 2022-11-17 16:29       ` Dmitry Vyukov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Vyukov @ 2022-11-17 16:29 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: bongsu.jeon, krzysztof.kozlowski, netdev, syzkaller, Jakub Kicinski

On Thu, 17 Nov 2022 at 15:58, Paolo Abeni <pabeni@redhat.com> wrote:
> > > On Tue, 2022-11-15 at 10:59 +0100, Dmitry Vyukov wrote:
> > > > Extend the test to check the scenario when NCI core tries to send data
> > > > to already closed device to ensure that nothing bad happens.
> > > >
> > > > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> > > > Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
> > > > Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > > Cc: Jakub Kicinski <kuba@kernel.org>
> > > > Cc: netdev@vger.kernel.org
> > > > ---
> > > >  tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++
> > > >  1 file changed, 10 insertions(+)
> > > >
> > > > diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c
> > > > index 162c41e9bcae8..272958a4ad102 100644
> > > > --- a/tools/testing/selftests/nci/nci_dev.c
> > > > +++ b/tools/testing/selftests/nci/nci_dev.c
> > > > @@ -888,6 +888,16 @@ TEST_F(NCI, deinit)
> > > >                          &msg);
> > > >       ASSERT_EQ(rc, 0);
> > > >       EXPECT_EQ(get_dev_enable_state(&msg), 0);
> > > > +
> > > > +     // Test that operations that normally send packets to the driver
> > > > +     // don't cause issues when the device is already closed.
> > > > +     // Note: the send of NFC_CMD_DEV_UP itself still succeeds it's just
> > > > +     // that the device won't actually be up.
> > > > +     close(self->virtual_nci_fd);
> > > > +     self->virtual_nci_fd = -1;
> > >
> > > I think you need to handle correctly negative value of virtual_nci_fd
> > > in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on
> > > pthread_join() - read() operation will fail in virtual_deinit*()
> >
> > Hi Paolo,
> >
> > In this test we also set self->open_state = 0. This will make
> > FIXTURE_TEARDOWN(NCI) skip all of the deinit code. It will still do
> > close(self->virtual_nci_fd) w/o checking the return value. So it will
> > be close(-1), which will return an error, but we won't check it.
>
> Thanks for the pointer. The code looks indeed correct.
>
> And sorry for the late nit picking, but I guess it's better to avoid
> the '//' comment marker and use instead the multi-line ones.

Right. I am used to a different style and checkpatch did not complain. Sent v2:
https://lore.kernel.org/all/20221117162101.1467069-1-dvyukov@google.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-17 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15  9:59 [PATCH net-next] NFC: nci: Extend virtual NCI deinit test Dmitry Vyukov
2022-11-17 12:47 ` Paolo Abeni
2022-11-17 13:47   ` Dmitry Vyukov
2022-11-17 14:58     ` Paolo Abeni
2022-11-17 16:29       ` Dmitry Vyukov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.