All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 1/5] lib: share common logging code
@ 2014-12-02 17:15 Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper Thomas Wood
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Thomas Wood @ 2014-12-02 17:15 UTC (permalink / raw
  To: intel-gfx

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 lib/igt_core.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 3fd4595..f7763b5 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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);
 }
 
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper
  2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
@ 2014-12-02 17:15 ` Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 3/5] lib: introduce log domains Thomas Wood
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Thomas Wood @ 2014-12-02 17:15 UTC (permalink / raw
  To: intel-gfx

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 tests/gem_tiled_swapping.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c
index 11bb245..7637cf3 100644
--- a/tests/gem_tiled_swapping.c
+++ b/tests/gem_tiled_swapping.c
@@ -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++) {
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH i-g-t 3/5] lib: introduce log domains
  2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper Thomas Wood
@ 2014-12-02 17:15 ` Thomas Wood
  2014-12-03 14:22   ` Daniel Vetter
  2014-12-02 17:15 ` [PATCH i-g-t 4/5] " Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 5/5] lib: write out recent log output if a test fails Thomas Wood
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Wood @ 2014-12-02 17:15 UTC (permalink / raw
  To: intel-gfx

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

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 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(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index ab82302..b0aeef3 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index f7763b5..4f4cf96 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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)
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a258348..5c5ee25 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -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;
 
 /**
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index eb8e085..0421ee0 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -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);
 }
 
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH i-g-t 4/5] lib: add optional log domain filtering
  2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 3/5] lib: introduce log domains Thomas Wood
@ 2014-12-02 17:15 ` Thomas Wood
  2014-12-02 17:15 ` [PATCH i-g-t 5/5] lib: write out recent log output if a test fails Thomas Wood
  3 siblings, 0 replies; 9+ messages in thread
From: Thomas Wood @ 2014-12-02 17:15 UTC (permalink / raw
  To: intel-gfx

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 lib/igt_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 4f4cf96..d53fabb 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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);
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH i-g-t 5/5] lib: write out recent log output if a test fails
  2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
                   ` (2 preceding siblings ...)
  2014-12-02 17:15 ` [PATCH i-g-t 4/5] " Thomas Wood
@ 2014-12-02 17:15 ` Thomas Wood
  3 siblings, 0 replies; 9+ messages in thread
From: Thomas Wood @ 2014-12-02 17:15 UTC (permalink / raw
  To: intel-gfx

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 lib/igt_core.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 10 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index d53fabb..c369ed7 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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)
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH i-g-t 3/5] lib: introduce log domains
  2014-12-02 17:15 ` [PATCH i-g-t 3/5] lib: introduce log domains Thomas Wood
@ 2014-12-03 14:22   ` Daniel Vetter
  2014-12-04 10:58     ` Thomas Wood
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Vetter @ 2014-12-03 14:22 UTC (permalink / raw
  To: Thomas Wood; +Cc: intel-gfx

On Tue, Dec 02, 2014 at 05:15:37PM +0000, Thomas Wood wrote:
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index a258348..5c5ee25 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -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
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH i-g-t 3/5] lib: introduce log domains
  2014-12-03 14:22   ` Daniel Vetter
@ 2014-12-04 10:58     ` Thomas Wood
  2014-12-10 17:24       ` [PATCH i-g-t v2 1/2] " Thomas Wood
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas Wood @ 2014-12-04 10:58 UTC (permalink / raw
  To: Daniel Vetter; +Cc: Intel Graphics Development


[-- Attachment #1.1: Type: text/plain, Size: 1471 bytes --]

On 3 December 2014 at 14:22, Daniel Vetter <daniel@ffwll.ch> wrote:

> On Tue, Dec 02, 2014 at 05:15:37PM +0000, Thomas Wood wrote:
> > diff --git a/lib/igt_core.h b/lib/igt_core.h
> > index a258348..5c5ee25 100644
> > --- a/lib/igt_core.h
> > +++ b/lib/igt_core.h
> > @@ -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?
>

Yes, or defined with -D in CFLAGS.


>
> 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.



> - 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.



>
> 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
>

[-- Attachment #1.2: Type: text/html, Size: 2582 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH i-g-t v2 1/2] lib: introduce log domains
  2014-12-04 10:58     ` Thomas Wood
@ 2014-12-10 17:24       ` Thomas Wood
  2014-12-10 17:24         ` [PATCH i-g-t v2 2/2] lib: add optional log domain filtering Thomas Wood
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas Wood @ 2014-12-10 17:24 UTC (permalink / raw
  To: intel-gfx

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.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 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(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index ab82302..3826a1c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 13a52a5..b6852dd 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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)
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a258348..5c5ee25 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -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;
 
 /**
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 1387d01..042e90e 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -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);
 }
 
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH i-g-t v2 2/2] lib: add optional log domain filtering
  2014-12-10 17:24       ` [PATCH i-g-t v2 1/2] " Thomas Wood
@ 2014-12-10 17:24         ` Thomas Wood
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Wood @ 2014-12-10 17:24 UTC (permalink / raw
  To: intel-gfx

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

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 docs/reference/intel-gpu-tools/igt_test_programs.xml |  6 ++++--
 lib/igt_core.c                                       | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/docs/reference/intel-gpu-tools/igt_test_programs.xml b/docs/reference/intel-gpu-tools/igt_test_programs.xml
index 970ecb9..36ad1f3 100644
--- a/docs/reference/intel-gpu-tools/igt_test_programs.xml
+++ b/docs/reference/intel-gpu-tools/igt_test_programs.xml
@@ -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>
 
diff --git a/lib/igt_core.c b/lib/igt_core.c
index b6852dd..695437c 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -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);
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-12-10 17:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 3/5] lib: introduce log domains Thomas Wood
2014-12-03 14:22   ` Daniel Vetter
2014-12-04 10:58     ` Thomas Wood
2014-12-10 17:24       ` [PATCH i-g-t v2 1/2] " Thomas Wood
2014-12-10 17:24         ` [PATCH i-g-t v2 2/2] lib: add optional log domain filtering Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 4/5] " Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 5/5] lib: write out recent log output if a test fails Thomas Wood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.