diff --git a/.gitignore b/.gitignore index d994130..7b8ddb8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ host_key host_key.pub *.swp .DS_Store +test.log +*.dSYM/ diff --git a/Makefile b/Makefile index e4595d9..fb80524 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ SOURCES = $(wildcard $(SRC_DIR)/*.c) OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) TARGET = tnt -.PHONY: all clean install uninstall +.PHONY: all clean install uninstall debug release asan valgrind check info all: $(TARGET) @@ -56,6 +56,19 @@ release: CFLAGS += -O3 -DNDEBUG release: clean $(TARGET) strip $(TARGET) +asan: CFLAGS += -g -fsanitize=address -fno-omit-frame-pointer +asan: LDFLAGS += -fsanitize=address +asan: clean $(TARGET) + @echo "AddressSanitizer build complete. Run with: ASAN_OPTIONS=detect_leaks=1 ./tnt" + +valgrind: debug + @echo "Run: valgrind --leak-check=full --track-origins=yes ./tnt" + +# Static analysis +check: + @command -v cppcheck >/dev/null 2>&1 && cppcheck --enable=warning,performance --quiet src/ || echo "cppcheck not installed" + @command -v clang-tidy >/dev/null 2>&1 && clang-tidy src/*.c -- -Iinclude $(INCLUDES) || echo "clang-tidy not installed" + # Show build info info: @echo "Compiler: $(CC)" diff --git a/test_basic.sh b/test_basic.sh new file mode 100755 index 0000000..b5a3548 --- /dev/null +++ b/test_basic.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Basic functional tests +# Usage: ./test_basic.sh + +PORT=${PORT:-2222} +PASS=0 +FAIL=0 + +cleanup() { + kill $SERVER_PID 2>/dev/null + rm -f test.log +} + +trap cleanup EXIT + +echo "=== TNT Basic Tests ===" + +# Start server +./tnt -p $PORT >test.log 2>&1 & +SERVER_PID=$! +sleep 2 + +# Test 1: Server started +if kill -0 $SERVER_PID 2>/dev/null; then + echo "✓ Server started" + PASS=$((PASS + 1)) +else + echo "✗ Server failed to start" + FAIL=$((FAIL + 1)) + exit 1 +fi + +# Test 2: SSH connection +if timeout 5 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ + -o BatchMode=yes -p $PORT localhost exit 2>/dev/null; then + echo "✓ SSH connection works" + PASS=$((PASS + 1)) +else + echo "✗ SSH connection failed" + FAIL=$((FAIL + 1)) +fi + +# Test 3: Message logging +echo "test message" | timeout 5 ssh -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null -p $PORT localhost >/dev/null 2>&1 & +sleep 3 +if [ -f messages.log ]; then + echo "✓ Message logging works" + PASS=$((PASS + 1)) +else + echo "✗ Message logging failed" + FAIL=$((FAIL + 1)) +fi + +# Summary +echo "" +echo "PASSED: $PASS" +echo "FAILED: $FAIL" +[ $FAIL -eq 0 ] && echo "All tests passed" || echo "Some tests failed" +exit $FAIL diff --git a/test_stress.sh b/test_stress.sh new file mode 100755 index 0000000..5b2d890 --- /dev/null +++ b/test_stress.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Stress test for TNT server +# Usage: ./test_stress.sh [num_clients] + +PORT=${PORT:-2222} +CLIENTS=${1:-10} +DURATION=${2:-30} + +echo "Starting TNT server on port $PORT..." +./tnt -p $PORT & +SERVER_PID=$! +sleep 2 + +if ! kill -0 $SERVER_PID 2>/dev/null; then + echo "Server failed to start" + exit 1 +fi + +echo "Spawning $CLIENTS clients for ${DURATION}s..." + +for i in $(seq 1 $CLIENTS); do + ( + sleep $((i % 5)) + echo "test user $i" | timeout $DURATION ssh -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null -p $PORT localhost \ + >/dev/null 2>&1 + ) & +done + +echo "Running stress test..." +sleep $DURATION + +echo "Cleaning up..." +kill $SERVER_PID 2>/dev/null +wait + +echo "Stress test complete" +ps aux | grep tnt | grep -v grep && echo "WARNING: tnt process still running"