-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildtools.py
1024 lines (951 loc) · 47.3 KB
/
buildtools.py
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os, sys, threading, shutil, re
import xml.etree.ElementTree as ET
from subprocess import Popen, PIPE, STDOUT
import subprocess # Added for GPU
class BuildContext:
def __init__(self, args):
self.CPPFLAGS = ""
self.EXTRAFLAGS = ""
self.LDFLAGS = "-L${INSTALL_DIR}/lib"
self.LASTLDFLAGS = ""
self.JNIEXT = ""
self.JNILIBFLAGS = ""
self.JNIBINFLAGS = ""
self.SOFLAGS = ""
self.SOEXT = ""
self.IGNORE_SYS_PREFIXES = ()
self.INPUT_PREFIX = ""
self.THIRD_PARTY_INPUT_PREFIX = ""
self.OUTPUT_PREFIX = ""
self.TEST_PREFIX = ""
self.INPUT = {}
self.SRC_INCLUDE_DIRS = []
self.OBJ_INCLUDE_DIRS = ["3pty-install/include"]
self.THIRD_PARTY_INPUT = {}
self.TESTS = {}
self.PLATFORM = os.uname()[0]
self.LEVEL = "DEBUG"
self.TARGET = "BUILD"
self.NM = "/usr/bin/nm"
self.NMFLAGS = "-n" # specialized by platform in build.py
self.COVERAGE = False
self.PROFILE = False
# Compiler Configuration
self.CC = "gcc"
self.CXX = "g++"
self.COMPILER_NAME = "Unknown"
self.COMPILER_CONFIGURED = False
self.MAJORVERSION = 0
self.MINORVERSION = 0
self.PATCHLEVEL = 0
self.S2GEO_LIBS = ""
self.GENERATOR_CLASSES = []
for arg in [x.strip().upper() for x in args]:
if arg in ["DEBUG", "RELEASE", "MEMCHECK", "MEMCHECK_NOFREELIST"]:
self.LEVEL = arg
if arg in ["BUILD", "CLEAN", "TEST", "VOLTRUN", "VOLTDBIPC"]:
self.TARGET = arg
if arg in ["COVERAGE"]:
self.COVERAGE = True
if arg in ["PROFILE"]:
self.PROFILE = True
# Exec build.local if available, a python script provided with this
# BuildContext object as the update-able symbol BUILD. These example
# build.local lines force the use of clang instead of gcc/g++.
# BUILD.CC = "clang"
# BUILD.CXX = "clang"
buildLocal = os.path.join(os.path.dirname(__file__), "build.local")
if os.path.exists(buildLocal):
execfile(buildLocal, dict(BUILD = self))
def getOpenSSLVersion(self):
return self.OPENSSL_VERSION
def getOpenSSLToken(self):
if self.PLATFORM == 'Darwin':
return "darwin64-x86_64-cc"
if self.PLATFORM == 'Linux':
if self.compilerName() == 'gcc':
return "linux-x86_64:gcc -fpic"
print("ERROR: Don't know what platform to use to configure openssl.")
sys.exit(-1)
def compilerName(self):
self.getCompilerVersion()
if self.COMPILER_NAME:
return self.COMPILER_NAME
else:
return "UnknownCompiler"
def compilerMajorVersion(self):
self.getCompilerVersion()
return self.MAJORVERSION
def compilerMinorVersion(self):
self.getCompilerVersion()
return self.MINORVERSION
def compilerPatchLevel(self):
self.getCompilerVersion()
return self.PATCHLEVEL
def getCompilerVersion(self):
if self.COMPILER_CONFIGURED:
return
self.COMPILER_CONFIGURED = True
vinfo = output = Popen([self.CXX, "-v"], stderr=PIPE).communicate()[1]
self.MAJORVERSION = 0
self.MINORVERSION = 0
self.PATCHLEVEL = 0
vvector = [0, 0, 0]
# Apple now uses clang and has its own versioning system.
# The version 7 compiler needs special compilation options.
# This is pretty dumb code that could be improved as we support more
# compilers and versions.
# Xcode versions before 10.10
# Xcode version 10.11
# Clang built not from apple.
# gcc
patterns = [
[ r"based on LLVM ([.0-9]*)[^.0-9]", "clang"],
[ r"Apple LLVM version ([.0-9]*)[^.0-9]", "clang"],
[ r"clang version ([.0-9]*)[^.0-9]", "clang"],
[ r"gcc version ([.0-9]*)[^.0-9]", "gcc" ],
]
for pattern in patterns:
m = re.search(pattern[0], vinfo)
if m:
self.COMPILER_NAME = pattern[1]
vinfo = m.group(1)
vvector = vinfo.split(".")
break
if self.COMPILER_NAME == "Unknown":
print("Cannot find compiler version by running \"%s\"" % self.CXX)
else:
vlen = len(vvector)
if vlen > 0:
self.MAJORVERSION = int(vvector[0])
if vlen > 1:
self.MINORVERSION = int(vvector[1])
if vlen > 2:
self.PATCHLEVEL = int(vvector[2])
def readFile(filename):
"read a file into a string"
FH=open(filename, 'r')
fileString = FH.read()
FH.close()
return fileString
# get the volt version by reading buildstring.txt
version = "0.0.0"
try:
version = readFile("version.txt")
version = version.strip()
except:
print("ERROR: Unable to read version number from version.txt.")
sys.exit(-1)
# Replace the extension of filename with the
# new extension. If the filename does not
# have an extension, the new extension is just
# appended.
def replaceSuffix(name, suffix):
pos = name.rindex(".")
if pos < 0:
return name + suffix;
else:
return name[:pos] + suffix;
def outputNamesForSource(filename):
relativepath = "/".join(filename.split("/")[2:])
jni_objname = "objects/" + replaceSuffix(relativepath, ".o")
static_objname = "static_objects/" + replaceSuffix(relativepath, ".o")
return os.path.normpath(jni_objname), os.path.normpath(static_objname)
def namesForTestCode(filename):
relativepath = "/".join(filename.split("/")[2:])
binname = "cpptests/" + relativepath
sourcename = filename + ".cpp"
objectname = "static_objects/" + filename.split("/")[-1] + ".o"
return os.path.normpath(binname), os.path.normpath(objectname), os.path.normpath(sourcename)
def formatList(list):
str = ""
indent = 16
for name in list:
if indent + len(name) + 1 > 120:
str += " \\\n\t\t"
indent = 16
str += (" " + name)
indent += len(name) + 1
return str
def buildGeneratedTests(CTX, makefile, all_gen_tests):
makefile.write("########################################################################\n")
makefile.write("#\n")
makefile.write("# Generated C++ Tests.\n")
makefile.write("#\n")
makefile.write("########################################################################\n")
makefile.write("GENERATED_DIR=${OBJDIR}/generated\n")
makefile.write("GENERATED_SRC=$(GENERATED_DIR)/src\n")
makefile.write("GENERATED_OBJ=$(GENERATED_DIR)/obj\n")
makefile.write("GENERATED_BIN=$(GENERATED_DIR)/bin\n")
makefile.write("\n")
makefile.write('GENERATED_FILES= \\\n')
for gtest in all_gen_tests:
makefile.write('\t${GENERATED_SRC}/%s/%s.cpp \\\n' % (gtest[0], gtest[1]))
makefile.write('\n')
makefile.write("GENERATED_OBJS=$(subst $(GENERATED_SRC),$(GENERATED_OBJ),$(patsubst %.cpp,%.o,${GENERATED_FILES}))\n")
makefile.write("GENERATED_TESTS=$(subst $(GENERATED_SRC),$(GENERATED_BIN),$(patsubst %.cpp,%,${GENERATED_FILES}))\n")
makefile.write("\n")
makefile.write("${GENERATED_BIN}/%: ${GENERATED_OBJ}/%.o objects/harness.o objects/volt.a \\\n")
makefile.write(" | make-generated-dirs build-third-party-tools\n")
makefile.write('\t@mkdir -p $(shell dirname "$@")\n')
makefile.write("\t$(LINK.cpp) -o $@ $< objects/harness.o objects/volt.a $(LASTLDFLAGS)\n")
makefile.write("\n")
makefile.write('${GENERATED_OBJ}/%.o: ${GENERATED_SRC}/%.cpp\n')
makefile.write('\t@mkdir -p $(shell dirname "$@")\n')
makefile.write("\t$(CCACHE) $(COMPILE.cpp) -I$(ROOTDIR)/$(TEST_PREFIX) -MMD -MP -o $@ $<\n")
makefile.write("\n")
makefile.write("build-generated-tests: ${GENERATED_TESTS}\n")
makefile.write("clean-generated-tests:\n")
makefile.write("\trm -rf ${GENERATED_OBJ}/* ${GENERATED_BIN}/*\n")
makefile.write('\n')
makefile.write('make-generated-dirs: ${GENERATED_DIR}\n')
makefile.write('\tmkdir -p ${GENERATED_OBJ} ${GENERATED_BIN}\n')
makefile.write('\n')
def buildThirdPartyTools(CTX, makefile):
makefile.write("########################################################################\n")
makefile.write("#\n")
makefile.write("# Third Party Tools Section Start\n")
makefile.write("#\n")
makefile.write("########################################################################\n")
makefile.write('#\n# Force all third party libraries and tools to be\n')
makefile.write('# configured and built and built here.\n#\n')
makefile.write('# openssl - We use this only to get the Bignum from libcrypto.\n')
makefile.write('# Note that this has to be before S2.\n');
makefile.write('# s2 - We use this for geospatial computations.\n');
makefile.write('# pcre2 - We use this for regular expressions.\n');
makefile.write('.PHONY: build-third-party-tools\n')
makefile.write('build-third-party-tools: build-openssl build-s2-geometry build-pcre2\n')
makefile.write('\n')
# define makefile variables for third party tools building use
makefile.write('#\n')
makefile.write('# These are the openssl library\'s source and install directories.\n')
makefile.write('# Note that we only use the BIGNUM functions from openssl.\n#\n')
makefile.write('OPENSSL_VERSION=%s\n' % CTX.OPENSSL_VERSION)
makefile.write('OPENSSL_SRC=${THIRD_PARTY_SRC}/openssl/openssl-${OPENSSL_VERSION}\n')
makefile.write('OPENSSL_INSTALL=${INSTALL_DIR}\n')
makefile.write('#\n')
makefile.write("# These are google S2 library's source and object directories.\n")
makefile.write("#\n")
makefile.write('GOOGLE_S2_SRC=${THIRD_PARTY_SRC}/google-s2-geometry\n')
makefile.write('GOOGLE_S2_INSTALL=${INSTALL_DIR}\n')
# tar ball third party tools
makefile.write('#\n')
makefile.write('# We keep tarballs of third party sources here.\n')
makefile.write('#\n')
makefile.write('TARBALLS_DIR=${THIRD_PARTY_SRC}/tarballs\n')
makefile.write('#\n')
makefile.write('# These are the PCRE2 library\'s source, build and install directories,\n')
makefile.write('# and the location of the source tarball\n')
makefile.write('PCRE2_VERSION=10.10\n')
makefile.write('PCRE2_NAME=pcre2-${PCRE2_VERSION}\n')
makefile.write('PCRE2_SRC=${THIRD_PARTY_SRC}/${PCRE2_NAME}\n')
makefile.write('PCRE2_OBJ=${OBJDIR}/${PCRE2_NAME}\n')
makefile.write('PCRE2_INSTALL=${INSTALL_DIR}\n')
makefile.write('PCRE2_TARBALL=${TARBALLS_DIR}/${PCRE2_NAME}.tar.bz2\n')
# define makefile target for debugging
makefile.write("#\n# This target lets us print makefile variables, for debugging\n")
makefile.write("#\n# the makefile.\n#\n")
makefile.write("echo_makefile_config:\n")
makefile.write('\t@echo "ROOTDIR = $(ROOTDIR)"\n')
makefile.write('\t@echo "OBJDIR = $(OBJDIR)"\n')
makefile.write('\t@echo "SRCDIR = $(SRCDIR)"\n')
makefile.write('\t@echo "THIRD_PARTY_SRC = $(THIRD_PARTY_SRC)"\n')
makefile.write('\t@echo "GOOGLE_S2_SRC = $(GOOGLE_S2_SRC)"\n')
makefile.write('\t@echo "GOOGLE_S2_INSTALL = $(GOOGLE_S2_INSTALL)"\n')
makefile.write('\t@echo "OPENSSL_SRC = $(OPENSSL_SRC)"\n')
makefile.write('\t@echo "OPENSSL_INSTALL = $(OPENSSL_INSTALL)"\n')
makefile.write('\t@echo "OPENSSL_VERSION = $(OPENSSL_VERSION)"\n')
makefile.write('\t@echo "GENERATED_TESTS = $(GENERATED_TESTS)"\n')
#
# start to build third party tools now
#
# OpenSSL
makefile.write('########################################################################\n')
makefile.write('# OpenSSL.\n')
makefile.write('########################################################################\n')
makefile.write('.PHONY: build-openssl configure-openssl compile-openssl install-openssl clean-openssl\n')
makefile.write('\n')
makefile.write('# OpenSSL\n')
makefile.write('build-openssl: configure-openssl compile-openssl install-openssl\n')
makefile.write('\n')
makefile.write('# If we have to configure openssl, first delete any.\n')
makefile.write('# existing installation. It confuses the configuration\n')
makefile.write('# and installation procedure.\n')
makefile.write('configure-openssl:\n')
makefile.write('\t(cd "${OPENSSL_SRC}"; \\\n')
makefile.write('\t if [ ! -f Makefile ] || [ Makefile -ot Makefile.org ] || [ ! -f "${INSTALL_DIR}/lib/libcrypto.a" ] || [ ! -f "${OPENSSL_SRC}/libcrypto.a" ] || [ ! -d "${INSTALL_DIR}/include/openssl" ] ; then \\\n')
makefile.write('\t rm -rf "${INSTALL_DIR}/include/openssl" "${INSTALL_DIR}/lib/libcrypto.a"; \\\n')
makefile.write('\t ./Configure "%s"; \\\n' % CTX.getOpenSSLToken() )
makefile.write('\t fi )\n')
makefile.write('\n')
makefile.write('compile-openssl: | configure-openssl\n')
makefile.write('\t(cd "$(OPENSSL_SRC)"; $(MAKE))\n')
makefile.write('\n')
makefile.write('install-openssl: | compile-openssl\n')
makefile.write('\tif [ ! -f "$(OPENSSL_INSTALL)/lib/libcrypto.a" ] ; then \\\n')
makefile.write('\t (cd "$(OPENSSL_SRC)"; $(MAKE) INSTALLTOP=\"$(OPENSSL_INSTALL)\" OPENSSLDIR=\"$(OPENSSL_INSTALL)\" install ) ; \\\n')
makefile.write('\tfi\n')
makefile.write('\n')
makefile.write('clean-openssl:\n')
makefile.write('\t(cd "${OPENSSL_SRC}"; $(MAKE) clean; mv Makefile Makefile.last)\n')
# Google S2
makefile.write('########################################################################\n')
makefile.write('# Google S2.\n')
makefile.write('########################################################################\n')
makefile.write("#\n# Google S2 uses cmake, which has different names for the\n")
makefile.write("# build types. It's easier to translate them here than to\n")
makefile.write("# reconfigure cmake.\n#\n")
makefile.write('ifeq (${BUILD},debug)\n')
makefile.write('S2_BUILD_TYPE=Debug\n')
makefile.write('else ifeq (${BUILD},memcheck)\n')
makefile.write('S2_BUILD_TYPE=Debug\n')
makefile.write('else ifeq (${BUILD},memcheck_nofreelist)\n')
makefile.write('S2_BUILD_TYPE=Debug\n')
makefile.write('else ifeq (${BUILD},release)\n')
makefile.write('S2_BUILD_TYPE=Release\n')
makefile.write('endif\n')
makefile.write('ifeq (${S2_BUILD_TYPE},)\n')
makefile.write('$(error "Unknown build type for S2 ($BUILD should be debug, release, memcheck, memcheck_nofreelist")\n')
makefile.write('endif\n')
makefile.write('\n')
makefile.write('.PHONY: build-s2-geometry configure-s2-geometry clean-s2-geometry\n')
makefile.write('build-s2-geometry: configure-s2-geometry | build-openssl \n')
makefile.write('\t@echo Building the S2 Library\n')
makefile.write('\tcd google-s2-geometry; ${MAKE} all install\n')
makefile.write('\n')
makefile.write("#\n# Sometimes cmake fails to configure. If the makefile is not there,\n")
makefile.write("# We need to remove all of it and start over again.\n#\n")
makefile.write('configure-s2-geometry:\n')
makefile.write('\t@echo Configuring The S2 Library for building.\n')
makefile.write("\tif [ ! -f google-s2-geometry/Makefile ] ; then \\\n")
makefile.write("\t rm -rf google-s2-geometry; \\\n")
makefile.write('\t mkdir -p google-s2-geometry; \\\n')
makefile.write('\t cd google-s2-geometry; \\\n')
makefile.write('\t\tcmake -DCXX_VERSION_FLAG=\"-std=%s\" -DVOLTDB_THIRD_PARTY_CPP_DIR=\"${THIRD_PARTY_SRC}\" -DCMAKE_INSTALL_PREFIX=\"${INSTALL_DIR}\" -DCMAKE_BUILD_TYPE=\"${S2_BUILD_TYPE}\" \"${GOOGLE_S2_SRC}\"; \\\n' % CTX.CXX_VERSION_FLAG )
makefile.write("\tfi\n")
makefile.write('\n')
makefile.write('clean-s2-geometry:\n')
makefile.write("\t@echo Deleting the S2 library\\\'s object files\n")
makefile.write('\trm -rf google-s2-geometry\n')
makefile.write('\n')
# pcre2
makefile.write('########################################################################\n')
makefile.write('# pcre2 - regular expressions.\n')
makefile.write('########################################################################\n')
makefile.write('.PHONY: build-pcre2 configure-pcre2 unpack-pcre2\n')
makefile.write('build-pcre2: configure-pcre2\n')
makefile.write('\tif [ ! -f "${PCRE2_INSTALL}/lib/libpcre2-8.a" ] ; then \\\n')
makefile.write('\t echo Building PCRE2 ; \\\n')
makefile.write('\t (cd "$(PCRE2_OBJ)"; ${MAKE} install); \\\n')
makefile.write('\tfi\n')
makefile.write('configure-pcre2: unpack-pcre2\n')
makefile.write('\tif [ ! -d "${PCRE2_OBJ}" ] ; then \\\n')
makefile.write('\t echo Configuring PCRE2; \\\n')
makefile.write('\t /bin/rm -rf "${PCRE2_OBJ}"; \\\n')
makefile.write('\t mkdir -p "${PCRE2_OBJ}"; \\\n')
makefile.write('\t cd "${PCRE2_OBJ}"; \\\n')
makefile.write('\t "${PCRE2_SRC}/configure" --disable-shared --with-pic --prefix="${PCRE2_INSTALL}" ; \\\n')
makefile.write('\tfi\n')
makefile.write('unpack-pcre2:\n')
makefile.write('\tif [ ! -d "$PCRE2_SRC" ] ; then \\\n')
makefile.write('\t tar -x -j -f "${PCRE2_TARBALL}" -C "${THIRD_PARTY_SRC}" ; \\\n')
makefile.write('fi\n')
# third party tools testing target
makefile.write('########################################################################\n')
makefile.write('# Testing of third party tools. We do not run this usually, but\n')
makefile.write('# it is convenient to put it in the makefile.\n')
makefile.write('# Note that these will not be run by Jenkins.\n')
makefile.write('########################################################################\n')
makefile.write('.PHONY: test-third-party-tools test-pcre2\n')
makefile.write('test-third-party-tools: test-pcre2\n')
makefile.write('test-pcre2: build-pcre2\n')
makefile.write('\t@echo Testing PCRE2 in ${PCRE2_OBJ}\n')
makefile.write('\t(cd "${PCRE2_OBJ}"; ${MAKE} check)\n')
makefile.write('\n')
makefile.write("########################################################################\n")
makefile.write("#\n")
makefile.write("# Third Party Tools Section End\n")
makefile.write("#\n")
makefile.write("########################################################################\n")
return None
def findRootDir():
wd = os.getcwd()
while wd != "/" and not os.path.exists(os.path.join(wd, "version.txt")):
wd = os.path.realpath(os.path.join(wd, ".."))
if wd != "/":
return wd
return None
def generatedEETestFiles(output_prefix, buildType, testClasses, doGenerateFiles):
rootdir = findRootDir()
if not rootdir:
print("Can't find root directory.")
sys.exit(100)
tcArgs = ["tools/generate-ee-unit-tests.sh",
"--build",
buildType,
"--voltdbroot",
rootdir,
"--objdir",
os.path.join(rootdir, output_prefix)]
if not doGenerateFiles:
tcArgs += ["--names-only"]
for tc in testClasses:
tcArgs += ["--test-class", tc.strip()]
p = Popen(tcArgs, stdout=PIPE)
p.wait()
#
# Sometimes, in a pro build, the command above
# makes the folder obj/${BUILD}/testoutput. We
# don't really want this here, and it causes the
# Jenkins jobs to fail. So we just delete it here.
#
os.system("rm -rf %s/obj/%s/testoutput" % (rootdir, buildType))
if p.returncode != 0:
print("Fatal Error: %s" % p.communicate()[0])
sys.exit(p.returncode)
processStdOut = p.communicate()[0]
names = processStdOut.split()
names = list(names)
all_gen_tests = list((name.split("/") for name in names))
return all_gen_tests
def buildMakefile(CTX):
global version
CPPFLAGS = " ".join(CTX.CPPFLAGS.split())
MAKECPPFLAGS = CPPFLAGS
for dir in CTX.SYSTEM_DIRS:
MAKECPPFLAGS += " -isystem $(ROOTDIR)/%s" % (dir)
for dir in CTX.SRC_INCLUDE_DIRS:
MAKECPPFLAGS += " -I$(ROOTDIR)/%s" % (dir)
for dir in CTX.OBJ_INCLUDE_DIRS:
MAKECPPFLAGS += " -I${OBJDIR}/%s" % (dir)
MAKECPPFLAGS += " -I${OBJDIR}"
JNILIBFLAGS = " ".join(CTX.JNILIBFLAGS.split())
JNIBINFLAGS = " ".join(CTX.JNIBINFLAGS.split())
INPUT_PREFIX = CTX.INPUT_PREFIX.rstrip("/")
THIRD_PARTY_INPUT_PREFIX = CTX.THIRD_PARTY_INPUT_PREFIX.rstrip("/")
OUTPUT_PREFIX = CTX.OUTPUT_PREFIX.rstrip("/")
TEST_PREFIX = CTX.TEST_PREFIX.rstrip("/")
IGNORE_SYS_PREFIXES = CTX.IGNORE_SYS_PREFIXES
JNIEXT = CTX.JNIEXT.strip()
NM = CTX.NM
NMFLAGS = CTX.NMFLAGS
THIRD_PARTY_INSTALL_DIR=(OUTPUT_PREFIX + "/" + "3pty-install")
# create directories for output if they don't exist
os.system("mkdir -p %s" % (OUTPUT_PREFIX))
os.system("mkdir -p %s" % THIRD_PARTY_INSTALL_DIR)
os.system("mkdir -p %s" % (OUTPUT_PREFIX + "/nativelibs"))
os.system("mkdir -p %s" % (OUTPUT_PREFIX + "/objects"))
os.system("mkdir -p %s" % (OUTPUT_PREFIX + "/static_objects"))
os.system("mkdir -p %s" % (OUTPUT_PREFIX + "/prod"))
input_paths = []
for dir in CTX.INPUT.keys():
input = CTX.INPUT[dir].split()
input_paths += [INPUT_PREFIX + "/" + dir + "/" + x for x in input]
third_party_input_paths = []
for dir in CTX.THIRD_PARTY_INPUT.keys():
input = CTX.THIRD_PARTY_INPUT[dir].split()
third_party_input_paths += [THIRD_PARTY_INPUT_PREFIX + "/" + dir + "/" + x for x in input]
# Added for GPU
# Get compute capability
subprocess.call(['make', '--directory=third_party/gpu/'])
p = subprocess.Popen("third_party/gpu/check_cc", shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
close_fds=True)
ComCap = p.stdout.readline()
if "A GPU which is capable of using CUDA is not detected..." in ComCap:
return False
NVCC = "nvcc --std c++11"
GPUFLAGS = " -L/usr/local/cuda/lib64 -lcuda -lstdc++ -lcudart -I/usr/local/cuda/include -I/usr/cuda/samples/common/inc -I../../src/ee/GPUetc/common/"
GPUFLAGS += " -I../../src/ee/GPUetc/executors/ -I../../src/ee/GPUetc/expressions/ -I../../src/ee/GPUetc/indexes/ -I../../src/ee/GPUetc/storage/"
#INCLUDE = "-isystem ../../third_party/cpp/ -lm"
GPUARCHFLAGS = "-arch sm_%s "%ComCap
ALL_CCFLAGS = "-Xcompiler '-fPIC'"
ALL_LDFLAGS = "-Xcompiler '-fPIC' -Xlinker '--dynamic-linker=/lib/ld-linux-armhf.so.3'"
os.system("mkdir -p %s"%(OUTPUT_PREFIX + "/objects/GPUetc/executors"))
os.system("mkdir -p %s"%(OUTPUT_PREFIX + "/objects/GPUetc/expressions"))
os.system("mkdir -p %s"%(OUTPUT_PREFIX + "/objects/GPUetc/indexes"))
os.system("mkdir -p %s"%(OUTPUT_PREFIX + "/objects/GPUetc/storage"))
# End of adding
# All permanent tests
tests = []
for dir in CTX.TESTS.keys():
test_names = CTX.TESTS[dir].split()
tests += [os.path.join(TEST_PREFIX, dir, test) for test in test_names]
# All generated tests.
all_gen_tests = generatedEETestFiles(OUTPUT_PREFIX,
CTX.LEVEL.lower(),
CTX.GENERATOR_CLASSES,
True)
makefile = file(OUTPUT_PREFIX + "/makefile", 'w')
makefile.write("BUILD=%s\n" % CTX.LEVEL.lower())
makefile.write("CC = %s\n" % CTX.CC)
makefile.write("CXX = %s\n" % CTX.CXX)
makefile.write("VOLT_LOG_LEVEL = %s\n" % CTX.LOG_LEVEL)
makefile.write("CPPFLAGS += %s\n" % (MAKECPPFLAGS))
makefile.write("LDFLAGS += %s\n" % (CTX.LDFLAGS))
makefile.write("LASTLDFLAGS += %s\n" % (CTX.LASTLDFLAGS))
makefile.write("LASTIPCLDFLAGS += %s\n" % (CTX.LASTIPCLDFLAGS))
makefile.write("JNILIBFLAGS += %s\n" % (JNILIBFLAGS))
makefile.write("JNIBINFLAGS += %s\n" % (JNIBINFLAGS))
makefile.write("JNIEXT = %s\n" % (JNIEXT))
makefile.write("NM = %s\n" % (NM))
makefile.write("NMFLAGS = %s\n" % (NMFLAGS))
makefile.write('RM = /bin/rm -rf\n')
makefile.write("#\n")
makefile.write("# Capture the (relative) name of the root directory.\n")
makefile.write("# Also, remember the obj directory,\n")
makefile.write("# which should be the directory we are currently in.\n")
makefile.write("#\n")
makefile.write('ROOTDIR=$(shell (cd ../..; /bin/pwd))\n')
makefile.write('OBJDIR=$(ROOTDIR)/obj/${BUILD}\n')
makefile.write('INSTALL_DIR=$(ROOTDIR)/%s\n' % THIRD_PARTY_INSTALL_DIR)
makefile.write("TEST_PREFIX=%s\n" % TEST_PREFIX)
makefile.write('#\n')
makefile.write('# This is the root of the cpp sources.\n')
makefile.write('#\n')
makefile.write("SRCDIR = $(ROOTDIR)/src/ee\n")
makefile.write('#\n')
makefile.write('# This is the root of the third party sources.\n')
makefile.write('#\n')
makefile.write("THIRD_PARTY_SRC = $(ROOTDIR)/third_party/cpp\n")
makefile.write("#\n")
# Added for GPU
makefile.write("NVCC += %s\n"%(NVCC))
makefile.write("GPUFLAGS += %s\n"%(GPUFLAGS))
#makefile.write("INCLUDE += %s\n"%(INCLUDE))
makefile.write("GPUARCHFLAGS += %s\n"%(GPUARCHFLAGS))
makefile.write("ALL_CCFLAGS += %s\n"%(ALL_CCFLAGS))
makefile.write("ALL_LDFLAGS += %s\n"%(ALL_LDFLAGS))
# End of adding
if CTX.TARGET == "CLEAN":
makefile.write(".PHONY: clean\n")
makefile.write("clean:\n")
makefile.write('\t${RM} "${PCRE2_SRC}"\n')
makefile.write('\t(cd "${OPENSSL_SRC}"; make clean)\n')
makefile.write('\trm -rf "${OBJDIR}"\n')
makefile.close()
return
makefile.write('########################################################################\n')
makefile.write('# MAIN target\n')
makefile.write('########################################################################\n')
makefile.write(".PHONY: main\n")
makefile.write('\n')
if CTX.TARGET == "VOLTRUN":
makefile.write("main: prod/voltrun\n")
elif CTX.TARGET == "TEST":
makefile.write("main:\n")
else:
makefile.write("main: nativelibs/libvoltdb-%s.$(JNIEXT)\n" % version)
jni_objects = []
static_objects = []
for filename in input_paths:
jni, static = outputNamesForSource(filename)
jni_objects.append(jni)
static_objects.append(static)
for filename in third_party_input_paths:
jni, static = outputNamesForSource(filename)
jni_objects.append(jni)
static_objects.append(static)
cleanobjs = []
makefile.write("# create symbols by running nm against libvoltdb-%s\n" % version)
nmfilename = ("nativelibs/libvoltdb-%s.sym" % version)
jnilibname = ("nativelibs/libvoltdb-%s.$(JNIEXT)" % version)
cleanobjs += [nmfilename]
makefile.write("%s: %s\n" % (nmfilename, jnilibname))
makefile.write("\t$(NM) $(NMFLAGS) %s > $@\n" % jnilibname)
makefile.write("\n")
# Added for GPU
jni_objects.append("objects/GPUetc/executors/gpuhj.co")
jni_objects.append("objects/GPUetc/executors/gpuij.co")
jni_objects.append("objects/GPUetc/executors/gpunij.co")
jni_objects.append("objects/GPUetc/executors/gprojection.co")
jni_objects.append("objects/GPUetc/executors/gseqscan.co")
jni_objects.append("objects/GPUetc/expressions/gexpression.co")
jni_objects.append("objects/GPUetc/indexes/HashIndex.co")
jni_objects.append("objects/GPUetc/indexes/TreeIndex.co")
jni_objects.append("objects/GPUetc/storage/gtuple.co")
jni_objects.append("objects/GPUetc/storage/gblock.co")
jni_objects.append("objects/GPUetc/storage/gtable.co")
# End of adding
makefile.write("# main jnilib target\n")
makefile.write("%s: %s\n" % (jnilibname, formatList(jni_objects)))
#makefile.write("\t$(LINK.cpp) $(JNILIBFLAGS) -o $@ $^ $(LASTLDFLAGS) \n")
makefile.write("\t$(LINK.cpp) $(JNILIBFLAGS) $(GPUFLAGS) -o $@ $^ $(LASTLDFLAGS) \n")
makefile.write("\n")
cleanobjs += [ jnilibname ]
makefile.write("# voltdb instance that loads the jvm from C++\n")
makefile.write("prod/voltrun: $(SRCDIR)/voltrun.cpp " + formatList(static_objects) + "\n")
makefile.write("\t$(LINK.cpp) $(JNIBINFLAGS) -o $@ $^ $(LASTLDFLAGS)\n")
makefile.write("\n")
cleanobjs += ["prod/voltrun"]
makefile.write("# voltdb execution engine that accepts work on a tcp socket (vs. jni)\n")
makefile.write("prod/voltdbipc: $(SRCDIR)/voltdbipc.cpp objects/volt.a\n")
makefile.write("\t$(LINK.cpp) -o $@ $^ $(LASTLDFLAGS) $(LASTIPCLDFLAGS)\n")
makefile.write("\n")
cleanobjs += ["prod/voltdbipc"]
makefile.write('\n')
makefile.write('\n')
makefile.write("objects/volt.a: %s\n" % formatList(jni_objects))
makefile.write("\t$(AR) $(ARFLAGS) $@ $?\n")
harness_source = TEST_PREFIX + "/harness.cpp"
makefile.write("objects/harness.o: $(ROOTDIR)/" + harness_source + "\n")
makefile.write("\t$(CCACHE) $(COMPILE.cpp) -MMD -MP -o $@ $(ROOTDIR)/" + harness_source + "\n")
makefile.write("-include %s\n" % "objects/harness.d")
makefile.write("\n")
cleanobjs += ["objects/volt.a", "objects/harness.o", "objects/harness.d"]
# build the third party tools
buildThirdPartyTools(CTX, makefile)
# Added for GPU
makefile.write("objects/GPUetc/executors/gpuhj.co:../../src/ee/GPUetc/executors/gpuhj.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/executors/gpuij.co:../../src/ee/GPUetc/executors/gpuij.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/executors/gpunij.co:../../src/ee/GPUetc/executors/gpunij.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/executors/gprojection.co:../../src/ee/GPUetc/executors/projection.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/executors/gseqscan.co:../../src/ee/GPUetc/executors/seqscan.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/expressions/gexpression.co:../../src/ee/GPUetc/expressions/gexpression.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/indexes/GHashIndex.co:../../src/ee/GPUetc/indexes/HashIndex.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/indexes/GTreeIndex.co:../../src/ee/GPUetc/indexes/TreeIndex.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/storage/gtuple.co:../../src/ee/GPUetc/storage/gtuple.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/storage/gblock.co:../../src/ee/GPUetc/storage/gblock.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
makefile.write("objects/GPUetc/storage/gtable.co:../../src/ee/GPUetc/storage/gtable.cu \n")
makefile.write("\t$(NVCC) $(GPUFLAGS) $(GPUARCHFLAGS) $(ALL_CCFLAGS) -c $< -o $@ \n")
# End of adding
makefile.write("########################################################################\n")
makefile.write("#\n# %s\n#\n" % "Volt Files")
makefile.write("########################################################################\n")
for filename in input_paths:
jni_objname, static_objname = outputNamesForSource(filename)
filename = os.path.normpath(filename.replace(INPUT_PREFIX, "$(SRCDIR)"))
jni_targetpath = OUTPUT_PREFIX + "/" + "/".join(jni_objname.split("/")[:-1])
static_targetpath = OUTPUT_PREFIX + "/" + "/".join(static_objname.split("/")[:-1])
os.system("mkdir -p %s" % (jni_targetpath))
os.system("mkdir -p %s" % (static_targetpath))
makefile.write("########################################################################\n")
makefile.write("#\n# %s\n#\n" % filename)
makefile.write("########################################################################\n")
makefile.write("%s: %s | build-third-party-tools \n" % (jni_objname, filename))
#makefile.write("\t$(CCACHE) $(COMPILE.cpp) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("\t$(CCACHE) $(COMPILE.cpp) $(GPUFLAGS) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("%s: %s | build-third-party-tools \n" % (static_objname, filename))
#makefile.write("\t$(CCACHE) $(COMPILE.cpp) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("\t$(CCACHE) $(COMPILE.cpp) $(GPUFLAGS) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("-include %s\n" % replaceSuffix(jni_objname, ".d"))
makefile.write("-include %s\n" % replaceSuffix(static_objname, ".d"))
cleanobjs += [jni_objname,
static_objname,
replaceSuffix(jni_objname, ".d"),
replaceSuffix(jni_objname, ".d")]
makefile.write("\n")
makefile.write("\n")
makefile.write("########################################################################\n")
makefile.write("#\n# %s\n#\n" % "Third Party Files")
makefile.write("########################################################################\n")
for filename in third_party_input_paths:
jni_objname, static_objname = outputNamesForSource(filename)
filename = filename.replace(THIRD_PARTY_INPUT_PREFIX, "$(THIRD_PARTY_SRC)")
jni_targetpath = OUTPUT_PREFIX + "/" + "/".join(jni_objname.split("/")[:-1])
static_targetpath = OUTPUT_PREFIX + "/" + "/".join(static_objname.split("/")[:-1])
os.system("mkdir -p %s" % (jni_targetpath))
os.system("mkdir -p %s" % (static_targetpath))
makefile.write("########################################################################\n")
makefile.write("#\n# %s\n#\n" % filename)
makefile.write("########################################################################\n")
makefile.write("%s: %s | build-third-party-tools \n" % (jni_objname, filename))
makefile.write("\t$(CCACHE) $(COMPILE.cpp) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("%s: %s | build-third-party-tools \n" % (static_objname, filename))
makefile.write("\t$(CCACHE) $(COMPILE.cpp) %s -MMD -MP -o $@ %s\n" % (CTX.EXTRAFLAGS, filename))
makefile.write("-include %s\n" % replaceSuffix(jni_objname, ".d"))
makefile.write("-include %s\n" % replaceSuffix(static_objname, ".d"))
cleanobjs += [jni_objname,
static_objname,
replaceSuffix(jni_objname, ".d"),
replaceSuffix(jni_objname, ".d")]
makefile.write("\n")
makefile.write("\n")
makefile.write('########################################################################\n')
makefile.write('#\n')
makefile.write('# Tests\n')
makefile.write('#\n')
makefile.write('########################################################################\n')
# build the generated tests.
buildGeneratedTests(CTX, makefile, all_gen_tests)
makefile.write("\n")
# A target for all the tests. This is what buildtools.py eventually uses.
makefile.write("#\n# A target for all the tests. This is what buildtools.py eventually uses.\n#\n")
makefile.write(".PHONY: test\n")
makefile.write("test: \\\n")
for test in tests:
binname, objectname, sourcename = namesForTestCode(test)
makefile.write(" " + binname + " \\\n")
makefile.write(" ${GENERATED_TESTS}")
if CTX.LEVEL == "MEMCHECK" or CTX.LEVEL == "MEMCHECK_NOFREELIST":
makefile.write("\\\n prod/voltdbipc\n")
makefile.write('\n')
for test in tests:
binname, objectname, sourcename = namesForTestCode(test)
# build the object file
makefile.write("########################################################################\n")
makefile.write("#\n")
makefile.write("# %s\n" % sourcename)
makefile.write("#\n")
makefile.write("########################################################################\n")
makefile.write("%s: $(ROOTDIR)/%s | build-third-party-tools \n" % (objectname, sourcename))
makefile.write("\t$(CCACHE) $(COMPILE.cpp) -I$(ROOTDIR)/${TEST_PREFIX} -MMD -MP -o $@ $(ROOTDIR)/%s\n" % sourcename)
makefile.write("-include %s\n" % replaceSuffix(objectname, ".d"))
# link the test
makefile.write("%s: objects/harness.o %s objects/volt.a | build-third-party-tools \n" % (binname, objectname))
makefile.write("\t$(LINK.cpp) -o %s %s objects/harness.o objects/volt.a %s\n" % (binname, objectname, CTX.LASTLDFLAGS))
makefile.write("\n")
targetpath = OUTPUT_PREFIX + "/" + "/".join(binname.split("/")[:-1])
os.system("mkdir -p %s" % (targetpath))
pysourcename = sourcename[:-3] + "py"
cleanobjs += [objectname, replaceSuffix(objectname, ".d"), binname]
if os.path.exists(pysourcename):
shutil.copy(pysourcename, targetpath)
cleanobjs += [targetpath]
makefile.write("########################################################################\n")
makefile.write("#\n")
makefile.write("# Cleaning\n")
makefile.write("#\n")
makefile.write("########################################################################\n")
makefile.write("\n")
makefile.write("clean: clean-s2-geometry clean-openssl clean-3pty-install clean-generated-tests\n")
makefile.write("\t${RM} %s\n" % formatList(cleanobjs))
makefile.write("\n")
makefile.write(".PHONY: clean-3pty-install\n")
makefile.write("clean-3pty-install:\n")
makefile.write("\t@${RM} -r \"${INSTALL_DIR}\"\n")
makefile.write('\t@${RM} %s\n' % formatList(cleanobjs))
makefile.write('\t@${RM} "${PCRE2_OBJ}"\n')
makefile.write('\t@${RM} "${PCRE2_SRC}"\n')
makefile.write("\n")
makefile.close()
return True
def buildIPC(CTX):
retval = os.system("make --directory=%s prod/voltdbipc -j4" % (CTX.OUTPUT_PREFIX))
return retval
class ValgrindErrorState:
def __init__(self, expectErrorsIn, retval, valgrindFile):
self.expectErrors = expectErrorsIn
self.foundErrors = False
self.valgrindFile = valgrindFile
self.retval = retval
self.errorStrings = []
self._process()
def _process(self):
tree = ET.parse(self.valgrindFile);
root = tree.getroot()
errs = root.findall(".//error")
for err in errs:
self.foundErrors = True
self.errorStrings.append(self._toString(err))
if self.foundErrors != (self.retval != 0):
print('We %s some errors, but the return value was %d'
% (('found' if self.foundErrors else 'did not find'),
self.retval))
def _toString(self, err):
elements = '';
for child in err:
if child.tag == 'kind':
elements += child.text.strip() + '\n'
elif child.tag == 'what':
elements += " " + child.text.strip() + "\n"
elif child.tag == 'xwhat':
elements += self._parseXWhat(child) + '\n'
elif child.tag == 'stack':
elements += self._parseStack(child) + '\n'
return elements
def _parseXWhat(self, xwhat):
leakedbytes = xwhat.find('leakedbytes')
leakedblocks = xwhat.find("leakedblocks")
text = xwhat.find('text')
if leakedbytes is not None:
leakedbytes = " Leaked Bytes: " + leakedbytes.text + "\n"
else:
leakedbytes = ""
if leakedblocks is not None:
leakedblocks = " Leaked Blocks: " + leakedblocks.text + "\n"
else:
leakedblocks = ""
if text is not None:
text = " " + text.text + "\n"
else:
text = ""
return text + leakedblocks + leakedbytes
def _parseStack(self, stack):
stackFrames = ""
stackNo = 0
for frame in stack:
if frame.tag != 'frame':
continue
ip = "<undefined ip>"
fn = "<undefined fn>"
dir = "<undefined dir>"
file = "<undefined file>"
lineNo = "<undefined line number>"
for elem in frame:
name = elem.tag
value = elem.text.strip()
if elem.tag == 'ip':
ip = value
elif elem.tag == 'fn':
fn = value
elif elem.tag == 'dir':
dir = value
elif elem.tag == 'file':
file = value
elif elem.tag == 'line':
lineNo = value
stackFrames += (" %03d.) %s: %s@%s/%s: line %s" % (stackNo, ip, fn, dir, file, lineNo)) + "\n"
return stackFrames
def isExpectedState(self):
return (self.expectErrors == self.foundErrors)
def errorMessage(self, retval):
if self.isExpectedState():
exp = " (Expected)"
else:
exp = ""
return ("%s\n%d Valgrind Errors, return value %d%s: \n" %
(":-----------------------------------------------------------:", \
len(self.errorStrings), \
retval, \
exp) \
+ "\n".join(self.errorStrings))
def makeValgrindFile(testdir, pidStr):
return os.path.join(testdir, "valgrind_ee_%s.xml" % pidStr)
def runTests(CTX):
failedTests = []
successes = 0
failures = 0
# We only want to use valgrind for MEMCHECK or MEMCHECK_NOFREELIST builds.
usingValgrind = CTX.LEVEL == "MEMCHECK" or CTX.LEVEL == "MEMCHECK_NOFREELIST"
#
# Set executing to False to test this function without
# really running tests. In this case, set exretval to 0 to simulate all
# successes. Set exretval to -1 to simulate all failures.
#
executing = True
exretval = 0
retval = os.system("make --directory=%s test -j4" % (CTX.OUTPUT_PREFIX))
if retval != 0:
return -1
TEST_PREFIX = CTX.TEST_PREFIX.rstrip("/")
OUTPUT_PREFIX = CTX.OUTPUT_PREFIX.rstrip("/")
GEN_TEST_PREFIX = os.path.join(OUTPUT_PREFIX, 'generated')
tests = []
# For each test we record:
# The name of the binary directory, excluding the category and test names,
# The Category name,
# The test name,
TEST_PERMANENT = True # Set to False for debugging
TEST_GENERATED = True # Set to False for debugging.
if TEST_PERMANENT:
for dirname in CTX.TESTS.keys():
test_names = CTX.TESTS[dirname].split()
tests += [(os.path.join(OUTPUT_PREFIX, 'cpptests'),
dirname,
testname) for testname in test_names]
if TEST_GENERATED:
for dirname, testname in generatedEETestFiles(OUTPUT_PREFIX, CTX.LEVEL.lower(),
CTX.GENERATOR_CLASSES, False):
tests += [(os.path.join(OUTPUT_PREFIX, 'generated', 'bin'),
dirname,
testname)]
noValgrindTests = [ "harness_test", "serializeio_test" ]
for bindirname, dirname, test in tests:
# We expect valgrind failures in all tests in memleaktests
# except for the test named no_losses.
expectErrors = (dirname == "memleaktests") and ( test != "no_losses" )
print("In %s/%s: %sexpecting errors"
% (dirname,
test,
"" if expectErrors else "not "))
srcpath = os.path.join("test", "ee", dirname, test)
targetpath = os.path.join(bindirname, dirname, test)
retval = 0
if test.endswith("CopyOnWriteTest") and CTX.LEVEL == "MEMCHECK_NOFREELIST":
continue
if os.path.exists(targetpath + ".py"):
retval = os.system("/usr/bin/env python " + targetpath + ".py")
else:
isValgrindTest = usingValgrind
errorState = None
if usingValgrind:
for nvgtest in noValgrindTests:
if targetpath.find(nvgtest) != -1:
isValgrindTest = False;
break
if CTX.PLATFORM == "Linux" and isValgrindTest:
print('Executing valgrind test %s' % targetpath)
valgrindDir = os.path.join(bindirname, dirname)
valgrindFile = makeValgrindFile(valgrindDir, "%p")
args = ["valgrind",
"--leak-check=full",
"--show-reachable=yes",
"--error-exitcode=1",
"--suppressions=" + os.path.join(TEST_PREFIX,
"test_utils/vdbsuppressions.supp"),
"--xml=yes",
"--xml-file=" + valgrindFile,
targetpath]
print('Full command: %s' % (" ".join(args)))
sys.stdout.flush()
if executing:
process = Popen(executable="valgrind",
args=args, stderr=PIPE, bufsize=-1)
out_err = process.stderr.readlines()
retval = process.wait()
print(' Returned code %d' % retval)
fileName = makeValgrindFile(valgrindDir, "%d" % process.pid)
errorState = ValgrindErrorState(expectErrors, retval, fileName)
else:
fileName = None
retval = exretval
print(' Test %s was not run.' % os.path.join(dirname, test))
# If there are as many errors as we expect,
# then delete the xml file. Otherwise keep it.
# It may be useful.
if errorState:
if errorState.isExpectedState():
successes += 1
if fileName:
try:
os.remove(fileName)
except ex:
pass
else:
failures += 1
failedTests += [os.path.join(dirname, test)]
print(errorState.errorMessage(retval))
sys.stdout.flush()