[PATCH 16/23] mcp-server: Make tests generic and add Makefile integration
John Kacur <[email protected]>
| Newsgroups | org.kernel.vger.linux-rt-users |
|---|---|
| Message-ID | <[email protected]> |
Make MCP server tests more robust by using dynamic test data discovery instead of hardcoded file paths. This allows tests to run with any available rteval result files. Test improvements: - Use glob patterns to find any rteval-*/summary.xml files - Automatically select the most recent test data - Add clear error messages when no test data is available - Exit cleanly with instructions to generate test data Makefile integration: - Add mcp-tests target to run all MCP server tests - Update help output to document new test target - Add to .PHONY declarations Tests now work with any available rteval data and provide helpful feedback when data is missing. Assisted-by: Claude:claude-sonnet-4-5 Signed-off-by: John Kacur <[email protected]> --- Makefile | 10 +++++++++- mcp-server/tests/test_histogram.py | 13 ++++++++++++- mcp-server/tests/test_per_cpu_stats.py | 13 ++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 57b37334136a..869d42d7eb11 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,13 @@ unit-tests: @echo "Running unit tests..." ./tests/run_tests.sh +mcp-tests: + @echo "Running MCP server tests..." + @echo "These tests require rteval result files to be present" + @echo "" + $(PYTHON) mcp-server/tests/test_histogram.py + $(PYTHON) mcp-server/tests/test_per_cpu_stats.py + tests: unit-tests test-all: @@ -135,6 +142,7 @@ help: @echo " runit: do a short testrun locally [default]" @echo " tests: run unit tests (alias for unit-tests)" @echo " unit-tests: run unit tests" + @echo " mcp-tests: run MCP server tests (requires rteval result files)" @echo " test-all: run ALL tests including root-required tests (requires root)" @echo " e2e-tests: run end-to-end tests" @echo " regression-tests: run regression tests for measurement modules (requires root)" @@ -157,4 +165,4 @@ tags: cleantags: rm -f tags -.PHONY: tests unit-tests test-all e2e-tests regression-tests cpuset-tests uninstall +.PHONY: tests unit-tests mcp-tests test-all e2e-tests regression-tests cpuset-tests uninstall diff --git a/mcp-server/tests/test_histogram.py b/mcp-server/tests/test_histogram.py index e60119ffc36d..a7e47c3cd2d0 100644 --- a/mcp-server/tests/test_histogram.py +++ b/mcp-server/tests/test_histogram.py @@ -13,7 +13,18 @@ from server import extract_histogram_data, calculate_percentiles # Find test file relative to script location # From tests/ -> mcp-server/ -> rteval/ script_dir = Path(__file__).parent -test_file = script_dir.parent.parent / "rteval-20260714-1" / "summary.xml" +rteval_dir = script_dir.parent.parent + +# Find any rteval result directory with summary.xml +test_files = list(rteval_dir.glob("rteval-*/summary.xml")) +if not test_files: + print("ERROR: No rteval result files found in", rteval_dir) + print("Please run rteval to generate test data first.") + sys.exit(1) + +# Use the most recent file +test_file = sorted(test_files)[-1] +print(f"Using test file: {test_file.parent.name}/summary.xml\n") print("Testing histogram extraction...") print("=" * 60) diff --git a/mcp-server/tests/test_per_cpu_stats.py b/mcp-server/tests/test_per_cpu_stats.py index d7544a18ce41..673cc89f0b08 100644 --- a/mcp-server/tests/test_per_cpu_stats.py +++ b/mcp-server/tests/test_per_cpu_stats.py @@ -14,15 +14,18 @@ async def main(): print("Testing get_per_cpu_stats tool") print("=" * 60) - # Find test data + # Find test data - use any available rteval result rteval_dir = Path(__file__).parent.parent.parent - test_file = rteval_dir / "rteval-20260714-1" / "summary.xml" + test_files = list(rteval_dir.glob("rteval-*/summary.xml")) - if not test_file.exists(): - print(f"✗ Test file not found: {test_file}") + if not test_files: + print(f"✗ No rteval result files found in {rteval_dir}") + print("Please run rteval to generate test data first.") sys.exit(1) - print(f"\nUsing test file: {test_file.name}\n") + # Use the most recent file + test_file = sorted(test_files)[-1] + print(f"\nUsing test file: {test_file.parent.name}/summary.xml\n") # Test 1: Basic per-CPU stats (sorted by maximum) print("1. Basic per-CPU stats sorted by maximum latency...") -- 2.55.0