MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / TC_sal_socket_bind

Function TC_sal_socket_bind

components/net/utest/tc_sal_socket.c:468–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468static void TC_sal_socket_bind(void)
469{
470 int sock = -1;
471 struct sockaddr_in addr;
472 int ret;
473 int test_port = get_available_port(TEST_SERVER_BASE_PORT);
474
475 LOG_I("Starting TC_sal_socket_bind tests...");
476
477 /* Test valid bind */
478 LOG_I("Creating socket for bind test on port %d...", test_port);
479 sock = create_test_socket(AF_INET, SOCK_STREAM, 0);
480 if (sock < 0)
481 {
482 LOG_E("Failed to create socket for bind test");
483 return;
484 }
485
486 memset(&addr, 0, sizeof(addr));
487 addr.sin_family = AF_INET;
488 addr.sin_addr.s_addr = htonl(INADDR_ANY);
489 addr.sin_port = htons(test_port);
490
491 LOG_I("Attempting to bind socket %d to port %d...", sock, test_port);
492 ret = sal_bind(sock, (struct sockaddr *)&addr, sizeof(addr));
493 LOG_I("Bind result: %d (expected 0)", ret);
494 uassert_int_equal(ret, 0);
495
496 close_test_socket(sock);
497 sock = -1;
498
499 LOG_I("Skipping NULL address bind test (would cause assertion)");
500
501 /* Test bind with invalid socket */
502 LOG_I("Testing bind with invalid socket...");
503 ret = sal_bind(-1, (struct sockaddr *)&addr, sizeof(addr));
504 LOG_I("Invalid socket bind result: %d (expected -1)", ret);
505 uassert_int_equal(ret, -1);
506
507 LOG_I("TC_sal_socket_bind tests completed");
508}
509
510static void TC_sal_socket_listen(void)
511{

Callers

nothing calls this directly

Calls 4

get_available_portFunction · 0.85
create_test_socketFunction · 0.85
sal_bindFunction · 0.85
close_test_socketFunction · 0.85

Tested by

no test coverage detected