Skip to contentSkip to conversation

lib: share common logging code

PATCH In review Thomas Wood 2 participants 9 messages Dec 2, 2014 – Dec 10, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 lib: share common logging code

---
 lib/igt_core.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
lib/igt_core.c +1 -13
index 3fd4595..f7763b5 100644
@@ -1433,20 +1433,8 @@ void igt_log(enum igt_log_level level, const char *format, ...)
 {
 	va_list args;
 
-	assert(format);
-
-	if (list_subtests)
-		return;
-
-	if (igt_log_level > level)
-		return;
-
 	va_start(args, format);
-	if (level == IGT_LOG_WARN) {
-		fflush(stdout);
-		vfprintf(stderr, format, args);
-	} else
-		vprintf(format, args);
+	igt_vlog(level, format, args)
 	va_end(args);
 }
 
Signature · 6 lines
2.1.0

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

PATCH 2/5 tests/gem_tiled_swapping: use igt_info logging wrapper

---
 tests/gem_tiled_swapping.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
tests/gem_tiled_swapping.c +5 -6
index 11bb245..7637cf3 100644
@@ -163,12 +163,11 @@ igt_main
 		threads = calloc(num_threads, sizeof(struct thread));
 		igt_assert(threads);
 
-		igt_log(IGT_LOG_INFO,
-			"Using %d 1MiB objects (available RAM: %ld/%ld, swap: %ld)\n",
-			count,
-			(long)intel_get_avail_ram_mb(),
-			(long)intel_get_total_ram_mb(),
-			(long)intel_get_total_swap_mb());
+		igt_info("Using %d 1MiB objects (available RAM: %ld/%ld, swap: %ld)\n",
+			 count,
+			 (long)intel_get_avail_ram_mb(),
+			 (long)intel_get_total_ram_mb(),
+			 (long)intel_get_total_swap_mb());
 		intel_require_memory(count, 1024*1024, CHECK_RAM | CHECK_SWAP);
 
 		for (n = 0; n < count; n++) {
Signature · 6 lines
2.1.0

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

PATCH 3/5 lib: introduce log domains

In reply to Thomas Wood

Log domains can be used to identify the source of log messages, such as the test being run or the helper library.

---
 lib/Makefile.am |  3 ++-
 lib/igt_core.c  | 21 +++++++++++++++------
 lib/igt_core.h  | 18 +++++++++++-------
 lib/igt_kms.c   |  2 +-
 4 files changed, 29 insertions(+), 15 deletions(-)
lib/Makefile.am +2 -1
index ab82302..b0aeef3 100644
@@ -10,7 +10,8 @@ noinst_HEADERS = check-ndebug.h
 
 AM_CPPFLAGS = -I$(top_srcdir)
 AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)  \
-	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\"
+	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
+	    -DIGT_LOG_DOMAIN=\""libintel_tools"\"
 
 
 LDADD = $(CAIRO_LIBS)
lib/igt_core.c +15 -6
index f7763b5..4f4cf96 100644
@@ -1429,12 +1429,12 @@ void igt_skip_on_simulation(void)
  * are disabled. "none" completely disables all output and is not recommended
  * since crucial issues only reported at the IGT_LOG_WARN level are ignored.
  */
-void igt_log(enum igt_log_level level, const char *format, ...)
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...)
 {
 	va_list args;
 
 	va_start(args, format);
-	igt_vlog(level, format, args)
+	igt_vlog(domain, level, format, args);
 	va_end(args);
 }
 
@@ -1451,8 +1451,10 @@ void igt_log(enum igt_log_level level, const char *format, ...)
  * If there is no need to wrap up a vararg list in the caller it is simpler to
  * just use igt_log().
  */
-void igt_vlog(enum igt_log_level level, const char *format, va_list args)
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
 {
+	FILE *file;
+
 	assert(format);
 
 	if (list_subtests)
@@ -1461,11 +1463,18 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args)
 	if (igt_log_level > level)
 		return;
 
+	if (!domain)
+		domain = command_str;
+
 	if (level == IGT_LOG_WARN) {
+		file = stderr;
 		fflush(stdout);
-		vfprintf(stderr, format, args);
-	} else
-		vprintf(format, args);
+	}
+	else
+		file = stdout;
+
+	fprintf(file, "(%s:%d) ", domain, getpid());
+	vfprintf(file, format, args);
 }
 
 static void igt_alarm_handler(int signal)
lib/igt_core.h +11 -7
index a258348..5c5ee25 100644
@@ -512,16 +512,20 @@ bool igt_run_in_simulation(void);
 void igt_skip_on_simulation(void);
 
 /* structured logging */
+#ifndef IGT_LOG_DOMAIN
+#define IGT_LOG_DOMAIN (NULL)
+#endif
+
 enum igt_log_level {
 	IGT_LOG_DEBUG,
 	IGT_LOG_INFO,
 	IGT_LOG_WARN,
 	IGT_LOG_NONE,
 };
-__attribute__((format(printf, 2, 3)))
-void igt_log(enum igt_log_level level, const char *format, ...);
-__attribute__((format(printf, 2, 0)))
-void igt_vlog(enum igt_log_level level, const char *format, va_list args);
+__attribute__((format(printf, 3, 4)))
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...);
+__attribute__((format(printf, 3, 0)))
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args);
 
 /**
  * igt_debug:
@@ -529,7 +533,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_DEBUG level.
  */
-#define igt_debug(f...) igt_log(IGT_LOG_DEBUG, f)
+#define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f)
 
 /**
  * igt_info:
@@ -537,7 +541,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_INFO level.
  */
-#define igt_info(f...) igt_log(IGT_LOG_INFO, f)
+#define igt_info(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_INFO, f)
 
 /**
  * igt_warn:
@@ -545,7 +549,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_WARN level.
  */
-#define igt_warn(f...) igt_log(IGT_LOG_WARN, f)
+#define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
 extern enum igt_log_level igt_log_level;
 
 /**
lib/igt_kms.c +1 -1
index eb8e085..0421ee0 100644
@@ -740,7 +740,7 @@ igt_display_log(igt_display_t *display, const char *fmt, ...)
 	igt_debug("display: ");
 	for (i = 0; i < display->log_shift; i++)
 		igt_debug("%s", LOG_SPACES);
-	igt_vlog(IGT_LOG_DEBUG, fmt, args);
+	igt_vlog(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, fmt, args);
 	va_end(args);
 }
 
Signature · 6 lines
2.1.0

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

Re: [PATCH i-g-t 3/5] lib: introduce log domains

lib/igt_core.h bool igt_run_in_simulation(void); · line 517

Quoted 11 lines · Thomas Wood
lib/igt_core.h +3 -0
index a258348..5c5ee25 100644
@@ -512,16 +512,20 @@ bool igt_run_in_simulation(void);
 void igt_skip_on_simulation(void);
 
 /* structured logging */
+#ifndef IGT_LOG_DOMAIN
+#define IGT_LOG_DOMAIN (NULL)
+#endif

I guess the idea is that different source files have a

#define IGT_LOG_DOMAIN "foobar"

at the top before any includes?

Would be great if you can add some good defaults as a patch on top:
- For everything in tests/*c I think we should add a suitable define in the Makefile, perhaps "test"
- Same for tools/ with "tools"
- lib/* should probably have per-file log domains, using the basename of the source file itself. Dunno whether there's a cool Makefile trick to make that happen.

With that added I think patches 1-4 are a nice addition to the igt logging.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH i-g-t 3/5] lib: introduce log domains

Quoted 15 lines · Daniel Vetter

lib/igt_core.h bool igt_run_in_simulation(void); · line 517

Quoted 11 lines · Thomas Wood
lib/igt_core.h +3 -0
index a258348..5c5ee25 100644
@@ -512,16 +512,20 @@ bool igt_run_in_simulation(void);
 void igt_skip_on_simulation(void);
 
 /* structured logging */
+#ifndef IGT_LOG_DOMAIN
+#define IGT_LOG_DOMAIN (NULL)
+#endif

I guess the idea is that different source files have a

Quoted 4 lines

#define IGT_LOG_DOMAIN "foobar"

at the top before any includes?

Yes, or defined with -D in CFLAGS.

Quoted 5 lines

Would be great if you can add some good defaults as a patch on top:
- For everything in tests/*c I think we should add a suitable define in the Makefile, perhaps "test"

The default domain for a test is the program name.

Quoted 5 lines

- Same for tools/ with "tools"
- lib/* should probably have per-file log domains, using the basename of the source file itself. Dunno whether there's a cool Makefile trick to make that happen.

The helper library is currently all within the same domain (defined in
Makefile.am), but separate domains for different parts of the library would improve the filtering options.

Quoted 9 lines

With that added I think patches 1-4 are a nice addition to the igt logging.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

#5 lore raw

PATCH v2 1/2 lib: introduce log domains

Log domains can be used to identify the source of log messages, such as the test being run or the helper library.

v2: Add separate domains for different parts of the helper library and
use an empty default domain for applications.
Expand the log output to include the process name and the log level of the message in addition to the domain and pid.
Print the expanded message only for warning and information messages.

---
 lib/Makefile.am |  3 ++-
 lib/igt_core.c  | 28 ++++++++++++++++++++++------
 lib/igt_core.h  | 18 +++++++++++-------
 lib/igt_kms.c   |  2 +-
 4 files changed, 36 insertions(+), 15 deletions(-)
lib/Makefile.am +2 -1
index ab82302..3826a1c 100644
@@ -10,7 +10,8 @@ noinst_HEADERS = check-ndebug.h
 
 AM_CPPFLAGS = -I$(top_srcdir)
 AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)  \
-	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\"
+	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
+	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\"
 
 
 LDADD = $(CAIRO_LIBS)
lib/igt_core.c +22 -6
index 13a52a5..b6852dd 100644
@@ -1429,12 +1429,12 @@ void igt_skip_on_simulation(void)
  * are disabled. "none" completely disables all output and is not recommended
  * since crucial issues only reported at the IGT_LOG_WARN level are ignored.
  */
-void igt_log(enum igt_log_level level, const char *format, ...)
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...)
 {
 	va_list args;
 
 	va_start(args, format);
-	igt_vlog(level, format, args);
+	igt_vlog(domain, level, format, args);
 	va_end(args);
 }
 
@@ -1451,8 +1451,16 @@ void igt_log(enum igt_log_level level, const char *format, ...)
  * If there is no need to wrap up a vararg list in the caller it is simpler to
  * just use igt_log().
  */
-void igt_vlog(enum igt_log_level level, const char *format, va_list args)
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
 {
+	FILE *file;
+	const char *igt_log_level_str[] = {
+		"DEBUG",
+		"INFO",
+		"WARNING",
+		"NONE"
+	};
+
 	assert(format);
 
 	if (list_subtests)
@@ -1462,10 +1470,18 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args)
 		return;
 
 	if (level == IGT_LOG_WARN) {
+		file = stderr;
 		fflush(stdout);
-		vfprintf(stderr, format, args);
-	} else
-		vprintf(format, args);
+	}
+	else
+		file = stdout;
+
+	if (level != IGT_LOG_INFO) {
+		fprintf(file, "(%s:%d) %s%s%s: ", program_invocation_short_name,
+			getpid(), (domain) ? domain : "", (domain) ? "-" : "",
+			igt_log_level_str[level]);
+	}
+	vfprintf(file, format, args);
 }
 
 static void igt_alarm_handler(int signal)
lib/igt_core.h +11 -7
index a258348..5c5ee25 100644
@@ -512,16 +512,20 @@ bool igt_run_in_simulation(void);
 void igt_skip_on_simulation(void);
 
 /* structured logging */
+#ifndef IGT_LOG_DOMAIN
+#define IGT_LOG_DOMAIN (NULL)
+#endif
+
 enum igt_log_level {
 	IGT_LOG_DEBUG,
 	IGT_LOG_INFO,
 	IGT_LOG_WARN,
 	IGT_LOG_NONE,
 };
-__attribute__((format(printf, 2, 3)))
-void igt_log(enum igt_log_level level, const char *format, ...);
-__attribute__((format(printf, 2, 0)))
-void igt_vlog(enum igt_log_level level, const char *format, va_list args);
+__attribute__((format(printf, 3, 4)))
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...);
+__attribute__((format(printf, 3, 0)))
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args);
 
 /**
  * igt_debug:
@@ -529,7 +533,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_DEBUG level.
  */
-#define igt_debug(f...) igt_log(IGT_LOG_DEBUG, f)
+#define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f)
 
 /**
  * igt_info:
@@ -537,7 +541,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_INFO level.
  */
-#define igt_info(f...) igt_log(IGT_LOG_INFO, f)
+#define igt_info(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_INFO, f)
 
 /**
  * igt_warn:
@@ -545,7 +549,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_WARN level.
  */
-#define igt_warn(f...) igt_log(IGT_LOG_WARN, f)
+#define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
 extern enum igt_log_level igt_log_level;
 
 /**
lib/igt_kms.c +1 -1
index 1387d01..042e90e 100644
@@ -855,7 +855,7 @@ igt_display_log(igt_display_t *display, const char *fmt, ...)
 	igt_debug("display: ");
 	for (i = 0; i < display->log_shift; i++)
 		igt_debug("%s", LOG_SPACES);
-	igt_vlog(IGT_LOG_DEBUG, fmt, args);
+	igt_vlog(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, fmt, args);
 	va_end(args);
 }
 
Signature · 6 lines
2.1.0

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

PATCH v2 2/2 lib: add optional log domain filtering

v2: add an "application" filter for the default domain (used by
applications)

---
 docs/reference/intel-gpu-tools/igt_test_programs.xml |  6 ++++--
 lib/igt_core.c                                       | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
docs/reference/intel-gpu-tools/igt_test_programs.xml +4 -2
index 970ecb9..36ad1f3 100644
@@ -35,9 +35,11 @@
           </varlistentry>
 
           <varlistentry>
-            <term><option>--debug</option></term>
+            <term><option>--debug[=log-domain]</option></term>
             <listitem><para>
-                print extra debugging information when running tests
+                print extra debugging information when running tests and
+                optionaly only show the messages from the specified log domain
+                (use "application" to specifiy the default application domain)
             </para></listitem>
           </varlistentry>
 
lib/igt_core.c +15 -2
index b6852dd..695437c 100644
@@ -228,6 +228,8 @@ enum {
  OPT_HELP = 'h'
 };
 
+static char* igt_log_domain_filter;
+
 __attribute__((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
 #define KERN_EMER	"<0>"
@@ -390,7 +392,7 @@ static void print_usage(const char *help_str, bool output_on_stderr)
 	fprintf(f, "Usage: %s [OPTIONS]\n", command_str);
 	fprintf(f, "  --list-subtests\n"
 		   "  --run-subtest <pattern>\n"
-		   "  --debug\n"
+		   "  --debug[=log-domain]\n"
 		   "  --help-description\n"
 		   "  --help\n");
 	if (help_str)
@@ -422,7 +424,7 @@ static int common_init(int argc, char **argv,
 		{"list-subtests", 0, 0, OPT_LIST_SUBTESTS},
 		{"run-subtest", 1, 0, OPT_RUN_SUBTEST},
 		{"help-description", 0, 0, OPT_DESCRIPTION},
-		{"debug", 0, 0, OPT_DEBUG},
+		{"debug", optional_argument, 0, OPT_DEBUG},
 		{"help", 0, 0, OPT_HELP},
 		{0, 0, 0, 0}
 	};
@@ -510,6 +512,8 @@ static int common_init(int argc, char **argv,
 		switch(c) {
 		case OPT_DEBUG:
 			igt_log_level = IGT_LOG_DEBUG;
+			if (optarg && strlen(optarg) > 0)
+				igt_log_domain_filter = strdup(optarg);
 			break;
 		case OPT_LIST_SUBTESTS:
 			if (!run_single_subtest)
@@ -1469,6 +1473,15 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
 	if (igt_log_level > level)
 		return;
 
+	if (igt_log_domain_filter) {
+		/* if null domain and filter is not "application", return */
+		if (!domain && strcmp(igt_log_domain_filter, "application"))
+			return;
+		/* else if domain and filter do not match, return */
+		else if (domain && strcmp(igt_log_domain_filter, domain))
+			return;
+	}
+
 	if (level == IGT_LOG_WARN) {
 		file = stderr;
 		fflush(stdout);
Signature · 6 lines
2.1.0

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

PATCH 4/5 lib: add optional log domain filtering

In reply to Thomas Wood
---
 lib/igt_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
lib/igt_core.c +12 -2
index 4f4cf96..d53fabb 100644
@@ -228,6 +228,8 @@ enum {
  OPT_HELP = 'h'
 };
 
+static char* igt_log_domain_filter;
+
 __attribute__((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
 #define KERN_EMER	"<0>"
@@ -390,7 +392,7 @@ static void print_usage(const char *help_str, bool output_on_stderr)
 	fprintf(f, "Usage: %s [OPTIONS]\n", command_str);
 	fprintf(f, "  --list-subtests\n"
 		   "  --run-subtest <pattern>\n"
-		   "  --debug\n"
+		   "  --debug[=log-domain]\n"
 		   "  --help-description\n"
 		   "  --help\n");
 	if (help_str)
@@ -422,7 +424,7 @@ static int common_init(int argc, char **argv,
 		{"list-subtests", 0, 0, OPT_LIST_SUBTESTS},
 		{"run-subtest", 1, 0, OPT_RUN_SUBTEST},
 		{"help-description", 0, 0, OPT_DESCRIPTION},
-		{"debug", 0, 0, OPT_DEBUG},
+		{"debug", optional_argument, 0, OPT_DEBUG},
 		{"help", 0, 0, OPT_HELP},
 		{0, 0, 0, 0}
 	};
@@ -510,6 +512,8 @@ static int common_init(int argc, char **argv,
 		switch(c) {
 		case OPT_DEBUG:
 			igt_log_level = IGT_LOG_DEBUG;
+			if (optarg)
+				igt_log_domain_filter = strdup(optarg);
 			break;
 		case OPT_LIST_SUBTESTS:
 			if (!run_single_subtest)
@@ -1463,9 +1467,15 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
 	if (igt_log_level > level)
 		return;
 
+	if (igt_log_level > level)
+		return;
+
 	if (!domain)
 		domain = command_str;
 
+	if (igt_log_domain_filter && strcmp(igt_log_domain_filter, domain))
+		return;
+
 	if (level == IGT_LOG_WARN) {
 		file = stderr;
 		fflush(stdout);
Signature · 6 lines
2.1.0

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

PATCH 5/5 lib: write out recent log output if a test fails

In reply to Thomas Wood
---
 lib/igt_core.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 10 deletions(-)
lib/igt_core.c +58 -10
index d53fabb..c369ed7 100644
@@ -50,6 +50,7 @@
 #include <termios.h>
 #include <errno.h>
 #include <time.h>
+#include <limits.h>
 
 #include "drmtest.h"
 #include "intel_chipset.h"
@@ -228,8 +229,16 @@ enum {
  OPT_HELP = 'h'
 };
 
+static const char *command_str;
+static int igt_exitcode = IGT_EXIT_SUCCESS;
+
 static char* igt_log_domain_filter;
 
+static struct {
+	char *entries[256];
+	uint8_t start, end;
+} log_buffer;
+
 __attribute__((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
 #define KERN_EMER	"<0>"
@@ -353,6 +362,38 @@ static void low_mem_killer_disable(bool disable)
 	chmod(adj_fname, buf.st_mode);
 }
 
+static void write_log(void)
+{
+	uint8_t i;
+	int log, pos;
+	char filename[NAME_MAX];
+	const char *ext = ".log";
+
+	/* don't write an empty log */
+	if (log_buffer.start == log_buffer.end)
+		return;
+
+	/* copy the test filename and append ".log" in a signal handler safe
+	 * way */
+	for (i = 0; command_str[i] && i < NAME_MAX - 5; i++)
+		filename[i] = command_str[i];
+	pos = i;
+	for (i = 0; pos + i < NAME_MAX; i++) {
+		filename[pos + i] = ext[i];
+		if (ext[i] == '\0')
+			break;
+	}
+
+	log = open(filename, O_CREAT|O_WRONLY);
+	i = log_buffer.start;
+	do {
+		int len = strlen(log_buffer.entries[i]);
+		write(log, log_buffer.entries[i], len);
+		i++;
+	} while (i != log_buffer.start && i != log_buffer.end);
+	close(log);
+}
+
 bool igt_exit_called;
 static void common_exit_handler(int sig)
 {
@@ -361,6 +402,10 @@ static void common_exit_handler(int sig)
 	/* When not killed by a signal check that igt_exit() has been properly
 	 * called. */
 	assert(sig != 0 || igt_exit_called);
+
+	/* write the log out to a file if the test failed */
+	if (sig || (igt_exitcode != IGT_EXIT_SUCCESS && igt_exitcode != IGT_EXIT_SKIP))
+		write_log();
 }
 
 static void print_test_description(void)
@@ -383,8 +428,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;
@@ -728,7 +771,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)
@@ -1458,21 +1500,28 @@ void igt_log(const char *domain, enum igt_log_level level, const char *format, .
 void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
 {
 	FILE *file;
+	char *line;
 
 	assert(format);
 
 	if (list_subtests)
 		return;
 
-	if (igt_log_level > level)
-		return;
+	if (!domain)
+		domain = command_str;
+
+	/* store any log output in ring buffer */
+	free(log_buffer.entries[log_buffer.end]);
+	vasprintf(&line, format, args);
+	asprintf(&log_buffer.entries[log_buffer.end], "(%s:%d) %s",
+		 domain, getpid(), line);
+	log_buffer.end++;
+	if (log_buffer.end == log_buffer.start)
+		log_buffer.start++;
 
 	if (igt_log_level > level)
 		return;
 
-	if (!domain)
-		domain = command_str;
-
 	if (igt_log_domain_filter && strcmp(igt_log_domain_filter, domain))
 		return;
 
@@ -1483,8 +1532,7 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
 	else
 		file = stdout;
 
-	fprintf(file, "(%s:%d) ", domain, getpid());
-	vfprintf(file, format, args);
+	fprintf(file, "(%s:%d) %s", domain, getpid(), line);
 }
 
 static void igt_alarm_handler(int signal)
Signature · 6 lines
2.1.0

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