Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6311361ybv; Tue, 18 Feb 2020 14:19:52 -0800 (PST) X-Google-Smtp-Source: APXvYqwqykB/A4esMOQTewSmyApDu8AJk/Wsb/ir4UvfyFq8a7o2yB4MQyHH4lPrCS/r/HlLyw++ X-Received: by 2002:a9d:6301:: with SMTP id q1mr16822296otk.299.1582064392029; Tue, 18 Feb 2020 14:19:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582064392; cv=none; d=google.com; s=arc-20160816; b=c5XtPfjgnCqhxY8Pjhjscs6PdWzgsDJZt8eDz45y9swRP0tOQCVXAARXHEdx4b0Rye Kj+OtPoYCMa6HovKzA+LHhrLmP+wd7nLdlyaIAhaZV+iztkD095h2Nn/UmuTAOnaBAYO U7krF3mHS6o3/MAgi3tPSPwP0qy605nhFXq70zpWsvldd6S3GuV9zrrsbk4XjolmJFdR a7UHOLjk4zceSDC75PJT+xTpHTchmsLQMAPpIuNoHmqevAp66x7AoKZqlccANBeXaPRc L8XlLVm66rEnKPMj9VzptqOs97PUPTsKu7ULa/vwEHFb4+I++ejfeIwXhEiKSwa+0CSc ZUeA== 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:mime-version :message-id:date:dkim-signature; bh=RNrdlMRH8bZOMGcbPYtMG19iVm6s1eWmiGtdcw35HDw=; b=E42Jw3cKKVElj1r7nEsNFON0WW01S3idOmXECaxtdlwO5V1AjTgtp3puneuqjGVlRu /nXyNHqxW3ajdsttu7MH8T8mhUnMXY6V02vVgyyosQUiWSL3BJqtgZ1TQ40F37OKMdB2 Y4DbmRkweAx1C3jBXBpLf4Ld1U25Xvha6z28yixBpm6g/BI4cdZBxiq/CksbyEtR78jz s4s5uvSdGDNDt4hK0k79YJ0DtuhtGvK9edrH91aPCVxIpWQs5Epewofbt+uM9vhChmyN UBgbHA+QYbdcUhYkWIkNvzLopdDXMOWdp13WFR3S186i1vVJUweQEJurr/7Q5gyGT+16 iyhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EuWV2B1r; 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 d15si50826otl.82.2020.02.18.14.19.40; Tue, 18 Feb 2020 14:19:52 -0800 (PST) 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=EuWV2B1r; 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 S1726444AbgBRWTW (ORCPT + 99 others); Tue, 18 Feb 2020 17:19:22 -0500 Received: from mail-ua1-f74.google.com ([209.85.222.74]:54634 "EHLO mail-ua1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbgBRWTV (ORCPT ); Tue, 18 Feb 2020 17:19:21 -0500 Received: by mail-ua1-f74.google.com with SMTP id y23so4355034uaq.21 for ; Tue, 18 Feb 2020 14:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=RNrdlMRH8bZOMGcbPYtMG19iVm6s1eWmiGtdcw35HDw=; b=EuWV2B1rhJOhQuPyn12KOWAfxA1LcgYVwXwkago/ZhpA2ebUOxjTnaa8wI2s9lejYw MMbwihbtFtdIoIVF5AdWNMztFfQwIxOnrTfFkoND9bW12lf58MkKK2mFgrxZdllWNojn HCXxZtNx3Fc9x3son29FBWsnCgMDZfxjyQJBepiWACUfUi7I6GunxGgSHuI1Jf5240S1 UnmpSUUmybTaPzTVvgqX5RkW2qh9mxbbl1iu0FktpIHGwg8TF54dHL70w+D28Rv3ppDb pOMojCLf1E6O7q1Bj5rTgQn2vNYffPLfsdlOcmSl+pMxXQ1Zp7BBaOWnkRxNZJcLLxZF BwCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=RNrdlMRH8bZOMGcbPYtMG19iVm6s1eWmiGtdcw35HDw=; b=hLQoJyyPGO6I2tFTQYi1Lb3YpuXjnTSTWmlgaP9dlvTyoAjEYZiHIhWEAcLVXdqxnw taRiI0Shcm1iI4VI8LsSeZdQlJ1bkA4Pb9mPoZEQy9rARkVbjyu+5sS7Bk9k46bUBezH JGVo2BJo12mF9HOOSukGAroR05Lv7G1hGpCYSR2NuiEymcAEc/rR/7IZy8HvUEt9lfmy n3zSYzbGZ97TMcOhiodi5lh4XfQo8V7eoGDL0iMNnccx553moIPQp4dV/wFZYxAeZ6Nc hbyB+uuAdVLRWnzQZP2IY4suz6kMERqWZKuPNNrb81sTCV9TWPXXwf3mu6uY/VoGRbtf P1ZA== X-Gm-Message-State: APjAAAXpUxD1NlPP1Uz1C/Pfzn3sjvdDUhtj7FHuE/WYgg8PondNGP3t 1tmLe0UzMt185NMW/pDPj9LIHgUwbdXfDCK/ X-Received: by 2002:ab0:6258:: with SMTP id p24mr11875147uao.24.1582064360629; Tue, 18 Feb 2020 14:19:20 -0800 (PST) Date: Tue, 18 Feb 2020 14:19:16 -0800 Message-Id: <20200218221916.239951-1-heidifahim@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v2] kunit: run kunit_tool from any directory From: Heidi Fahim To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org Cc: frowand.list@gmail.com, Heidi Fahim 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 Implemented small fix so that the script changes work directories to the root of the linux kernel source tree from which kunit.py is run. This enables the user to run kunit from any working directory. Originally considered using os.path.join but this is more error prone as we would have to find all file path usages and modify them accordingly. Using os.chdir ensures that the entire script is run within /linux. Signed-off-by: Heidi Fahim Reviewed-by: Brendan Higgins --- tools/testing/kunit/kunit.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 3f552e847a14..060d960a7029 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -26,6 +26,8 @@ KunitResult = namedtuple('KunitResult', ['status','result']) KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig', 'json']) +KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0] + class KunitStatus(Enum): SUCCESS = auto() CONFIG_FAILURE = auto() @@ -37,6 +39,13 @@ def create_default_kunitconfig(): shutil.copyfile('arch/um/configs/kunit_defconfig', kunit_kernel.kunitconfig_path) +def get_kernel_root_path(): + parts = sys.argv[0] if not __file__ else __file__ + parts = os.path.realpath(parts).split('tools/testing/kunit') + if len(parts) != 2: + sys.exit(1) + return parts[0] + def run_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitRequest) -> KunitResult: config_start = time.time() @@ -130,6 +139,9 @@ def main(argv, linux=None): cli_args = parser.parse_args(argv) if cli_args.subcommand == 'run': + if get_kernel_root_path(): + os.chdir(get_kernel_root_path()) + if cli_args.build_dir: if not os.path.exists(cli_args.build_dir): os.mkdir(cli_args.build_dir) -- 2.25.0.265.gbab2e86ba0-goog