-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add basic CI/CD testing infrastructure (MVP) #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yc199911
wants to merge
1
commit into
RinHizakura:main
Choose a base branch
from
yc199911:add-basic-ci-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Basic CI/CD test script for mini-gdbstub | ||
| # This is a MVP (Minimum Viable Product) version | ||
|
|
||
| set -e # Exit on any error | ||
|
|
||
| # Configuration | ||
| GDBSTUB_HOST="127.0.0.1" | ||
| GDBSTUB_PORT="1234" | ||
| TIMEOUT=10 | ||
| GDB_TIMEOUT=30 | ||
| BUILD_DIR="build" | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| log_info() { | ||
| echo -e "${GREEN}[INFO]${NC} $1" | ||
| } | ||
|
|
||
| log_warn() { | ||
| echo -e "${YELLOW}[WARN]${NC} $1" | ||
| } | ||
|
|
||
| log_error() { | ||
| echo -e "${RED}[ERROR]${NC} $1" | ||
| } | ||
|
|
||
| # Cleanup function - will be called on script exit | ||
| cleanup() { | ||
| log_info "Cleaning up..." | ||
| if [ ! -z "$GDBSTUB_PID" ]; then | ||
| log_info "Stopping gdbstub server (PID: $GDBSTUB_PID)" | ||
| kill $GDBSTUB_PID 2>/dev/null || true | ||
| wait $GDBSTUB_PID 2>/dev/null || true | ||
| fi | ||
| # Clean up temporary files | ||
| rm -f /tmp/gdb_test.gdb /tmp/gdb_output.log | ||
| } | ||
|
|
||
| # Set trap to call cleanup on script exit | ||
| trap cleanup EXIT | ||
|
|
||
| # Step 1: Build stage | ||
| log_info "=== Step 1: Building project ===" | ||
| make clean || true | ||
| make build-emu || { | ||
| log_error "Build failed" | ||
| exit 1 | ||
| } | ||
| log_info "Build completed successfully" | ||
|
|
||
| # Step 2: Start gdbstub server | ||
| log_info "=== Step 2: Starting gdbstub server ===" | ||
| make run-gdbstub & | ||
| GDBSTUB_PID=$! | ||
| log_info "Started gdbstub server in background (PID: $GDBSTUB_PID)" | ||
|
|
||
| # Step 3: Wait for server to be ready | ||
| log_info "=== Step 3: Waiting for server to be ready ===" | ||
| for i in $(seq 1 $TIMEOUT); do | ||
| # Check if emulator process is still running | ||
| if ! ps -p $GDBSTUB_PID > /dev/null 2>&1; then | ||
| log_error "Emulator process died unexpectedly" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if netstat -tlnp 2>/dev/null | grep -q ":$GDBSTUB_PORT " || \ | ||
| ss -tlnp 2>/dev/null | grep -q ":$GDBSTUB_PORT "; then | ||
| log_info "Server is ready on port $GDBSTUB_PORT" | ||
| break | ||
| fi | ||
|
|
||
| if [ $i -eq $TIMEOUT ]; then | ||
| log_error "Timeout waiting for server to start" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log_info "Waiting for server... ($i/$TIMEOUT)" | ||
| sleep 1 | ||
| done | ||
|
|
||
| # Step 4: Basic connection test | ||
| log_info "=== Step 4: Basic connection test ===" | ||
|
|
||
| # Detect which GDB to use | ||
| if command -v riscv64-unknown-elf-gdb >/dev/null 2>&1; then | ||
| GDB_CMD="riscv64-unknown-elf-gdb" | ||
| elif command -v gdb-multiarch >/dev/null 2>&1; then | ||
| GDB_CMD="gdb-multiarch" | ||
| else | ||
| log_error "No suitable GDB found" | ||
| log_error "Please install gdb-multiarch or riscv64-unknown-elf-gdb" | ||
| exit 1 | ||
| fi | ||
| log_info "Using GDB: $GDB_CMD" | ||
|
|
||
| # Create a simple GDB script for testing | ||
| cat > /tmp/gdb_test.gdb << 'EOF' | ||
| set confirm off | ||
| set print pretty on | ||
| set architecture riscv:rv64 | ||
| target remote 127.0.0.1:1234 | ||
| info registers | ||
| continue | ||
| quit | ||
| EOF | ||
|
|
||
| # Run GDB test with timeout | ||
| log_info "Running GDB connection test..." | ||
| if timeout ${GDB_TIMEOUT}s $GDB_CMD -batch -x /tmp/gdb_test.gdb ${BUILD_DIR}/emu/test.obj 2>&1 | tee /tmp/gdb_output.log; then | ||
| log_info "GDB connection test completed" | ||
| else | ||
| exit_code=$? | ||
| if [ $exit_code -eq 124 ]; then | ||
| log_error "GDB connection test timed out after ${GDB_TIMEOUT} seconds" | ||
| else | ||
| log_error "GDB connection test failed" | ||
| fi | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Step 5: Verify test results | ||
| log_info "=== Step 5: Verifying results ===" | ||
|
|
||
| if grep -q "The target architecture is set to" /tmp/gdb_output.log; then | ||
| log_info "✓ GDB connection successful" | ||
| else | ||
| log_warn "Connection verification unclear" | ||
| fi | ||
|
|
||
| if grep -q "SIGTRAP" /tmp/gdb_output.log; then | ||
| log_info "✓ Program completed successfully" | ||
| else | ||
| log_warn "Program completion verification unclear" | ||
| fi | ||
|
|
||
| log_info "=== Test completed successfully! ===" | ||
|
|
||
| # Cleanup will be called automatically by trap | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't expect to build the project under the script, because this can make it inconvenient to check which step fails from the dashboard.
Please check .github/workflows/tests.yml. In fact, I already have one script to run some simple checks. Although it is quite simple, you can refer to this and merge these two for better coverage.