From patchwork Tue Dec 2 17:15:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 5421741 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 57AB49F1C5 for ; Tue, 2 Dec 2014 17:21:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DB0B202EC for ; Tue, 2 Dec 2014 17:21:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7C7A7202E6 for ; Tue, 2 Dec 2014 17:21:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B2B26F4F5; Tue, 2 Dec 2014 09:21:25 -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 2F3EA6F4F6 for ; Tue, 2 Dec 2014 09:21:23 -0800 (PST) Received: by mail-wg0-f54.google.com with SMTP id l2so17597523wgh.13 for ; Tue, 02 Dec 2014 09:21:22 -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:in-reply-to :references; bh=lU2AvvLP0sWYmFk9J7XI/61DYmgpz870Y1NTf8X5TKw=; b=hNVFmZVmDKZuCATr99XoZsMPx3GzMzeUktGUtQ1cUkRozyTYUtSYlUHTtw3tTFKRQ9 DABiHF6Kx4EErNx1MiRmUzEmBk61f9OLwlvBbAGmoKggfkTqjrGZ0IqJCMLB/QYkKcqJ Mw8Yl8CDnPiWBd6RFqBxyxiMi6yfe8WPINGLNGkrADY+4T69yz5oOt+hHQlEN2VxaVIU mJO7tcIoicRz7Ww2EeuubeDTs2HROIbv5DVYATUvBFBbKhdLy2VaZMMkqAmNZzKvbu78 SZB61ZOo3cXQSjfNCkxCbE/b4HyKD7L0AUhfXl+tQPEgRCKdfLr3KOF150Sm1c5Lwxw6 VVJw== X-Gm-Message-State: ALoCoQmAVYcsRLGphHFlAGuUG2Rkt8TZ3gIFJR2jXAhvSgJc/u3t/6I4FCRUd4Mut7tzxvKmDojP X-Received: by 10.180.73.235 with SMTP id o11mr75566464wiv.51.1417540549253; Tue, 02 Dec 2014 09:15:49 -0800 (PST) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id n3sm32725757wjz.21.2014.12.02.09.15.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Dec 2014 09:15:48 -0800 (PST) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Tue, 2 Dec 2014 17:15:39 +0000 Message-Id: <1417540539-23069-5-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1417540539-23069-1-git-send-email-thomas.wood@intel.com> References: <1417540539-23069-1-git-send-email-thomas.wood@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 5/5] lib: write out 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 Signed-off-by: Thomas Wood --- 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 #include #include +#include #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)