Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp105049ima; Tue, 23 Oct 2018 20:34:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5cXwH+vrkbIldzf/zQTIK56idgjDMPsvw9nCLAa+ozvImMy70h6hoRuQe9waKoGM/RwTUiE X-Received: by 2002:a63:7a5b:: with SMTP id j27mr982668pgn.112.1540352086518; Tue, 23 Oct 2018 20:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540352086; cv=none; d=google.com; s=arc-20160816; b=IoKSjiMW9py3IzUb+bP2C5N7xq/J5x67oFQjZSj+lcwLufWI3I6DiSaGxTUy0GTrwy sxcfhNFV+HnQOr4UL047VifyKhPOiraSHZfJCGp71+YNUMMu+p8gOG87FD8NecdJgoDe d63Yct2LnQ6AH36Z1EOtJ7qhgf/e/e6SkzwHH3bvbryCH1jpwtk9qB8klF2SNaB6TTJ3 mG3CTGDuNLvJbMpXiXAheETowBZQ89isP/869h/DW0KrLaBOz0eziPqZ6idPLh2fwRIj ez+bjpEEixfdGO7DvP7jqr9OsMZ3/xwr0QGgJh1rwbZYw6ouFJ6C1OOZL2HtOnYeP3vK BA5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=44RvLdlbHWeLbsI4FsWkczRJMebcjaBtMNCiH44tKr0=; b=APm6TleXbPtckmghKyjoQ8ZnwxNNPVhIxC66HR+zR+f64gkk8yO/IHsvEVHsmkPo5K PfL1rqpAiXPrfKaJnhfBzNiogm0ImjcucZbesm5DVeuq7l2p8E8wX6U3ny6u0/NrgwHr 8OPMWGoCUcfaNqeIirmag7NCNZ8yBQe5ZRIWvvIwEIhM6W7y85QoDaNL0JPDkVwGmXsR sZZQ9ROOCxUOk90JxW+DWdAL+bOwTHhvglfj5i6PLsi/dn6LvvSp0UjbEAOAZqDyWKtW JQsplJIggdqQa56dMHoMBc3FnBygYFC7seWsExyMyBejCL3PxtX4vHjW+2qbc2iOSpwQ ZpAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AB6ok6PX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3-v6si3276932pgj.74.2018.10.23.20.34.30; Tue, 23 Oct 2018 20:34:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AB6ok6PX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726501AbeJXMAL (ORCPT + 99 others); Wed, 24 Oct 2018 08:00:11 -0400 Received: from mail-oi1-f201.google.com ([209.85.167.201]:55334 "EHLO mail-oi1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbeJXMAK (ORCPT ); Wed, 24 Oct 2018 08:00:10 -0400 Received: by mail-oi1-f201.google.com with SMTP id m129-v6so2493150oif.22 for ; Tue, 23 Oct 2018 20:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=44RvLdlbHWeLbsI4FsWkczRJMebcjaBtMNCiH44tKr0=; b=AB6ok6PXf9wGtYqQaN8gyoMLpZEzKJCwiN4OhbIFy/qhSvJz7T85MzLTEVa5WyftLU Zj9/+0PEE9UUjrPcKFTnjad7y6c8J5QhyD8nS/SK6OeQf8KAN8LJIBbq1GtkYlLATYlm XuGhc+WVLGI4RnNCnl3GHr1IsiMKGr1YnByk13qhCKHoPCgqZyLsR8NhP4AoPjLLmJvI HtRNhfgUtT0PWXXzQTmOox/QL7sHfUxZAk9EfWY7S1/VCgNskcVGlpl2zz+gCE9D4Exb EkjD/I05wGnrEpqk4N9vy8WimHN7Bka9Wxk+G6l477RjELqGvZ+2YhvU26zWMKM+0s/1 sCSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=44RvLdlbHWeLbsI4FsWkczRJMebcjaBtMNCiH44tKr0=; b=OiH8+l8AWUg/Zej/5aLRCbDLN1xPg2kK2jKc5Wnj1LD+i7p82KndaLYFVKCq1YHaVe 2F8A6eh0l6EX8b+RCHPTK+1IDTHtiDFowVJrsU0zZHrlZSZgNeYgFrZmTFJufJoDOC+r lkH6vz2XXFAU2CvDw/+fLAymXnVgXP+GxMeIX/TMxSlD+hIpcsdX5qTApyjSs0HZYRL9 teyi6FG+FDTUjP8uYJ23Sz2wTlnOqQO1YdGnbG4cGn/WOfDWCh1V2eSOMwLdXQQ2Ib0q +83Wi8Mmwr0j5eSAL41hNrpR39FmIjehnhLPhNtxwLdy87v0k6yQ+r70/G4HInzgRT7x lf+w== X-Gm-Message-State: AGRZ1gLzFcNWl76oEVkdogpq0j8nh2AuxSsMgs71zR/Y2TK/df8ibdfL ixCy0DELnYq0UeAIbSPV9aO718PgFyjD5540mze0eg== X-Received: by 2002:a9d:48f8:: with SMTP id a53mr318139otj.18.1540339204891; Tue, 23 Oct 2018 17:00:04 -0700 (PDT) Date: Tue, 23 Oct 2018 16:57:47 -0700 In-Reply-To: <20181023235750.103146-1-brendanhiggins@google.com> Message-Id: <20181023235750.103146-12-brendanhiggins@google.com> Mime-Version: 1.0 References: <20181023235750.103146-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [RFC v2 11/14] kunit: add KUnit wrapper script and simple output parser From: Brendan Higgins To: gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org, shuah@kernel.org Cc: joel@jms.id.au, mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, julia.lawall@lip6.fr, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, robh@kernel.org, dan.j.williams@intel.com, linux-nvdimm@lists.01.org, kieran.bingham@ideasonboard.com, Brendan Higgins , Felix Guo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The KUnit wrapper script interfaces with the two modules (kunit_config.py and kunit_kernel.py) and provides a command line interface for running KUnit tests. This interface allows the caller to specify options like test timeouts. The script handles configuring, building and running the kernel and tests. The output parser (kunit_parser.py) simply strips out all the output from the kernel that is outputted as part of it's initialization sequence. This ensures that only the output from KUnit is displayed on the screen. A full version of the output is written to test.log, or can be seen by passing --raw_output to the wrapper script. Signed-off-by: Felix Guo Signed-off-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 40 +++++++++++++++++++++++++++++ tools/testing/kunit/kunit_kernel.py | 3 +-- tools/testing/kunit/kunit_parser.py | 24 +++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 tools/testing/kunit/kunit.py create mode 100644 tools/testing/kunit/kunit_parser.py diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py new file mode 100755 index 0000000000000..1356be404996b --- /dev/null +++ b/tools/testing/kunit/kunit.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 + +# A thin wrapper on top of the KUnit Kernel + +import argparse +import sys +import os + +import kunit_config +import kunit_kernel +import kunit_parser + +parser = argparse.ArgumentParser(description='Runs KUnit tests.') + +parser.add_argument('--raw_output', help='don\'t format output from kernel', + action='store_true') + +parser.add_argument('--timeout', help='maximum number of seconds to allow for ' + 'all tests to run. This does not include time taken to ' + 'build the tests.', type=int, default=300, + metavar='timeout') + +cli_args = parser.parse_args() +linux = kunit_kernel.LinuxSourceTree() + +success = linux.build_reconfig() +if not success: + quit() + +print('Building KUnit Kernel ...') +success = linux.build_um_kernel() +if not success: + quit() + +print('Starting KUnit Kernel ...') +if cli_args.raw_output: + kunit_parser.raw_output(linux.run_kernel(timeout=cli_args.timeout)) +else: + kunit_parser.parse_run_tests(linux.run_kernel(timeout=cli_args.timeout)) diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index 87abaede50513..c1259b174f7d4 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -113,8 +113,7 @@ class LinuxSourceTree(object): return False return True - def run_kernel(self, args=[]): - timeout = None + def run_kernel(self, args=[], timeout=None): args.extend(['mem=256M']) process = self._ops.linux_bin(args, timeout) with open('test.log', 'w') as f: diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py new file mode 100644 index 0000000000000..1dff3adb73bd3 --- /dev/null +++ b/tools/testing/kunit/kunit_parser.py @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 + +import re + +kunit_start_re = re.compile('console .* enabled') +kunit_end_re = re.compile('List of all partitions:') + +def isolate_kunit_output(kernel_output): + started = False + for line in kernel_output: + if kunit_start_re.match(line): + started = True + elif kunit_end_re.match(line): + break + elif started: + yield line + +def raw_output(kernel_output): + for line in kernel_output: + print(line) + +def parse_run_tests(kernel_output): + for output in isolate_kunit_output(kernel_output): + print(output) -- 2.19.1.568.g152ad8e336-goog