コード例 #1
0
void test_ListenerCmd_CheckIncomingMessages_should_handle_redundant_ADD_SOCKET_command(void) {
    l->fds[INCOMING_MSG_PIPE_ID].fd = 5;
    l->fds[INCOMING_MSG_PIPE_ID].revents = POLLIN;
    l->read_buf = malloc(256);

    connection_info *ci = calloc(1, sizeof(*ci));
    *(int *)&ci->fd = 5;    

    listener_msg *msg = &l->msgs[0];
    msg->type = MSG_ADD_SOCKET;
    msg->u.add_socket.info = ci;
    msg->u.add_socket.notify_fd = 18;

    l->tracked_fds = 1;
    l->fds[INCOMING_MSG_PIPE].fd = ci->fd;

    cmd_buf[0] = 0;
    syscall_read_ExpectAndReturn(l->fds[INCOMING_MSG_PIPE_ID].fd, cmd_buf, sizeof(cmd_buf), 1);

    expect_notify_caller(l, 18);
    int res = 1;

    ListenerTask_ReleaseMsg_Expect(l, msg);
    ListenerCmd_CheckIncomingMessages(l, &res);
    
    TEST_ASSERT_EQUAL(0, res);
}
コード例 #2
0
void test_ListenerCmd_CheckIncomingMessages_should_handle_incoming_ADD_SOCKET_command(void) {
    connection_info *ci = calloc(1, sizeof(*ci));
    *(int *)&ci->fd = 91;

    listener_msg msg = {
        .type = MSG_ADD_SOCKET,
        .u.add_socket = {
            .info = ci,
            .notify_fd = 7,
        },
    };

    setup_command(&msg, NULL);
    int res = 1;

    l->tracked_fds = 3;
    for (int i = 0; i < l->tracked_fds; i++) {
        l->fds[i + INCOMING_MSG_PIPE].fd = i;
        l->fds[i + INCOMING_MSG_PIPE].events = POLLIN;
    }

    expect_notify_caller(l, 7);
    ListenerTask_ReleaseMsg_Expect(l, &l->msgs[0]);
    ListenerCmd_CheckIncomingMessages(l, &res);

    TEST_ASSERT_EQUAL(ci, l->fd_info[3]);
    TEST_ASSERT_EQUAL(ci->fd, l->fds[3 + INCOMING_MSG_PIPE].fd);
    TEST_ASSERT_EQUAL(31, ci->to_read_size);
    TEST_ASSERT_EQUAL(POLLIN, l->fds[3 + INCOMING_MSG_PIPE].events);
    TEST_ASSERT_EQUAL(4, l->tracked_fds);
}
コード例 #3
0
void test_ListenerHelper_PushMessage_should_expose_errors(void)
{
    l->commit_pipe = 100;
    listener_msg *msg = &l->msgs[9];
    memset(msg_buf, 0xFF, sizeof(msg_buf));
    msg->pipes[0] = 23;

    errno = EIO;
    syscall_write_ExpectAndReturn(l->commit_pipe, msg_buf, sizeof(msg_buf), -1);
    
    int reply_fd = -1;
    ListenerTask_ReleaseMsg_Expect(l, msg);
    TEST_ASSERT_FALSE(ListenerHelper_PushMessage(l, msg, &reply_fd));
}