mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 16:20:05 +01:00
test: add extra highlighting for the backtrace
Pass through the function name where the condition failed so we can highlight that line in the backtrace. Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1159>
This commit is contained in:
parent
8cd5cad1c1
commit
bcb467da4c
4 changed files with 31 additions and 13 deletions
|
|
@ -43,12 +43,16 @@
|
|||
* If use_colors is true, highlight_before may specify
|
||||
* a substring for a line before which the backtrace is
|
||||
* colored.
|
||||
*
|
||||
* If use_colors is true, highlight_extra may specify
|
||||
* a substring for a line that has extra highlighting.
|
||||
*/
|
||||
static inline void
|
||||
backtrace_print(FILE *fp,
|
||||
bool use_colors,
|
||||
const char *highlight_after,
|
||||
const char *highlight_before)
|
||||
const char *highlight_before,
|
||||
const char *highlight_extra)
|
||||
{
|
||||
#if HAVE_GSTACK
|
||||
pid_t parent, child;
|
||||
|
|
@ -98,8 +102,15 @@ backtrace_print(FILE *fp,
|
|||
while (line && *line) {
|
||||
if (highlight && highlight_before && strstr(*line, highlight_before))
|
||||
highlight = false;
|
||||
|
||||
const char *hlcolor = highlight ? ANSI_BRIGHT_CYAN : "";
|
||||
|
||||
if (highlight && highlight_extra &&
|
||||
strstr(*line, highlight_extra))
|
||||
hlcolor = ANSI_BRIGHT_MAGENTA;
|
||||
|
||||
fprintf(fp, "%s%s%s\n",
|
||||
highlight ? ANSI_BRIGHT_CYAN : "",
|
||||
hlcolor,
|
||||
*line,
|
||||
highlight ? ANSI_NORMAL : "");
|
||||
if (!highlight && highlight_after && strstr(*line, highlight_after))
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ sighandler_forked_child(int signal)
|
|||
* the backtrace anyway - we only need to backtrace the other signals
|
||||
*/
|
||||
if (signal != SIGABRT)
|
||||
litest_backtrace();
|
||||
litest_backtrace(NULL);
|
||||
|
||||
raise(signal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,15 +168,22 @@ _litest_checkpoint(const char *func,
|
|||
}
|
||||
|
||||
void
|
||||
litest_backtrace(void)
|
||||
litest_backtrace(const char *func)
|
||||
{
|
||||
#ifndef LITEST_DISABLE_BACKTRACE_LOGGING
|
||||
if (RUNNING_ON_VALGRIND) {
|
||||
fprintf(stderr, "Using valgrind, omitting backtrace\n");
|
||||
return;
|
||||
}
|
||||
char buf[256];
|
||||
|
||||
backtrace_print(stderr, use_colors, "in litest_backtrace", "in litest_runner_test_run");
|
||||
snprintf(buf, sizeof(buf), "in %s", func);
|
||||
|
||||
backtrace_print(stderr,
|
||||
use_colors,
|
||||
"in litest_backtrace",
|
||||
"in litest_runner_test_run",
|
||||
func ? buf : NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +209,7 @@ litest_fail_condition(const char *file,
|
|||
}
|
||||
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
litest_backtrace(func);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +227,7 @@ litest_fail_comparison_int(const char *file,
|
|||
litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("Resolved to: %d %s %d\n", a, operator, b);
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
litest_backtrace(func);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +245,7 @@ litest_fail_comparison_double(const char *file,
|
|||
litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("Resolved to: %.3f %s %.3f\n", a, operator, b);
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
litest_backtrace(func);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +258,7 @@ litest_fail_comparison_ptr(const char *file,
|
|||
{
|
||||
litest_log("FAILED COMPARISON: %s\n", comparison);
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
litest_backtrace(func);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +275,7 @@ litest_fail_comparison_str(const char *file,
|
|||
litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("Resolved to: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
litest_backtrace(func);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -3708,7 +3715,7 @@ _litest_assert_event_type_is_one_of(struct libinput_event *event, ...)
|
|||
fprintf(stderr, "\n");
|
||||
|
||||
litest_print_event(event, "Wrong event is:");
|
||||
litest_backtrace();
|
||||
litest_backtrace(__func__);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
@ -3748,7 +3755,7 @@ _litest_assert_event_type_not_one_of(struct libinput_event *event, ...)
|
|||
libinput_event_get_type(event));
|
||||
|
||||
litest_print_event(event,"\nWrong event is: ");
|
||||
litest_backtrace();
|
||||
litest_backtrace(__func__);
|
||||
litest_runner_abort();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ litest_fail_comparison_str(const char *file,
|
|||
#define litest_assert_double_ge(a_, b_)\
|
||||
litest_assert_double_ge_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
|
||||
|
||||
void litest_backtrace(void);
|
||||
void litest_backtrace(const char *func);
|
||||
|
||||
enum litest_device_type {
|
||||
LITEST_NO_DEVICE = -1,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue