From patchwork Wed Dec 17 16:45:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 5507931 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D72C1BEEA8 for ; Wed, 17 Dec 2014 16:46:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A4E6209A6 for ; Wed, 17 Dec 2014 16:45:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C093820A29 for ; Wed, 17 Dec 2014 16:45:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33EDD6E958; Wed, 17 Dec 2014 08:45:53 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com [74.125.82.54]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F75E6E958 for ; Wed, 17 Dec 2014 08:45:51 -0800 (PST) Received: by mail-wg0-f54.google.com with SMTP id l2so20912131wgh.41 for ; Wed, 17 Dec 2014 08:45:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=duOlWtm4MHJR8NYhv+ydLkLG9xVBIIECxuFnyDbpRWg=; b=Mcjb36mfNWw0AKq/FBZmyZ5VPMweAH/1tABbfcM/BQVggcHpwq0WelsdRsGrkpepAr 72RpzJNZpLDyDR5bHYyVaNHYGfp8EZ8ie75kzxwuo3GdQcX110aFplINXbRADsmh5/IG 92szsyIBgNInNsbg3b18vt3SQIuiIuiWct4c6648hV12DX/55xmQ7TpYwbBzEiGalm53 rPziH//R/K1omqcQZGpaaxfq3q8ORnw8aAzO2ITcrUIGvmNjmHDD7bF6x+7YThJHTXa/ uNb/rKLuVSBRM1dAa0EkGQWJscZ9iRWMuJWRNGfpVHtdtOlU4/LacVyreG7iEkaCmuF/ +zkg== X-Gm-Message-State: ALoCoQkVcPC19vhLY6ZEjjsoJ++EaW3dSI2ljOS16ACy/M0ZUNN0vlps1dHA00lnMNlN/xXpkVQj X-Received: by 10.180.187.67 with SMTP id fq3mr15870188wic.37.1418834750418; Wed, 17 Dec 2014 08:45:50 -0800 (PST) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id ec2sm6762267wib.23.2014.12.17.08.45.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 08:45:49 -0800 (PST) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Wed, 17 Dec 2014 16:45:43 +0000 Message-Id: <1418834747-5598-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.1.0 Subject: [Intel-gfx] [PATCH i-g-t 1/5] lib: print recent log output if a test fails X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Print recent log entries if a test or subtest fails and the current log level is set to info. v2: Write log to stderr after test or subtest failure and make log buffering thread safe. Signed-off-by: Thomas Wood --- lib/igt_core.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 08e0c47..457b3b1 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include "drmtest.h" #include "intel_chipset.h" @@ -228,8 +230,18 @@ 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; +static pthread_mutex_t log_buffer_mutex = PTHREAD_MUTEX_INITIALIZER; + + __attribute__((format(printf, 1, 2))) static void kmsg(const char *format, ...) #define KERN_EMER "<0>" @@ -353,6 +365,52 @@ static void low_mem_killer_disable(bool disable) chmod(adj_fname, buf.st_mode); } +#define write_log_msg(x) write(STDERR_FILENO, x, strlen(x)) + +/* this function must be safe to be called inside a signal handler */ +static void write_log(void) +{ + uint8_t i; + char *last_line; + + pthread_mutex_lock(&log_buffer_mutex); + + /* don't write an empty log */ + if (log_buffer.start == log_buffer.end) { + pthread_mutex_unlock(&log_buffer_mutex); + return; + } + + if (in_subtest) { + write_log_msg("--- Subtest "); + write_log_msg(in_subtest); + } else { + write_log_msg("--- Test "); + write_log_msg(command_str); + } + write_log_msg(" failed.\n"); + write_log_msg("--- Log Start\n"); + + i = log_buffer.start; + do { + last_line = log_buffer.entries[i]; + write_log_msg(last_line); + + /* ensure each line ends in a newline */ + for (int pos = 0; last_line[pos] != '\0'; pos++) { + if (last_line[pos] != '\n' + && last_line[pos + 1] == '\0') + write_log_msg("\n"); + } + + i++; + } while (i != log_buffer.start && i != log_buffer.end); + + write_log_msg("--- Log End\n"); + + pthread_mutex_unlock(&log_buffer_mutex); +} + bool igt_exit_called; static void common_exit_handler(int sig) { @@ -361,6 +419,14 @@ 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 a signal was received or a simple + * test failed (tests with subtests write the log after the subtest + * failure) */ + if (sig || (!test_with_subtests + && igt_exitcode != IGT_EXIT_SUCCESS + && igt_exitcode != IGT_EXIT_SKIP)) + write_log(); } static void print_test_description(void) @@ -383,8 +449,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 +792,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) @@ -862,6 +925,7 @@ void igt_fail(int exitcode) exit(exitcode); if (in_subtest) { + write_log(); if (exitcode == IGT_EXIT_TIMEOUT) exit_subtest("TIMEOUT"); else @@ -1460,6 +1524,7 @@ 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; const char *program_name; const char *igt_log_level_str[] = { "DEBUG", @@ -1479,16 +1544,37 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format, if (list_subtests) return; + vasprintf(&line, format, args); + + /* save log output when log level is info */ + if (igt_log_level == IGT_LOG_INFO) { + pthread_mutex_lock(&log_buffer_mutex); + + free(log_buffer.entries[log_buffer.end]); + asprintf(&log_buffer.entries[log_buffer.end], + "(%s:%d) %s%s%s: %s", + program_name, getpid(), + (domain) ? domain : "", + (domain) ? "-" : "", + igt_log_level_str[level], + line); + log_buffer.end++; + if (log_buffer.end == log_buffer.start) + log_buffer.start++; + + pthread_mutex_unlock(&log_buffer_mutex); + } + if (igt_log_level > level) - return; + goto out; if (igt_log_domain_filter) { /* if null domain and filter is not "application", return */ if (!domain && strcmp(igt_log_domain_filter, "application")) - return; + goto out; /* else if domain and filter do not match, return */ else if (domain && strcmp(igt_log_domain_filter, domain)) - return; + goto out; } if (level == IGT_LOG_WARN) { @@ -1503,7 +1589,10 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format, (domain) ? domain : "", (domain) ? "-" : "", igt_log_level_str[level]); } - vfprintf(file, format, args); + fwrite(line, sizeof(char), strlen(line), file); + +out: + free(line); } static void igt_alarm_handler(int signal)