From patchwork Wed Nov 28 19:36:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 10703243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC82215A8 for ; Wed, 28 Nov 2018 19:38:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDB6E29F77 for ; Wed, 28 Nov 2018 19:38:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0A112B182; Wed, 28 Nov 2018 19:38:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54C4D29F77 for ; Wed, 28 Nov 2018 19:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729451AbeK2Gk7 (ORCPT ); Thu, 29 Nov 2018 01:40:59 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:52198 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729433AbeK2Gk6 (ORCPT ); Thu, 29 Nov 2018 01:40:58 -0500 Received: by mail-pg1-f202.google.com with SMTP id t26so12701615pgu.18 for ; Wed, 28 Nov 2018 11:38:13 -0800 (PST) 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=PSWj5cFU+jrigLyNwOIkjVkSQOjGgnr+grtJvw72p2k=; b=ZVg5n/fJ90O5sJ3IAOCgBQT0Y735goRSISlmv+c+yyF4e39VXUeukE1DtCXZgiFsws 3CywqLzYt/Xhiav0fZQYXuP0MBPa2nj7xGUqjl4yl6PkgRF46WyaNehaXEstMd/0ZPco VTeAOL/V+elEzDVz8z+IOR1L3qbY93bwZ/KLsOrNx4lPYIJw6R+nr+w1Bow/TVkgE3+o BbHyFCw6lvIp1p/XeyiTcwpouOAogKZFDv1/WBmGooPKp1CAggkUUd+xFA//d4OZe+rO kNdACscRvJZ+9+nUv6754NjbTu0ZDERwEC42qfElTYMeQmt85QBlULjbj4UXeWOt1QPD RdxA== 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=PSWj5cFU+jrigLyNwOIkjVkSQOjGgnr+grtJvw72p2k=; b=FFyWoPFCas7xQD5CWDHhbJqRP8+c6AEOIobs2QvUVAjDCopneiBPqUC4AGF/lu+U/q lHmHmyuFoE9MDyhNecaTOXEPkPO6rQbgBIG3skOPC0pARxpXpswo9ol+V1jowijUoPSZ ug4iJhZ/FKk+vl4GQ2cf7OepyLh/BwPtXUyMc9YKRCzEJkjcDhBXduvnWjaZKdyddTtM a4D/U8JcoOslyd7VfgeV6ms6snN5hhdJ4MWGXyCk9Q3v1mIjQI4FAQtvVK6NNdD+Naej P6tILoAHToVwgQvHjyysHmlrn4LgQ3dA59MNGhDyIaOnFwzfEpMRWXVHwLcrTBEyQYBt l0VQ== X-Gm-Message-State: AA+aEWYAogQ0FHn6mTwfHBjRjwttJ91EfCA8XYEGcDjc5ksiKtS0LIDr sR1voafehv0QA9FrYbIAV0wN/QVbjpMTMPnz9Djo4Q== X-Google-Smtp-Source: AFSGD/UNL8VzMXvdy/txBvVB+FEhEs2NNoQ9cq2xnih5rgsgUaCtXAFa837C43GfxD4knn2v0XS0RHUhlr4yWXZK/F1pTA== X-Received: by 2002:a63:b601:: with SMTP id j1mr2949103pgf.58.1543433893299; Wed, 28 Nov 2018 11:38:13 -0800 (PST) Date: Wed, 28 Nov 2018 11:36:29 -0800 In-Reply-To: <20181128193636.254378-1-brendanhiggins@google.com> Message-Id: <20181128193636.254378-13-brendanhiggins@google.com> Mime-Version: 1.0 References: <20181128193636.254378-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog Subject: [RFC v3 12/19] 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, frowand.list@gmail.com, knut.omang@oracle.com, Brendan Higgins , Felix Guo Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 bba7ea7ca1869..623f25b16f6c8 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -116,8 +116,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)