mirror of
https://github.com/m1ngsama/TNT.git
synced 2025-12-24 10:51:41 +00:00
Add development and testing infrastructure
Added build targets: - make asan - AddressSanitizer for memory bugs - make debug - Debug symbols - make valgrind - Valgrind helper - make check - Static analysis (cppcheck, clang-tidy) Added test scripts: - test_basic.sh - Basic functionality tests * Server startup * SSH connection * Message logging - test_stress.sh - Load testing * Configurable client count * Configurable duration * Automatic cleanup Updated .gitignore: - test.log - *.dSYM/ Philosophy: Simple, minimal, Unix-style tools. No dependencies on complex test frameworks.
This commit is contained in:
parent
6c9d243f9a
commit
90ddd7fade
4 changed files with 114 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,3 +6,5 @@ host_key
|
||||||
host_key.pub
|
host_key.pub
|
||||||
*.swp
|
*.swp
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
test.log
|
||||||
|
*.dSYM/
|
||||||
|
|
|
||||||
15
Makefile
15
Makefile
|
|
@ -23,7 +23,7 @@ SOURCES = $(wildcard $(SRC_DIR)/*.c)
|
||||||
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
||||||
TARGET = tnt
|
TARGET = tnt
|
||||||
|
|
||||||
.PHONY: all clean install uninstall
|
.PHONY: all clean install uninstall debug release asan valgrind check info
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
|
@ -56,6 +56,19 @@ release: CFLAGS += -O3 -DNDEBUG
|
||||||
release: clean $(TARGET)
|
release: clean $(TARGET)
|
||||||
strip $(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
|
# Show build info
|
||||||
info:
|
info:
|
||||||
@echo "Compiler: $(CC)"
|
@echo "Compiler: $(CC)"
|
||||||
|
|
|
||||||
60
test_basic.sh
Executable file
60
test_basic.sh
Executable file
|
|
@ -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
|
||||||
38
test_stress.sh
Executable file
38
test_stress.sh
Executable file
|
|
@ -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"
|
||||||
Loading…
Reference in a new issue