Skip to contentSkip to conversation

printing log messages on test failure

PATCH New Thomas Wood 1 participant 3 messages Jan 29, 2015 Library code

lore
Share & tools
lore
#0 lore raw

cover printing log messages on test failure

This series replaces the earlier one dealing with printing recent log messages and avoids any issues with signal handlers by only printing the log on a test failure.

Thomas Wood (2):
lib: add a ring buffer for log entries
lib: print recent log messages to stderr when a test or subtest fails

 lib/Makefile.am |   3 +-
 lib/igt_core.c  | 112 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 100 insertions(+), 15 deletions(-)
Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/2 lib: add a ring buffer for log entries

---
 lib/Makefile.am |  3 ++-
 lib/igt_core.c  | 72 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 63 insertions(+), 12 deletions(-)
lib/Makefile.am +2 -1
index 3826a1c..a5a4390 100644
@@ -11,7 +11,8 @@ noinst_HEADERS = check-ndebug.h
 AM_CPPFLAGS = -I$(top_srcdir)
 AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)  \
 	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
-	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\"
+	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\" \
+	    -pthread
 
 
 LDADD = $(CAIRO_LIBS)
lib/igt_core.c +61 -11

118 lines not on this page · raw message

Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/2 lib: print recent log messages to stderr when a test or subtest fails

In reply to Thomas Wood
---
 lib/igt_core.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)
lib/igt_core.c +37 -3
index b03b7df..596ab77 100644
@@ -236,6 +236,9 @@ enum {
  OPT_HELP = 'h'
 };
 
+static int igt_exitcode = IGT_EXIT_SUCCESS;
+static const char *command_str;
+
 static char* igt_log_domain_filter;
 static struct {
 	char *entries[256];
@@ -265,7 +268,39 @@ static void _igt_log_buffer_reset(void)
 	pthread_mutex_unlock(&log_buffer_mutex);
 }
 
+static void _igt_log_buffer_dump(void)
+{
+	uint8_t i;
+
+	if (in_subtest)
+		fprintf(stderr, "Subtest %s failed.\n", in_subtest);
+	else
+		fprintf(stderr, "Test %s failed.\n", command_str);
+
+	if (log_buffer.start == log_buffer.end) {
+		fprintf(stderr, "No log.\n");
+		return;
+	}
+
+	pthread_mutex_lock(&log_buffer_mutex);
 
+	fprintf(stderr, "Log Start\n");
+
+	i = log_buffer.start;
+	do {
+		char *last_line = log_buffer.entries[i];
+		fprintf(stderr, "%s%s", last_line,
+			(last_line[strlen(last_line)-1] != '\n') ? "\n" : "");
+		i++;
+	} while (i != log_buffer.start && i != log_buffer.end);
+
+	/* reset the buffer */
+	log_buffer.start = log_buffer.end = 0;
+
+	pthread_mutex_unlock(&log_buffer_mutex);
+
+	fprintf(stderr, "Log End\n");
+}
 
 __attribute__((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
@@ -422,8 +457,6 @@ static void print_version(void)
 		uts.sysname, uts.release, uts.machine);
 }
 
-static const char *command_str;
-
 static void print_usage(const char *help_str, bool output_on_stderr)
 {
 	FILE *f = output_on_stderr ? stderr : stdout;
@@ -777,7 +810,6 @@ bool igt_only_list_subtests(void)
 static bool skipped_one = false;
 static bool succeeded_one = false;
 static bool failed_one = false;
-static int igt_exitcode = IGT_EXIT_SUCCESS;
 
 static void exit_subtest(const char *) __attribute__((noreturn));
 static void exit_subtest(const char *result)
@@ -910,6 +942,8 @@ void igt_fail(int exitcode)
 	if (test_child)
 		exit(exitcode);
 
+	_igt_log_buffer_dump();
+
 	if (in_subtest) {
 		if (exitcode == IGT_EXIT_TIMEOUT)
 			exit_subtest("TIMEOUT");
Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx