|
| 1 | +#!/bin/bash |
| 2 | +# ============================================================================= |
| 3 | +# Platform Comprehensive Test Suite |
| 4 | +# ============================================================================= |
| 5 | +# Runs all tests including unit tests, integration tests, Docker tests, |
| 6 | +# and multi-validator P2P network tests. |
| 7 | +# |
| 8 | +# Usage: |
| 9 | +# ./scripts/test-comprehensive.sh |
| 10 | +# |
| 11 | +# Requirements: |
| 12 | +# - Docker daemon running |
| 13 | +# - Rust toolchain installed |
| 14 | +# - Network access for Bittensor integration tests |
| 15 | +# ============================================================================= |
| 16 | + |
| 17 | +set -e |
| 18 | + |
| 19 | +# Colors for output |
| 20 | +RED='\033[0;31m' |
| 21 | +GREEN='\033[0;32m' |
| 22 | +YELLOW='\033[1;33m' |
| 23 | +BLUE='\033[0;34m' |
| 24 | +NC='\033[0m' # No Color |
| 25 | + |
| 26 | +# Test result counters |
| 27 | +PASSED=0 |
| 28 | +FAILED=0 |
| 29 | +SKIPPED=0 |
| 30 | + |
| 31 | +# Log functions |
| 32 | +log_info() { |
| 33 | + echo -e "${BLUE}[INFO]${NC} $1" |
| 34 | +} |
| 35 | + |
| 36 | +log_success() { |
| 37 | + echo -e "${GREEN}[PASS]${NC} $1" |
| 38 | + ((PASSED++)) |
| 39 | +} |
| 40 | + |
| 41 | +log_failure() { |
| 42 | + echo -e "${RED}[FAIL]${NC} $1" |
| 43 | + ((FAILED++)) |
| 44 | +} |
| 45 | + |
| 46 | +log_warning() { |
| 47 | + echo -e "${YELLOW}[WARN]${NC} $1" |
| 48 | +} |
| 49 | + |
| 50 | +log_skip() { |
| 51 | + echo -e "${YELLOW}[SKIP]${NC} $1" |
| 52 | + ((SKIPPED++)) |
| 53 | +} |
| 54 | + |
| 55 | +# Header |
| 56 | +echo "=============================================================================" |
| 57 | +echo " Platform Comprehensive Test Suite" |
| 58 | +echo "=============================================================================" |
| 59 | +echo "" |
| 60 | +date |
| 61 | +echo "" |
| 62 | + |
| 63 | +# ============================================================================= |
| 64 | +# Phase 1: Build |
| 65 | +# ============================================================================= |
| 66 | +echo "" |
| 67 | +echo "=============================================================================" |
| 68 | +echo "Phase 1: Build (cargo build --release)" |
| 69 | +echo "=============================================================================" |
| 70 | + |
| 71 | +log_info "Building workspace..." |
| 72 | +if cargo build --release 2>&1; then |
| 73 | + log_success "Build completed successfully" |
| 74 | +else |
| 75 | + log_failure "Build failed" |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +# ============================================================================= |
| 80 | +# Phase 2: Unit Tests |
| 81 | +# ============================================================================= |
| 82 | +echo "" |
| 83 | +echo "=============================================================================" |
| 84 | +echo "Phase 2: Unit Tests (cargo test --workspace)" |
| 85 | +echo "=============================================================================" |
| 86 | + |
| 87 | +log_info "Running unit tests..." |
| 88 | +if cargo test --workspace --release 2>&1 | tee /tmp/unit_tests.log; then |
| 89 | + UNIT_RESULTS=$(grep -E "^test result:" /tmp/unit_tests.log | tail -1) |
| 90 | + log_success "Unit tests completed: $UNIT_RESULTS" |
| 91 | +else |
| 92 | + log_failure "Unit tests failed" |
| 93 | +fi |
| 94 | + |
| 95 | +# ============================================================================= |
| 96 | +# Phase 3: Docker Integration Tests |
| 97 | +# ============================================================================= |
| 98 | +echo "" |
| 99 | +echo "=============================================================================" |
| 100 | +echo "Phase 3: Docker Integration Tests" |
| 101 | +echo "=============================================================================" |
| 102 | + |
| 103 | +# Check Docker availability |
| 104 | +if docker info > /dev/null 2>&1; then |
| 105 | + log_info "Docker daemon available" |
| 106 | + |
| 107 | + # Secure Container Runtime tests |
| 108 | + log_info "Running secure-container-runtime Docker tests..." |
| 109 | + if cargo test -p secure-container-runtime --release -- --ignored 2>&1 | tee /tmp/docker_tests.log; then |
| 110 | + log_success "Secure container runtime Docker tests passed" |
| 111 | + else |
| 112 | + log_failure "Secure container runtime Docker tests failed" |
| 113 | + fi |
| 114 | + |
| 115 | + # Challenge Orchestrator Docker tests |
| 116 | + log_info "Running challenge-orchestrator Docker tests..." |
| 117 | + if cargo test -p challenge-orchestrator --release -- --ignored 2>&1; then |
| 118 | + log_success "Challenge orchestrator Docker tests passed" |
| 119 | + else |
| 120 | + log_failure "Challenge orchestrator Docker tests failed" |
| 121 | + fi |
| 122 | +else |
| 123 | + log_skip "Docker not available, skipping Docker tests" |
| 124 | +fi |
| 125 | + |
| 126 | +# ============================================================================= |
| 127 | +# Phase 4: Bittensor Integration Tests |
| 128 | +# ============================================================================= |
| 129 | +echo "" |
| 130 | +echo "=============================================================================" |
| 131 | +echo "Phase 4: Bittensor Integration Tests" |
| 132 | +echo "=============================================================================" |
| 133 | + |
| 134 | +log_info "Running Bittensor integration tests (requires network)..." |
| 135 | +if timeout 120 cargo test -p platform-bittensor --release -- --ignored 2>&1; then |
| 136 | + log_success "Bittensor integration tests passed" |
| 137 | +else |
| 138 | + log_warning "Bittensor integration tests failed or timed out (may require network)" |
| 139 | +fi |
| 140 | + |
| 141 | +# ============================================================================= |
| 142 | +# Phase 5: Security Policy Tests |
| 143 | +# ============================================================================= |
| 144 | +echo "" |
| 145 | +echo "=============================================================================" |
| 146 | +echo "Phase 5: Security Policy Tests" |
| 147 | +echo "=============================================================================" |
| 148 | + |
| 149 | +log_info "Verifying security policies..." |
| 150 | + |
| 151 | +# Test that Docker socket mounting is blocked |
| 152 | +log_info "Testing Docker socket mount blocking..." |
| 153 | +if cargo test -p secure-container-runtime test_default_policy_blocks_docker_socket --release 2>&1; then |
| 154 | + log_success "Docker socket mount blocking verified" |
| 155 | +else |
| 156 | + log_failure "Docker socket mount blocking test failed" |
| 157 | +fi |
| 158 | + |
| 159 | +# Test image whitelist |
| 160 | +log_info "Testing image whitelist enforcement..." |
| 161 | +if cargo test -p secure-container-runtime test_strict_policy_blocks_non_whitelisted_images --release 2>&1; then |
| 162 | + log_success "Image whitelist enforcement verified" |
| 163 | +else |
| 164 | + log_failure "Image whitelist enforcement test failed" |
| 165 | +fi |
| 166 | + |
| 167 | +# Test resource limits |
| 168 | +log_info "Testing resource limit enforcement..." |
| 169 | +if cargo test -p secure-container-runtime test_policy_enforces_resource_limits --release 2>&1; then |
| 170 | + log_success "Resource limit enforcement verified" |
| 171 | +else |
| 172 | + log_failure "Resource limit enforcement test failed" |
| 173 | +fi |
| 174 | + |
| 175 | +# ============================================================================= |
| 176 | +# Phase 6: P2P Consensus Tests |
| 177 | +# ============================================================================= |
| 178 | +echo "" |
| 179 | +echo "=============================================================================" |
| 180 | +echo "Phase 6: P2P Consensus Tests" |
| 181 | +echo "=============================================================================" |
| 182 | + |
| 183 | +log_info "Running P2P consensus unit tests..." |
| 184 | +if cargo test -p platform-p2p-consensus --release 2>&1 | tee /tmp/p2p_tests.log; then |
| 185 | + P2P_RESULTS=$(grep -E "^test result:" /tmp/p2p_tests.log | tail -1) |
| 186 | + log_success "P2P consensus tests: $P2P_RESULTS" |
| 187 | +else |
| 188 | + log_failure "P2P consensus tests failed" |
| 189 | +fi |
| 190 | + |
| 191 | +# ============================================================================= |
| 192 | +# Phase 7: Storage Tests |
| 193 | +# ============================================================================= |
| 194 | +echo "" |
| 195 | +echo "=============================================================================" |
| 196 | +echo "Phase 7: Storage Tests" |
| 197 | +echo "=============================================================================" |
| 198 | + |
| 199 | +log_info "Running storage tests..." |
| 200 | +if cargo test -p platform-storage --release 2>&1; then |
| 201 | + log_success "Storage tests passed" |
| 202 | +else |
| 203 | + log_failure "Storage tests failed" |
| 204 | +fi |
| 205 | + |
| 206 | +log_info "Running distributed storage tests..." |
| 207 | +if cargo test -p platform-distributed-storage --release 2>&1; then |
| 208 | + log_success "Distributed storage tests passed" |
| 209 | +else |
| 210 | + log_failure "Distributed storage tests failed" |
| 211 | +fi |
| 212 | + |
| 213 | +# ============================================================================= |
| 214 | +# Summary |
| 215 | +# ============================================================================= |
| 216 | +echo "" |
| 217 | +echo "=============================================================================" |
| 218 | +echo " Test Summary" |
| 219 | +echo "=============================================================================" |
| 220 | +echo "" |
| 221 | +echo -e " ${GREEN}Passed:${NC} $PASSED" |
| 222 | +echo -e " ${RED}Failed:${NC} $FAILED" |
| 223 | +echo -e " ${YELLOW}Skipped:${NC} $SKIPPED" |
| 224 | +echo "" |
| 225 | + |
| 226 | +if [ $FAILED -eq 0 ]; then |
| 227 | + echo -e "${GREEN}All tests passed!${NC}" |
| 228 | + exit 0 |
| 229 | +else |
| 230 | + echo -e "${RED}Some tests failed. Please review the output above.${NC}" |
| 231 | + exit 1 |
| 232 | +fi |
0 commit comments