test: print the log message to a buffer, then print the whole lot

This reduces the number of actual printf calls to one and makes it
easier to search for a string in the message for highlighting.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1226>
This commit is contained in:
Peter Hutterer 2025-06-17 11:09:33 +10:00
parent 76f88deb24
commit 9f6b294e36

View file

@ -1275,7 +1275,8 @@ litest_log_handler(struct libinput *libinput,
va_list args) va_list args)
{ {
const char *priority = NULL; const char *priority = NULL;
const char *color; const char *color = "";
const char *color_reset = ANSI_NORMAL;
switch(pri) { switch(pri) {
case LIBINPUT_LOG_PRIORITY_INFO: case LIBINPUT_LOG_PRIORITY_INFO:
@ -1294,32 +1295,31 @@ litest_log_handler(struct libinput *libinput,
abort(); abort();
} }
_autofree_ char *msg = strdup_vprintf(format, args);
if (!use_colors) if (!use_colors)
color = ""; color_reset = "";
else if (strstr(format, "tap:")) else if (strstr(msg, "tap:"))
color = ANSI_BLUE; color = ANSI_BLUE;
else if (strstr(format, "thumb state:")) else if (strstr(msg, "thumb state:"))
color = ANSI_YELLOW; color = ANSI_YELLOW;
else if (strstr(format, "button state:")) else if (strstr(msg, "button state:"))
color = ANSI_MAGENTA; color = ANSI_MAGENTA;
else if (strstr(format, "touch-size:") || else if (strstr(msg, "touch-size:") ||
strstr(format, "pressure:")) strstr(msg, "pressure:"))
color = ANSI_GREEN; color = ANSI_GREEN;
else if (strstr(format, "palm:") || else if (strstr(msg, "palm:") ||
strstr(format, "thumb:")) strstr(msg, "thumb:"))
color = ANSI_CYAN; color = ANSI_CYAN;
else if (strstr(format, "edge-scroll:")) else if (strstr(msg, "edge-scroll:"))
color = ANSI_BRIGHT_GREEN; color = ANSI_BRIGHT_GREEN;
else if (strstr(format, "gesture:")) else if (strstr(msg, "gesture:"))
color = ANSI_BRIGHT_YELLOW; color = ANSI_BRIGHT_YELLOW;
fprintf(stderr, "%slitest %s ", color, priority); fprintf(stderr, "%slitest %s %s%s", color, priority, msg, color_reset);
vfprintf(stderr, format, args);
if (use_colors)
fprintf(stderr, ANSI_NORMAL);
if (strstr(format, "client bug: ") || if (strstr(msg, "client bug: ") ||
strstr(format, "libinput bug: ")) { strstr(msg, "libinput bug: ")) {
/* valgrind is too slow and some of our offsets are too /* valgrind is too slow and some of our offsets are too
* short, don't abort if during a valgrind run we get a * short, don't abort if during a valgrind run we get a
* negative offset */ * negative offset */
@ -1333,7 +1333,7 @@ litest_log_handler(struct libinput *libinput,
} }
} }
if (strstr(format, "Touch jump detected and discarded")) { if (strstr(msg, "Touch jump detected and discarded")) {
litest_abort_msg("libinput touch jump triggered, aborting."); litest_abort_msg("libinput touch jump triggered, aborting.");
} }
} }