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 --- src/main/java/testing/QuietProtocolTestRunner.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/main/java/testing/QuietProtocolTestRunner.java (limited to 'src/main/java/testing/QuietProtocolTestRunner.java') diff --git a/src/main/java/testing/QuietProtocolTestRunner.java b/src/main/java/testing/QuietProtocolTestRunner.java new file mode 100644 index 0000000..d3b35a1 --- /dev/null +++ b/src/main/java/testing/QuietProtocolTestRunner.java @@ -0,0 +1,79 @@ +package testing; + +import java.io.PrintStream; +import java.io.OutputStream; + +/** + * A test runner that suppresses GUI-related error messages while still showing test results. + * This provides a cleaner output when running headless tests. + */ +public class QuietProtocolTestRunner { + + public static void main(String[] args) { + // Create a custom PrintStream that filters out specific error messages + PrintStream originalErr = System.err; + PrintStream filteredErr = new PrintStream(new FilteredOutputStream(originalErr)); + + try { + // Redirect System.err to our filtered stream + System.setErr(filteredErr); + + // Run the actual test runner + System.out.println("=== DS-Sim Protocol Test Runner (Quiet Mode) ===\n"); + System.out.println("Note: GUI errors are suppressed for cleaner output.\n"); + + // Pass through any arguments (like -v for verbose) + ProtocolTestRunnerWithLogs.main(args); + + } finally { + // Restore original error stream + System.setErr(originalErr); + } + } + + /** + * An OutputStream that filters out specific error messages. + */ + private static class FilteredOutputStream extends OutputStream { + private final PrintStream target; + private final StringBuilder buffer = new StringBuilder(); + + public FilteredOutputStream(PrintStream target) { + this.target = target; + } + + @Override + public void write(int b) { + buffer.append((char) b); + + // Check if we have a complete line + if (b == '\n') { + String line = buffer.toString(); + + // Filter out specific GUI-related errors + if (!line.contains("Component must have a valid peer") && + !line.contains("java.lang.IllegalStateException") && + !line.contains("at java.desktop/") && + !line.contains("at simulator.VSSimulatorVisualization.paint") && + !line.contains("createBufferStrategy") && + !line.contains("FlipBufferStrategy")) { + + // Pass through other messages + target.print(line); + } + + buffer.setLength(0); + } + } + + @Override + public void flush() { + target.flush(); + } + + @Override + public void close() { + target.close(); + } + } +} \ No newline at end of file -- cgit v1.2.3