Makefile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # SeaweedFS FUSE Integration Testing Makefile
  2. # Configuration
  3. WEED_BINARY := weed
  4. GO_VERSION := 1.24
  5. TEST_TIMEOUT := 30m
  6. COVERAGE_FILE := coverage.out
  7. # Default target
  8. .DEFAULT_GOAL := help
  9. # Check if weed binary exists
  10. check-binary:
  11. @if [ ! -f "$(WEED_BINARY)" ]; then \
  12. echo "❌ SeaweedFS binary not found at $(WEED_BINARY)"; \
  13. echo " Please run 'make' in the root directory first"; \
  14. exit 1; \
  15. fi
  16. @echo "✅ SeaweedFS binary found"
  17. # Check FUSE installation
  18. check-fuse:
  19. @if command -v fusermount >/dev/null 2>&1; then \
  20. echo "✅ FUSE is installed (Linux)"; \
  21. elif command -v umount >/dev/null 2>&1 && [ "$$(uname)" = "Darwin" ]; then \
  22. echo "✅ FUSE is available (macOS)"; \
  23. else \
  24. echo "❌ FUSE not found. Please install:"; \
  25. echo " Ubuntu/Debian: sudo apt-get install fuse"; \
  26. echo " CentOS/RHEL: sudo yum install fuse"; \
  27. echo " macOS: brew install macfuse"; \
  28. exit 1; \
  29. fi
  30. # Check Go version
  31. check-go:
  32. @go version | grep -q "go1\.[2-9][0-9]" || \
  33. go version | grep -q "go1\.2[1-9]" || \
  34. (echo "❌ Go $(GO_VERSION)+ required. Current: $$(go version)" && exit 1)
  35. @echo "✅ Go version check passed"
  36. # Verify all prerequisites
  37. check-prereqs: check-go check-fuse
  38. @echo "✅ All prerequisites satisfied"
  39. # Build the SeaweedFS binary (if needed)
  40. build:
  41. @echo "🔨 Building SeaweedFS..."
  42. cd ../.. && make
  43. @echo "✅ Build complete"
  44. # Initialize go module (if needed)
  45. init-module:
  46. @if [ ! -f go.mod ]; then \
  47. echo "📦 Initializing Go module..."; \
  48. go mod init seaweedfs-fuse-tests; \
  49. go mod tidy; \
  50. fi
  51. # Run all tests
  52. test: check-prereqs init-module
  53. @echo "🧪 Running all FUSE integration tests..."
  54. go test -v -timeout $(TEST_TIMEOUT) ./...
  55. # Run tests with coverage
  56. test-coverage: check-prereqs init-module
  57. @echo "🧪 Running tests with coverage..."
  58. go test -v -timeout $(TEST_TIMEOUT) -coverprofile=$(COVERAGE_FILE) ./...
  59. go tool cover -html=$(COVERAGE_FILE) -o coverage.html
  60. @echo "📊 Coverage report generated: coverage.html"
  61. # Run specific test categories
  62. test-basic: check-prereqs init-module
  63. @echo "🧪 Running basic file operations tests..."
  64. go test -v -timeout $(TEST_TIMEOUT) -run TestBasicFileOperations
  65. test-directory: check-prereqs init-module
  66. @echo "🧪 Running directory operations tests..."
  67. go test -v -timeout $(TEST_TIMEOUT) -run TestDirectoryOperations
  68. test-concurrent: check-prereqs init-module
  69. @echo "🧪 Running concurrent operations tests..."
  70. go test -v -timeout $(TEST_TIMEOUT) -run TestConcurrentFileOperations
  71. test-stress: check-prereqs init-module
  72. @echo "🧪 Running stress tests..."
  73. go test -v -timeout $(TEST_TIMEOUT) -run TestStressOperations
  74. test-large-files: check-prereqs init-module
  75. @echo "🧪 Running large file tests..."
  76. go test -v -timeout $(TEST_TIMEOUT) -run TestLargeFileOperations
  77. # Run tests with debugging enabled
  78. test-debug: check-prereqs init-module
  79. @echo "🔍 Running tests with debug output..."
  80. go test -v -timeout $(TEST_TIMEOUT) -args -debug
  81. # Run tests and keep temp files for inspection
  82. test-no-cleanup: check-prereqs init-module
  83. @echo "🧪 Running tests without cleanup (for debugging)..."
  84. go test -v -timeout $(TEST_TIMEOUT) -args -no-cleanup
  85. # Quick smoke test
  86. test-smoke: check-prereqs init-module
  87. @echo "💨 Running smoke tests..."
  88. go test -v -timeout 5m -run TestBasicFileOperations/CreateAndReadFile
  89. # Run benchmarks
  90. benchmark: check-prereqs init-module
  91. @echo "📈 Running benchmarks..."
  92. go test -v -timeout $(TEST_TIMEOUT) -bench=. -benchmem
  93. # Validate test files compile
  94. validate: init-module
  95. @echo "✅ Validating test files..."
  96. go build -o /dev/null ./...
  97. @echo "✅ All test files compile successfully"
  98. # Clean up generated files
  99. clean:
  100. @echo "🧹 Cleaning up..."
  101. rm -f $(COVERAGE_FILE) coverage.html
  102. rm -rf /tmp/seaweedfs_fuse_test_*
  103. go clean -testcache
  104. @echo "✅ Cleanup complete"
  105. # Format Go code
  106. fmt:
  107. @echo "🎨 Formatting Go code..."
  108. go fmt ./...
  109. # Run linter
  110. lint:
  111. @echo "🔍 Running linter..."
  112. @if command -v golangci-lint >/dev/null 2>&1; then \
  113. golangci-lint run; \
  114. else \
  115. echo "⚠️ golangci-lint not found, running go vet instead"; \
  116. go vet ./...; \
  117. fi
  118. # Run all quality checks
  119. check: validate lint fmt
  120. @echo "✅ All quality checks passed"
  121. # Install development dependencies
  122. install-deps:
  123. @echo "📦 Installing development dependencies..."
  124. go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
  125. go mod download
  126. go mod tidy
  127. # Quick development setup
  128. setup: install-deps build check-prereqs
  129. @echo "🚀 Development environment ready!"
  130. # Docker-based testing
  131. test-docker:
  132. @echo "🐳 Running tests in Docker..."
  133. docker build -t seaweedfs-fuse-tests -f Dockerfile.test ../..
  134. docker run --rm --privileged seaweedfs-fuse-tests
  135. # Create Docker test image
  136. docker-build:
  137. @echo "🐳 Building Docker test image..."
  138. @cat > Dockerfile.test << 'EOF' ;\
  139. FROM golang:$(GO_VERSION) ;\
  140. RUN apt-get update && apt-get install -y fuse ;\
  141. WORKDIR /seaweedfs ;\
  142. COPY . . ;\
  143. RUN make ;\
  144. WORKDIR /seaweedfs/test/fuse ;\
  145. RUN go mod init seaweedfs-fuse-tests && go mod tidy ;\
  146. CMD ["make", "test"] ;\
  147. EOF
  148. # GitHub Actions workflow
  149. generate-workflow:
  150. @echo "📝 Generating GitHub Actions workflow..."
  151. @mkdir -p ../../.github/workflows
  152. @cat > ../../.github/workflows/fuse-integration.yml << 'EOF' ;\
  153. name: FUSE Integration Tests ;\
  154. ;\
  155. on: ;\
  156. push: ;\
  157. branches: [ master, main ] ;\
  158. pull_request: ;\
  159. branches: [ master, main ] ;\
  160. ;\
  161. jobs: ;\
  162. fuse-integration: ;\
  163. runs-on: ubuntu-latest ;\
  164. timeout-minutes: 45 ;\
  165. ;\
  166. steps: ;\
  167. - name: Checkout code ;\
  168. uses: actions/checkout@v4 ;\
  169. ;\
  170. - name: Set up Go ;\
  171. uses: actions/setup-go@v4 ;\
  172. with: ;\
  173. go-version: '$(GO_VERSION)' ;\
  174. ;\
  175. - name: Install FUSE ;\
  176. run: sudo apt-get update && sudo apt-get install -y fuse ;\
  177. ;\
  178. - name: Build SeaweedFS ;\
  179. run: make ;\
  180. ;\
  181. - name: Run FUSE Integration Tests ;\
  182. run: | ;\
  183. cd test/fuse ;\
  184. make test ;\
  185. ;\
  186. - name: Upload test artifacts ;\
  187. if: failure() ;\
  188. uses: actions/upload-artifact@v3 ;\
  189. with: ;\
  190. name: test-logs ;\
  191. path: /tmp/seaweedfs_fuse_test_* ;\
  192. EOF
  193. @echo "✅ GitHub Actions workflow generated"
  194. # Performance profiling
  195. profile: check-prereqs init-module
  196. @echo "📊 Running performance profiling..."
  197. go test -v -timeout $(TEST_TIMEOUT) -cpuprofile cpu.prof -memprofile mem.prof -bench=.
  198. @echo "📊 Profiles generated: cpu.prof, mem.prof"
  199. @echo "📊 View with: go tool pprof cpu.prof"
  200. # Memory leak detection
  201. test-memory: check-prereqs init-module
  202. @echo "🔍 Running memory leak detection..."
  203. go test -v -timeout $(TEST_TIMEOUT) -race -test.memprofile mem.prof
  204. # List available test functions
  205. list-tests:
  206. @echo "📋 Available test functions:"
  207. @grep -r "^func Test" *.go | sed 's/.*func \(Test[^(]*\).*/ \1/' | sort
  208. # Get test status and statistics
  209. test-stats: check-prereqs init-module
  210. @echo "📊 Test statistics:"
  211. @go test -v ./... | grep -E "(PASS|FAIL|RUN)" | \
  212. awk '{ \
  213. if ($$1 == "RUN") tests++; \
  214. else if ($$1 == "PASS") passed++; \
  215. else if ($$1 == "FAIL") failed++; \
  216. } END { \
  217. printf " Total tests: %d\n", tests; \
  218. printf " Passed: %d\n", passed; \
  219. printf " Failed: %d\n", failed; \
  220. printf " Success rate: %.1f%%\n", (passed/tests)*100; \
  221. }'
  222. # Watch for file changes and run tests
  223. watch:
  224. @echo "👀 Watching for changes..."
  225. @if command -v entr >/dev/null 2>&1; then \
  226. find . -name "*.go" | entr -c make test-smoke; \
  227. else \
  228. echo "⚠️ 'entr' not found. Install with: apt-get install entr"; \
  229. echo " Falling back to manual test run"; \
  230. make test-smoke; \
  231. fi
  232. # Show help
  233. help:
  234. @echo "SeaweedFS FUSE Integration Testing"
  235. @echo "=================================="
  236. @echo ""
  237. @echo "Prerequisites:"
  238. @echo " make check-prereqs - Check all prerequisites"
  239. @echo " make setup - Complete development setup"
  240. @echo " make build - Build SeaweedFS binary"
  241. @echo ""
  242. @echo "Testing:"
  243. @echo " make test - Run all tests"
  244. @echo " make test-basic - Run basic file operations tests"
  245. @echo " make test-directory - Run directory operations tests"
  246. @echo " make test-concurrent - Run concurrent operations tests"
  247. @echo " make test-stress - Run stress tests"
  248. @echo " make test-smoke - Quick smoke test"
  249. @echo " make test-coverage - Run tests with coverage report"
  250. @echo ""
  251. @echo "Debugging:"
  252. @echo " make test-debug - Run tests with debug output"
  253. @echo " make test-no-cleanup - Keep temp files for inspection"
  254. @echo " make profile - Performance profiling"
  255. @echo " make test-memory - Memory leak detection"
  256. @echo ""
  257. @echo "Quality:"
  258. @echo " make validate - Validate test files compile"
  259. @echo " make lint - Run linter"
  260. @echo " make fmt - Format code"
  261. @echo " make check - Run all quality checks"
  262. @echo ""
  263. @echo "Utilities:"
  264. @echo " make clean - Clean up generated files"
  265. @echo " make list-tests - List available test functions"
  266. @echo " make test-stats - Show test statistics"
  267. @echo " make watch - Watch files and run smoke tests"
  268. @echo ""
  269. @echo "Docker & CI:"
  270. @echo " make test-docker - Run tests in Docker"
  271. @echo " make generate-workflow - Generate GitHub Actions workflow"
  272. .PHONY: help check-prereqs check-binary check-fuse check-go build init-module \
  273. test test-coverage test-basic test-directory test-concurrent test-stress \
  274. test-large-files test-debug test-no-cleanup test-smoke benchmark validate \
  275. clean fmt lint check install-deps setup test-docker docker-build \
  276. generate-workflow profile test-memory list-tests test-stats watch