NFC: nci: Extend virtual NCI deinit test
Subsystems (5)
PATCH 1/1 NFC: nci: Extend virtual NCI deinit test
Extend the test to check the scenario when NCI core tries to send data to already closed device to ensure that nothing bad happens.
--- tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/testing/selftests/nci/nci_dev.c +10 -0
@@ -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
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Paolo Abeni
maintainerQuoted 17 lines · Dmitry Vyukov
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 <[email protected]>Cc Bongsu Jeon <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Jakub Kicinski <[email protected]>--- tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/selftests/nci/nci_dev.c +0
-0
tools/testing/selftests/nci/nci_dev.c TEST_F(NCI, deinit) · line 897
Quoted 10 lines
tools/testing/selftests/nci/nci_dev.c +7
-0@@ -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
Quoted 25 lines · Paolo Abeni
Quoted 23 lines · Dmitry Vyukov
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 <[email protected]>Cc Bongsu Jeon <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Jakub Kicinski <[email protected]>--- tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/selftests/nci/nci_dev.c +3
-0@@ -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.
Quoted 8 lines
tools/testing/selftests/nci/nci_dev.c TEST_F(NCI, deinit) · line 897
Quoted 4 lines
tools/testing/selftests/nci/nci_dev.c +4
-0+// 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_fdinFIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert onpthread_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.
Paolo Abeni
maintainerQuoted 35 lines · Dmitry Vyukov
Quoted 25 lines · Paolo Abeni
Quoted 23 lines · Dmitry Vyukov
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 <[email protected]>Cc Bongsu Jeon <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Jakub Kicinski <[email protected]>--- tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/selftests/nci/nci_dev.c +3
-0@@ -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. Quoted 8 lines
tools/testing/selftests/nci/nci_dev.c TEST_F(NCI, deinit) · line 897
Quoted 4 lines
tools/testing/selftests/nci/nci_dev.c +4
-0+// 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_fdinFIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert onpthread_join()-read()operation will fail in virtual_deinit*()
Quoted 6 lines
Hi Paolo,
In this test we also set
self->open_state= 0. This will makeFIXTURE_TEARDOWN(NCI)skip all of the deinit code. It will still doclose(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
Quoted 40 lines · Paolo Abeni
Quoted 33 lines
Quoted 24 lines · Dmitry Vyukov
Quoted 23 lines
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 <[email protected]>Cc Bongsu Jeon <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Jakub Kicinski <[email protected]>--- tools/testing/selftests/nci/nci_dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/selftests/nci/nci_dev.c +3
-0@@ -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. Quoted 8 lines
tools/testing/selftests/nci/nci_dev.c TEST_F(NCI, deinit) · line 897
Quoted 4 lines
tools/testing/selftests/nci/nci_dev.c +4
-0+// 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_fdinFIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert onpthread_join()-read()operation will fail in virtual_deinit*()Quoted 6 lines
Hi Paolo,
In this test we also set
self->open_state= 0. This will makeFIXTURE_TEARDOWN(NCI)skip all of the deinit code. It will still doclose(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.
Quoted 4 lines
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/[email protected]/