From d3b697218773eaa5a3dd368705184726dbc0fa38 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 21 Jun 2025 15:54:07 +0300 Subject: Implement headless testing framework for DS-Sim protocol simulations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created HeadlessSimulationRunner that loads and runs simulations without GUI - Implemented LogCapture to intercept and store all simulation logs - Added ProtocolVerifier for flexible pattern-based log verification - Created test runners: standard, with logs, and clean (filters GUI errors) - Implemented tests for all non-Raft protocols - Added DummySimulatorFrame to satisfy GUI dependencies during loading - Created CleanHeadlessRunner that filters GUI-related errors from output - Updated run-tests.sh script with quiet mode option - Documented the framework architecture and usage The framework successfully runs protocol tests and verifies behavior through log analysis. GUI errors occur internally due to tight coupling in DS-Sim but are filtered in quiet mode for clean output. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../java/testing/examples/InteractiveTest.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/testing/examples/InteractiveTest.java (limited to 'src/main/java/testing/examples/InteractiveTest.java') diff --git a/src/main/java/testing/examples/InteractiveTest.java b/src/main/java/testing/examples/InteractiveTest.java new file mode 100644 index 0000000..8cc93e8 --- /dev/null +++ b/src/main/java/testing/examples/InteractiveTest.java @@ -0,0 +1,66 @@ +package testing.examples; + +import testing.*; +import java.util.Scanner; + +public class InteractiveTest { + public static void main(String[] args) throws Exception { + Scanner scanner = new Scanner(System.in); + HeadlessSimulationRunner runner = new HeadlessSimulationRunner(); + + System.out.println("=== Interactive Headless Test ==="); + System.out.println("\nAvailable simulations:"); + System.out.println("1. ping-pong.dat"); + System.out.println("2. broadcast.dat"); + System.out.println("3. berkeley.dat"); + System.out.println("4. raft-working.dat"); + + System.out.print("\nEnter simulation filename (or full path): "); + String filename = scanner.nextLine(); + + // Add saved-simulations/ prefix if not present + if (!filename.contains("/")) { + filename = "saved-simulations/" + filename; + } + + System.out.print("Run duration in ms (default 2000): "); + String durationStr = scanner.nextLine(); + long duration = durationStr.isEmpty() ? 2000 : Long.parseLong(durationStr); + + System.out.print("Pattern to search for (optional): "); + String pattern = scanner.nextLine(); + + try { + System.out.println("\nRunning simulation..."); + SimulationResult result = runner.runSimulation(filename, duration); + + System.out.println("\nResults:"); + System.out.println("- Total logs: " + result.getAllLogs().size()); + System.out.println("- Processes: " + result.getMetrics().getNumProcesses()); + + if (!pattern.isEmpty()) { + int count = result.countLogs(pattern); + System.out.println("- Pattern '" + pattern + "' found: " + count + " times"); + + if (count > 0) { + System.out.println("\nMatching logs:"); + result.findAll(pattern).stream() + .limit(5) + .forEach(log -> System.out.println(" " + log)); + } + } + + System.out.println("\nFirst 10 logs:"); + result.getAllLogs().stream() + .limit(10) + .forEach(log -> System.out.println(" [" + log.getTimestamp() + "] " + + log.getMessage())); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + } finally { + runner.shutdown(); + scanner.close(); + } + } +} \ No newline at end of file -- cgit v1.2.3