Skip to content

Commit 0a068ec

Browse files
committed
[nrf fromtree] tests: coap_client: Test for operating on socket while another fails
CoAP client should be able to push data through functioning socket while another sockets is failing or reporting poll() errors. Signed-off-by: Seppo Takalo <[email protected]> (cherry picked from commit 237b26c)
1 parent abae788 commit 0a068ec

File tree

1 file changed

+42
-3
lines changed
  • tests/net/lib/coap_client/src

1 file changed

+42
-3
lines changed

tests/net/lib/coap_client/src/main.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ extern void net_coap_init(void);
395395
static void *suite_setup(void)
396396
{
397397
net_coap_init();
398-
coap_client_init(&client, NULL);
398+
zassert_ok(coap_client_init(&client, NULL));
399+
zassert_ok(coap_client_init(&client2, NULL));
399400

400401
return NULL;
401402
}
@@ -891,8 +892,6 @@ ZTEST(coap_client, test_multiple_clients)
891892
zassert_ok(k_sem_init(&sem1, 0, 1));
892893
zassert_ok(k_sem_init(&sem2, 0, 1));
893894

894-
zassert_ok(coap_client_init(&client2, NULL));
895-
896895
k_sleep(K_MSEC(1));
897896

898897
LOG_INF("Sending requests");
@@ -977,6 +976,46 @@ ZTEST(coap_client, test_poll_err_after_response)
977976
zassert_not_ok(k_sem_take(&sem1, K_MSEC(MORE_THAN_EXCHANGE_LIFETIME_MS)));
978977
}
979978

979+
ZTEST(coap_client, test_poll_err_on_another_sock)
980+
{
981+
int ret = 0;
982+
struct k_sem sem1, sem2;
983+
struct sockaddr address = {0};
984+
struct coap_client_request client_request = {
985+
.method = COAP_METHOD_GET,
986+
.confirmable = true,
987+
.path = test_path,
988+
.fmt = COAP_CONTENT_FORMAT_TEXT_PLAIN,
989+
.cb = coap_callback,
990+
.payload = short_payload,
991+
.len = strlen(short_payload),
992+
.user_data = &sem1
993+
};
994+
struct coap_client_request request2 = client_request;
995+
996+
request2.user_data = &sem2;
997+
998+
zassert_ok(k_sem_init(&sem1, 0, 1));
999+
zassert_ok(k_sem_init(&sem2, 0, 1));
1000+
1001+
z_impl_zsock_sendto_fake.custom_fake = z_impl_zsock_sendto_custom_fake_no_reply;
1002+
set_socket_events(client.fd, ZSOCK_POLLERR);
1003+
1004+
k_sleep(K_MSEC(1));
1005+
1006+
ret = coap_client_req(&client2, client2.fd, &address, &request2, NULL);
1007+
zassert_true(ret >= 0, "Sending request failed, %d", ret);
1008+
ret = coap_client_req(&client, client.fd, &address, &client_request, NULL);
1009+
zassert_true(ret >= 0, "Sending request failed, %d", ret);
1010+
1011+
set_socket_events(client2.fd, ZSOCK_POLLIN);
1012+
1013+
zassert_ok(k_sem_take(&sem1, K_MSEC(MORE_THAN_EXCHANGE_LIFETIME_MS)));
1014+
zassert_equal(last_response_code, -EIO, "");
1015+
zassert_ok(k_sem_take(&sem2, K_MSEC(MORE_THAN_EXCHANGE_LIFETIME_MS)));
1016+
zassert_equal(last_response_code, COAP_RESPONSE_CODE_OK, "");
1017+
}
1018+
9801019
ZTEST(coap_client, test_duplicate_response)
9811020
{
9821021
int ret = 0;

0 commit comments

Comments
 (0)