Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp701702pxb; Thu, 30 Sep 2021 15:28:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx7c94gk0AiKLXx5wjYJvDpLJRuTEhmCd16EfvxtcIbl8YhX8fLTl+CMlGf/dKer2rB744 X-Received: by 2002:a17:90a:8c84:: with SMTP id b4mr7107600pjo.240.1633040906313; Thu, 30 Sep 2021 15:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633040906; cv=none; d=google.com; s=arc-20160816; b=TY7IC/mjrIhL6M1AumYkk6lC09g8jUDcZ3cBBm5vlRAow5IuSitT/EwOFEtmGhTYZC /NeEZPoThf37RMPJauX6ogW23p8Po1tBakkr1riSHdGiE1kDYySwe/J781RIdaNPNkYP nItpCGousPOydBbfHafz8/xaNMykilH1v4Z/3PbIzt67AzSMUIuexOQgEAy7uWSVO9wR ux+wpTNr79AhSSm5v5Ox1eeODEULydnS+G2WYrF0MEqYL8ICdOKEHDEqaYLHR4+TMkcV rrOhU2OYMwnffaD3XjuGL2gQmdgYoTrecfZo44NnEuZXYJq7LJzrmz2r5yfMkFDOIIRL c+Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=z6dVUuB/preBAw36L3iIbKM/7YhV1FOdhtHcIIfrVic=; b=Fd7cddbyjVZgOi5BAi01dqjD8M2pMrawuitUq0zpNN9tp60bJdJ8/GN1fn68z14+9V zYR04uBiLv6G6/gVmqBbM7YcHxYghQ78r1VGHSJMBozX10YukmliqYmluAIRLjwcfIzs s8imc2H5RufsbvRw7UUJQElASdilhirXrpZ24lOV760AZ7F+1zReLnRPu1m1LZeanKKp YuMmMZ/0O2dAHAN2U2AGn4tIr9RwsCSvVsHaFqhAIDJGcesJgkDva/gpVgH1uqGRIUaB egFHpXG0KoNlcYaL8G1+lrn4xOd83h7IWRF8xJBVwlMMD09nWaJTOfKVr0UlA8lx0lwk uG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ULi4LhqT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id oa10si5653550pjb.77.2021.09.30.15.28.12; Thu, 30 Sep 2021 15:28:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ULi4LhqT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1348440AbhI3WWl (ORCPT + 99 others); Thu, 30 Sep 2021 18:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347909AbhI3WWk (ORCPT ); Thu, 30 Sep 2021 18:22:40 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B2B0C06176C for ; Thu, 30 Sep 2021 15:20:57 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id v10-20020ad4554a000000b0038250b18b6dso11898252qvy.12 for ; Thu, 30 Sep 2021 15:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=z6dVUuB/preBAw36L3iIbKM/7YhV1FOdhtHcIIfrVic=; b=ULi4LhqTk8zMBfs13R14ymGCfISY4HCN8+7jauN/grgOxCjlJkXf9mhboF8zEufzGI lZadeKsHjAqxwlcdZUh7Bho6EvktousLU/nxqjsCC+XtCx7KGU4nr3Ru2MOz47/nXVbj abjvQ8yEF9TiS4weUFLanEKRxJPnWWniQgdWMlO3/TTZul5gShF7gd+7L2NjQyVdzXv9 FAgfCkIIEGJ7hmN0XnkH/xHg1Rlu3h5lMMbE+FKwhP640FF3VGpeY0YyoJuxrVBnXL77 s9uvyij4sgcjlX0+CDvQgNakZr198jHnW+WnrrMqW2R7mFCBNOFcLvk5TBErcJ2V3i0H nnsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=z6dVUuB/preBAw36L3iIbKM/7YhV1FOdhtHcIIfrVic=; b=caIZRblgIDi74uCUd8ufOipNyKSLIFPf/iCxuzvhSgf51vFXxmVUvM9Xzd0c6wqgoL ZBtxC3Ciamyt7NiLn98vQL96LoIK5UzlExDy85zPB+KRPvUg/EvtlXrDVUSCMo4MLV9W 9wRkf9inuzuUgoBetdb52KXHJnWeVpF7jRu+s6fZRVhqKI3O1Q2hBM/fbPocxVBMgwHA aEKaGETXqjdIulXumcVgopbgsc7+EnJ+/pN5iTaCWxT6JiB3YaN++YiB66UCvatksO86 usN5CdHhxSrkqLa3ylmSPVpuKYyjFAxh0owayvjGrSzN2iFtcRf3R9mIv1xaH2vurszD 6dXw== X-Gm-Message-State: AOAM531XfPst27Tj2rS8zBny+Y0wpFzJO/EyMSxNvJuuJRJ27FA7vV3r bq5dV62OTP0AqVqMqVZrksbDFAnNfDpvGg== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:39fa:d88:fb3b:880e]) (user=dlatypov job=sendgmr) by 2002:ad4:5aa4:: with SMTP id u4mr6334829qvg.62.1633040456209; Thu, 30 Sep 2021 15:20:56 -0700 (PDT) Date: Thu, 30 Sep 2021 15:20:46 -0700 In-Reply-To: <20210930222048.1692635-1-dlatypov@google.com> Message-Id: <20210930222048.1692635-3-dlatypov@google.com> Mime-Version: 1.0 References: <20210930222048.1692635-1-dlatypov@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 2/4] kunit: tool: factor exec + parse steps into a function From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently this code is copy-pasted between the normal "run" subcommand and the "exec" subcommand. Given we don't have any interest in just executing the tests without giving the user any indication what happened (i.e. parsing the output), make a function that does both this things and can be reused. This will be useful when we allow more complicated ways of running tests, e.g. invoking the kernel multiple times instead of just once, etc. We remove input_data from the ParseRequest so the callers don't have to pass in a dummy value for this field. Named tuples are also immutable, so if they did pass in a dummy, exec_tests() would need to make a copy to call parse_tests(). Removing it also makes KunitParseRequest match the other *Request types, as they only contain user arguments/flags, not data. Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit.py | 44 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 66f67af97971..31eec9f6ecc3 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -34,7 +34,7 @@ KunitExecRequest = namedtuple('KunitExecRequest', ['timeout', 'build_dir', 'alltests', 'filter_glob', 'kernel_args']) KunitParseRequest = namedtuple('KunitParseRequest', - ['raw_output', 'input_data', 'build_dir', 'json']) + ['raw_output', 'build_dir', 'json']) KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'alltests', 'filter_glob', 'kernel_args', 'json', 'make_options']) @@ -91,23 +91,25 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree, 'built kernel successfully', build_end - build_start) -def exec_tests(linux: kunit_kernel.LinuxSourceTree, - request: KunitExecRequest) -> KunitResult: +def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest, + parse_request: KunitParseRequest) -> KunitResult: kunit_parser.print_with_timestamp('Starting KUnit Kernel ...') test_start = time.time() - result = linux.run_kernel( + run_result = linux.run_kernel( args=request.kernel_args, timeout=None if request.alltests else request.timeout, - filter_glob=request.filter_glob, + filter_glob=request.filter_glob, build_dir=request.build_dir) test_end = time.time() + exec_time = test_end - test_start - return KunitResult(KunitStatus.SUCCESS, - result, - test_end - test_start) + # Named tuples are immutable, so we rebuild them here manually + result = parse_tests(parse_request, run_result) + + return KunitResult(status=result.status, result=result.result, elapsed_time=exec_time) -def parse_tests(request: KunitParseRequest) -> KunitResult: +def parse_tests(request: KunitParseRequest, input_data: Iterable[str]) -> KunitResult: parse_start = time.time() test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS, @@ -115,7 +117,7 @@ def parse_tests(request: KunitParseRequest) -> KunitResult: 'Tests not Parsed.') if request.raw_output: - output: Iterable[str] = request.input_data + output: Iterable[str] = input_data if request.raw_output == 'all': pass elif request.raw_output == 'kunit': @@ -126,7 +128,7 @@ def parse_tests(request: KunitParseRequest) -> KunitResult: print(line.rstrip()) else: - test_result = kunit_parser.parse_run_tests(request.input_data) + test_result = kunit_parser.parse_run_tests(input_data) parse_end = time.time() if request.json: @@ -165,15 +167,11 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree, exec_request = KunitExecRequest(request.timeout, request.build_dir, request.alltests, request.filter_glob, request.kernel_args) - exec_result = exec_tests(linux, exec_request) - if exec_result.status != KunitStatus.SUCCESS: - return exec_result - parse_request = KunitParseRequest(request.raw_output, - exec_result.result, request.build_dir, request.json) - parse_result = parse_tests(parse_request) + + exec_result = exec_tests(linux, exec_request, parse_request) run_end = time.time() @@ -184,7 +182,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree, config_result.elapsed_time, build_result.elapsed_time, exec_result.elapsed_time)) - return parse_result + return exec_result def add_common_opts(parser) -> None: parser.add_argument('--build_dir', @@ -381,15 +379,12 @@ def main(argv, linux=None): cli_args.alltests, cli_args.filter_glob, cli_args.kernel_args) - exec_result = exec_tests(linux, exec_request) parse_request = KunitParseRequest(cli_args.raw_output, - exec_result.result, cli_args.build_dir, cli_args.json) - result = parse_tests(parse_request) + result = exec_tests(linux, exec_request, parse_request) kunit_parser.print_with_timestamp(( - 'Elapsed time: %.3fs\n') % ( - exec_result.elapsed_time)) + 'Elapsed time: %.3fs\n') % (result.elapsed_time)) if result.status != KunitStatus.SUCCESS: sys.exit(1) elif cli_args.subcommand == 'parse': @@ -399,10 +394,9 @@ def main(argv, linux=None): with open(cli_args.file, 'r') as f: kunit_output = f.read().splitlines() request = KunitParseRequest(cli_args.raw_output, - kunit_output, None, cli_args.json) - result = parse_tests(request) + result = parse_tests(request, kunit_output) if result.status != KunitStatus.SUCCESS: sys.exit(1) else: -- 2.33.0.800.g4c38ced690-goog