#include <wayland-client.h>
#include "shared/helpers.h"
#include "shared/zalloc.h"
+#include "shared/timespec-util.h"
#include "shared/os-compatibility.h"
#include "presentation-time-client-protocol.h"
return (uint32_t)ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
}
-static void
-timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
- uint32_t tv_sec_lo, uint32_t tv_nsec)
-{
- tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
- tm->tv_nsec = tv_nsec;
-}
-
static int
timespec_diff_to_usec(const struct timespec *a, const struct timespec *b)
{
timespec_from_nsec(a, b * 1000000);
}
+/* Convert protocol data to timespec
+ *
+ * \param a[out] timespec
+ * \param tv_sec_hi the high bytes of seconds part
+ * \param tv_sec_lo the low bytes of seconds part
+ * \param tv_nsec the nanoseconds part
+ */
+static inline void
+timespec_from_proto(struct timespec *a, uint32_t tv_sec_hi,
+ uint32_t tv_sec_lo, uint32_t tv_nsec)
+{
+ a->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
+ a->tv_nsec = tv_nsec;
+}
+
/* Check if a timespec is zero
*
* \param a timespec
#include "shared/helpers.h"
#include "shared/xalloc.h"
+#include "shared/timespec-util.h"
#include "weston-test-client-helper.h"
#include "presentation-time-client-protocol.h"
};
static void
-timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
- uint32_t tv_sec_lo, uint32_t tv_nsec)
-{
- tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
- tm->tv_nsec = tv_nsec;
-}
-
-static void
feedback_sync_output(void *data,
struct wp_presentation_feedback *presentation_feedback,
struct wl_output *output)
ZUC_ASSERT_EQ(1000000, a.tv_nsec);
}
+ZUC_TEST(timespec_test, timespec_from_proto)
+{
+ struct timespec a;
+
+ timespec_from_proto(&a, 0, 0, 0);
+ ZUC_ASSERT_EQ(0, a.tv_sec);
+ ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+ timespec_from_proto(&a, 0, 1234, 9999);
+ ZUC_ASSERT_EQ(1234, a.tv_sec);
+ ZUC_ASSERT_EQ(9999, a.tv_nsec);
+
+ timespec_from_proto(&a, 0x1234, 0x5678, 1);
+ ZUC_ASSERT_EQ((time_t)0x0000123400005678LL, a.tv_sec);
+ ZUC_ASSERT_EQ(1, a.tv_nsec);
+}
+
ZUC_TEST(timespec_test, timespec_is_zero)
{
struct timespec zero = { 0 };