-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakeCommon
198 lines (160 loc) · 7.29 KB
/
MakeCommon
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
SRC = ../src
INC = $(SRC)
INC_PUBLIC = ../inc
LIBPATH = ../lib/$(PLATFORM)
INC_FILES = $(INC_PUBLIC)/AccuTrak.h $(INC)/PatchManager.h $(INC)/PatchSym.h $(INC)/FuncTypes.h $(INC)/ReplacementMalloc.h $(INC)/ReplacementMallocImpl.h $(INC)/SysAlloc.h $(INC)/MallocLogger.h
LIBACCUTRAK = $(LIBPATH)/libaccutrak.$(LIBSUFFIX)
TARGETS = $(LIBACCUTRAK) MallocLogViewer MallocLogConsolidator MallocReplay ##MallocHeapViewer
all: $(TARGETS) TestSuite
$(LIBACCUTRAK): AccuTrak.o PatchManager.o $(PATCHFORMAT).o ConfigParser.o SysAlloc.o MallocDeadPage.o MallocPadding.o MallocPrivateHeap.o MallocLogger.o $(BACKTRACE).o Utility.o
$(LINKER) $(LINK_OPT) $(AT_EXP) -o $@ $^ $(SYSLIBS)
################################################################################
# object rule
################################################################################
%.o: $(SRC)/%.cpp $(INC_FILES)
$(COMPILER) $(COMP_OPT) $<
################################################################################
# Utlity tool executable rule
################################################################################
%: %.o Utility.o
$(LINKER) $(EXEC_LDFLAGS) -o $@ $^ $(SYSLIBS)
# special tool rule
MallocReplay: MallocReplay.o PerfCounter.o CustomMalloc.o $(ATOMICOBJ)
$(LINKER) $(EXEC_LDFLAGS) -o $@ $^ -L$(LIBPATH) $(LINK_MBLIB) $(LINK_SHLIB) $(SYSLIBS)
MallocHeapViewer: MallocHeapViewer.o
$(LINKER) $(EXEC_LDFLAGS) -o $@ $^ $(SYSLIBS)
# $(LINKER) $(EXEC_LDFLAGS) -o $@ $^ $(SYSLIBS) -L$(CHART_LIB_PATH) -lM8Chart -lpgunix -lcairo -lpng12 -lM8Base4 -lM7XptVec -lM8FileSystem -lM8DatTy4 -lM8icuuc22 -lM8icudata -lM8icuin22 -lM7XptPdf -lM8Synch4 -lM8CurIni
HeapImage.o: $(SRC)/HeapImage.cpp
$(COMPILER) $(COMP_OPT) -DNDEBUG $(MSTR_INC) $<
################################################################################
# tests suite
################################################################################
TESTSRC = ../test_src
TestSuite: TestPatch TestOverrun TestUnderrun TestPatchDSO libfoo.$(LIBSUFFIX) TestRealloc TestPreLoad TestNew \
TestRecord TestSize TestAccessFree TestDoubleFree TestBenchmark $(EXTRA_TEST)
TestObjs = TestPatch.o TestOverrun.o TestUnderrun.o TestPatchDSO.o \
TestRealloc.o TestPreLoad.o TestNew.o \
TestRecord.o TestSize.o TestAccessFree.o TestDoubleFree.o TestBenchmark.o
.SECONDARY: $(TestObjs)
################################################################################
# test object/executable rule
################################################################################
Test%.o: $(TESTSRC)/Test%.cpp $(INC_FILES)
$(COMPILER) $(COMP_OPT) $<
foo.o: $(TESTSRC)/foo.cpp
$(COMPILER) $(COMP_OPT) $<
# test executable rule
Test%: Test%.o $(LIBACCUTRAK)
$(LINKER) $(EXEC_LDFLAGS) -o $@ $< -L$(LIBPATH) $(SYSLIBS)
# special executable rule
libfoo.${LIBSUFFIX}: foo.o
$(LINKER) $(LINK_OPT) -o $@ $< -L$(LIBPATH) $(SYSLIBS)
TestPreLoad: TestPreLoad.o libfoo.${LIBSUFFIX}
$(LINKER) $(EXEC_LDFLAGS) -o $@ $< -ldl -L./ -lfoo
TestPrivateHeap: TestPrivateHeap.o libfoo.${LIBSUFFIX} $(LIBACCUTRAK)
$(LINKER) $(EXEC_LDFLAGS) -o $@ $< -L$(LIBPATH) -laccutrak -lsmartheap_smp64 -L./ -lfoo
clean:
-rm *.o core* $(TARGETS)
-rm Test* lib*
#use command: "make -k -s run" to run whole test suite
run: Test1 Test2 Test3 Test4 Test5 Test6 Test7 Test8 Test9
################################################################################
# run tests
################################################################################
Test1: TestPatch
echo "-------------------------------------------"
echo "Test1 symbol patching"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatch.ini; \
export LD_LIBRARY_PATH=$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestPatch"
Test2: TestOverrun
echo "-------------------------------------------"
echo "Test2 over run checking, should seg fault"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatch.ini; \
export LD_LIBRARY_PATH=$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestOverrun"
Test3: TestUnderrun
echo "-------------------------------------------"
echo "Test3 under run checking, should seg fault"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestUnderrun.ini; \
export LD_LIBRARY_PATH=$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestUnderrun"
Test4: TestPatchDSO libfoo.${LIBSUFFIX}
echo "-------------------------------------------"
echo "Test4 DSO symbol patching"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatchDSO.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestPatchDSO"
Test5: TestRealloc
echo "-------------------------------------------"
echo "Test5 realloc"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatch.ini; \
export LD_LIBRARY_PATH=$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestRealloc"
Test6: TestPreLoad
echo "-------------------------------------------"
echo "Test6 preload AccuTrak (only if OS support PRELOAD)"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatchDSO.ini; \
export LD_PRELOAD=$(LIBACCUTRAK); \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
./TestPreLoad"
Test7: TestNew
echo "-------------------------------------------"
echo "Test7 patch operator new, over run checking, should seg fault"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPatch.ini; \
export LD_LIBRARY_PATH=$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestNew"
Test8: TestPrivateHeap
echo "-------------------------------------------"
echo "Test8 Allocate memory from private heap in libfoo.so"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestPrivateHeap.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestPrivateHeap"
Test9: TestRecord libfoo.${LIBSUFFIX}
echo "-------------------------------------------"
echo "Test9 Record all"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestRecord.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestRecord"
Test10: TestSize
echo "-------------------------------------------"
echo "Test10 Track blocks within size range"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestSize.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestSize"
Test11: TestAccessFree
echo "-------------------------------------------"
echo "Test11 Touch freed block and we should seg fault"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestAccessFree.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestAccessFree"
Test12: TestDoubleFree
echo "-------------------------------------------"
echo "Test12 Free a block twice and we should be stopped by AccuTrak"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestDoubleFree.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
./TestDoubleFree"
Test13: TestBenchmark
echo "-------------------------------------------"
echo "Test13 Allocate memory in multiple threads in deadpage mode"
/bin/bash -c "export AT_CONFIG_FILE=$(TESTSRC)/TestBenchmark.ini; \
export LD_LIBRARY_PATH=./:$(LIBPATH); \
export LIBPATH=./:$(LIBPATH); \
export LD_PRELOAD=$(LIBACCUTRAK); \
/usr/bin/time -p ./TestBenchmark"