summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-21 21:27:31 +0300
committerPaul Buetow <paul@buetow.org>2025-06-21 21:27:31 +0300
commit0841f0f9a1e3f3708d8c511a6290344e73607aab (patch)
tree4ae7fe60878b693d6975093acb491d977d247acd /scripts
parentce82046a11521b0537ac2150a07a4de54aec883a (diff)
Move test scripts to scripts/ directory and fix simulation completion
- Moved test-protocols.sh, test-quick.sh, test-verbose.sh to scripts/ - Updated references in README.md and docs/testing-guide.md - Fixed HeadlessSimulationRunner to properly run simulations to completion - Fixed message delivery timing (now respects 500-2000ms delays) - Added proper process time synchronization - Fixed HeadlessProtocolRunner to exit cleanly 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/test-protocols.sh70
-rwxr-xr-xscripts/test-quick.sh21
-rwxr-xr-xscripts/test-verbose.sh57
3 files changed, 148 insertions, 0 deletions
diff --git a/scripts/test-protocols.sh b/scripts/test-protocols.sh
new file mode 100755
index 0000000..2edbef9
--- /dev/null
+++ b/scripts/test-protocols.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+#
+# DS-Sim Protocol Test Runner
+#
+# This script runs protocol simulation tests in headless mode.
+# GUI decoupling has been implemented, so tests run cleanly without GUI errors.
+#
+
+echo "DS-Sim Protocol Test Runner"
+echo "=========================="
+echo
+
+# Check if we're in the right directory
+if [ ! -f "pom.xml" ]; then
+ echo "ERROR: Please run this script from the project root directory"
+ exit 1
+fi
+
+# Build if needed
+if [ ! -d "target/classes" ]; then
+ echo "Building project..."
+ mvn compile -q || { echo "Build failed!"; exit 1; }
+fi
+
+# Menu
+echo "Choose an option:"
+echo "1) Run all protocol tests"
+echo "2) Run specific protocol test"
+echo "3) Run tests with detailed logs"
+echo "4) Test GUI decoupling (verify no GUI errors)"
+echo "5) Exit"
+echo
+
+read -p "Enter choice [1-5]: " choice
+
+case $choice in
+ 1)
+ echo "Running all protocol tests..."
+ java -cp target/classes:target/test-classes -Djava.awt.headless=true testing.HeadlessProtocolRunner
+ ;;
+ 2)
+ echo "Available simulations:"
+ ls saved-simulations/*.dat | sed 's/saved-simulations\// - /g'
+ echo
+ read -p "Enter simulation name (without .dat): " sim
+ if [ -f "saved-simulations/${sim}.dat" ]; then
+ java -cp target/classes:target/test-classes -Djava.awt.headless=true \
+ testing.HeadlessProtocolRunner "saved-simulations/${sim}.dat"
+ else
+ echo "Simulation not found!"
+ fi
+ ;;
+ 3)
+ echo "Running tests with detailed logs..."
+ java -cp target/classes:target/test-classes -Djava.awt.headless=true \
+ -Dds.sim.verbose=true testing.HeadlessProtocolRunner
+ ;;
+ 4)
+ echo "Testing GUI decoupling..."
+ java -cp target/classes:target/test-classes testing.TestNoGuiErrors
+ ;;
+ 5)
+ echo "Exiting..."
+ exit 0
+ ;;
+ *)
+ echo "Invalid choice!"
+ exit 1
+ ;;
+esac \ No newline at end of file
diff --git a/scripts/test-quick.sh b/scripts/test-quick.sh
new file mode 100755
index 0000000..a37c399
--- /dev/null
+++ b/scripts/test-quick.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# Quick test to verify simulation runs correctly
+#
+
+echo "Quick DS-Sim Protocol Test"
+echo "========================="
+echo
+
+# Test ping-pong with shorter timeout
+echo "Testing ping-pong protocol..."
+timeout 5 java -cp target/classes:target/test-classes \
+ -Djava.awt.headless=true \
+ -Dds.sim.headless=true \
+ testing.HeadlessProtocolRunner saved-simulations/ping-pong.dat
+
+if [ $? -eq 124 ]; then
+ echo "✗ Test timed out after 5 seconds"
+else
+ echo "✓ Test completed successfully"
+fi \ No newline at end of file
diff --git a/scripts/test-verbose.sh b/scripts/test-verbose.sh
new file mode 100755
index 0000000..e3362b3
--- /dev/null
+++ b/scripts/test-verbose.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+#
+# Test verbose logging for DS-Sim protocols
+#
+
+echo "DS-Sim Verbose Logging Test"
+echo "=========================="
+echo
+echo "This demonstrates real-time logging during protocol simulation."
+echo
+
+# Compile if needed
+if [ ! -d "target/classes" ]; then
+ echo "Building project..."
+ mvn compile -q || { echo "Build failed!"; exit 1; }
+fi
+
+# Run ping-pong for just 2 seconds with verbose output
+echo "Running ping-pong protocol for 2 seconds with verbose output..."
+echo
+
+# Create a simple test that runs for a limited time
+cat > /tmp/TestVerbose.java << 'EOF'
+import testing.*;
+
+public class TestVerbose {
+ public static void main(String[] args) throws Exception {
+ String simFile = args.length > 0 ? args[0] : "saved-simulations/ping-pong.dat";
+ int duration = args.length > 1 ? Integer.parseInt(args[1]) : 2000;
+
+ System.out.println("Loading: " + simFile);
+ System.out.println("Duration: " + duration + "ms");
+ System.out.println("\n--- Real-Time Log Output ---\n");
+
+ HeadlessSimulationRunner runner = new HeadlessSimulationRunner();
+ runner.setPrintLogs(true);
+
+ try {
+ SimulationResult result = runner.runSimulation(simFile, duration);
+ System.out.println("\n--- Simulation Complete ---");
+ System.out.println("Total events: " + result.getAllLogs().size());
+ } finally {
+ runner.shutdown();
+ }
+ }
+}
+EOF
+
+# Compile and run the test
+javac -cp target/classes /tmp/TestVerbose.java -d /tmp
+java -cp /tmp:target/classes:target/test-classes -Djava.awt.headless=true TestVerbose "$@"
+
+# Clean up
+rm -f /tmp/TestVerbose.java /tmp/TestVerbose.class
+
+# Exit cleanly
+exit 0 \ No newline at end of file