Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp709552pxb; Thu, 30 Sep 2021 15:42:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxVEuHh+IHXTiPi2pjPoU50yGtbLdjnmuH4CyAihZBaXPiWi02AD1kTYAGYVm6gi6SLQWF X-Received: by 2002:a62:1d02:0:b0:448:604e:fb83 with SMTP id d2-20020a621d02000000b00448604efb83mr6742778pfd.12.1633041733827; Thu, 30 Sep 2021 15:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633041733; cv=none; d=google.com; s=arc-20160816; b=U/8C/upYCjNfyZpP/SUbyVvtW5zGkmNJJVdmHSRXCuc4YN7ZlRoWj/aYR3Suc8KMO4 mG+2ctbE9WZfx5HjML/nnfUUPeuhb31QMNCcPnjRiG0UYedjrRDVdIYMZ1ym6DUB3QA4 iCXjF10PRURehhiZF9Qhu0kaKHcEU9m2AvnCZZS0CW18WWVBkLljBj8HAiK1QJcHZF4b mJQPCvzfLC8vstAsW2F2c4QC49mkz19PVpovqtHRLkmIHJVc9wkX3IS+3E8371ncWmdL LR268iqSbMGvYuWqOc/abSEzxyw7p9iwisG3+3aKtcbVdgk3r3SXJr/CD89a7cTtaLC3 rv9w== 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=ZWOGiAg/qbE1DMbUltGKFl+kd+3yzrZtbswNYmTN0Nw=; b=reXAbSlIX6PYDZcN7tYJ0PD+vyDQphwxXCq3HbYtec4t/Ux1ZO7M89VDNa+f59qjza RSELdKaznhLQQiwte/sPmHl7Sy07v5fpJ67pgvoJRpOQpvCX9pBVmaOee4P6OLAH9iq5 oCAd4MZl07M8ed/5mm6SNleLhoN5Q/iENm9470bqLT88jMRLAFIZWMrMqwTsMoBGm+FU 0pd1gy8t++DkeJ14R6wYIGtK6fIct6b2Ss1i/YDgHuEfG/aXKde8fS2JZdYbgq/rh1HX 0PTiKHag0ZJCIgCojNVZVRzUITQkf7YLH41GP72dsl1R4yNnx55uYRHWEtelcLaCCPwB bwPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="JA1wjF/e"; 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 n9si7166332plf.285.2021.09.30.15.42.01; Thu, 30 Sep 2021 15:42:13 -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="JA1wjF/e"; 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 S1348511AbhI3WWr (ORCPT + 99 others); Thu, 30 Sep 2021 18:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348505AbhI3WWm (ORCPT ); Thu, 30 Sep 2021 18:22:42 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3286AC06176E for ; Thu, 30 Sep 2021 15:20:59 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id h10-20020ac8584a000000b002a712bc435fso5360820qth.20 for ; Thu, 30 Sep 2021 15:20:59 -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=ZWOGiAg/qbE1DMbUltGKFl+kd+3yzrZtbswNYmTN0Nw=; b=JA1wjF/eWT7CmE0a0OIWWBxASbq7N8xp0S4DPIFLF9PYDmApZ2F2mdWMioiCdit3Px uBwDISb+JMb/odfZQ8p/0LA7kLjlhbSl3zjZbVzzxSFjEqA1/RYNPIshbvxMxLcmerLT 8JpLNwO+vWnBW8SaWPIvBAis6iNvV9QRoP43ISe//q8UGnLmbk7hn9b4dWKG4nCSr7u9 Ip6WMEuHV9j7KEklRbq3dSYJG2696/dFF81jSdYWJCLVgCaXfyzYwNuSRON+aMhEuOL1 54s3JfxVuWwDjCts9wsJA1JPuHcu6zNZpS6kDdDulu6akDIL1ZbB1BkMgzP3oH/D+wdA KCEw== 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=ZWOGiAg/qbE1DMbUltGKFl+kd+3yzrZtbswNYmTN0Nw=; b=ECrE5t+K9pd7OJ4U7snLVlkBCXb7/Z5i3hZZ5mX/fRqKGj0X1NV0TTBEidG205kPyp 8COG/ntcn96wvr937MmR8lAqTlHSXQNGPFTRnUTilTqfflVKgwQpxoFuYdzYGbGPY1M1 gVVs2OznYOZcIN7Gq77xxug4tgVLhEoEowY5wL3s05uk1TMj738FYAgx72O/GKSgy8dM VeGYtg0f9LENlf43xBH5EJlPhr1Gk5d4bxp7qJoFhmFyDOzyCZ+vI7OsqGKvGMeVeani 9nZf+Qt+SzW3wZCOYPHlpZzCcwD2pr7MD+gwiSdCiuaPDtpiDg9HXd/gYB87y1lrKHmK u9xg== X-Gm-Message-State: AOAM5328fW9RaM/2lCqFFj1JQA1vZE4Em8+wJfCmHoB+WZ1E8kQE2g6z nQylTRWRCZiGa3BNQITgXAWzHVvEHqWSDw== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:39fa:d88:fb3b:880e]) (user=dlatypov job=sendgmr) by 2002:a0c:aa99:: with SMTP id f25mr7773849qvb.12.1633040458354; Thu, 30 Sep 2021 15:20:58 -0700 (PDT) Date: Thu, 30 Sep 2021 15:20:47 -0700 In-Reply-To: <20210930222048.1692635-1-dlatypov@google.com> Message-Id: <20210930222048.1692635-4-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 3/4] kunit: tool: actually track how long it took to run tests 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 This is a long standing bug in kunit tool. Since these files were added, run_kernel() has always yielded lines. That means, the call to run_kernel() returns before the kernel finishes executing tests, potentially before a single line of output is even produced. So code like this time_start = time.time() result = linux.run_kernel(...) time_end = time.time() would only measure the time taken for python to give back the generator object. From a caller's perspective, the only way to know the kernel has exited is for us to consume all the output from the `result` generator object. Alternatively, we could change run_kernel() to try and do its own book keeping and return the total time, but that doesn't seem worth it. This change makes us record `time_end` after we're done parsing all the output (which should mean we've consumed all of it, or errored out). That means we're including in the parsing time as well, but that should be quite small, and it's better than claiming it took 0s to run tests. Let's use this as an example: $ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunit example Before: Elapsed time: 7.684s total, 0.001s configuring, 4.692s building, 0.000s running After: Elapsed time: 6.283s total, 0.001s configuring, 3.202s building, 3.079s running Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 31eec9f6ecc3..5e717594df5b 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -101,12 +101,14 @@ def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest, filter_glob=request.filter_glob, build_dir=request.build_dir) + result = parse_tests(parse_request, run_result) + + # run_kernel() doesn't block on the kernel exiting. + # That only happens after we get the last line of output from `run_result`. + # So exec_time here actually contains parsing + execution time, which is fine. test_end = time.time() exec_time = 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, input_data: Iterable[str]) -> KunitResult: -- 2.33.0.800.g4c38ced690-goog