From patchwork Mon Jul 29 22:10:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 815503 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17B1318757E; Mon, 29 Jul 2024 22:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722291046; cv=none; b=OsL8k6jaHv1ervRpp6+dfPUp+npZBvwYGTBXv3B8bz6zWtpN44VvHP1ECZRgq6awN7ZOEIgywcerZ3t3/2euG/dUspTZeCMHQ+uUYzOfy81+VjpDgTNCsSLS4s1pMfnAUYtmsvRBDE6Dk0jRk8xGEdbFDzNU4Ugh38JDwW/RVdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722291046; c=relaxed/simple; bh=6YNsQUMmPU179nCKPnqAzIhOWJRb8yPnMuiRFNI2E5I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IThZYI0pDM2IuEMNvp1LBmCdNHxjGXNLofcY8lmBdB9nRSAQrfrO0MnP7wArWmcuMDo6qd7znJozXPYi3k8GyZFhAorqIUIUjJQP7tHZpy/ga1l/KY5CXbkj2kdjv1ozut0dlkT85RmgaPCKPUdVzvrglm2/iUuaw3vaHFWgD0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1fc658b6b2eso27750185ad.0; Mon, 29 Jul 2024 15:10:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722291044; x=1722895844; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LLdLgsZNnbXZLDfh9as321ac5PoX6veTzjkDDPiycaI=; b=UwxrN+1dutfU5qvucQLycYCLj0r3TPX6wHAxFKA9PJM2nGBGyK4dP5XBM7zM1mbNAi tDFKfao9gwLZAUdrLS8x8FpfArsPwV8w1KRQgKRXJyE1Q4PqCBLZ458f2xM6lZhSdlgg HpnevEGJ4hxNCzBYwX6WMcH74fgildavh1o8fePtQ1ebzgwIE5eYUxGuqdyvgh6iGggL KrnCzlh2Eci8cPfThzG5btRAQ/wmKWkUjqLXLomiyqwWQWaPPLrqZfr5yfOaxQkPky/4 OhOcI1SmgnPckzl9TqZ5mgn1s5X1CAMVby19f8U+6zBHLMBtMDh/BlROQZRZMmkW3DpT fn7Q== X-Forwarded-Encrypted: i=1; AJvYcCUqlSI4E+A4bwMUWVdAap2tguXpYkJVNAmcbvDsrvDJHkCD5sV7D1ZbOMySMmUhb5bXoycyoPh19eudbFkZ2aOjiFHOr2A0R+S6ZgBfBgyf X-Gm-Message-State: AOJu0YyUYVUPiGxOfyWV18pKzBUUFQZAmo0y7GBf4QkQXHBu43SOZciY /4hp8BRp/43j4qTQGXZB57b8AyEhD09XXIg2tGZO6aphdoNxmIayQ+CnopU= X-Google-Smtp-Source: AGHT+IE2R0RjergZ/Zh5Yo4aquL9u0tsjBrrMGgEJRoEbR3OZ408IYfFR5mG34jjdbcTk7jw7aXFXQ== X-Received: by 2002:a17:902:e846:b0:1fb:44e1:b5d6 with SMTP id d9443c01a7336-1ff04827042mr106986965ad.23.1722291044051; Mon, 29 Jul 2024 15:10:44 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:73b6:7410:eb24:cba4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f2fc46sm87867505ad.207.2024.07.29.15.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 15:10:43 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Shuah Khan , Joe Damato , Petr Machata , linux-kselftest@vger.kernel.org Subject: [PATCH net-next 1/2] selftests: net-drv: exercise queue stats when the device is down Date: Mon, 29 Jul 2024 15:10:41 -0700 Message-ID: <20240729221042.2700882-1-sdf@fomichev.me> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Verify that total device stats don't decrease after it has been turned down. Also make sure the device doesn't crash when we access per-queue stats when it's down (in case it tries to access some pointers that are NULL). KTAP version 1 1..5 ok 1 stats.check_pause ok 2 stats.check_fec ok 3 stats.pkt_byte_sum ok 4 stats.qstat_by_ifindex ok 5 stats.check_down \# Totals: pass:5 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Stanislav Fomichev --- Cc: Shuah Khan Cc: Joe Damato Cc: Petr Machata Cc: linux-kselftest@vger.kernel.org --- tools/testing/selftests/drivers/net/stats.py | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py index 820b8e0a22c6..6f8bef379565 100755 --- a/tools/testing/selftests/drivers/net/stats.py +++ b/tools/testing/selftests/drivers/net/stats.py @@ -5,6 +5,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError from lib.py import NetDrvEnv +from lib.py import ip ethnl = EthtoolFamily() netfam = NetdevFamily() @@ -133,9 +134,37 @@ rtnl = RtnlFamily() ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex') +def check_down(cfg) -> None: + try: + qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True) + except NlError as e: + if e.error == 95: + raise KsftSkipEx("qstats not supported by the device") + raise + + ip(f"link set dev {cfg.dev['ifname']} down") + + try: + qstat = qstat[0] + qstat2 = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] + for k, v in qstat.items(): + if k not in qstat2: + # skip the stats that are not globally preserved + continue + if qstat2[k] < qstat[k]: + raise Exception(f"{k} ({qstat2[k]}) should be preserved but has lower value ({qstat[k]}) when the device is down") + + # exercise per-queue API to make sure that "device down" state + # is handled correctly and doesn't crash + netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True) + finally: + ip(f"link set dev {cfg.dev['ifname']} up") + + def main() -> None: with NetDrvEnv(__file__) as cfg: - ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex], + ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex, + check_down], args=(cfg, )) ksft_exit() From patchwork Mon Jul 29 22:10:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 815139 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81D6918E75C; Mon, 29 Jul 2024 22:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722291048; cv=none; b=V7wQpQuUbQWPUkg/DgxJLiI6xcEpkJMrkx8kyq4+JYyAdDx8AebjsfgKuCrMccf7HqAqYcowX3SpWc9C5RNSZp8LftiXIlI5qZv2A2jb5Zr8lCerDmmnV/Y2QeoOfXZ9sJhzoJ4PQ8XTVloo306Pt2CJ1CaidG6z87OqL7ObIHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722291048; c=relaxed/simple; bh=Dk214mxztzvWyeIrTyzDucKVtnvYCgeVAsvCu+M+ruY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SYZ+vG6DFLE3hng69rGCHb1y7FGtrzv97zZohrlu04qpu5xgdQRD8k+XESHmg5vXaAAjIc+sIzB12K8jhdo3YZs2w4BJCwfUFWW/n3/VFu4VRcex+ecUE+qMY9h9Z36TiNmZ2fJ2SRRwhTEjPjCsoRYbNBvbS9Zhzk7yOB4oxLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2cb5789297eso2247887a91.3; Mon, 29 Jul 2024 15:10:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722291045; x=1722895845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pOiPyoNdl7TPztzL8etHRqD2fbBoXV6bGhf/vraszoA=; b=f2rVWuSuSSfumCCLoWexB0Hk7x3jJc1VncYx5FzavRnasDoK3HUqeOJo6RyGwSni54 HnbEpl5dbkJR2OXkpa4sAbXQkfUtBpCCbzvFcszQa2alRtk6UjaAzwzXBB/DSWEHIQNq lpK41srJd+WPRV85Pwcaig/QcOb8hZtOc6njSX1xtwPXHQCtxvyRr6pN1T13pXM1jhOc X5X0fPLG9kb6+wUsC0dCodLWYP4obaojMVofu+4p0cf25E9ChSrsOqNyB2XKfP+2pMIw VjpLcKCvFIXyUEDNVRHZwzmFvdnVtY8OQYlURB90D71saIklhD2Pxeu0cs/LDi+rCsex uP1Q== X-Forwarded-Encrypted: i=1; AJvYcCW8I8TbSyFoLUwMY86ydZkCLga7x3bJM/YO1alXou7cCeenjVl/7tA5t5JLb0Esth942UH2ULOj1VvfBIo/KYggrxbl9kqSsq39V8RmgmWv X-Gm-Message-State: AOJu0YxTf+g37VL+A64l5eYB8UEyC1oHJHpT1FWlk2zwuY1GCm3xbUoe kNBVm0+qBgxQlCOQE9kF1E31/xqB1tV6oclF5/Sf7Juony6h1LJKpvCKJOU= X-Google-Smtp-Source: AGHT+IF77MQGSfHl7ZRZR+Kak1oX9tNEjGEbERLvWXD/szso1fslZwK0vS+pGsdF0hoUyb5Se6h7Pg== X-Received: by 2002:a17:90a:6581:b0:2ca:8684:401a with SMTP id 98e67ed59e1d1-2cf7e5f27a9mr7164747a91.32.1722291045284; Mon, 29 Jul 2024 15:10:45 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:73b6:7410:eb24:cba4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cdba3e527esm10931103a91.16.2024.07.29.15.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 15:10:44 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Shuah Khan , Joe Damato , Petr Machata , linux-kselftest@vger.kernel.org Subject: [PATCH net-next 2/2] selftests: net: ksft: support marking tests as disruptive Date: Mon, 29 Jul 2024 15:10:42 -0700 Message-ID: <20240729221042.2700882-2-sdf@fomichev.me> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240729221042.2700882-1-sdf@fomichev.me> References: <20240729221042.2700882-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (not sure we want this, but just throwing it out there..) Add new @ksft_disruptive decorator to mark the tests that might be disruptive to the system. Depending on how well the previous test works in the CI we might want to disable disruptive tests by default and only let the developers run them manually. In the future we can add similar decorators to, for example, avoid running slow tests all the time. And/or have some option to run only 'fast' tests for some sort of smoke test scenario. $ ./stats.py --skip-disruptive KTAP version 1 1..5 ok 1 stats.check_pause ok 2 stats.check_fec ok 3 stats.pkt_byte_sum ok 4 stats.qstat_by_ifindex ok 5 stats.check_down # SKIP marked as disruptive \# Totals: pass:4 fail:0 xfail:0 xpass:0 skip:1 error:0 Signed-off-by: Stanislav Fomichev --- Cc: Shuah Khan Cc: Joe Damato Cc: Petr Machata Cc: linux-kselftest@vger.kernel.org --- tools/testing/selftests/drivers/net/stats.py | 2 ++ tools/testing/selftests/net/lib/py/ksft.py | 22 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py index 6f8bef379565..04508894ef9c 100755 --- a/tools/testing/selftests/drivers/net/stats.py +++ b/tools/testing/selftests/drivers/net/stats.py @@ -3,6 +3,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx +from lib.py import ksft_disruptive from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError from lib.py import NetDrvEnv from lib.py import ip @@ -134,6 +135,7 @@ rtnl = RtnlFamily() ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex') +@ksft_disruptive def check_down(cfg) -> None: try: qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index f26c20df9db4..f6545a45942a 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 +import argparse import builtins +import functools import inspect import sys import time @@ -10,6 +12,7 @@ from .utils import global_defer_queue KSFT_RESULT = None KSFT_RESULT_ALL = True +KSFT_ARGS = None class KsftFailEx(Exception): @@ -127,7 +130,26 @@ KSFT_RESULT_ALL = True KSFT_RESULT = False +def ksft_disruptive(func): + """ + Decorator that marks the test as disruptive. Disruptive tests + can be skipped by adding --skip-disruptive argument. + """ + + @functools.wraps(func) + def wrapper(*args, **kwargs): + if KSFT_ARGS.skip_disruptive: + raise KsftSkipEx(f"marked as disruptive") + return func(*args, **kwargs) + return wrapper + + def ksft_run(cases=None, globs=None, case_pfx=None, args=()): + parser = argparse.ArgumentParser() + parser.add_argument('--skip-disruptive', default=False, action='store_true', help='skip tests that might be disruptive (e.g. restart the interface)') + global KSFT_ARGS + KSFT_ARGS = parser.parse_args() + cases = cases or [] if globs and case_pfx: