Skip to contentSkip to conversation

selftests: tc-testing: fix list_categories() crash on list type

PATCH Applied [email protected] 3 participants 6 messages Feb 28 – Mar 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: tc-testing: fix list_categories() crash on list type

From: Naveen Anandhan <[email protected]>

list_categories() builds a set directly from the 'category' field of each test case. Since 'category' is a list, set(map(...)) attempts to insert lists into a set, which raises:

TypeError: unhashable type: 'list'

Flatten category lists and collect unique category names using set.update() instead.

---
 tools/testing/selftests/tc-testing/tdc_helper.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/tc-testing/tdc_helper.py +7 -3
index e06f03c0fb5d..adb52fe3acc1 100644
@@ -38,10 +38,14 @@ def list_test_cases(testlist):
 
 
 def list_categories(testlist):
-    """ Show all categories that are present in a test case file. """
-    categories = set(map(lambda x: x['category'], testlist))
+    """Show all unique categories present in the test cases."""
+    categories = set()
+    for t in testlist:
+        if 'category' in t:
+            categories.update(t['category'])
+
     print("Available categories:")
-    print(", ".join(str(s) for s in categories))
+    print(", ".join(sorted(categories)))
     print("")
 
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · On Sat, 28 Feb 2026 13:17:35 +0530 [email protected] wrote:

list_categories() builds a set directly from the 'category' field of each test case. Since 'category' is a list, set(map(...)) attempts to insert lists into a set, which raises:

TypeError: unhashable type: 'list'

Flatten category lists and collect unique category names using set.update() instead.

How did you find this issue?

I can't figure out what's calling this function in the first place.

Signature · 1 line
pw-bot: cr
author
#2 lore raw
Quoted 2 lines

How did you find this issue? I can't figure out what's calling this function in the first place.

I encountered this while running the tc-testing selftests locally.

The script raised the error:

TypeError: unhashable type: 'list'

The traceback pointed to list_categories(), where a set(map(...)) was being created from the 'category' field.

Since 'category' is a list in the test cases, Python attempts to insert the list itself into the set, which raises the unhashable type error. After tracing this, I updated the logic to flatten the category lists and collect unique category names using set.update().

Quoted 17 lines · Jakub Kicinski
Quoted 9 lines · On Sat, 28 Feb 2026 13:17:35 +0530 [email protected] wrote:

list_categories() builds a set directly from the 'category' field of each test case. Since 'category' is a list, set(map(...)) attempts to insert lists into a set, which raises:

TypeError: unhashable type: 'list'

Flatten category lists and collect unique category names using set.update() instead.

How did you find this issue?

I can't figure out what's calling this function in the first place. --
pw-bot: cr

maintainer
#3 lore raw
Quoted 4 lines · On Wed, 4 Mar 2026 08:04:18 +0530 Naveen A wrote:
Quoted 2 lines

How did you find this issue? I can't figure out what's calling this function in the first place.

I encountered this while running the tc-testing selftests locally.

Running locally meaning? via tdc.py ? Or some other way ?

$ git grep list_categories
tools/testing/selftests/tc-testing/tdc_helper.py:def list_categories(testlist):

I guess I don't understand what the purpose if tdc_helper.py is but the function you're polishing appears not to be called today..

author
#4 lore raw

You're right — after checking with git grep, it looks like list_categories() is not currently called anywhere in the tc-testing framework.

I originally noticed the issue while manually testing the helper function in a small Python snippet, which triggered the error:

TypeError: unhashable type: 'list'

since the test definitions use a list for category, e.g.:

"category": ["filter", "fw"]

So the patch was intended to make the helper handle that format correctly. But since the function appears unused today.

Thanks for pointing that out.

Quoted 14 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 4 Mar 2026 08:04:18 +0530 Naveen A wrote:
Quoted 2 lines

How did you find this issue? I can't figure out what's calling this function in the first place.

I encountered this while running the tc-testing selftests locally.

Running locally meaning? via tdc.py ? Or some other way ?

$ git grep list_categories
tools/testing/selftests/tc-testing/tdc_helper.py:def list_categories(testlist):

I guess I don't understand what the purpose if tdc_helper.py is but the function you're polishing appears not to be called today..

#5 lore raw
In reply to [email protected]
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 8 lines · On Sat, 28 Feb 2026 13:17:35 +0530 you wrote:

From: Naveen Anandhan <[email protected]>

list_categories() builds a set directly from the 'category' field of each test case. Since 'category' is a list, set(map(...)) attempts to insert lists into a set, which raises:

[...]

Here is the summary with links:
- selftests: tc-testing: fix list_categories() crash on list type

    https://git.kernel.org/netdev/net/c/fbdfa8da05b6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html