mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 17:42:03 +02:00
selftests: nci: Extract the start/stop discovery function
To reuse the start/stop discovery code in other testcase, extract the code. Signed-off-by: Bongsu Jeon <bongsu.jeon@samsung.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
6ebbc9680a
commit
72696bd8a0
|
|
@ -517,38 +517,61 @@ static void *virtual_poll_stop(void *data)
|
||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NCI, start_poll)
|
int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pid)
|
||||||
{
|
{
|
||||||
__u16 nla_start_poll_type[2] = {NFC_ATTR_DEVICE_INDEX,
|
__u16 nla_start_poll_type[2] = {NFC_ATTR_DEVICE_INDEX,
|
||||||
NFC_ATTR_PROTOCOLS};
|
NFC_ATTR_PROTOCOLS};
|
||||||
void *nla_start_poll_data[2] = {&self->dev_idex, &self->proto};
|
void *nla_start_poll_data[2] = {&dev_idx, &proto};
|
||||||
int nla_start_poll_len[2] = {4, 4};
|
int nla_start_poll_len[2] = {4, 4};
|
||||||
pthread_t thread_t;
|
pthread_t thread_t;
|
||||||
int status;
|
int status;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = pthread_create(&thread_t, NULL, virtual_poll_start,
|
rc = pthread_create(&thread_t, NULL, virtual_poll_start,
|
||||||
(void *)&self->virtual_nci_fd);
|
(void *)&virtual_fd);
|
||||||
ASSERT_GT(rc, -1);
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
rc = send_cmd_mt_nla(self->sd, self->fid, self->pid, NFC_CMD_START_POLL, 2,
|
rc = send_cmd_mt_nla(sd, fid, pid, NFC_CMD_START_POLL, 2, nla_start_poll_type,
|
||||||
nla_start_poll_type, nla_start_poll_data,
|
nla_start_poll_data, nla_start_poll_len, NLM_F_REQUEST);
|
||||||
nla_start_poll_len, NLM_F_REQUEST);
|
if (rc != 0)
|
||||||
EXPECT_EQ(rc, 0);
|
return rc;
|
||||||
|
|
||||||
pthread_join(thread_t, (void **)&status);
|
pthread_join(thread_t, (void **)&status);
|
||||||
ASSERT_EQ(status, 0);
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid)
|
||||||
|
{
|
||||||
|
pthread_t thread_t;
|
||||||
|
int status;
|
||||||
|
int rc;
|
||||||
|
|
||||||
rc = pthread_create(&thread_t, NULL, virtual_poll_stop,
|
rc = pthread_create(&thread_t, NULL, virtual_poll_stop,
|
||||||
(void *)&self->virtual_nci_fd);
|
(void *)&virtual_fd);
|
||||||
ASSERT_GT(rc, -1);
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
rc = send_cmd_with_idx(self->sd, self->fid, self->pid,
|
rc = send_cmd_with_idx(sd, fid, pid,
|
||||||
NFC_CMD_STOP_POLL, self->dev_idex);
|
NFC_CMD_STOP_POLL, dev_idx);
|
||||||
EXPECT_EQ(rc, 0);
|
if (rc != 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
pthread_join(thread_t, (void **)&status);
|
pthread_join(thread_t, (void **)&status);
|
||||||
ASSERT_EQ(status, 0);
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(NCI, start_poll)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
|
||||||
|
status = start_polling(self->dev_idex, self->proto, self->virtual_nci_fd,
|
||||||
|
self->sd, self->fid, self->pid);
|
||||||
|
EXPECT_EQ(status, 0);
|
||||||
|
|
||||||
|
status = stop_polling(self->dev_idex, self->virtual_nci_fd, self->sd,
|
||||||
|
self->fid, self->pid);
|
||||||
|
EXPECT_EQ(status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NCI, deinit)
|
TEST_F(NCI, deinit)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user