void test_ListenerHelper_PushMessage_should_retry_and_add_a_message_to_the_listeners_command_queue_on_EINTR(void) { l->commit_pipe = 100; listener_msg *msg = &l->msgs[9]; memset(msg_buf, 0xFF, sizeof(msg_buf)); msg->pipes[0] = 23; errno = EINTR; syscall_write_ExpectAndReturn(l->commit_pipe, msg_buf, sizeof(msg_buf), -1); syscall_write_ExpectAndReturn(l->commit_pipe, msg_buf, sizeof(msg_buf), sizeof(msg_buf)); int reply_fd = -1; TEST_ASSERT_TRUE(ListenerHelper_PushMessage(l, msg, &reply_fd)); TEST_ASSERT_EQUAL(23, reply_fd); }
void test_ListenerCmd_NotifyCaller_should_write_backpressure_to_reply_buffer(void) { int fd = 5; ListenerTask_GetBackpressure_ExpectAndReturn(l, 0x1234); syscall_write_ExpectAndReturn(fd, reply_buf, sizeof(reply_buf), 3); ListenerCmd_NotifyCaller(l, fd); TEST_ASSERT_EQUAL(0x34, reply_buf[1]); TEST_ASSERT_EQUAL(0x12, reply_buf[2]); }
void test_ListenerCmd_NotifyCaller_should_write_tag_to_caller_fd(void) { int fd = 5; ListenerTask_GetBackpressure_ExpectAndReturn(l, 0); syscall_write_ExpectAndReturn(fd, reply_buf, sizeof(reply_buf), 3); ListenerCmd_NotifyCaller(l, fd); TEST_ASSERT_EQUAL(LISTENER_MSG_TAG, reply_buf[0]); TEST_ASSERT_EQUAL(0, reply_buf[1]); TEST_ASSERT_EQUAL(0, reply_buf[2]); }
bus_sink_cb_res_t test_sink_cb(uint8_t *read_buf, size_t read_size, void *socket_udata) { (void)read_buf; (void)read_size; (void)socket_udata; return (bus_sink_cb_res_t) { .next_read = 31, }; } static void expect_notify_caller(listener *l, int fd) { ListenerTask_GetBackpressure_ExpectAndReturn(l, 0); syscall_write_ExpectAndReturn(fd, reply_buf, sizeof(reply_buf), 3); }
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)); }