forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_commit_test.py
More file actions
1248 lines (1073 loc) · 43.3 KB
/
run_commit_test.py
File metadata and controls
1248 lines (1073 loc) · 43.3 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
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
#!/usr/bin/env python2
#
# Python commit test run script.
#
# Intended to work on Linux, OS X, and Windows (both Cygwin and command
# prompt). Some notes for portability:
#
# * Use os.path.join() to join paths.
#
# * Use tarfile, zipfile, etc instead of native commands to avoid awkward
# situations on Windows, e.g. we might be running from the command prompt
# and executing 'tar' which is provided by Cygwin. Paths will work very
# badly in such situations. In general, don't mix Cygwin / non-Cygwin
# commands on Windows.
#
# * Avoid Duktape Makefile targets: they sometimes depend on /tmp which
# interferes with parallel runs.
#
# * Avoid mixing Cygwin and non-Cygwin repo snapshots (and git commands),
# as there are issues with mixed use like permissions causing unintended
# diffs.
#
import os
import sys
import re
import json
import optparse
import subprocess
import time
import datetime
import traceback
import tarfile
import zipfile
import md5
#
# Parameters and option parsing, some control globals
#
# Whitelisted repos, limit to main repo for now.
repo_whitelist = [
'svaarala/duktape'
]
# Strict reponame filter.
re_reponame = re.compile(r'^[a-zA-Z0-9/-]+$')
# Parse arguments.
parser = optparse.OptionParser()
parser.add_option('--repo-full-name', dest='repo_full_name', help='Full name of repository, e.g. "svaarala/duktape"')
parser.add_option('--repo-clone-url', dest='repo_clone_url', help='Repo HTTPS clone URI, e.g. "https://github.com/svaarala/duktape.git"')
parser.add_option('--commit-name', dest='commit_name', help='Commit SHA hash or tag name')
parser.add_option('--fetch-ref', dest='fetch_ref', default=None, help='Ref to fetch before checkout out SHA (e.g. +refs/pull/NNN/head)')
parser.add_option('--context', dest='context', help='Context identifying test type, e.g. "linux-x64-ecmatest"')
parser.add_option('--temp-dir', dest='temp_dir', help='Automatic temp dir created by testclient, automatically deleted (recursively) by testclient when test is done')
parser.add_option('--repo-snapshot-dir', dest='repo_snapshot_dir', help='Directory for repo tar.gz snapshots for faster test init')
(opts, args) = parser.parse_args()
repo_full_name = opts.repo_full_name
assert(repo_full_name is not None)
repo_clone_url = opts.repo_clone_url
assert(repo_clone_url is not None)
commit_name = opts.commit_name
assert(commit_name is not None)
context = opts.context
assert(context is not None)
temp_dir = opts.temp_dir
assert(temp_dir is not None)
repo_snapshot_dir = opts.repo_snapshot_dir
assert(repo_snapshot_dir is not None)
#
# Helpers
#
def newenv(**kw):
ret = {}
for k in os.environ.keys():
ret[k] = str(os.environ[k])
for k in kw.keys():
ret[k] = str(kw[k])
#print('Final environment: %r' % ret)
return ret
def execute(cmd, env=None, catch=False, input='', dump_stdout=True, dump_stderr=True):
print(' - ' + repr(cmd))
success = True
def dump(x):
if isinstance(x, unicode):
x = x.encode('utf-8')
if len(x) == 0 or x[-1] != '\n':
x = x + '\n'
sys.stdout.write(x)
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
ret = proc.communicate(input=input)
if ret[0] != '' and dump_stdout:
dump(ret[0])
if ret[1] != '' and dump_stderr:
dump(ret[1])
if proc.returncode != 0:
if catch:
success = False
else:
raise Exception('command failed: %r' % cmd)
return {
'returncode': proc.returncode,
'stdout': ret[0],
'stderr': ret[1],
'success': success
}
def unpack_targz(fn):
print('Extracting %s to %s' % (fn, os.getcwd()))
t = tarfile.open(fn)
t.extractall()
t.close()
def unpack_zip(fn):
print('Extracting %s to %s' % (fn, os.getcwd()))
z = zipfile.ZipFile(fn, 'r')
z.extractall()
z.close()
def get_binary_size(fn):
# Pattern works for Linux and OS X.
res = execute([ 'size', fn ])
m = re.compile(r'.*?^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*?', re.MULTILINE | re.DOTALL).match(res['stdout'])
if m is None:
raise Exception('cannot figure out size for binary %r' % fn)
return {
'text': int(m.group(1)),
'data': int(m.group(2)),
'bss': int(m.group(3)),
'total': int(m.group(4))
}
def format_size_diff(newsz, oldsz):
return '%d %d %d (%d %d %d): %d' % (
newsz['text'], newsz['data'], newsz['bss'],
oldsz['text'], oldsz['data'], oldsz['bss'],
newsz['total'] - oldsz['total']
)
def format_size(sz):
return '%d %d %d' % (sz['text'], sz['data'], sz['bss'])
output_result_json = {}
def set_output_result(doc):
for k in doc.keys():
output_result_json[k] = doc[k]
def set_output_field(key, value):
output_result_json[key] = value
def prep(options=None, options_yaml=None):
cwd = os.getcwd()
execute([ 'rm', '-rf', os.path.join(cwd, 'prep') ])
cmd = [
'python2', os.path.join(cwd, 'tools', 'configure.py'),
'--source-directory', os.path.join(cwd, 'src-input'),
'--output-directory', os.path.join(cwd, 'prep'),
'--config-metadata', os.path.join(cwd, 'config')
]
cmd += [ '--line-directives' ]
if options is not None:
cmd += options
if options_yaml is not None:
with open(os.path.join(cwd, 'prep_options.yaml'), 'wb') as f:
f.write(options_yaml)
cmd += [ '--option-file', os.path.join(cwd, 'prep_options.yaml') ]
print('Prep options:')
execute([ 'cat', os.path.join(cwd, 'prep_options.yaml') ])
execute(cmd)
execute([ 'ls', '-l', os.path.join(cwd, 'prep') ])
#
# Test context handlers
#
def genconfig_dist_src(genconfig_opts):
cwd = os.getcwd()
execute([
'python2', os.path.join(cwd, 'tools', 'genconfig.py'),
'--metadata', os.path.join(cwd, 'config'),
'--output', os.path.join(cwd, 'dist', 'src', 'duk_config.h')
] + genconfig_opts + [
'duk-config-header'
])
def context_codepolicycheck():
return execute([ 'make', 'codepolicycheck' ], env=newenv(TRAVIS=1), catch=True)['success']
def context_helper_x64_ecmatest(env=None, genconfig_opts=[], valgrind=False):
cwd = os.getcwd()
execute([ 'make', 'dist' ])
genconfig_dist_src(genconfig_opts)
execute([ 'make', 'duk', 'runtestsdeps' ])
opts = []
if valgrind:
opts.append('--valgrind')
return execute([
'node',
os.path.join(cwd, 'runtests', 'runtests.js'),
'--prep-test-path', os.path.join(cwd, 'util', 'prep_test.py'),
'--minify-uglifyjs2', os.path.join(cwd, 'UglifyJS2', 'bin', 'uglifyjs'),
'--util-include-path', os.path.join(cwd, 'tests', 'ecmascript'),
'--known-issues', os.path.join(cwd, 'doc', 'testcase-known-issues.yaml'),
'--run-duk', '--cmd-duk', os.path.join(cwd, 'duk'),
'--num-threads', '1',
'--log-file', os.path.join(cwd, 'test.out')
] + opts + [
os.path.join(cwd, 'tests', 'ecmascript')
], env=env, catch=True)['success']
def context_linux_x64_ecmatest():
return context_helper_x64_ecmatest(env=newenv())
def context_linux_arm_ecmatest():
return context_helper_x64_ecmatest(env=newenv()) # no difference to x64 now
def context_linux_x64_ecmatest_assert():
return context_helper_x64_ecmatest(env=newenv(), genconfig_opts=[ '-DDUK_USE_ASSERTIONS' ])
def context_linux_x64_ecmatest_valgrind():
return context_helper_x64_ecmatest(env=newenv(), valgrind=True)
def context_helper_x64_apitest(env=None, genconfig_opts=[], valgrind=False):
cwd = os.getcwd()
execute([ 'make', 'dist' ])
genconfig_dist_src(genconfig_opts)
execute([ 'make', 'apiprep' ])
opts = []
if valgrind:
opts.append('--valgrind')
return execute([
'node',
os.path.join(cwd, 'runtests', 'runtests.js'),
'--prep-test-path', os.path.join(cwd, 'util', 'prep_test.py'),
'--minify-uglifyjs2', os.path.join(cwd, 'UglifyJS2', 'bin', 'uglifyjs'),
'--util-include-path', os.path.join(cwd, 'tests', 'ecmascript'),
'--known-issues', os.path.join(cwd, 'doc', 'testcase-known-issues.yaml'),
'--run-duk', '--cmd-duk', os.path.join(cwd, 'duk'),
'--num-threads', '1',
'--log-file', os.path.join(cwd, 'test.out'),
os.path.join(cwd, 'tests', 'api')
] + opts + [
], env=env, catch=True)['success']
def context_linux_x64_apitest():
return context_helper_x64_apitest(env=newenv())
def context_linux_arm_apitest():
return context_helper_x64_apitest(env=newenv()) # no difference to x64 now
def context_linux_x64_apitest_assert():
return context_helper_x64_apitest(env=newenv(), genconfig_opts=[ '-DDUK_USE_ASSERTIONS' ])
def context_linux_x64_apitest_valgrind():
return context_helper_x64_apitest(env=newenv(), valgrind=True)
def context_linux_x64_v8_bench_pass():
cwd = os.getcwd()
print('NOTE: This performance test is executed as a functional')
print('test because it also stress GC etc; the benchmark score')
print('is meaningless unless executed on dedicated hardware.')
print('')
unpack_targz(os.path.join(repo_snapshot_dir, 'google-v8-benchmark-v7.tar.gz'))
execute([ 'make', 'duk' ])
os.chdir(os.path.join(cwd, 'tests', 'google-v8-benchmark-v7'))
execute([ 'make', 'combined.js' ])
os.chdir(cwd)
execute([ os.path.join(cwd, 'duk'), os.path.join('tests', 'google-v8-benchmark-v7', 'combined.js') ])
return True
def context_linux_x64_octane():
cwd = os.getcwd()
execute([ 'make', 'duk.O2' ])
os.chdir(os.path.join(cwd, 'tests', 'octane'))
scores = []
for i in xrange(5):
res = execute([ 'make', 'test' ])
m = re.match(r'.*?SCORE (\d+)', res['stdout'], re.DOTALL)
if m is not None:
scores.append(float(m.group(1)))
print('scores so far: min=%f, max=%f, avg=%f: %r' % (min(scores), max(scores), sum(scores) / float(len(scores)), scores))
set_output_result({
'description': '%.1f (%d-%d)' % (float(sum(scores) / float(len(scores))), int(min(scores)), int(max(scores))),
'score_avg': float(sum(scores) / float(len(scores))),
'score_min': int(min(scores)),
'score_max': int(max(scores))
})
return True
def context_linux_x64_duk_clang():
cwd = os.getcwd()
execute([ 'make', 'duk-clang' ])
res = execute([
os.path.join(cwd, 'duk-clang'),
'-e', 'print("hello world!");'
])
return res['stdout'] == 'hello world!\n'
def context_linux_x64_duk_gxx():
cwd = os.getcwd()
execute([ 'make', 'duk-g++' ])
res = execute([
os.path.join(cwd, 'duk-g++'),
'-e', 'print("hello world!");'
])
return res['stdout'] == 'hello world!\n'
def context_helper_get_binary_size_diff(compfn):
cwd = os.getcwd()
execute([ 'git', 'clean', '-f' ])
execute([ 'git', 'reset', '--quiet', '--hard' ])
compfn()
newsz = get_binary_size(os.path.join(cwd, 'duk'))
execute([ 'git', 'clean', '-f' ])
execute([ 'git', 'reset', '--quiet', '--hard' ])
execute([ 'git', 'checkout', '--quiet', 'master' ])
execute([ 'git', 'clean', '-f' ])
execute([ 'git', 'reset', '--quiet', '--hard' ])
execute([ 'make', 'clean' ])
compfn()
oldsz = get_binary_size(os.path.join(cwd, 'duk'))
set_output_result({
'description': format_size_diff(newsz, oldsz),
'oldsz': oldsz,
'newsz': newsz
})
return True
def context_linux_x64_gcc_defsize_makeduk():
cwd = os.getcwd()
def comp():
execute([ 'make', 'duk' ])
return context_helper_get_binary_size_diff(comp)
def context_helper_defsize_fltoetc(archopt):
cwd = os.getcwd()
def comp():
execute([ 'make', 'dist' ])
execute([
'gcc', '-oduk', archopt,
'-Os', '-fomit-frame-pointer',
'-fno-stack-protector',
'-flto', '-fno-asynchronous-unwind-tables',
'-ffunction-sections', '-Wl,--gc-sections',
'-I' + os.path.join('dist', 'src'),
'-I' + os.path.join('dist', 'examples', 'cmdline'),
os.path.join(cwd, 'dist', 'src', 'duktape.c'),
os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'),
'-lm'
])
return context_helper_get_binary_size_diff(comp)
def context_linux_x64_gcc_defsize_fltoetc():
return context_helper_defsize_fltoetc('-m64')
def context_linux_x86_gcc_defsize_fltoetc():
return context_helper_defsize_fltoetc('-m32')
def context_linux_x32_gcc_defsize_fltoetc():
return context_helper_defsize_fltoetc('-mx32')
def context_linux_arm_gcc_defsize_fltoetc():
return context_helper_defsize_fltoetc('-marm')
def context_linux_thumb_gcc_defsize_fltoetc():
return context_helper_defsize_fltoetc('-mthumb')
def context_helper_minsize_fltoetc(archopt, strip):
cwd = os.getcwd()
def comp():
execute([ 'make', 'clean' ])
execute([ 'rm', '-rf', os.path.join(cwd, 'prep') ])
cmd = [
'python2', os.path.join(cwd, 'tools', 'configure.py'),
'--source-directory', os.path.join(cwd, 'src-input'),
'--output-directory', os.path.join(cwd, 'prep'),
'--config-metadata', os.path.join(cwd, 'config'),
'--option-file', os.path.join(cwd, 'config', 'examples', 'low_memory.yaml')
]
if strip:
cmd += [
'--option-file', os.path.join(cwd, 'config', 'examples', 'low_memory_strip.yaml'),
'--unicode-data', os.path.join(cwd, 'src-input', 'UnicodeData-8bit.txt'),
'--special-casing', os.path.join(cwd, 'src-input', 'SpecialCasing-8bit.txt')
]
execute(cmd)
execute([
'gcc', '-oduk', archopt,
'-Os', '-fomit-frame-pointer',
'-fno-stack-protector',
'-flto', '-fno-asynchronous-unwind-tables',
'-ffunction-sections', '-Wl,--gc-sections',
'-I' + os.path.join('prep'),
'-I' + os.path.join('examples', 'cmdline'),
os.path.join(cwd, 'prep', 'duktape.c'),
os.path.join(cwd, 'examples', 'cmdline', 'duk_cmdline.c'),
'-lm'
])
res = execute([
os.path.join(cwd, 'duk')
], input='1+2, "hello world!"')
return 'hello world' in res['stdout']
return context_helper_get_binary_size_diff(comp)
def context_linux_x64_gcc_minsize_fltoetc():
return context_helper_minsize_fltoetc('-m64', False)
def context_linux_x86_gcc_minsize_fltoetc():
return context_helper_minsize_fltoetc('-m32', False)
def context_linux_x32_gcc_minsize_fltoetc():
return context_helper_minsize_fltoetc('-mx32', False)
def context_linux_arm_gcc_minsize_fltoetc():
return context_helper_minsize_fltoetc('-marm', False)
def context_linux_thumb_gcc_minsize_fltoetc():
return context_helper_minsize_fltoetc('-mthumb', False)
def context_linux_x64_gcc_stripsize_fltoetc():
return context_helper_minsize_fltoetc('-m64', True)
def context_linux_x86_gcc_stripsize_fltoetc():
return context_helper_minsize_fltoetc('-m32', True)
def context_linux_x32_gcc_stripsize_fltoetc():
return context_helper_minsize_fltoetc('-mx32', True)
def context_linux_arm_gcc_stripsize_fltoetc():
return context_helper_minsize_fltoetc('-marm', True)
def context_linux_thumb_gcc_stripsize_fltoetc():
return context_helper_minsize_fltoetc('-mthumb', True)
def context_linux_x64_cpp_exceptions():
# For now rather simple: compile, run, and grep for my_class
# destruction prints. There are only 3 without C++ exceptions
# and 15 with them.
cwd = os.getcwd()
prep(options=[ '-DDUK_USE_CPP_EXCEPTIONS' ])
execute([
'g++', '-oduk-cpp-exc',
'-I' + os.path.join(cwd, 'prep'),
os.path.join(cwd, 'prep', 'duktape.c'),
os.path.join(cwd, 'examples', 'cpp-exceptions', 'cpp_exceptions.cpp'),
'-lm'
])
res = execute([
os.path.join(cwd, 'duk-cpp-exc')
])
count = 0
for line in res['stdout'].split('\n'):
if 'my_class instance destroyed' in line:
count += 1
print('Destruct count: %d' % count)
if count >= 15:
print('C++ exceptions seem to be working')
return True
else:
print('C++ exceptions don\'t seem to be working')
return False
def context_linux_x86_duklow():
cwd = os.getcwd()
execute([ 'make', 'duk-low' ])
res = execute([
os.path.join(cwd, 'duk-low'),
'-e', 'print("hello world!");'
])
return 'hello world!\n' in res['stdout']
def context_linux_x86_duklow_norefc():
cwd = os.getcwd()
execute([ 'make', 'duk-low-norefc' ])
res = execute([
os.path.join(cwd, 'duk-low-norefc'),
'-e', 'print("hello world!");'
])
return 'hello world!\n' in res['stdout']
def context_linux_x86_duklow_rombuild():
cwd = os.getcwd()
execute([ 'make', 'duk-low-rom' ])
got_hello = False
got_startrek = False
res = execute([
os.path.join(cwd, 'duk-low-rom'),
'-e', 'print("hello world!");'
])
got_hello = ('hello world!\n' in res['stdout']) # duk-low-rom stdout has pool dumps etc
print('Got hello: %r' % got_hello)
res = execute([
os.path.join(cwd, 'duk-low-rom'),
'-e', 'print("StarTrek.ent:", StarTrek.ent);'
])
got_startrek = ('StarTrek.ent: true\n' in res['stdout'])
print('Got StarTrek: %r' % got_startrek)
return got_hello and got_startrek
def context_linux_x64_test262test():
cwd = os.getcwd()
execute([ 'make', 'duk' ])
# Unpack separately, 'make clean' wipes this.
unpack_targz(os.path.join(repo_snapshot_dir, 'test262-es5-tests.tar.gz'))
unpack_zip(os.path.join(cwd, 'es5-tests.zip'))
os.chdir(os.path.join(cwd, 'test262-es5-tests'))
res = execute([
'python2',
os.path.join(cwd, 'test262-es5-tests', 'tools', 'packaging', 'test262.py'),
'--command', os.path.join(cwd, 'duk') + ' {{path}}'
], dump_stdout=False, dump_stderr=True)
test262_log = res['stdout']
os.chdir(cwd)
res = execute([
'python2',
os.path.join(cwd, 'util', 'filter_test262_log.py'),
os.path.join(cwd, 'doc', 'test262-known-issues.yaml')
], input=test262_log)
# Test result plumbing a bit awkward but works for now.
# Known and diagnosed issues are considered a "pass" for
# GitHub status.
return 'TEST262 SUCCESS\n' in res['stdout']
def context_linux_x64_duk_dddprint():
cwd = os.getcwd()
prep(options_yaml=r"""
DUK_USE_ASSERTIONS: true
DUK_USE_SELF_TESTS: true
DUK_USE_DEBUG: true
DUK_USE_DEBUG_LEVEL: 2
DUK_USE_DEBUG_WRITE:
verbatim: "#define DUK_USE_DEBUG_WRITE(level,file,line,func,msg) do {fprintf(stderr, \"%ld %s:%ld (%s): %s\\n\", (long) (level), (file), (long) (line), (func), (msg));} while(0)"
""")
res = execute([
'gcc', '-oduk',
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join(cwd, 'prep'),
'-I' + os.path.join(cwd, 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'extras', 'print-alert'),
os.path.join(cwd, 'prep', 'duktape.c'),
os.path.join(cwd, 'examples', 'cmdline', 'duk_cmdline.c'),
os.path.join(cwd, 'extras', 'print-alert', 'duk_print_alert.c'),
'-lm'
], catch=True)
if not res['success']:
print('Compilation failed.')
return False
res = execute([
os.path.join(cwd, 'duk'),
'-e', 'print("Hello world!");'
], dump_stderr=False)
return 'Hello world!\n' in res['stdout']
def context_linux_x64_duk_separate_src():
cwd = os.getcwd()
execute([ 'make', 'dist' ])
os.chdir(os.path.join(cwd, 'dist'))
cfiles =[]
for fn in os.listdir(os.path.join(cwd, 'dist', 'src-separate')):
if fn[-2:] == '.c':
cfiles.append(os.path.join(cwd, 'dist', 'src-separate', fn))
cfiles.append(os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'))
cfiles.append(os.path.join(cwd, 'dist', 'extras', 'print-alert', 'duk_print_alert.c'))
execute([
'gcc', '-oduk',
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join(cwd, 'dist', 'src-separate'),
'-I' + os.path.join(cwd, 'dist', 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'dist', 'extras', 'print-alert')
] + cfiles + [
'-lm'
])
res = execute([
os.path.join(cwd, 'dist', 'duk'),
'-e', 'print("Hello world!");'
])
return 'Hello world!\n' in res['stdout']
def context_linux_x86_packed_tval():
cwd = os.getcwd()
execute([ 'make', 'dist' ])
os.chdir(os.path.join(cwd, 'dist'))
execute([
'gcc', '-oduk', '-m32',
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join(cwd, 'dist', 'src'),
'-I' + os.path.join(cwd, 'dist', 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'dist', 'extras', 'print-alert'),
os.path.join(cwd, 'dist', 'src', 'duktape.c'),
os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'),
os.path.join(cwd, 'dist', 'extras', 'print-alert', 'duk_print_alert.c'),
'-lm'
])
# Size of a 3-element array is 25 + 3x16 = 73 on x64 and
# 13 + 3x8 = 37 on x86.
res = execute([
os.path.join(cwd, 'dist', 'duk'),
'-e',
'var arr = Duktape.compact([1,2,3]); ' +
'print(Duktape.info(true).itag >= 0xf000); ' + # packed internal tag
'print(Duktape.info(arr).pbytes <= 40)' # array size (1 element + .length property)
]);
return res['stdout'] == 'true\ntrue\n'
def context_linux_x86_dist_genconfig():
cwd = os.getcwd()
execute([ 'make', 'dist' ])
os.chdir(os.path.join(cwd, 'dist'))
execute([
'python2', os.path.join(cwd, 'dist', 'tools', 'genconfig.py'),
'--metadata', os.path.join(cwd, 'dist', 'config'),
'--output', os.path.join(cwd, 'dist', 'src', 'duk_config.h'), # overwrite default duk_config.h
'-DDUK_USE_FASTINT', '-UDUK_USE_JX', '-UDUK_USE_JC',
'duk-config-header'
])
os.chdir(os.path.join(cwd, 'dist'))
execute([
'gcc', '-oduk',
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join(cwd, 'dist', 'src'),
'-I' + os.path.join(cwd, 'dist', 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'dist', 'extras', 'print-alert'),
os.path.join(cwd, 'dist', 'src', 'duktape.c'),
os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'),
os.path.join(cwd, 'dist', 'extras', 'print-alert', 'duk_print_alert.c'),
'-lm'
])
res = execute([
os.path.join(cwd, 'dist', 'duk'),
'-e', 'try { print(Duktape.enc("jx", {})); } catch (e) { print("ERROR: " + e.name); }'
])
return 'ERROR: TypeError\n' in res['stdout']
def context_linux_x64_error_variants():
# Test Duktape build using:
# (1) verbose and non-paranoid errors
# (2) verbose and paranoid errors
# (3) non-verbose errors
cwd = os.getcwd()
retval = True
for params in [
{ 'genconfig_opts': [ '-DDUK_USE_VERBOSE_ERRORS', '-UDUK_USE_PARANOID_ERRORS' ],
'binary_name': 'duk.verbose_nonparanoid' },
{ 'genconfig_opts': [ '-DDUK_USE_VERBOSE_ERRORS', '-DDUK_USE_PARANOID_ERRORS' ],
'binary_name': 'duk.verbose_paranoid' },
{ 'genconfig_opts': [ '-UDUK_USE_VERBOSE_ERRORS', '-UDUK_USE_PARANOID_ERRORS' ],
'binary_name': 'duk.nonverbose' },
]:
os.chdir(cwd)
execute([ 'make', 'clean', 'dist' ])
os.chdir(os.path.join(cwd, 'dist'))
execute([
'python2', os.path.join(cwd, 'dist', 'tools', 'genconfig.py'),
'--metadata', os.path.join(cwd, 'dist', 'config'),
'--output', os.path.join(cwd, 'dist', 'src', 'duk_config.h') # overwrite default duk_config.h
] + params['genconfig_opts'] + [
'duk-config-header'
])
execute([
'gcc', '-o' + params['binary_name'],
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join(cwd, 'dist', 'src'),
'-I' + os.path.join(cwd, 'dist', 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'dist', 'extras', 'print-alert'),
os.path.join(cwd, 'dist', 'src', 'duktape.c'),
os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'),
os.path.join(cwd, 'dist', 'extras', 'print-alert', 'duk_print_alert.c'),
'-lm'
])
execute([ 'size', params['binary_name'] ])
with open('test.js', 'wb') as f:
f.write("""\
try {
(undefined).foo = 123;
} catch (e) {
print('ERRORNAME: ' + e.name);
print('ERRORMESSAGE: ' + e);
print(e.stack);
}
""")
res = execute([
os.path.join(cwd, 'dist', params['binary_name']),
'test.js'
])
if 'ERRORNAME: TypeError\n' not in res['stdout']:
print('Cannot find error name in output')
retval = False
# For now, just check that the code compiles and error Type is
# correct. XXX: add check for error message too.
return retval
def context_helper_hello_ram(archopt):
cwd = os.getcwd()
def test(genconfig_opts):
os.chdir(cwd)
execute([ 'make', 'clean' ])
execute([ 'rm', '-rf', os.path.join(cwd, 'prep') ])
cmd = [
'python2', os.path.join(cwd, 'tools', 'configure.py'),
'--source-directory', os.path.join(cwd, 'src-input'),
'--output-directory', os.path.join(cwd, 'prep'),
'--config-metadata', os.path.join(cwd, 'config'),
'--rom-support'
] + genconfig_opts
print(repr(cmd))
execute(cmd)
execute([
'gcc', '-ohello', archopt,
'-Os', '-fomit-frame-pointer',
'-fno-stack-protector',
'-flto', '-fno-asynchronous-unwind-tables',
'-ffunction-sections', '-Wl,--gc-sections',
'-I' + os.path.join('prep'),
os.path.join(cwd, 'prep', 'duktape.c'),
os.path.join(cwd, 'examples', 'hello', 'hello.c'),
'-lm'
])
execute([
'size',
os.path.join(cwd, 'hello')
])
execute([
'valgrind', '--tool=massif',
'--massif-out-file=' + os.path.join(cwd, 'massif.out'),
'--peak-inaccuracy=0.0',
os.path.join(cwd, 'hello')
])
res = execute([
'ms_print',
os.path.join(cwd, 'massif.out')
], dump_stdout=False)
lines = res['stdout'].split('\n')
print('\n'.join(lines[0:50])) # print 50 first lines only
# KB
#107.5^ :
# | @#::::@:: :::@::: : :
kb = '???'
re_kb = re.compile(r'^([0-9\.]+)\^.*?$')
for line in lines[0:10]:
m = re_kb.match(line)
if m is not None:
kb = m.group(1)
print(' --> KB: ' + kb)
return kb
print('--- Default')
print('')
kb_default = test([])
print('')
print('--- No bufferobject support')
print('')
kb_nobufobj = test([
'-UDUK_USE_BUFFEROBJECT_SUPPORT'
])
print('')
print('--- ROM built-ins, global object inherits from ROM global')
print('--- No other low memory options (fast paths, pointer compression, etc)')
print('')
kb_rom = test([
'-DDUK_USE_ROM_OBJECTS',
'-DDUK_USE_ROM_STRINGS',
'-DDUK_USE_ROM_GLOBAL_INHERIT',
'-UDUK_USE_HSTRING_ARRIDX'
])
set_output_result({
'description': '%s %s %s (kB)' % (kb_default, kb_nobufobj, kb_rom),
'kb_default': kb_default,
'kb_nobufobj': kb_nobufobj,
'kb_rom': kb_rom
})
return True
def context_linux_x64_hello_ram():
return context_helper_hello_ram('-m64')
def context_linux_x86_hello_ram():
return context_helper_hello_ram('-m32')
def context_linux_x32_hello_ram():
return context_helper_hello_ram('-mx32')
def mandel_test(archopt, genconfig_opts):
cwd = os.getcwd()
execute([ 'make', 'dist' ])
execute([
'python2', os.path.join(cwd, 'tools', 'genconfig.py'),
'--metadata', os.path.join(cwd, 'config'),
'--output', os.path.join(cwd, 'dist', 'src', 'duk_config.h')
] + genconfig_opts + [
'duk-config-header'
])
execute([
'gcc', '-oduk', archopt,
'-Os', '-fomit-frame-pointer',
'-fno-stack-protector',
'-flto', '-fno-asynchronous-unwind-tables',
'-ffunction-sections', '-Wl,--gc-sections',
'-DDUK_CMDLINE_PRINTALERT_SUPPORT',
'-I' + os.path.join('dist', 'src'),
'-I' + os.path.join(cwd, 'dist', 'examples', 'cmdline'),
'-I' + os.path.join(cwd, 'dist', 'extras', 'print-alert'),
'-I' + os.path.join('dist', 'examples', 'cmdline'),
os.path.join(cwd, 'dist', 'src', 'duktape.c'),
os.path.join(cwd, 'dist', 'examples', 'cmdline', 'duk_cmdline.c'),
os.path.join(cwd, 'dist', 'extras', 'print-alert', 'duk_print_alert.c'),
'-lm'
])
execute([ 'size', os.path.join(cwd, 'duk') ])
res = execute([
os.path.join(cwd, 'duk'),
'-e', 'print(Duktape.version); print(Duktape.env); print(Math.PI)'
])
res = execute([
os.path.join(cwd, 'duk'),
os.path.join('dist', 'mandel.js')
])
md5_stdout = md5.md5(res['stdout']).digest().encode('hex')
md5_expect = '627cd86f0a4255e018c564f86c6d0ab3'
print(md5_stdout)
print(md5_expect)
return md5_stdout == md5_expect
def context_linux_regconst_variants():
res = True
res = res and mandel_test('-m64', [ '-DDUK_USE_EXEC_REGCONST_OPTIMIZE' ])
res = res and mandel_test('-m64', [ '-UDUK_USE_EXEC_REGCONST_OPTIMIZE' ])
res = res and mandel_test('-m32', [ '-DDUK_USE_EXEC_REGCONST_OPTIMIZE' ])
res = res and mandel_test('-m32', [ '-UDUK_USE_EXEC_REGCONST_OPTIMIZE' ])
return res
def context_linux_tval_variants():
# Cover most duk_tval.h cases, but only for little endian now.
res = True
for archopt in [ '-m64', '-m32' ]:
optsets = []
optsets.append([ '-UDUK_USE_PACKED_TVAL', '-DDUK_USE_64BIT_OPS', '-DDUK_USE_FASTINT' ])
optsets.append([ '-UDUK_USE_PACKED_TVAL', '-DDUK_USE_64BIT_OPS', '-UDUK_USE_FASTINT' ])
optsets.append([ '-UDUK_USE_PACKED_TVAL', '-UDUK_USE_64BIT_OPS', '-UDUK_USE_FASTINT' ])
if archopt == '-m32':
optsets.append([ '-DDUK_USE_PACKED_TVAL', '-DDUK_USE_64BIT_OPS', '-DDUK_USE_FASTINT' ])
optsets.append([ '-DDUK_USE_PACKED_TVAL', '-DDUK_USE_64BIT_OPS', '-UDUK_USE_FASTINT' ])
optsets.append([ '-DDUK_USE_PACKED_TVAL', '-UDUK_USE_64BIT_OPS', '-UDUK_USE_FASTINT' ])
for optset in optsets:
res = res and mandel_test(archopt, optset)
return res
def context_linux_x64_minisphere():
cwd = os.getcwd()
execute([ 'make', 'dist' ])
# Unpack minisphere snapshot and copy Duktape files over.
unpack_targz(os.path.join(repo_snapshot_dir, 'minisphere-20160516.tar.gz'))
prep(options=[ '--fixup-file', os.path.join(cwd, 'minisphere', 'src', 'engine', 'duk_custom.h') ])
for i in [ 'duktape.c', 'duktape.h', 'duk_config.h' ]:
execute([
'cp',
os.path.join(cwd, 'prep', i),
os.path.join(cwd, 'minisphere', 'src', 'shared', i)
])
# sudo apt-get install liballegro5-dev libmng-dev
os.chdir(os.path.join(cwd, 'minisphere'))
return execute([ 'make' ], catch=True)['success']
def context_linux_x64_dukluv():
cwd = os.getcwd()
execute([ 'make', 'dist' ])
# Unpack dukluv snapshot and symlink dukluv/lib/duktape to dist.
unpack_targz(os.path.join(repo_snapshot_dir, 'dukluv-20160528.tar.gz'))
execute([
'mv',
os.path.join(cwd, 'dukluv', 'lib', 'duktape'),
os.path.join(cwd, 'dukluv', 'lib', 'duktape-moved')
])
execute([
'ln',
'-s',
os.path.join(cwd, 'dist'),
os.path.join(cwd, 'dukluv', 'lib', 'duktape')
])
os.chdir(os.path.join(cwd, 'dukluv'))
execute([ 'mkdir', 'build' ])
os.chdir(os.path.join(cwd, 'dukluv', 'build'))
execute([ 'cmake', '..' ])
res = execute([ 'make' ], catch=True)
if not res['success']:
print('Build failed!')
return False
# Binary is in dukluv/build/dukluv.
execute([
os.path.join(cwd, 'dukluv', 'build', 'dukluv'),
os.path.join(cwd, 'dukluv', 'test-argv.js')
])
return True
def context_linux_graph_hello_size_helper(archopt):
cwd = os.getcwd()
cmd = [
'python2', os.path.join(cwd, 'tools', 'configure.py'),
'--source-directory', os.path.join(cwd, 'src-input'),
'--output-directory', os.path.join(cwd, 'prep'),
'--config-metadata', os.path.join(cwd, 'config'),
'--option-file', os.path.join(cwd, 'config', 'examples', 'low_memory.yaml')
]
execute(cmd)
execute([
'gcc', '-ohello', archopt,
'-std=c99', '-Wall',
'-Os', '-fomit-frame-pointer',
'-flto', '-fno-asynchronous-unwind-tables',
'-ffunction-sections', '-Wl,--gc-sections',
'-fno-stack-protector',
'-I' + os.path.join('prep'),
os.path.join(cwd, 'prep', 'duktape.c'),
os.path.join(cwd, 'examples', 'hello', 'hello.c'),
'-lm'
])
sz = get_binary_size(os.path.join(cwd, 'hello'))
set_output_result({
'description': format_size(sz),
'newsz': sz
})
return True
def context_linux_x64_graph_hello_size():
return context_linux_graph_hello_size_helper('-m64')
def context_linux_x86_graph_hello_size():
return context_linux_graph_hello_size_helper('-m32')
def context_linux_x32_graph_hello_size():
return context_linux_graph_hello_size_helper('-mx32')
def context_linux_arm_graph_hello_size():
return context_linux_graph_hello_size_helper('-marm')
def context_linux_thumb_graph_hello_size():
return context_linux_graph_hello_size_helper('-mthumb')
def context_codemetrics():
def scandir(path):
count = 0
lines = 0
for fn in os.listdir(path):
count += 1
with open(os.path.join(path, fn), 'rb') as f:
data = f.read()