#include "kdbus-util.h"
#include "kdbus-enum.h"
-int timeout_msg_recv(struct kdbus_conn *conn, uint64_t *expected)
+wur int timeout_msg_recv(struct kdbus_conn *conn, uint64_t type, uint64_t *cookie_reply, uint64_t *seqnum, uint64_t *monotonic_ns, uint64_t *realtime_ns)
{
struct kdbus_cmd_recv recv = { .size = sizeof(recv) };
struct kdbus_msg *msg;
msg = (struct kdbus_msg *)(conn->buf + recv.msg.offset);
- ASSERT_RETURN_VAL(msg->payload_type == KDBUS_PAYLOAD_KERNEL, -EINVAL);
- ASSERT_RETURN_VAL(msg->src_id == KDBUS_SRC_ID_KERNEL, -EINVAL);
- ASSERT_RETURN_VAL(msg->dst_id == conn->id, -EINVAL);
+ ASSERT_RETURN_VAL(msg->payload_type,==,(typeof(msg->payload_type))KDBUS_PAYLOAD_KERNEL, -EINVAL);
+ ASSERT_RETURN_VAL(msg->src_id,==,(typeof(msg->src_id))KDBUS_SRC_ID_KERNEL, -EINVAL);
+ ASSERT_RETURN_VAL(msg->dst_id,==,conn->id, -EINVAL);
+
+ {
+ const struct kdbus_item *item;
+ bool have_type = false;
+ bool have_timestamp = false;
+
+ KDBUS_ITEM_FOREACH(item, msg, items) {
+ if (item->type == type) {
+ ASSERT_ZERO(have_type);
+ have_type = true;
+ ASSERT_RETURN(item->size,==,2*sizeof(uint64_t));
+ continue;
+ }
+ ASSERT_RETURN(item->type,==,(uint64_t)KDBUS_ITEM_TIMESTAMP);
+ ASSERT_ZERO(have_timestamp);
+ have_timestamp = true;
+ ASSERT_RETURN(item->size,==,2*sizeof(uint64_t) + sizeof(struct kdbus_timestamp));
+ #define S(P) if (P) *P = item->timestamp.P;
+ S(seqnum)
+ S(monotonic_ns)
+ S(realtime_ns)
+ #undef S
+ }
+ }
- *expected &= ~(1ULL << msg->cookie_reply);
+ *cookie_reply = msg->cookie_reply;
kdbus_printf("Got message timeout for cookie %llu\n",
msg->cookie_reply);
return 0;
}
-int kdbus_test_timeout(struct kdbus_test_env *env)
+wur int kdbus_test_timeout(struct kdbus_test_env *env)
{
struct kdbus_conn *conn_a, *conn_b;
struct pollfd fd;
uint64_t expected = 0;
uint64_t cookie = 0xdeadbeef;
- conn_a = kdbus_hello(env->buspath, 0, NULL, 0);
- conn_b = kdbus_hello(env->buspath, 0, NULL, 0);
- ASSERT_RETURN(conn_a && conn_b);
+ ASSERT_NONZERO(conn_a = kdbus_hello(env->buspath, 0, NULL, 0));
+ ASSERT_NONZERO(conn_b = kdbus_hello(env->buspath, 0, NULL, 0));
fd.fd = conn_b->fd;
for (i = 0; i < n_msgs; i++, cookie++) {
kdbus_printf("Sending message with cookie %llu ...\n",
(unsigned long long)cookie);
- ASSERT_RETURN(kdbus_msg_send(conn_b, NULL, cookie,
- KDBUS_MSG_EXPECT_REPLY,
- (i + 1) * 100ULL * 1000000ULL, 0,
- conn_a->id, 0, NULL) == 0);
+ ASSERT_ZERO(kdbus_msg_send(conn_b, NULL, cookie, KDBUS_MSG_EXPECT_REPLY, (i + 1) * 100ULL * 1000000ULL, 0, conn_a->id));
expected |= 1ULL << cookie;
}
for (;;) {
+ uint64_t cookie_reply;
fd.events = POLLIN | POLLPRI | POLLHUP;
fd.revents = 0;
break;
if (fd.revents & POLLIN)
- ASSERT_RETURN(!timeout_msg_recv(conn_b, &expected));
+ ASSERT_ZERO(timeout_msg_recv(conn_b, KDBUS_ITEM_REPLY_TIMEOUT, &cookie_reply, NULL, NULL, NULL));
- if (expected == 0)
+ if (!(expected &= ~(1ULL << cookie_reply)))
break;
}
- ASSERT_RETURN(expected == 0);
+ ASSERT_ZERO(expected);
kdbus_conn_free(conn_a);
kdbus_conn_free(conn_b);