-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.mk
More file actions
165 lines (149 loc) · 5.56 KB
/
Copy pathtests.mk
File metadata and controls
165 lines (149 loc) · 5.56 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
# Testing Framework - Diagnostic tests for tracer and server
# Used to generate test data for flame graph analysis
# Test configuration
TESTS_DIR = tests
TESTS_OUTPUT_DIR = $(TARGET_DIR)/test_output
CXX_TEST_FLAGS := -std=c++17 \
-O0 \
-g \
-fno-inline \
-fno-omit-frame-pointer \
-fno-optimize-sibling-calls \
-pthread
# Create test output directory
.PHONY: test-setup
test-setup:
@mkdir -p $(TESTS_OUTPUT_DIR)
# ============= RUST TEST TARGETS =============
# Build all Rust test binaries
.PHONY: build-rust-tests
build-rust-tests: test-setup
@echo "🦀 Building Rust test programs..."
@for test_file in $(TESTS_DIR)/*_test.rs; do \
if [ -f "$$test_file" ]; then \
test_name=$$(basename "$$test_file" .rs); \
echo "📦 Building $$test_name..."; \
rustc "$$test_file" -o "$(TESTS_OUTPUT_DIR)/$$test_name" || exit 1; \
fi \
done
# Build specific Rust test
$(TESTS_OUTPUT_DIR)/%_test: $(TESTS_DIR)/%_test.rs | test-setup
@echo "📦 Building $*_test..."
@rustc $< -o $@
# ============= C++ TEST TARGETS =============
# Build all C++ test binaries
.PHONY: build-cpp-tests
build-cpp-tests: test-setup
@echo "⚙️ Building C++ test programs..."
@for test_file in $(TESTS_DIR)/*_test.cpp; do \
if [ -f "$$test_file" ]; then \
test_name=$$(basename "$$test_file" .cpp); \
echo "📦 Building $$test_name..."; \
g++ $(CXX_TEST_FLAGS) "$$test_file" -o "$(TESTS_OUTPUT_DIR)/$$test_name" || exit 1; \
fi \
done
# Build specific C++ test
$(TESTS_OUTPUT_DIR)/%_test: $(TESTS_DIR)/%_test.cpp | test-setup
@echo "📦 Building $*_test..."
@g++ $(CXX_TEST_FLAGS) $< -o $@
# ============= TEST EXECUTION =============
# Run specific test with tracer
.PHONY: run-test-%
run-test-%: $(TESTS_OUTPUT_DIR)/%_test tracer-lib
@echo "🧪 Running $*_test with memory tracer..."
@if [ -f "$(TESTS_DIR)/$*_test.in" ]; then \
echo "📥 Using input file: $(TESTS_DIR)/$*_test.in"; \
echo "Command: LD_PRELOAD=$(TRACER_LIB) $(TESTS_OUTPUT_DIR)/$*_test < $(TESTS_DIR)/$*_test.in"; \
LD_PRELOAD=$(TRACER_LIB) $(TESTS_OUTPUT_DIR)/$*_test < $(TESTS_DIR)/$*_test.in; \
else \
echo "Command: LD_PRELOAD=$(TRACER_LIB) $(TESTS_OUTPUT_DIR)/$*_test"; \
LD_PRELOAD=$(TRACER_LIB) $(TESTS_OUTPUT_DIR)/$*_test; \
fi
# ============= INTERACTIVE TEST SELECTION =============
.PHONY: test-select
test-select: build-rust-tests build-cpp-tests tracer-lib
@echo "🎯 Available test programs:"
@echo "Select a test to run with tracer:"
@tests_list=$$(find $(TESTS_OUTPUT_DIR) -name "*_test" -executable -type f | sort); \
if [ -z "$$tests_list" ]; then \
echo "❌ No test programs found. Create test files in $(TESTS_DIR)/ with *_test.rs or *_test.cpp suffix"; \
exit 1; \
fi; \
select test_prog in $$tests_list "Exit"; do \
case $$test_prog in \
"Exit") \
echo "👋 Exiting test selection"; \
break; \
;; \
"") \
echo "❌ Invalid selection. Please try again."; \
;; \
*) \
echo "🧪 Running $$test_prog with memory tracer..."; \
test_name=$$(basename "$$test_prog" _test); \
input_file="$(TESTS_DIR)/$${test_name}_test.in"; \
if [ -f "$$input_file" ]; then \
echo "📥 Using input file: $$input_file"; \
echo "Command: LD_PRELOAD=$(TRACER_LIB) $$test_prog < $$input_file"; \
LD_PRELOAD=$(TRACER_LIB) "$$test_prog" < "$$input_file"; \
else \
echo "Command: LD_PRELOAD=$(TRACER_LIB) $$test_prog"; \
LD_PRELOAD=$(TRACER_LIB) "$$test_prog"; \
fi; \
break; \
;; \
esac; \
done
# ============= UTILITY TARGETS =============
# List available tests
.PHONY: list-tests
list-tests:
@echo "📋 Available test source files:"
@if [ -d "$(TESTS_DIR)" ]; then \
find $(TESTS_DIR) -name "*_test.rs" -o -name "*_test.cpp" | sort || echo " No test files found"; \
else \
echo " Tests directory $(TESTS_DIR) does not exist"; \
fi
@echo ""
@echo "📋 Built test binaries:"
@if [ -d "$(TESTS_OUTPUT_DIR)" ]; then \
find $(TESTS_OUTPUT_DIR) -name "*_test" -executable -type f | sort || echo " No test binaries found"; \
else \
echo " Test output directory $(TESTS_OUTPUT_DIR) does not exist"; \
fi
# Clean test artifacts
.PHONY: clean-tests
clean-tests:
@echo "🧹 Cleaning test artifacts..."
@rm -rf $(TESTS_OUTPUT_DIR)
# Help for testing
.PHONY: test-help
test-help:
@echo "🧪 Testing Framework Help"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "📁 Test file naming convention:"
@echo " Rust tests: $(TESTS_DIR)/<name>_test.rs"
@echo " C++ tests: $(TESTS_DIR)/<name>_test.cpp"
@echo " Input files: $(TESTS_DIR)/<name>_test.in (optional, for interactive tests)"
@echo ""
@echo "🎯 Build targets:"
@echo " build-rust-tests - Build all Rust test programs"
@echo " build-cpp-tests - Build all C++ test programs"
@echo ""
@echo "🚀 Run targets:"
@echo " run-test-<name> - Run specific test with tracer"
@echo " test-select - Interactive test selection menu"
@echo ""
@echo "📋 Utility targets:"
@echo " list-tests - List available test files and binaries"
@echo " clean-tests - Clean test artifacts"
@echo ""
@echo "💡 Example usage:"
@echo " make run-test-malloc # Run malloc_test program"
@echo " make run-test-interactive # Run interactive_test with input file"
@echo " make test-select # Interactive selection"
@echo ""
@echo "💡 Features:"
@echo " - Automatic input redirection for .in files"
@echo " - Interactive test selection menu"
@echo " - Memory tracing with $(TRACER_LIB)"