-
Notifications
You must be signed in to change notification settings - Fork 15
/
lci.py
executable file
·786 lines (756 loc) · 22.7 KB
/
lci.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import glob
from elementtree import ElementTree
def stripSpecifics(lbl):
l = lbl[:]
if l.find('-')>0:
l = l.split('-')[0]
return l
def stripCamelCase(lbl):
l=''
for x in lbl:
if x.islower() or x=='.':
l+=x
else:
break
return l
class Chain:
def __init__(self,*arr):
self.array=[]
for a in arr:
self.array.append(a)
def __call__(self):
return '.'.join(self.array)
def __repr__(self):
return '-'+'.'.join(self.array)+'-'
# singular items are strings, slices are Chains
def __getitem__(self,key):
if type(key)==type(slice(0,1,None)):
return ChainFromArray(self.array[key])
else:
return self.array[key]
def __len__(self):
return len(self.array)
def __eq__(self,other):
if type(other)==type(''):
return self.array==other.split('.')
else:
return self.array==other.array
def dotNodeName(self,target):
name = self.array[0]
for a in self.array[1:]:
name += '_'+stripSpecifics(a)
return name+'_'+target
def bgfFileName(self):
name = [self.array[0]]
for a in self.array[1:]:
if name[-1].isdigit():
if name[-2]==stripCamelCase(a):
name[-1] = str(int(name[-1])+1)
else:
name.append(stripCamelCase(a))
elif name[-1]==stripCamelCase(a):
name.append('2')
else:
name.append(stripCamelCase(a))
return '.'.join(name)+'.bgf'
def futureBgfFileName(self,next):
tmp = self.array[:]
self.array.append(stripCamelCase(next))
name = self.bgfFileName()
self.array = tmp
return name
def append(self,step):
self.array.append(step)
def spaceNotation(self):
tmp = self.array[:]
tmp.reverse()
return ' '.join(tmp)
def type(self):
t = 0
for a in self.array[1:]:
if ttype[a] in ('synchronization','postextraction','normalization'):
t = -1
if ttype[a] in ('transformation','refactoring'):
t = 1
return t
def lastAction(self):
return self.array[-1]
def ChainFromArray(a):
x = Chain()
x.array = a[:]
return x
# A global flag, if set, LCI will exit with a non-zero status
problem = False
# output streams redirected to null
shutup = ' 1> /dev/null 2> /dev/null'
# transformation type per action: postextraction, synchronization, etc
ttype = {}
orderedsrc = []
shortcuts = {}
actions = []
autoactions = {}
testsets = {}
tester = {}
extractor = {}
treeExtractor = {}
treeEvaluator = {}
targets = {}
parser = {}
evaluator = {}
testset = []
graphBig = []
graphSmall = []
log = None
tools = {}
treeTools = {}
automethods = {}
almostFailed = []
failed = []
def writeLog(s):
log.write(s+'\n')
log.flush()
def sysexit(n):
log.close()
sys.exit(n)
def readConfiguration (cfg):
config = ElementTree.parse(cfg)
# shortcuts
for xmlnode in config.findall('//shortcut'):
shortcuts[xmlnode.findtext('name')]=expandxml(xmlnode.findall('expansion')[0],{})
# actions
for xmlnode in config.findall('//target/branch/*/perform'):
if xmlnode.text not in actions:
actions.append(xmlnode.text)
# automated actions
for xmlnode in config.findall('//target/branch/*/automated'):
if xmlnode.findtext('result') not in actions:
actions.append(xmlnode.findtext('result'))
autoactions[xmlnode.findtext('result')]=xmlnode.findtext('method')
# testset
for xmlnode in config.findall('//testset'):
testsets[xmlnode.findtext('name')]=expandxml(xmlnode.findall('command')[0],{})
# sources
for xmlnode in config.findall('//source'):
orderedsrc.append(xmlnode.findtext('name'));
extractor[xmlnode.findtext('name')]=expandxml(xmlnode.findall('grammar/extraction')[0],{})
if xmlnode.findall('grammar/parsing'):
parser[xmlnode.findtext('name')]=expandxml(xmlnode.findall('grammar/parsing')[0],{})
if xmlnode.findall('grammar/evaluation'):
evaluator[xmlnode.findtext('name')]=expandxml(xmlnode.findall('grammar/evaluation')[0],{})
if xmlnode.findall('tree/extraction'):
treeExtractor[xmlnode.findtext('name')]=expandxml(xmlnode.findall('tree/extraction')[0],{})
if xmlnode.findall('tree/evaluation'):
treeEvaluator[xmlnode.findtext('name')]=expandxml(xmlnode.findall('tree/evaluation')[0],{})
tmp = []
for set in xmlnode.findall('testing/set'):
tmp.append(set.text)
tester[xmlnode.findtext('name')]=tmp[:]
# targets
for xmlnode in config.findall('//target'):
name = xmlnode.findtext('name')
targets[name]= []
for br in xmlnode.findall('branch'):
for phase in br.findall('*'):
if phase.tag == 'input':
branch = Chain(br.findtext('input'))
else:
for p in phase.findall('*'):
if p.tag == 'perform':
branch.append(p.text)
ttype[p.text] = phase.tag
elif p.tag == 'automated':
branch.append(p.findtext('result'))
ttype[p.findtext('result')] = phase.tag
else:
print '[WARN] Unknown tag skipped:',p.tag
targets[name].append(branch)
# tools
for xmlnode in config.findall('//tool'):
tools[xmlnode.findtext('name')] = expandxml(xmlnode.findall('grammar')[0],{})
if xmlnode.findall('tree'):
treeTools[xmlnode.findtext('name')] = expandxml(xmlnode.findall('tree')[0],{})
# methods
for xmlnode in config.findall('//generator'):
automethods[xmlnode.findtext('name')] = expandxml(xmlnode.findall('command')[0],{})
print 'Read',
if shortcuts:
print len(shortcuts),'shortcuts,',
if tools or treeTools:
print `len(tools)`+'+'+`len(treeTools)`,'tools,',
if actions:
if autoactions:
print len(actions),'actions ('+`len(autoactions)`,'automated),',
else:
print len(actions),'actions,',
if automethods:
print len(automethods),'generators,',
if targets:
print len(targets),'targets,',
if testsets:
print len(testsets),'test sets,',
if extractor:
print len(extractor),'sources,',
if parser or evaluator:
print len(parser),'parsers &',len(evaluator),'evaluators,',
print 'LCF is fine.'
def expandone(tag,text,rep):
if text:
wte = text
else:
wte = tag.replace('expand-','')
if shortcuts.has_key(wte):
return shortcuts[wte]
elif rep.has_key(wte):
return rep[wte]
else:
# postpone expanding
return '%'+wte+'%'
def expandxml(mixed,rep):
s = mixed.text
for tag in mixed.getchildren():
s += expandone(tag.tag,tag.text,rep)
s += tag.tail
return s.strip()
def quote(a):
return '"'+a+'"'
def addarc(fromnode,tonode,q,labelnode):
if [fromnode,tonode,q,labelnode] not in graphBig:
graphBig.append([fromnode,tonode,q,labelnode])
def makeGraph():
# first we generate a complete picture
for x in targets.keys():
for branch in targets[x]:
graphSmall.append((branch[0],x))
if len(branch)==1:
graphBig.append((branch,Chain(x),'',x))
else:
for i in range(1,len(branch)-1):
graphBig.append((branch[:i],branch[:(i+1)],stripSpecifics(branch[i]),x))
graphBig.append((branch[:-1],Chain(x),stripSpecifics(branch[-1]),x))
def distanceBetween(node,tgt):
if node()==tgt:
return '?'
if len(targets[tgt])!=2:
print '[WARN] Only binary branches supported for now.'
return '?'
if targets[tgt][0]().find(node())==0:
return compareGrammars(node,targets[tgt][1])
elif targets[tgt][1]().find(node())==0:
return compareGrammars(node,targets[tgt][0])
print '[FAIL]',node(),'not found on the way to target',tgt
return '?'
def compareGrammars(bgf,arr):
goal = arr[0]
for a in arr().split('.')[1:]:
if ttype[a] in ('synchronization','postextraction','normalization'):
goal += '.'+stripCamelCase(a)
#print '[----] Ready:',bgf,'vs',goal
#print '[++++] Distance is:',
#run = 'expr `'+tools['comparison'] + ' bgf/'+bgf.bgfFileName()+' bgf/'+goal+'.bgf | grep "Fail:" | wc -l` + `'+tools['comparison'] + ' bgf/'+bgf.bgfFileName()+' bgf/'+goal+'.bgf | grep "only:" | grep -o "\[..*\]" | wc -w`'
run = tools['comparison'] + ' bgf/'+bgf.bgfFileName()+' bgf/'+goal+'.bgf | grep "only:" | grep -o "\[..*\]" | wc -w'
writeLog(run)
if os.system(run+' > TMP-res'):
#print '[WARN] Cannot count name mismatches between',bgf(),'and',goal
#return '?'
nameDiffs = '0'
else:
num = open('TMP-res','r')
nameDiffs = num.readline().strip()
num.close()
run = tools['comparison'] + ' bgf/'+bgf.bgfFileName()+' bgf/'+goal+'.bgf | grep Fail'
writeLog(run)
if os.system(run+' > TMP-res'):
#print '[WARN] Cannot count structural mismatches between',bgf(),'and',goal
#return '?'
strDiffs = 0
else:
num = open('TMP-res','r')
strDiffs = 0
for line in num.readlines():
nsn = line.strip().split('(')[1].split(')')[0].split('/')
strDiffs += max(int(nsn[0]),int(nsn[1]))
num.close()
return nameDiffs+'+'+`strDiffs`
def dumpGraph(df):
dot = open(df+'_large.dot','w')
dot.write('''digraph generated{
edge [fontsize=24];
node [fontsize=24];
{rank=same;
node [shape=ellipse, style=bold];
edge[style=invis,weight=10];
''')
for x in orderedsrc:
dot.write(quote(x))
if x in failed:
dot.write(' [color=red]')
elif x in almostFailed:
dot.write(' [color=blue]')
dot.write(';')
for x in orderedsrc:
dot.write(quote(x))
if x==orderedsrc[-1]:
dot.write(';')
else:
dot.write('->')
dot.write('}\n')
dot.write('node [shape=octagon, style=bold];\n')
for x in targets.keys():
dot.write(quote(x+'_'+x)+' [label="'+x+'"]')
if x in failed:
dot.write(' [color=red]')
dot.write(';')
dot.write('node [shape=circle, style=solid];\n')
# connect real target&source nodes with the "zero step" ones
for x in targets.keys():
for branch in targets[x]:
if branch[0] in targets.keys():
dot.write(quote(branch[0]+'_'+branch[0])+'->'+branch[:1].dotNodeName(x)+';')
else:
dot.write(quote(branch[0])+'->'+branch[:1].dotNodeName(x)+';')
# continue
nodezz=[]
dablNodezz=[]
for arc in graphBig:
dot.write(arc[0].dotNodeName(arc[3]))
dot.write('->'+arc[1].dotNodeName(arc[3]))
if (arc[0],arc[3]) not in nodezz:
nodezz.append((arc[0],arc[3]))
if (arc[1],arc[3]) not in nodezz:
nodezz.append((arc[1],arc[3]))
if (arc[0][-1] in targets.keys()) or (arc[0][-1] in orderedsrc) or (arc[0][-1] in ttype.keys() and ttype[arc[0][-1]] in ('synchronization','postextraction','normalization')):
if (arc[1][-1] in targets.keys()) or (arc[1][-1] in ttype.keys() and ttype[arc[1][-1]] in ('transformation','refactoring')):
dablNodezz.append(arc[0].dotNodeName(arc[3]))
par = ''
if arc[2]:
par += 'label="'+arc[2]+'" '
if arc[1] in failed:
par += 'color=red '
if arc[1]() in targets.keys():
pseudo = arc[0][:]
pseudo.append(arc[2])
if pseudo in failed:
par += 'color=red '
if par:
dot.write(' ['+par+']')
dot.write(';\n')
#currentFileName = df+'.'+nodezz[0][1]+'.csv'
#currentFile = open(currentFileName,'w')
#print nodezz
for nNg in nodezz:
node,goal=nNg
#if df+'.'+goal+'.csv' != currentFileName:
# currentFile.close()
# currentFileName = df+'.'+goal+'.csv'
# currentFile = open(currentFileName,'w')
if node in failed:
colour = 'red'
elif node in almostFailed:
colour = 'blue'
else:
colour = 'black'
if node() in targets.keys():
dot.write(quote(node()+'_'+goal))
tmp =quote(node()+'_'+goal)
# test for end targets that do not need extra boxes
else:
dot.write(node.dotNodeName(goal))
tmp = node.dotNodeName(goal)
cx = distanceBetween(node,goal)
#print '[----]',node,'(->',goal,') =',cx,'['+tmp+']'
dot.write(' [color='+colour)
if cx != '?':
dot.write(', label="'+cx+'"')
#currentFile.write(node.lastAction()+','+`eval(cx)`+'\n')
if node.dotNodeName(goal) in dablNodezz:
# synch point
dot.write(', shape=doublecircle')
dot.write('];\n')
#currentFile.close()
dot.write('}')
dot.close()
run = 'dot -Tpdf '+dot.name+' -o '+df+'_large.pdf'
writeLog(run)
if os.system(run):
print '[WARN] Detailed diagram not generated'
problem = True
dot = open(df+'_small.dot','w')
dot.write('digraph generated{ {rank=same; edge[style=invis,weight=10];\n')
for x in orderedsrc:
dot.write(quote(x))
if x in failed:
dot.write(' [color=red]')
elif x in almostFailed:
dot.write(' [color=blue]')
dot.write(';')
for x in orderedsrc:
dot.write(quote(x))
if x==orderedsrc[-1]:
dot.write(';')
else:
dot.write('->')
dot.write('}')
dot.write('node [shape=octagon]\n')
for x in targets.keys():
dot.write(quote(x))
if x in failed:
dot.write(' [color=red]')
elif x in almostFailed:
dot.write(' [color=blue]')
dot.write(';')
for arc in graphSmall:
dot.write(quote(arc[0])+'->'+quote(arc[1]))
if arc[0] in failed and arc[1] in failed:
dot.write(' [color=red]')
dot.write(';\n')
dot.write('}')
dot.close()
run = 'dot -Tpdf '+dot.name+' -o '+df+'_small.pdf'
writeLog(run)
if os.system(run):
print '[WARN] Abstract diagram not generated.'
problem = True
else:
print '[PASS] Diagram generation completed.'
def copyFile(x,y):
xh=open(x,'r')
yh=open(y,'w')
yh.writelines(xh.readlines())
xh.close()
yh.close()
def extractAll():
for bgf in extractor.keys():
run = extractor[bgf]+' bgf/'+bgf+'.bgf'
writeLog(run)
if os.system(run+shutup):
if os.access('snapshot/'+bgf+'.bgf',os.R_OK):
print '[WARN] Extraction of',bgf+'.bgf failed, LCI rolled back'
copyFile('snapshot/'+bgf+'.bgf','bgf/'+bgf+'.bgf')
writeLog('cp snapshot/'+bgf+'.bgf bgf/'+bgf+'.bgf')
almostFailed.append(bgf)
else:
print '[FAIL] Extraction of',bgf+'.bgf failed'
failed.append(Chain(bgf))
problem = True
#sysexit(3)
else:
run = tools['comparison'] + ' bgf/'+bgf+'.bgf snapshot/'+bgf+'.bgf'
writeLog(run)
if os.system(run+shutup):
# different from the saved version
print '[PASS] Extracted a newer version of',bgf+'.bgf'
copyFile('bgf/'+bgf+'.bgf','snapshot/'+bgf+'.bgf')
writeLog('cp bgf/'+bgf+'.bgf snapshot/'+bgf+'.bgf')
print '[PASS] Extraction finished.'
def validateAll():
problem = False
for bgf in extractor.keys():
if Chain(bgf) in failed:
continue
run = tools['validation']+' bgf/'+bgf+'.bgf'
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL] Validation failed on',bgf+'.bgf'
failed.append(Chain(bgf))
#sysexit(3)
if not problem:
print '[PASS] Validation finished.'
def runTransforms(cut,current,whichtypes):
ontheroll = True
for a in cut[1:]:
if ontheroll:
if ttype[a] not in whichtypes:
continue
if a in autoactions.keys():
#print 'Automated action',a,'spotted!
run = automethods[autoactions[a]]+' bgf/'+current.bgfFileName()+' xbgf/'+a+'.xbgf'
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL]',
ontheroll = False
else:
print '[PASS]',
print 'Generated',ttype[a],a+'.xbgf','from',current.bgfFileName()
if ontheroll:
run = tools['transformation']+' xbgf/'+a+'.xbgf bgf/'+current.bgfFileName()+' bgf/'+current.futureBgfFileName(a)
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL]',
failed.append(current[:])
failed[-1].append(a)
ontheroll = False
else:
print '[PASS]',
print 'Applied generated',a+'.xbgf','to',current.bgfFileName()
else:
#???
run = tools['transformation']+' xbgf/'+a+'.xbgf bgf/'+current.bgfFileName()+' bgf/'+current.futureBgfFileName(a)
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL]',
failed.append(current[:])
failed[-1].append(a)
ontheroll = False
else:
print '[PASS]',
print 'Applied',ttype[a],a+'.xbgf','to',current.bgfFileName()
else:
failed.append(current[:])
failed[-1].append(a)
current.append(a)
return ontheroll,current
def transformationChain(cut,target):
# executes preparational actions (abstract, unerase, etc) before comparison
if len(cut)==1:
# nothing to do
return Chain(cut[0])
else:
# start point at source or target
current = Chain(cut[0])
# action names will be appended:
# x.bgf -> x.corrupt.bgf -> x.corrupt.confuse.bgf -> x.corrupt.confuse.destroy.bgf -> ...
# the very last one will be diffed
ontheroll,current = runTransforms(cut,current,('postextraction','synchronization','normalization'))
if ontheroll:
print '[PASS]',
else:
print '[FAIL]',
print 'Postextraction and synchronyzation finished for target',target+'.'
# same for transformation
ontheroll,current = runTransforms(cut,current,('transformation','refactoring'))
# end of branch
if cut in failed:
print '[FAIL]',
else:
print '[PASS]',
print 'Branch finished as',current.bgfFileName()
if cut not in failed and tools.has_key('validation'):
a = tools['validation']+' bgf/'+current.bgfFileName()
writeLog(a)
if os.system(a+shutup):
problem = True
print '[FAIL]',
else:
print '[PASS]',
print 'Branch result validated'
return current
def orderTargets():
unordered = targets.keys()[:]
ordered = []
while len(unordered):
for t in unordered:
flag = True
for i in targets[t]:
if (i[0] not in ordered) and (i[0] not in extractor.keys()):
flag = False
if flag:
ordered.append(t)
unordered.remove(t)
return ordered
def buildTargets():
for t in orderTargets():
inputs = targets[t]
fileinputs = []
for i in range(0,len(inputs)):
fileinputs.append(transformationChain(inputs[i],t))
if len(inputs)>1:
# need to diff
diffAll(t,fileinputs[0],fileinputs[1:])
# save resulting name
cx = 0
while cx<len(fileinputs):
if fileinputs[cx] not in failed:
break
cx+=1
if cx<len(fileinputs):
print '[PASS] Target',t,'reached as',fileinputs[cx].bgfFileName()
copyFile('bgf/'+fileinputs[cx].bgfFileName(),'bgf/'+t+'.bgf')
writeLog('cp bgf/'+fileinputs[cx].bgfFileName()+' bgf/'+t+'.bgf')
else:
# Tough luck: all branches failed
print '[FAIL] Target',t,'unreachable'
def diffAll(t,car,cdr):
#print car,cdr
if len(cdr)==1:
run = tools['comparison']+' bgf/'+car.bgfFileName()+' bgf/'+cdr[0].bgfFileName()
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL] Mismatch in target',t+':',car.bgfFileName(),'differs from',cdr[0].bgfFileName()
failed.append(Chain(t))
#sysexit(3)
else:
for head in cdr:
diffAll(t,car,[head])
diffAll(t,cdr[:1],cdr[1:])
def chainXBTF(testcase,steps,t):
fr = testcase
for step in steps:
if step==steps[-1]:
# name it after the target
re = fr.split('.')[0]+'.'+t+'.btf'
else:
# name it as input.transformationName.btf
re = '.'.join(fr.split('.')[:-1])+'.'+step+'.btf'
run = treeTools['transformation']+' xbgf/'+step+'.xbgf '+fr+' '+re
writeLog(run)
#print 'Performing coupled',step,'on',fr,'-',
if os.system(run+shutup):
problem = True
print '[FAIL] Performing coupled',step,'on',fr,'failed'
break
fr = re
print '[PASS] Performed coupled',steps.spaceNotation(),'on',testcase,
if treeTools.has_key('validation'):
run = treeTools['validation']+' '+re
if os.system(run+shutup):
problem = True
print '- NOT valid'
else:
print '- valid'
else:
print
def diffBTFs(t):
if len(testsets)<2:
# with one test set there's nothing to diff
return
if 'comparison' not in treeTools.keys():
# no tree diff tool specified
return
basetestset = testsets.keys()[0]
for basetestcase in glob.glob(basetestset+'/*.'+t+'.btf'):
for testset in testsets.keys()[1:]:
for testcase in glob.glob(testset+'/'+basetestcase.split('/')[1]):
run = treeTools['comparison']+' '+basetestcase+' '+testcase
if os.system(run+shutup):
problem = True
print '[FAIL]',
else:
print '[PASS]',
print 'Found and compared',basetestcase.split('/')[1],'in',basetestset,'and',testset
def convergeTestSets():
for testset in testsets.keys():
# extracting
run = testsets[testset]+' '+testset
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL] Test set',testset,'could not be extracted'
continue
print '[PASS] Test set',testset,'extracted'
for src in treeExtractor.keys():
for testset in tester[src]:
for testcase in glob.glob(testset+'/*.src'):
run = treeExtractor[src]+' '+testcase+' '+testcase+'.btf'
writeLog(run)
if os.system(run+shutup):
problem = True
print '[FAIL]',
else:
print '[PASS]',
print 'Tree extracted from',testcase
for t in orderTargets():
for branch in targets[t]:
if treeExtractor.has_key(branch[0]):
# it's a source, let's check it we have an extracted tree
for testset in tester[branch[0]]:
for testcase in glob.glob(testset+'/*.src.btf'):
chainXBTF(testcase,branch[1:],t)
if targets.has_key(branch[0]):
# it's a target, let's see if we have any test cases arrived at it
for testset in testsets.keys():
for testcase in glob.glob(testset+'/*.'+branch[0]+'.btf'):
chainXBTF(testcase,branch[1:],t)
diffBTFs(t)
final = orderTargets()[-1]
for evaluator in treeEvaluator.keys():
pass
def runTestSets():
for testset in testsets.keys():
# testing parser
for testcase in glob.glob(testset+'/*.src'):
results={}
for program in parser.keys():
if testset in tester[program]:
run = parser[program]+' '+testcase
writeLog(run)
results[program]=os.system(run+shutup)
if results.values()==[0]*len(results):
print '[PASS] Test case',testcase,'parsed'
else:
problem = True
print '[FAIL] Test case',testcase,'failed parsing'
for r in results.keys():
if results[r]:
print '[FAIL]',r,'did not parse it correctly'
# testing evaluator
for testcase in glob.glob(testset+'/*.run'):
results={}
for program in evaluator.keys():
if testset in tester[program]:
run = evaluator[program]+' '+testcase.replace('.run','.ctx')+' '+testcase+' '+testcase.replace('.run','.val')
writeLog(run)
results[program]=os.system(run+shutup)
if results.values()==[0]*len(results):
print '[PASS] Test case',testcase,'evaluated'
else:
problem = True
print '[FAIL] Test case',testcase,'failed evaluation'
for r in results.keys():
if results[r]:
print '[FAIL]',r,'evaluated it differently'
def checkConsistency():
# some simple assertions
# all targets depend on existing targets or sources
for t in targets.keys():
for i in targets[t]:
if not (targets.has_key(i[0]) or extractor.has_key(i[0])):
print '[FAIL] Target',t,'needs',i[0],'which is not defined'
sysexit(7)
# all actions can be found
try:
for a in actions:
if a not in autoactions.keys():
open('xbgf/'+a+'.xbgf','r').close()
except IOError, e:
print '[FAIL] Undefined action used: need',e.filename
#sysexit(8)
# all automated actions can be found
for a in autoactions.keys():
if autoactions[a] not in automethods.keys():
print '[FAIL] Automation method',autoactions[a],'not found (automated action',a+')'
sysexit(18)
if __name__ == "__main__":
print 'Language Covergence Infrastructure v1.15'
if len(sys.argv) == 3:
log = open(sys.argv[1].split('.')[0]+'.log','w')
readConfiguration(sys.argv[1])
checkConsistency()
makeGraph()
extractAll()
if tools.has_key('validation'):
validateAll()
buildTargets()
print '----- Grammar convergence phase finished. -----'
if testsets:
runTestSets()
convergeTestSets()
print '----- Tree convergence phase finished. -----'
else:
print '[WARN] No testing performed.'
#dumpGraph(sys.argv[2])
if problem:
sysexit(100)
log.close()
else:
print 'Usage:'
print ' ',sys.argv[0],'<configuration file>','<diagram prefix>'
sysexit(1)