From: Peter Hutterer Date: Thu, 12 Sep 2024 03:40:44 +0000 (+1000) Subject: test: improve event debugging a bit X-Git-Tag: 1.27.0~138 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=596d86ecc1c44becf07c42c3f90e7f9003d6f1db;p=platform%2Fupstream%2Flibinput.git test: improve event debugging a bit 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: --- diff --git a/test/litest.c b/test/litest.c index 7070435e..787e84ae 100644 --- a/test/litest.c +++ b/test/litest.c @@ -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); diff --git a/test/litest.h b/test/litest.h index f247f0af..e12ec89b 100644 --- a/test/litest.h +++ b/test/litest.h @@ -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,