aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/lib/py
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2024-04-19 19:35:42 -0700
committerJakub Kicinski <kuba@kernel.org>2024-04-23 10:09:49 -0700
commit23710925928310ec481fc0909a4d44ef89f4241a (patch)
tree29534a354ee4ae330feb4b9f2823252accf19945 /tools/testing/selftests/net/lib/py
parent8af4f60472fce1f22db5068107b37bcc1a65eabd (diff)
selftests: drv-net: test dumping qstats per device
Add a test for dumping qstats device by device. ksft framework grows a ksft_raises() helper, to be used under with, which should be familiar to unittest users. Link: https://lore.kernel.org/r/20240420023543.3300306-5-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/lib/py')
-rw-r--r--tools/testing/selftests/net/lib/py/ksft.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index 25f2572fa540..e7f79f6185b0 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -53,6 +53,24 @@ def ksft_ge(a, b, comment=""):
_fail("Check failed", a, "<", b, comment)
+class ksft_raises:
+ def __init__(self, expected_type):
+ self.exception = None
+ self.expected_type = expected_type
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ if exc_type is None:
+ _fail(f"Expected exception {str(self.expected_type.__name__)}, none raised")
+ elif self.expected_type != exc_type:
+ _fail(f"Expected exception {str(self.expected_type.__name__)}, raised {str(exc_type.__name__)}")
+ self.exception = exc_val
+ # Suppress the exception if its the expected one
+ return self.expected_type == exc_type
+
+
def ksft_busy_wait(cond, sleep=0.005, deadline=1, comment=""):
end = time.monotonic() + deadline
while True: