From patchwork Tue Mar 1 21:27:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8470661 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E97429F9A0 for ; Tue, 1 Mar 2016 21:28:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F4032034B for ; Tue, 1 Mar 2016 21:28:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C97DD20357 for ; Tue, 1 Mar 2016 21:27:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753122AbcCAV1y (ORCPT ); Tue, 1 Mar 2016 16:27:54 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34748 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752774AbcCAV1u (ORCPT ); Tue, 1 Mar 2016 16:27:50 -0500 Received: by mail-pa0-f42.google.com with SMTP id fy10so118782024pac.1 for ; Tue, 01 Mar 2016 13:27:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WqhU/k5frFypUQyoJ2kdaImddFRVKiSuzDoQH9meyDM=; b=LeiVULYU6lZwtuOCrKw4QGoHPk54n65A1uNTTGglP6p0w9Hxfh1fSNISLuaGCfobJ2 9iANmCId9fMQEocIShZInC8qX0vlLo0TuNxlX/SlO+BU18NZ5uTUCY6kYFXPTDcUK86Z dHIpfLLoBHCZG6yFfH6mWUU52AQEp/1hrqc6NssAdKeMx8z1b1mFE+aTbfXXjKtln+IP DQqqOqRZ3CjdjlQJKeiFhlTUGUSEvS911LoyfqzySLQz73j1DANnBj0qR2xKgRNqtbJ9 WakV820LiIlk3dyHcq58K+hDjcCbRMf+12orshOCiK5+o+0s7ydbgX5Z2SQ7xWGzp6Bv M59g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WqhU/k5frFypUQyoJ2kdaImddFRVKiSuzDoQH9meyDM=; b=OIxUuayYPOug8bXByfW44dGE3QRec1nvDL17/O+j8/YHlSTZuxsitfb4lf53gO4868 HfTFz4iz0IwLviHRJvT/idSBW/lg/BiinzDSHKHp03DB383/4xNY5C+8EhHcqKA1ZPSU yIBk45tMOqEpuDnHTujlPRWeJZG9tGtEBq3TTicDbPL8SH06tyXegJqbrhKqF9cednQ2 2eoxaAIOoqAIUyB4bAOxY16DRvXy9an+kjLIKC8UXBtQ7rLfEsaBCiMMt1LU96eMBxN9 JqmYmLHpG7RCdMC46M9hT0nB+pt9jYXIgLyDl1p5diptEmMb0hhHKTfYiy4FgXGe8VFw Ex2A== X-Gm-Message-State: AD7BkJKUXcV8VW+GpWCh2d7G3UkEEPaYx580Uk7f1L7z0mUP3mPf+UO9kMvvgg+kfSy8mwif X-Received: by 10.66.217.230 with SMTP id pb6mr33579835pac.63.1456867669672; Tue, 01 Mar 2016 13:27:49 -0800 (PST) Received: from localhost ([2620:0:1009:3:b1e9:1d95:1ce5:e70c]) by smtp.gmail.com with ESMTPSA id dg1sm47714317pad.18.2016.03.01.13.27.48 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 13:27:48 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests 5/5] scripts: pretty print stack traces Date: Tue, 1 Mar 2016 13:27:38 -0800 Message-Id: <1456867658-10937-6-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456867658-10937-1-git-send-email-pfeiner@google.com> References: <1456867658-10937-1-git-send-email-pfeiner@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Optionally pretty print stacks in test.log with 'run_tests.sh -p'. The script runs addresses through addr2line to get file names and line numbers. Also prints out source code lines if files are available. For example 0x004013f5: ac_test_exec at x86/access.c:818 } > ac_test_setup_pte(at, pool); r = ac_test_do_access(at); 0x004014dd: ac_test_run at x86/access.c:852 ++tests; > successes += ac_test_exec(&at, &pool); } while (ac_test_bump(&at)); 0x0040157d: main at x86/access.c:873 printf("starting test\n\n"); > r = ac_test_run(); return r ? 0 : 1; 0x0040028e: start64 at x86/cstart64.S:206 lea __argv(%rip), %rsi > call main mov %eax, %edi Signed-off-by: Peter Feiner --- run_tests.sh | 10 +++++-- scripts/pretty_print_stacks.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 scripts/pretty_print_stacks.py diff --git a/run_tests.sh b/run_tests.sh index 2c8af36..13bc089 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,6 +1,7 @@ #!/bin/bash verbose="no" +pretty="no" if [ ! -f config.mak ]; then echo "run ./configure && make first. See ./configure -h" @@ -18,6 +19,7 @@ Usage: $0 [-g group] [-h] [-v] -g: Only execute tests in the given group -h: Output this help text -v: Enables verbose mode + -p: Pretty print stack traces in test.log Set the environment variable QEMU=/path/to/qemu-system-ARCH to specify the appropriate qemu binary for ARCH-run. @@ -27,8 +29,9 @@ EOF RUNTIME_arch_run="./$TEST_DIR/run" source scripts/runtime.bash +log_redir=">> test.log" -while getopts "g:hv" opt; do +while getopts "g:hvp" opt; do case $opt in g) only_group=$OPTARG @@ -40,13 +43,16 @@ while getopts "g:hv" opt; do v) verbose="yes" ;; + p) + log_redir="> >(./scripts/pretty_print_stacks.py \$kernel >> test.log)" + ;; *) exit ;; esac done -RUNTIME_arch_run="./$TEST_DIR/run >> test.log" +RUNTIME_arch_run="./$TEST_DIR/run $log_redir" config=$TEST_DIR/unittests.cfg rm -f test.log echo > test.log diff --git a/scripts/pretty_print_stacks.py b/scripts/pretty_print_stacks.py new file mode 100755 index 0000000..49564bd --- /dev/null +++ b/scripts/pretty_print_stacks.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import re +import subprocess +import sys + +if len(sys.argv) != 2: + sys.stderr.write('usage: %s \n' % sys.argv[0]) + sys.exit(1) + +binary = sys.argv[1] + +# Subvert output buffering. +def puts(string): + sys.stdout.write(string) + sys.stdout.flush() + +try: + while True: + # Subvert input buffering. + line = sys.stdin.readline() + if line == '': + break + + if not line.strip().startswith('STACK:'): + puts(line) + continue + + addrs = line.split()[1:] + # Output like this: + # 0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208 + # (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1) + cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address'] + cmd.extend(addrs) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + out, err = p.communicate() + if p.returncode != 0: + puts(line) + continue + + for line in out.splitlines(): + m = re.match('(.*) at [^ ]*/kvm-unit-tests/([^ ]*):([0-9]+)(.*)', line) + if m is None: + puts('%s\n' % line) + continue + + head, path, line, tail = m.groups() + line = int(line) + puts('%s at %s:%d%s\n' % (head, path, line, tail)) + try: + lines = open(path).readlines() + except IOError: + continue + if line > 1: + puts(' %s\n' % lines[line - 2].rstrip()) + puts(' > %s\n' % lines[line - 1].rstrip()) + if line < len(lines): + puts(' %s\n' % lines[line].rstrip()) +except: + sys.exit(1)