[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fd8a7bc9-4eb9-4898-be79-ab8d3af28ce7@davidwei.uk>
Date: Tue, 2 Apr 2024 17:15:32 -0700
From: David Wei <dw@...idwei.uk>
To: Jakub Kicinski <kuba@...nel.org>, davem@...emloft.net
Cc: netdev@...r.kernel.org, edumazet@...gle.com, pabeni@...hat.com,
shuah@...nel.org, sdf@...gle.com, donald.hunter@...il.com,
linux-kselftest@...r.kernel.org, petrm@...dia.com
Subject: Re: [PATCH net-next 4/7] selftests: nl_netdev: add a trivial Netlink
netdev test
On 2024-04-01 18:05, Jakub Kicinski wrote:
> Add a trivial test using YNL.
>
> $ ./tools/testing/selftests/net/nl_netdev.py
> KTAP version 1
> 1..2
> ok 1 nl_netdev.empty_check
> ok 2 nl_netdev.lo_check
>
> Instantiate the family once, it takes longer than the test itself.
>
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
> CC: shuah@...nel.org
> CC: linux-kselftest@...r.kernel.org
> ---
> tools/testing/selftests/net/Makefile | 1 +
> tools/testing/selftests/net/nl_netdev.py | 24 ++++++++++++++++++++++++
> 2 files changed, 25 insertions(+)
> create mode 100755 tools/testing/selftests/net/nl_netdev.py
>
> diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> index cb418a2346bc..5e34c93aa51b 100644
> --- a/tools/testing/selftests/net/Makefile
> +++ b/tools/testing/selftests/net/Makefile
> @@ -34,6 +34,7 @@ TEST_PROGS += gre_gso.sh
> TEST_PROGS += cmsg_so_mark.sh
> TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
> TEST_PROGS += netns-name.sh
> +TEST_PROGS += nl_netdev.py
> TEST_PROGS += srv6_end_dt46_l3vpn_test.sh
> TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
> TEST_PROGS += srv6_end_dt6_l3vpn_test.sh
> diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py
> new file mode 100755
> index 000000000000..40a59857f984
> --- /dev/null
> +++ b/tools/testing/selftests/net/nl_netdev.py
> @@ -0,0 +1,24 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: GPL-2.0
> +
> +from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily
> +
> +
> +nf = NetdevFamily()
> +
> +
> +def empty_check() -> None:
> + global nf
I know you're rolling your own instead of using unittest or pytest. How
about adding a Test class of some sort and make each test case a method?
Then you wouldn't need to do this for each test case.
Also it would allow you to share some base functionality across
different test suites.
> + devs = nf.dev_get({}, dump=True)
> + ksft_ge(len(devs), 1)
> +
> +
> +def lo_check() -> None:
> + global nf
> + lo_info = nf.dev_get({"ifindex": 1})
> + ksft_eq(len(lo_info['xdp-features']), 0)
> + ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0)
> +
> +
> +if __name__ == "__main__":
> + ksft_run([empty_check, lo_check])
Powered by blists - more mailing lists