From patchwork Fri Apr 12 14:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 788469 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B1A18626D; Fri, 12 Apr 2024 14:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931282; cv=none; b=X6FU/TepBgpqwA/aa3drDoIkngySfOV9WCjiuUcSobKyOitTcFGMc3SkBcGHRG64zitKp6fYQXCY9nqxEODJPMjZt4cTB6mIaAWSMqfTwiF2Y6VpDN2fN9KgcWK3L8U5ZDWmMduZ4dXL1xQjr2i1nnweHvueMUIPenaiY62+X+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931282; c=relaxed/simple; bh=8BkxfNl3hd9M6SMm4rbkPdYQAOfcfQq2OyLXTwlHs5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CZcA8ujTsODtSaV/1HUMjbHlZbWEiuL+GSEKLWCdfoOoH5JM/A7GwHdpBv5CwMfFc6qf0fPRoxzMrwvceXuSuDrLn4FyuTdm/HCS4k7X8yr2mD0VyTUPvTYKaK6mQxaRNDL+qBd+ZIfCR5ECfuHL0QhMuGggRPH/G4r79YzKicw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qr8C/F80; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qr8C/F80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61BD6C32783; Fri, 12 Apr 2024 14:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931281; bh=8BkxfNl3hd9M6SMm4rbkPdYQAOfcfQq2OyLXTwlHs5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qr8C/F80BCKzlhkmpbQ+LWalzFhxeRAgmBLJETWAm8Os8FJpUBwnj2Y/0g+eOP3Bg 07OMUI2AtMNg3U851iZZze3ICFHUIdUAWr3qMEShHQZusThKS+d9MeOjM2kA8GkzbK edKOZ5XHz2HI8MQH1p/u8HLN91tktkqPgmAQU0Ah1e11jHW/4SVFWNQg8RZDf2LTsZ /IwddFazxeMzGz1GUsmxkDIZMzbPNh8y+uIg0Eub6jAeQi+h68uOrhYY+sVwROGmpu aKeAPguN16sJIEVZRfm2GmsdV/6kx8rf6nLnbCp/9mBHnm4nEx7JMYcVPfV6YZ2hPz EbZr8DA2wqlTA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski , Donald Hunter , jiri@resnulli.us Subject: [PATCH net-next v2 2/6] tools: ynl: don't return None for dumps Date: Fri, 12 Apr 2024 07:14:32 -0700 Message-ID: <20240412141436.828666-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 YNL currently reports None for empty dump: $ cli.py ...netdev.yaml --dump page-pool-get None This doesn't matter for the CLI but when writing YNL based tests having to deal with either list or None is annoying. Limit the None conversion to non-dump ops: $ cli.py ...netdev.yaml --dump page-pool-get [] Reviewed-by: Donald Hunter Signed-off-by: Jakub Kicinski --- CC: jiri@resnulli.us --- tools/net/ynl/lib/ynl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 0ba5f6fb8747..a67f7b6fef92 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -995,9 +995,11 @@ genl_family_name_to_id = None rsp_msg.update(self._decode_struct(decoded.raw, op.fixed_header)) rsp.append(rsp_msg) + if dump: + return rsp if not rsp: return None - if not dump and len(rsp) == 1: + if len(rsp) == 1: return rsp[0] return rsp From patchwork Fri Apr 12 14:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 788468 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59CD31272C9; Fri, 12 Apr 2024 14:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931283; cv=none; b=dxL+qRHUFeQQD5Dv1Svt65Zf8/V05kTyfdXiF/xmm4cuHKhUXZPykKj4AamSD1Ju44NCv9o2Q9N8ivX9eWZpHWGn0/mWs9AnEsGr86bsyAQrhfWG/iBvjrph7Gg1DR5Fa9zO7UmnxCCkmYQXPmyTQygJ64l5uUp0fYYKNrNtsD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931283; c=relaxed/simple; bh=0MWRd4EmeqVTRPzqiaWIWceaTlo+U4X9A0S+WknwrN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rCGAVc61+POGrYtLMm9/VVnPOWxIgezJ2v3jJGUmTVVOQCdN+SWtZJiVbE2/LU2gNvZ3NgfuijJhdNF6QQv7/08/XwC1EpfrbTeOtnWPX9oxEMWF9uTWh4HQc4nh8Q0YdMz8aSO4bGNMIbMuRoHe23aN/NqotIsMEZhFUUL7l+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nunpo8eT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nunpo8eT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ABAFC2BD10; Fri, 12 Apr 2024 14:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931282; bh=0MWRd4EmeqVTRPzqiaWIWceaTlo+U4X9A0S+WknwrN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nunpo8eTnvGh5k74JHkzjc3g/coowjGKfESETpvOpdSpMXoovfr4UP+W8GFiPesym T1fM+lxsEeOxJS5WCiyWOcRygUi1e8Oo7n6bHAmcdPp2EbeB7GGUYZJNLD4mOJSb26 IXgRHH2ioK7ttgb+Vxm65l4vs0B6jCukJ9rLjcdIZkq9T+tuanElNR9qDZgeYhrRQz kuLSiruvxWM6ld1+tjDbJQ31pAsmZuW+QJot9ux7m/aVx2XQwbKrJvKZZr8bdwOs56 LeGbEy9kLOanqstFG3P1cOSVs9WG4TiirKCg13sTlTGPhHKX4X3mXqj2VuFr3Duz31 kXUvrihdr87TQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 4/6] selftests: net: print full exception on failure Date: Fri, 12 Apr 2024 07:14:34 -0700 Message-ID: <20240412141436.828666-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of a summary line print the full exception. This makes debugging Python tests much easier. Reviewed-by: Petr Machata Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/ksft.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index b4b0bfff68b0..793e4761645e 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -2,6 +2,7 @@ import builtins import inspect +import traceback from .consts import KSFT_MAIN_NAME KSFT_RESULT = None @@ -85,7 +86,8 @@ KSFT_RESULT = None totals['xfail'] += 1 continue except Exception as e: - for line in str(e).split('\n'): + tb = traceback.format_exc() + for line in tb.strip().split('\n'): ksft_pr("Exception|", line) ktap_result(False, cnt, case) totals['fail'] += 1 From patchwork Fri Apr 12 14:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 788467 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875B0127E1A; Fri, 12 Apr 2024 14:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931284; cv=none; b=UtUtgHD0eEXi+q9sFOawRBsKkiOVD55UDkMcENNPm6ASS3+asMlESWgFqsyh/utxrVmf8UpVf9NniPHyeLP3HtoFp94MOVq+3og4ZHtWjitMMbssm2TEHfOaRE7ag1yziLIbeQlw/HA6hOaggoiCM4C9TSCS29IC2a8exu8hxdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931284; c=relaxed/simple; bh=a/xwDv1uI1eJafNxyFB3fcAD3BCfsSqkG8l2bCUThIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zsez1QACwutgbNm1jcGFsYFEmmsdkbdknsGFhqPLiV/4B2wwBgDQ3kEEaxH7xt8A9Cvhq9Z73efCJ80wFc2YhmRm8Zxn0udXYuMXWi6V0CIrzitlsKZXqLjI/RvMcPV6LrSPDRLTJgUm/GNRV21I5L5/JkhOAvDtv5vATvjPO/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WMOkwjqD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WMOkwjqD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1E38C4AF0E; Fri, 12 Apr 2024 14:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931284; bh=a/xwDv1uI1eJafNxyFB3fcAD3BCfsSqkG8l2bCUThIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WMOkwjqDeZMrtWjW+EuM5BRU0pg3VGxVxY+Q+U6Q4DpJ9kJ76D+Oh1d5MmDn4rH7X z1wEHdYOEm+O9623Vi4+U/qiGn9dIMNjGJ92bVwUT0TPf946y0D8NYiuARivdOHqVD 5aP1B/eof8Rh96k7F3sdyVA0GKA4Z+l3G7ujzlyLeLfGsQiDADuE/sbNX3J5c2l5OY vZo1KGjAPoQRxnvBYOk50bpICinlCgrDcFfeaj4wQo7p+ke4tJj5L8Ug1dtGn6GECC i5YTyKMtLFoPsmQltHQYm5LcS/IpQD9MyzB5YdG5iIwL9rrPJyuN5lubgjjPFtUE7S fa1QweTOEhVZA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 6/6] selftests: net: exercise page pool reporting via netlink Date: Fri, 12 Apr 2024 07:14:36 -0700 Message-ID: <20240412141436.828666-7-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a Python test for the basic ops. # ./net/nl_netdev.py KTAP version 1 1..3 ok 1 nl_netdev.empty_check ok 2 nl_netdev.lo_check ok 3 nl_netdev.page_pool_check # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Jakub Kicinski --- v2: - move up / down to the test - add helper for getting pp - add busy_wait helper - rename undeteched --- tools/testing/selftests/net/lib/py/ksft.py | 12 ++++ tools/testing/selftests/net/lib/py/nsim.py | 1 + tools/testing/selftests/net/nl_netdev.py | 76 +++++++++++++++++++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index 793e4761645e..3769b9197213 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -2,6 +2,7 @@ import builtins import inspect +import time import traceback from .consts import KSFT_MAIN_NAME @@ -50,6 +51,17 @@ KSFT_RESULT = None _fail("Check failed", a, "<", b, comment) +def ksft_busy_wait(cond, sleep=0.005, deadline=1, comment=""): + end = time.monotonic() + deadline + while True: + if cond(): + return + if time.monotonic() > end: + _fail("Waiting for condition timed out", comment) + return + time.sleep(sleep) + + def ktap_result(ok, cnt=1, case="", comment=""): res = "" if not ok: diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py index 94aa32f59fdb..06896cdf7c18 100644 --- a/tools/testing/selftests/net/lib/py/nsim.py +++ b/tools/testing/selftests/net/lib/py/nsim.py @@ -28,6 +28,7 @@ from .utils import cmd, ip self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index) ret = ip("-j link show dev %s" % ifname, ns=ns) self.dev = json.loads(ret.stdout)[0] + self.ifindex = self.dev["ifindex"] def dfs_write(self, path, val): self.nsimdev.dfs_write(f'ports/{self.port_index}/' + path, val) diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py index 2b8b488fb419..6909b1760739 100755 --- a/tools/testing/selftests/net/nl_netdev.py +++ b/tools/testing/selftests/net/nl_netdev.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 -from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily +import time +from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, ksft_busy_wait +from lib.py import NetdevFamily, NetdevSimDev, ip def empty_check(nf) -> None: @@ -15,9 +17,79 @@ from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0) +def page_pool_check(nf) -> None: + with NetdevSimDev() as nsimdev: + nsim = nsimdev.nsims[0] + + def up(): + ip(f"link set dev {nsim.ifname} up") + + def down(): + ip(f"link set dev {nsim.ifname} down") + + def get_pp(): + pp_list = nf.page_pool_get({}, dump=True) + return [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + + # No page pools when down + down() + ksft_eq(len(get_pp()), 0) + + # Up, empty page pool appears + up() + pp_list = get_pp() + ksft_ge(len(pp_list), 0) + refs = sum([pp["inflight"] for pp in pp_list]) + ksft_eq(refs, 0) + + # Down, it disappears, again + down() + pp_list = get_pp() + ksft_eq(len(pp_list), 0) + + # Up, allocate a page + up() + nsim.dfs_write("pp_hold", "y") + pp_list = nf.page_pool_get({}, dump=True) + refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex]) + ksft_ge(refs, 1) + + # Now let's leak a page + down() + pp_list = get_pp() + ksft_eq(len(pp_list), 1) + refs = sum([pp["inflight"] for pp in pp_list]) + ksft_eq(refs, 1) + attached = [pp for pp in pp_list if "detach-time" not in pp] + ksft_eq(len(attached), 0) + + # New pp can get created, and we'll have two + up() + pp_list = get_pp() + attached = [pp for pp in pp_list if "detach-time" not in pp] + detached = [pp for pp in pp_list if "detach-time" in pp] + ksft_eq(len(attached), 1) + ksft_eq(len(detached), 1) + + # Free the old page and the old pp is gone + nsim.dfs_write("pp_hold", "n") + # Freeing check is once a second so we may need to retry + ksft_busy_wait(lambda: len(get_pp()) == 1, deadline=2) + + # And down... + down() + ksft_eq(len(get_pp()), 0) + + # Last, leave the page hanging for destroy, nothing to check + # we're trying to exercise the orphaning path in the kernel + up() + nsim.dfs_write("pp_hold", "y") + + def main() -> None: nf = NetdevFamily() - ksft_run([empty_check, lo_check], args=(nf, )) + ksft_run([empty_check, lo_check, page_pool_check], + args=(nf, )) if __name__ == "__main__":