X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=drm-lease-manager%2Ftest%2Ftest-socket-client.c;h=fa26500eef1c8a7156a39848b0d95f5c92063080;hb=e9e5cf1f67a45e4d409dc9e1caa6ce8151579c88;hp=260437ae08697a9d4628c9822cce27da6e75fb50;hpb=f991de200799118355fd75237a740321bda7aaa7;p=src%2Fdrm-lease-manager.git diff --git a/drm-lease-manager/test/test-socket-client.c b/drm-lease-manager/test/test-socket-client.c index 260437a..fa26500 100644 --- a/drm-lease-manager/test/test-socket-client.c +++ b/drm-lease-manager/test/test-socket-client.c @@ -28,6 +28,7 @@ #include #include +#include "dlm-protocol.h" #include "socket-path.h" #define DEFAULT_RECV_TIMEOUT (100) // timeout in ms to receive data from server @@ -39,6 +40,14 @@ struct client_state { struct test_config *config; }; +static void send_lease_request(int socket, enum dlm_opcode opcode) +{ + struct dlm_client_request req = { + .opcode = opcode, + }; + send_dlm_client_request(socket, &req); +} + static void client_gst_socket_status(int socket_fd, struct test_config *config) { @@ -57,40 +66,6 @@ static void client_gst_socket_status(int socket_fd, struct test_config *config) return; } -static int receive_fd_from_socket(int sockfd) -{ - union { - struct cmsghdr align; - char buf[CMSG_SPACE(sizeof(int))]; - } u; - - char data; - struct iovec iov = {.iov_base = &data, .iov_len = sizeof(data)}; - struct msghdr msg = { - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = u.buf, - .msg_controllen = sizeof(u.buf), - }; - - if (recvmsg(sockfd, &msg, 0) < 0) - return -1; - - int recv_fd = -1; - for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - ck_assert_int_eq(cmsg->cmsg_level, SOL_SOCKET); - - if (cmsg->cmsg_type != SCM_RIGHTS) - continue; - - int nfds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); - ck_assert_int_eq(nfds, 1); - recv_fd = *(int *)CMSG_DATA(cmsg); - } - return recv_fd; -} - static void *test_client_thread(void *arg) { struct client_state *cstate = arg; @@ -104,7 +79,7 @@ static void *test_client_thread(void *arg) sockaddr_set_lease_server_path(&address, config->lease->name), true); - int client = socket(PF_UNIX, SOCK_STREAM, 0); + int client = socket(PF_UNIX, SOCK_SEQPACKET, 0); ck_assert_int_ge(client, 0); int ret; @@ -115,16 +90,19 @@ static void *test_client_thread(void *arg) return NULL; } + send_lease_request(client, DLM_GET_LEASE); + if (!config->recv_timeout) config->recv_timeout = DEFAULT_RECV_TIMEOUT; client_gst_socket_status(client, config); if (config->has_data) { - config->received_fd = receive_fd_from_socket(client); + config->received_fd = receive_lease_fd(client); } cstate->socket_fd = client; + send_lease_request(client, DLM_RELEASE_LEASE); return NULL; }