public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Clark Williams <williams@redhat.com>, Tomas Glozar <tglozar@redhat.com>
Subject: [PATCH 4/7] rteval: Add temporary test for core sharing validation with mocked isolated CPUs
Date: Tue, 21 Apr 2026 14:26:15 -0400	[thread overview]
Message-ID: <20260421182618.261347-5-jkacur@redhat.com> (raw)
In-Reply-To: <20260421182618.261347-1-jkacur@redhat.com>

Add comprehensive test script to validate core sharing warnings without
requiring actual isolated CPUs. This test uses mocked isolated CPUs to
verify both console warnings and XML report generation.

The test simulates CPUs 0, 8, 1, 9 as isolated and validates:
- Console warnings are generated correctly
- XML CoreSharingWarnings section is properly added
- Warnings only appear when at least one CPU is isolated
- Warning format includes "(isol)" markers correctly

This is a temporary test file for development and verification.
It can be removed once the feature is tested with real isolated CPUs.

Test results show all functionality working correctly:
- Console warnings: 3/3 scenarios pass
- XML generation: warnings properly added to CPUtopology section

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 test_full_validation.py | 151 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)
 create mode 100644 test_full_validation.py

diff --git a/test_full_validation.py b/test_full_validation.py
new file mode 100644
index 000000000000..98c286fab344
--- /dev/null
+++ b/test_full_validation.py
@@ -0,0 +1,151 @@
+#!/usr/bin/env python3
+"""
+Test core sharing validation with mocked isolated CPUs
+Tests both console warnings and XML output
+"""
+
+import sys
+sys.path.insert(0, '.')
+
+from unittest.mock import patch, Mock
+import libxml2
+from rteval.systopology import validate_core_sharing
+
+# Mock isolated CPUs: simulate CPUs 0, 8, 1, 9 as isolated
+# Based on actual topology: CPUs 0 and 8 share a core, 1 and 9 share a core
+MOCK_ISOLATED_CPUS = [0, 8, 1, 9]
+
+print("=" * 70)
+print("TESTING CORE SHARING VALIDATION")
+print("=" * 70)
+print()
+print("System core topology (from actual hardware):")
+from rteval.sysinfo.coresiblings import CoreSiblings
+cs = CoreSiblings()
+for i, group in enumerate(cs.get_core_groups()[:4]):
+    print(f"  Core {i}: {sorted(group)}")
+print()
+print(f"Simulating isolated CPUs: {MOCK_ISOLATED_CPUS}")
+print()
+
+# Test 1: Console warnings
+print("=" * 70)
+print("TEST 1: Console Warnings")
+print("=" * 70)
+print()
+
+with patch('rteval.systopology.SysTopology') as mock_systopo:
+    mock_instance = mock_systopo.return_value
+    mock_instance.isolated_cpus.return_value = MOCK_ISOLATED_CPUS
+
+    print("Scenario 1: Housekeeping and Measurement share core")
+    print("  Housekeeping: [0]  (isolated)")
+    print("  Measurement:  [8]  (isolated, shares core with 0)")
+    print("  Load:         [2]  (non-isolated)")
+    warnings = validate_core_sharing([0], [8], [2])
+    if warnings:
+        print(f"  ✓ Got {len(warnings)} warning(s):")
+        for w in warnings:
+            print(f"    {w}")
+    else:
+        print("  ✗ No warnings!")
+    print()
+
+    print("Scenario 2: All three workload types on different cores")
+    print("  Housekeeping: [0]  (isolated)")
+    print("  Measurement:  [1]  (isolated, different core)")
+    print("  Load:         [2]  (non-isolated, different core)")
+    warnings = validate_core_sharing([0], [1], [2])
+    if warnings:
+        print(f"  ✗ Unexpected warnings: {warnings}")
+    else:
+        print("  ✓ No warnings (correct!)")
+    print()
+
+    print("Scenario 3: Multiple conflicts")
+    print("  Housekeeping: [0]     (isolated)")
+    print("  Measurement:  [8]     (isolated, shares core with 0)")
+    print("  Load:         [1,9]   (1 and 9 both isolated, share a core)")
+    warnings = validate_core_sharing([0], [8], [1, 9])
+    if warnings:
+        print(f"  ✓ Got {len(warnings)} warning(s):")
+        for w in warnings:
+            print(f"    {w}")
+    else:
+        print("  ✗ No warnings!")
+    print()
+
+# Test 2: XML output
+print("=" * 70)
+print("TEST 2: XML Report Generation")
+print("=" * 70)
+print()
+
+with patch('rteval.systopology.SysTopology') as mock_systopo:
+    mock_instance = mock_systopo.return_value
+    mock_instance.isolated_cpus.return_value = MOCK_ISOLATED_CPUS
+    mock_instance.isolated_cpus_str.return_value = [str(cpu) for cpu in MOCK_ISOLATED_CPUS]
+
+    from rteval.sysinfo.cputopology import CPUtopology
+    from rteval.Log import Log
+
+    # Create CPUtopology and parse
+    cputop = CPUtopology()
+    cputop._parse()
+
+    # Now add warnings with conflicting CPU lists
+    print("Adding warnings for:")
+    print("  Housekeeping: [0]  (isolated)")
+    print("  Measurement:  [8]  (isolated, shares core with 0)")
+    print("  Load:         [1,9] (both isolated, share core with each other)")
+    print()
+
+    # First verify that validation itself works with the mock
+    from rteval.systopology import validate_core_sharing
+    test_warnings = validate_core_sharing([0], [8], [1, 9])
+    print(f"Direct validation call returned {len(test_warnings)} warning(s)")
+    print()
+
+    cputop.add_core_sharing_warnings([0], [8], [1, 9])
+
+    # Get the XML
+    xml = cputop.MakeReport()
+
+    # Check for warnings in XML
+    # Search for CoreSharingWarnings child node
+    warnings_section = None
+    child = xml.children
+    while child:
+        if child.name == 'CoreSharingWarnings':
+            warnings_section = child
+            break
+        child = child.next
+
+    if warnings_section:
+        warning_list = []
+        warning_child = warnings_section.children
+        while warning_child:
+            if warning_child.name == 'warning':
+                warning_list.append(warning_child.getContent())
+            warning_child = warning_child.next
+
+        if warning_list:
+            print(f"✓ Found {len(warning_list)} warning(s) in XML:")
+            for w in warning_list:
+                print(f"  - {w}")
+        else:
+            print("✗ CoreSharingWarnings section exists but is empty!")
+    else:
+        print("✗ No CoreSharingWarnings section found in XML!")
+
+    print()
+    print("Full CPUtopology XML section:")
+    print("-" * 70)
+    temp_doc = libxml2.newDoc("1.0")
+    temp_doc.setRootElement(xml.docCopyNode(temp_doc, 1))
+    temp_doc.saveFormatFileEnc("-", "UTF-8", 1)
+
+print()
+print("=" * 70)
+print("ALL TESTS COMPLETE")
+print("=" * 70)
-- 
2.53.0


  parent reply	other threads:[~2026-04-21 18:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21 18:26 [PATCH 0/7] Core sharing validation for CPU isolation John Kacur
2026-04-21 18:26 ` [PATCH 1/7] rteval: Add CoreSiblings class for CPU core topology queries John Kacur
2026-04-21 18:26 ` [PATCH 2/7] rteval: Add core sharing validation for CPU isolation John Kacur
2026-04-21 18:26 ` [PATCH 3/7] rteval: Include core sharing warnings in XML report John Kacur
2026-04-21 18:26 ` John Kacur [this message]
2026-04-21 18:26 ` [PATCH 5/7] rteval: Display core sharing warnings in text report John Kacur
2026-04-21 18:26 ` [PATCH 6/7] rteval: Add --warn-non-isolated-core-sharing option for measurement vs load warnings John Kacur
2026-04-21 18:26 ` [PATCH 7/7] rteval: Include --warn-non-isolated-core-sharing warnings in XML report 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=20260421182618.261347-5-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