Skip to contentSkip to conversation

NFC: nci: Extend virtual NCI deinit test

PATCH Superseded Dmitry Vyukov 2 participants 5 messages Nov 15, 2022 – Nov 17, 2022

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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 +10 -0
index 162c41e9bcae8..272958a4ad102 100644
@@ -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
maintainer
#1 lore raw
Quoted 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.

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
index 162c41e9bcae8..272958a4ad102 100644

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

#2 lore raw
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.

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
index 162c41e9bcae8..272958a4ad102 100644
@@ -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_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.

maintainer
#3 lore raw
Quoted 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.

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
index 162c41e9bcae8..272958a4ad102 100644
@@ -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_fd in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on pthread_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 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

#4 lore raw
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.

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
index 162c41e9bcae8..272958a4ad102 100644
@@ -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_fd in FIXTURE_TEARDOWN(NCI), otherwise it should trigger an assert on pthread_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 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.

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]/