Release Readt
Some checks failed
CI / build-linux-and-wasm (x64-linux) (push) Has been cancelled

This commit is contained in:
2026-01-25 22:08:16 +05:30
parent 601b573983
commit ebde7c7e66
19 changed files with 51 additions and 567 deletions

View File

@ -20,82 +20,56 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, SocketOps)
// -------------------------------------------------------------------------
// 1. Initialization Logic
// -------------------------------------------------------------------------
auto test_initialization() -> bool {
IAT_CHECK(SocketOps::is_initialized());
// Increment ref count
const auto res = SocketOps::initialize();
IAT_CHECK(res.has_value());
// Decrement ref count
SocketOps::terminate();
// Should still be initialized (ref count > 0)
IAT_CHECK(SocketOps::is_initialized());
return true;
}
// -------------------------------------------------------------------------
// 2. Port Availability Checks
// -------------------------------------------------------------------------
auto test_port_availability() -> bool {
// We cannot easily guarantee a port is free or taken without binding it,
// and SocketOps doesn't expose a generic TCP bind in its public API
// (only Unix sockets).
// However, we can verify the functions execute without crashing.
const u16 port = 54321;
// These return bools, we just ensure they run.
(void)SocketOps::is_port_available_tcp(port);
(void)SocketOps::is_port_available_udp(port);
return true;
}
// -------------------------------------------------------------------------
// 3. Unix Domain Socket Lifecycle (Create, Bind, Listen, Connect)
// -------------------------------------------------------------------------
auto test_unix_socket_lifecycle() -> bool {
const String socket_path = "iatest_ipc.sock";
// Ensure clean state
SocketOps::unlink_file(socket_path.c_str());
// 1. Create Server Socket
auto server_res = SocketOps::create_unix_socket();
IAT_CHECK(server_res.has_value());
SocketHandle server = *server_res;
// 2. Bind
auto bind_res = SocketOps::bind_unix_socket(server, socket_path.c_str());
if (!bind_res) {
// If bind fails (e.g. permissions), we clean up and fail the test
SocketOps::close(server);
return false;
}
// 3. Listen
auto listen_res = SocketOps::listen(server);
IAT_CHECK(listen_res.has_value());
// 4. Create Client Socket
auto client_res = SocketOps::create_unix_socket();
IAT_CHECK(client_res.has_value());
SocketHandle client = *client_res;
// 5. Connect
// Note: This relies on the OS backlog. We aren't calling accept() on the
// server, but connect() should succeed if the server is listening.
auto connect_res =
SocketOps::connect_unix_socket(client, socket_path.c_str());
IAT_CHECK(connect_res.has_value());
// 6. Cleanup
SocketOps::close(client);
SocketOps::close(server);
SocketOps::unlink_file(socket_path.c_str());
@ -103,20 +77,15 @@ auto test_unix_socket_lifecycle() -> bool {
return true;
}
// -------------------------------------------------------------------------
// 4. Unix Socket Error Handling
// -------------------------------------------------------------------------
auto test_unix_socket_errors() -> bool {
const String socket_path = "iatest_missing.sock";
// Ensure it doesn't exist
SocketOps::unlink_file(socket_path.c_str());
auto client_res = SocketOps::create_unix_socket();
IAT_CHECK(client_res.has_value());
SocketHandle client = *client_res;
// Should fail to connect to non-existent file
auto connect_res =
SocketOps::connect_unix_socket(client, socket_path.c_str());
IAT_CHECK_NOT(connect_res.has_value());
@ -126,9 +95,6 @@ auto test_unix_socket_errors() -> bool {
return true;
}
// -------------------------------------------------------------------------
// Registration
// -------------------------------------------------------------------------
IAT_BEGIN_TEST_LIST()
IAT_ADD_TEST(test_initialization);
IAT_ADD_TEST(test_port_availability);