public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: linux-rt-users@vger.kernel.org
Cc: Clark Williams <williams@redhat.com>, Tomas Glozar <tglozar@redhat.com>
Subject: [PATCH 5/6] rteval: Add unit tests for CpuList class
Date: Fri, 17 Apr 2026 15:51:12 -0400	[thread overview]
Message-ID: <20260417195113.177799-6-jkacur@redhat.com> (raw)
In-Reply-To: <20260417195113.177799-1-jkacur@redhat.com>

Add comprehensive unit tests for the new CpuList class covering:
- Basic creation from strings and lists
- Operators (__contains__, __iter__, __eq__, __len__)
- Method chaining with online/isolated filtering
- Backward compatibility with module-level functions
- String representation (__str__ and __repr__)

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 tests/test_cpulist_class.py | 121 ++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 tests/test_cpulist_class.py

diff --git a/tests/test_cpulist_class.py b/tests/test_cpulist_class.py
new file mode 100644
index 000000000000..bcb92e4a719d
--- /dev/null
+++ b/tests/test_cpulist_class.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python3
+"""Test script for the new CpuList class"""
+
+import sys
+sys.path.insert(0, '.')
+
+from rteval.cpulist_utils import CpuList, expand_cpulist, collapse_cpulist
+
+def test_basic_creation():
+    """Test basic CpuList creation"""
+    print("=" * 60)
+    print("Test 1: Basic Creation")
+    print("=" * 60)
+
+    # Create from string
+    cpus1 = CpuList("0-7,9-11")
+    print(f"CpuList('0-7,9-11') = {cpus1}")
+    print(f"  cpus: {cpus1.cpus}")
+    print(f"  len: {len(cpus1)}")
+
+    # Create from list
+    cpus2 = CpuList([0, 1, 2, 3, 7, 8, 9])
+    print(f"\nCpuList([0,1,2,3,7,8,9]) = {cpus2}")
+    print(f"  cpus: {cpus2.cpus}")
+
+    print()
+
+def test_operators():
+    """Test CpuList operators"""
+    print("=" * 60)
+    print("Test 2: Operators")
+    print("=" * 60)
+
+    cpus = CpuList("0-7")
+
+    # __contains__
+    print(f"cpus = {cpus}")
+    print(f"  3 in cpus: {3 in cpus}")
+    print(f"  10 in cpus: {10 in cpus}")
+
+    # __iter__
+    print(f"  Iteration: ", end="")
+    for cpu in cpus:
+        print(cpu, end=" ")
+    print()
+
+    # __eq__
+    cpus2 = CpuList([0, 1, 2, 3, 4, 5, 6, 7])
+    print(f"  cpus == CpuList([0-7]): {cpus == cpus2}")
+
+    print()
+
+def test_chaining():
+    """Test method chaining (requires system with online/isolated info)"""
+    print("=" * 60)
+    print("Test 3: Method Chaining (filtering won't occur on systems without online/isolated CPU support)")
+    print("=" * 60)
+
+    cpus = CpuList("0-15")
+    print(f"Original: {cpus}")
+    print(f"  CPU count: {len(cpus)}")
+
+    try:
+        online = cpus.online()
+        print(f"Online: {online}")
+        print(f"  CPU count: {len(online)}")
+
+        nonisolated = cpus.online().nonisolated()
+        print(f"Online + Non-isolated: {nonisolated}")
+        print(f"  CPU count: {len(nonisolated)}")
+    except Exception as e:
+        print(f"  (Skipped: {e})")
+
+    print()
+
+def test_backward_compatibility():
+    """Test that module-level functions still work"""
+    print("=" * 60)
+    print("Test 4: Backward Compatibility")
+    print("=" * 60)
+
+    # Old style - module functions
+    expanded = expand_cpulist("0-3,7-9")
+    print(f"expand_cpulist('0-3,7-9') = {expanded}")
+
+    collapsed = collapse_cpulist([0, 1, 2, 3, 7, 8, 9])
+    print(f"collapse_cpulist([0,1,2,3,7,8,9]) = {collapsed}")
+
+    # New style - static methods
+    expanded2 = CpuList.expand("0-3,7-9")
+    print(f"CpuList.expand('0-3,7-9') = {expanded2}")
+
+    collapsed2 = CpuList.collapse([0, 1, 2, 3, 7, 8, 9])
+    print(f"CpuList.collapse([0,1,2,3,7,8,9]) = {collapsed2}")
+
+    print()
+
+def test_repr():
+    """Test repr"""
+    print("=" * 60)
+    print("Test 5: Repr")
+    print("=" * 60)
+
+    cpus = CpuList("0-3,7-9")
+    print(f"repr: {repr(cpus)}")
+    print(f"str:  {str(cpus)}")
+
+    print()
+
+if __name__ == '__main__':
+    print("\nTesting CpuList class implementation\n")
+
+    test_basic_creation()
+    test_operators()
+    test_chaining()
+    test_backward_compatibility()
+    test_repr()
+
+    print("=" * 60)
+    print("All tests completed!")
+    print("=" * 60)
-- 
2.53.0


  parent reply	other threads:[~2026-04-17 19:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 19:51 [PATCH 0/6] rteval: Improve CPU management infrastructure and add housekeeping option John Kacur
2026-04-17 19:51 ` [PATCH 1/6] rteval: Add cpuset module for cgroup v2 management John Kacur
2026-04-17 19:51 ` [PATCH 2/6] rteval: Fix xmlout unit test XSL file path John Kacur
2026-04-17 19:51 ` [PATCH 3/6] rteval: Add CpuList class to cpulist_utils module John Kacur
2026-04-17 19:51 ` [PATCH 4/6] rteval: Migrate call sites to use CpuList class where beneficial John Kacur
2026-04-17 19:51 ` John Kacur [this message]
2026-04-17 19:51 ` [PATCH 6/6] rteval: Add --housekeeping option to reserve isolated CPUs John Kacur
2026-04-20  9:33   ` Tomas Glozar
2026-04-20 21:42     ` John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260417195113.177799-6-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=tglozar@redhat.com \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox