-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (250 loc) · 8.4 KB
/
Makefile
File metadata and controls
286 lines (250 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# FACT System Testing Makefile
# Provides convenient commands for running tests, benchmarks, and monitoring
.PHONY: help test test-unit test-integration test-performance test-security test-all
.PHONY: benchmark benchmark-continuous coverage clean setup install-test-deps
.PHONY: validate-targets monitor lint format
# Default target
help:
@echo "🧪 FACT System Testing Commands"
@echo "================================"
@echo ""
@echo "Test Commands:"
@echo " make test-unit - Run unit tests"
@echo " make test-integration - Run integration tests"
@echo " make test-performance - Run performance benchmarks"
@echo " make test-security - Run security tests"
@echo " make test-all - Run complete test suite"
@echo ""
@echo "Benchmark Commands:"
@echo " make benchmark - Run performance benchmarks"
@echo " make benchmark-continuous DURATION=10 - Run continuous benchmarks (minutes)"
@echo " make validate-targets - Validate performance targets"
@echo ""
@echo "Development Commands:"
@echo " make coverage - Generate test coverage report"
@echo " make setup - Setup test environment"
@echo " make install-test-deps - Install test dependencies"
@echo " make clean - Clean test artifacts"
@echo " make lint - Run code linting"
@echo " make format - Format code"
@echo ""
@echo "Monitoring Commands:"
@echo " make monitor - Start continuous monitoring"
# Setup and dependencies
setup: install-test-deps
@echo "🔧 Setting up FACT test environment..."
@mkdir -p test_results logs
@mkdir -p tests/{unit,integration,performance,security}
@echo "✅ Test environment setup complete"
install-test-deps:
@echo "📦 Installing test dependencies..."
@pip install -r requirements-test.txt
@echo "✅ Test dependencies installed"
# Unit tests
test-unit:
@echo "🧪 Running unit tests..."
@python -m pytest tests/unit/ -v \
--tb=short \
--cov=src \
--cov-report=term-missing \
--cov-report=html:test_results/coverage_html \
--junitxml=test_results/unit_tests.xml \
-m "not slow"
# Integration tests
test-integration:
@echo "🔗 Running integration tests..."
@python -m pytest tests/integration/ -v \
--tb=short \
-m "integration" \
--junitxml=test_results/integration_tests.xml
# Performance benchmarks
test-performance:
@echo "📈 Running performance benchmarks..."
@python -m pytest tests/performance/ -v \
--tb=short \
-m "performance" \
--benchmark-only \
--benchmark-json=test_results/benchmark_results.json \
--junitxml=test_results/performance_tests.xml
# Security tests
test-security:
@echo "🛡️ Running security tests..."
@python -m pytest tests/unit/ tests/integration/ -v \
--tb=short \
-m "security" \
--junitxml=test_results/security_tests.xml
# Complete test suite
test-all:
@echo "🚀 Running complete FACT test suite..."
@python tests/test_runner.py --test-type all --verbose
# Fast test run (skip slow tests)
test:
@echo "⚡ Running fast test suite..."
@python tests/test_runner.py --test-type all --skip-slow
# Benchmark commands
benchmark: test-performance
benchmark-continuous:
@echo "📊 Running continuous benchmarks for $(DURATION) minutes..."
@python tests/test_runner.py --continuous $(DURATION)
validate-targets:
@echo "🎯 Validating performance targets..."
@python tests/test_runner.py --test-type performance --validate-targets
# Coverage reporting
coverage:
@echo "📊 Generating comprehensive coverage report..."
@python -m pytest tests/unit/ tests/integration/ \
--cov=src \
--cov-report=html:test_results/coverage_html \
--cov-report=term \
--cov-report=xml:test_results/coverage.xml \
--cov-fail-under=80
@echo "📁 Coverage report available at test_results/coverage_html/index.html"
# Monitoring and continuous integration
monitor:
@echo "📊 Starting continuous monitoring..."
@while true; do \
echo "🔄 Running monitoring cycle at $$(date)"; \
python tests/test_runner.py --test-type performance --validate-targets; \
echo "😴 Sleeping for 5 minutes..."; \
sleep 300; \
done
# Code quality
lint:
@echo "🔍 Running code linting..."
@python -m flake8 src/ tests/ --max-line-length=100
@python -m mypy src/ --ignore-missing-imports
@echo "✅ Linting complete"
format:
@echo "🎨 Formatting code..."
@python -m black src/ tests/ --line-length=100
@python -m isort src/ tests/
@echo "✅ Code formatting complete"
# Database tests
test-database:
@echo "🗄️ Running database-specific tests..."
@python -m pytest tests/unit/test_database_operations.py tests/integration/ -v \
-m "database" \
--junitxml=test_results/database_tests.xml
# Cache tests
test-cache:
@echo "⚡ Running cache-specific tests..."
@python -m pytest tests/unit/test_cache_mechanism.py tests/integration/ -v \
-m "cache" \
--junitxml=test_results/cache_tests.xml
# Tool tests
test-tools:
@echo "🔧 Running tool framework tests..."
@python -m pytest tests/unit/test_tool_framework.py tests/integration/ -v \
-m "tools" \
--junitxml=test_results/tools_tests.xml
# Performance analysis
analyze-performance:
@echo "📈 Analyzing performance results..."
@python -c "
import json
from pathlib import Path
results_file = Path('test_results/benchmark_results.json')
if results_file.exists():
with open(results_file) as f:
data = json.load(f)
print('📊 Performance Analysis:')
# Add performance analysis logic here
else:
print('❌ No benchmark results found. Run make benchmark first.')
"
# Load testing
load-test:
@echo "🚛 Running load tests..."
@python -m pytest tests/performance/ -v \
-k "load or concurrent or throughput" \
--junitxml=test_results/load_tests.xml
# Stress testing
stress-test:
@echo "💪 Running stress tests..."
@python -m pytest tests/performance/ -v \
-k "stress or sustained or memory" \
--junitxml=test_results/stress_tests.xml
# Clean up
clean:
@echo "🧹 Cleaning test artifacts..."
@rm -rf test_results/*
@rm -rf .pytest_cache
@rm -rf __pycache__
@find . -name "*.pyc" -delete
@find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
@echo "✅ Cleanup complete"
# Development workflow
dev-test:
@echo "🔄 Running development test cycle..."
@make test-unit
@make test-integration
@make validate-targets
# CI/CD pipeline simulation
ci-pipeline:
@echo "🚀 Running CI/CD pipeline simulation..."
@make lint
@make test-all
@make coverage
@make validate-targets
@echo "✅ CI/CD pipeline complete"
# Generate test report
report:
@echo "📋 Generating comprehensive test report..."
@python -c "
import json
import os
from datetime import datetime
from pathlib import Path
# Collect all test results
results_dir = Path('test_results')
report = {
'timestamp': datetime.now().isoformat(),
'test_files': [],
'summary': {'total': 0, 'passed': 0, 'failed': 0}
}
for xml_file in results_dir.glob('*_tests.xml'):
report['test_files'].append(str(xml_file))
# Save report
with open(results_dir / 'test_report.json', 'w') as f:
json.dump(report, f, indent=2)
print('📊 Test report generated at test_results/test_report.json')
"
# Variables
DURATION ?= 10
# Special targets for different environments
test-docker:
@echo "🐳 Running tests in Docker environment..."
@docker run --rm -v $(PWD):/app -w /app python:3.9 make test-all
test-local:
@echo "🏠 Running tests in local environment..."
@make test-all
# Help for specific test categories
help-performance:
@echo "📈 Performance Testing Help"
@echo "=========================="
@echo ""
@echo "Available performance tests:"
@echo " - Cache hit latency (target: <50ms)"
@echo " - Cache miss latency (target: <140ms)"
@echo " - Tool execution (target: <10ms)"
@echo " - Overall response (target: <100ms)"
@echo " - Cost reduction validation"
@echo " - Throughput testing"
@echo ""
@echo "Commands:"
@echo " make benchmark - Run all performance tests"
@echo " make validate-targets - Check if targets are met"
@echo " make load-test - Run load testing"
@echo " make stress-test - Run stress testing"
help-coverage:
@echo "📊 Coverage Testing Help"
@echo "======================="
@echo ""
@echo "Coverage targets:"
@echo " - Unit test coverage: >90%"
@echo " - Integration coverage: >80%"
@echo " - Overall coverage: >85%"
@echo ""
@echo "Commands:"
@echo " make coverage - Generate coverage report"
@echo " make test-unit - Run tests with coverage"