test: improve event debugging a bit
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 12 Sep 2024 03:40:44 +0000 (13:40 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 19 Sep 2024 05:07:44 +0000 (15:07 +1000)
Add a litest_checkpoint macro and convert a few of the litest_assert
macros to make use of that - this gives us a printf of the call site in
case it fails.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1048>

test/litest.c
test/litest.h

index 7070435e51e5741c1c8a25d74c438551f9dfabd4..787e84ae5421dc74d2b6a18928f33cce02314fae 100644 (file)
@@ -115,6 +115,23 @@ static void litest_setup_quirks(struct list *created_files_list,
 #define litest_vlog(...) { /* __VA_ARGS__ */ }
 #endif
 
+void
+_litest_checkpoint(const char *func,
+                  int line,
+                  const char *format,
+                  ...)
+{
+       char buf[1024];
+       va_list args;
+
+       va_start(args, format);
+       if (verbose) {
+               vsnprintf(buf, sizeof(buf), format, args);
+               printf(ANSI_BRIGHT_BLUE "%s():%d - " ANSI_BRIGHT_RED "%s" ANSI_NORMAL "\n", func, line, buf); \
+       }
+       va_end(args);
+}
+
 static void
 litest_backtrace(void)
 {
@@ -3371,11 +3388,15 @@ litest_assert_event_type(struct libinput_event *event,
 }
 
 void
-litest_assert_empty_queue(struct libinput *li)
+_litest_assert_empty_queue(struct libinput *li,
+                          const char *func,
+                          int line)
 {
        bool empty_queue = true;
        struct libinput_event *event;
 
+       _litest_checkpoint(func, line, "asserting empty queue");
+
        libinput_dispatch(li);
        while ((event = libinput_get_event(li))) {
                empty_queue = false;
@@ -3634,11 +3655,19 @@ litest_assert_key_event(struct libinput *li, unsigned int key,
 }
 
 void
-litest_assert_button_event(struct libinput *li, unsigned int button,
-                          enum libinput_button_state state)
+_litest_assert_button_event(struct libinput *li, unsigned int button,
+                           enum libinput_button_state state,
+                           const char *func, int line)
 {
        struct libinput_event *event;
 
+       _litest_checkpoint(func,
+                          line,
+                          "asserting button event %s (%d) state %d",
+                          libevdev_event_code_get_name(EV_KEY, button),
+                          button,
+                          state);
+
        litest_wait_for_event(li);
        event = libinput_get_event(li);
 
@@ -3715,12 +3744,20 @@ litest_is_gesture_event(struct libinput_event *event,
 }
 
 void
-litest_assert_gesture_event(struct libinput *li,
-                           enum libinput_event_type type,
-                           int nfingers)
+_litest_assert_gesture_event(struct libinput *li,
+                            enum libinput_event_type type,
+                            int nfingers,
+                            const char *func,
+                            int line)
 {
        struct libinput_event *event;
 
+       _litest_checkpoint(func,
+                          line,
+                          "asserting gesture event %s %dfg",
+                          litest_event_type_str(type),
+                          nfingers);
+
        litest_wait_for_event(li);
        event = libinput_get_event(li);
 
@@ -4126,13 +4163,20 @@ litest_assert_axis_end_sequence(struct libinput *li,
 }
 
 void
-litest_assert_only_typed_events(struct libinput *li,
-                               enum libinput_event_type type)
+_litest_assert_only_typed_events(struct libinput *li,
+                                enum libinput_event_type type,
+                                const char *func,
+                                int line)
 {
        struct libinput_event *event;
 
        litest_assert(type != LIBINPUT_EVENT_NONE);
 
+       _litest_checkpoint(func,
+                          line,
+                          "asserting only typed events %s",
+                          litest_event_type_str(type));
+
        libinput_dispatch(li);
        event = libinput_get_event(li);
        litest_assert_notnull(event);
index f247f0afba37ce8bbf3d754c1b89c8952949a7ee..e12ec89bd11649a4028f9de78c159634f22aefe0 100644 (file)
@@ -83,6 +83,13 @@ struct test_collection {
        }; \
        static void (name##_setup)(void)
 
+__attribute__ ((format (printf, 3, 0)))
+void _litest_checkpoint(const char *func,
+                       int line,
+                       const char *format,
+                       ...);
+#define litest_checkpoint(...) \
+       _litest_checkpoint(__func__, __LINE__, __VA_ARGS__)
 
 /**
  * litest itself needs the user_data to store some test-suite-specific
@@ -782,8 +789,13 @@ void
 litest_assert_event_type(struct libinput_event *event,
                         enum libinput_event_type want);
 
+#define litest_assert_empty_queue(li_) \
+       _litest_assert_empty_queue(li_, __func__, __LINE__)
+
 void
-litest_assert_empty_queue(struct libinput *li);
+_litest_assert_empty_queue(struct libinput *li,
+                          const char *func,
+                          int line);
 
 void
 litest_assert_touch_sequence(struct libinput *li);
@@ -872,10 +884,14 @@ void
 litest_assert_key_event(struct libinput *li, unsigned int key,
                        enum libinput_key_state state);
 
+#define litest_assert_button_event(li_, button_, state_) \
+       _litest_assert_button_event(li_, button_, state_, __func__, __LINE__)
+
 void
-litest_assert_button_event(struct libinput *li,
-                          unsigned int button,
-                          enum libinput_button_state state);
+_litest_assert_button_event(struct libinput *li,
+                           unsigned int button,
+                           enum libinput_button_state state,
+                           const char *func, int line);
 
 void
 litest_assert_switch_event(struct libinput *li,
@@ -894,9 +910,13 @@ litest_assert_axis_end_sequence(struct libinput *li,
                                enum libinput_pointer_axis axis,
                                enum libinput_pointer_axis_source source);
 
+#define litest_assert_only_typed_events(...) \
+       _litest_assert_only_typed_events(__VA_ARGS__, __func__, __LINE__)
 void
-litest_assert_only_typed_events(struct libinput *li,
-                               enum libinput_event_type type);
+_litest_assert_only_typed_events(struct libinput *li,
+                                enum libinput_event_type type,
+                                const char *func,
+                                int line);
 
 void
 litest_assert_only_axis_events(struct libinput *li,
@@ -928,10 +948,15 @@ litest_assert_pad_key_event(struct libinput *li,
                            unsigned int key,
                            enum libinput_key_state state);
 
+#define litest_assert_gesture_event(...) \
+       _litest_assert_gesture_event(__VA_ARGS__, __func__, __LINE__)
+
 void
-litest_assert_gesture_event(struct libinput *li,
-                           enum libinput_event_type type,
-                           int nfingers);
+_litest_assert_gesture_event(struct libinput *li,
+                            enum libinput_event_type type,
+                            int nfingers,
+                            const char *func,
+                            int line);
 
 struct libevdev_uinput *
 litest_create_uinput_device(const char *name,