-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
86 lines (75 loc) · 3.19 KB
/
app.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
from sys import argv
from json import dump
import src
from src.setting import *
from src.makeVscm import genVscm
from src.modifyCode import readVscm
from src.modifyVscm import applyNNResult
from src.testcase import readTC
from src.findVarError import findVarErr
if __name__ == "__main__":
if len(argv) < 4:
if JSONFILE_OUT:
print('Usage: python3 app.py [SRC-file] [input-TC-dir] [output-TC-dir] [Json-output-file]')
else:
print('Usage: python3 app.py [SRC-file] [input-TC-dir] [output-TC-dir]')
exit(-1)
elif JSONFILE_OUT and (len(argv) < 5):
print('Usage: python3 app.py [SRC-file] [input-TC-dir] [output-TC-dir] [Json-output-file]')
exit(-1)
else:
targetFilename = os.path.abspath(argv[1])
inputTCdirname = os.path.abspath(argv[2])
outputTCdirname = os.path.abspath(argv[3])
if JSONFILE_OUT:
jsonOutFilename = os.path.abspath(argv[4])
with open(targetFilename, 'r') as tf:
code = tf.readlines()
genVscm(targetFilename, VSCM_FILENAME)
vscm = sorted(readVscm(VSCM_FILENAME), key=lambda x: (x['targetLine'], x['targetColumn'], x['targetStr']))
if USE_MODEL:
vscm, _ = applyNNResult(vscm, targetFilename)
itcs, otcs = readTC(inputTCdirname, outputTCdirname)
mc, mci, vi, rs, rc, et, vic = findVarErr(
code,
vscm,
MODIFIEDSRC_FILENAME,
COMPILED_FILENAME,
MOD_LIMIT,
itcs,
otcs,
SINGLE_TIMEOUT,
TOTAL_TIMEOUT,
PROGRESS_PRINT
)
if PROGRESS_PRINT:
print('app.py : dbg: findVarErr2 FINISHED')
if INFO_PRINT:
if rs == 0:
print('RESULT: SUCCESS')
else:
print('RESULT: FAILED')
print('ITER COUNT =\t', vic)
print('ELAPSED TIME =\t', et)
if rs == 0:
print('MODIFIED LINES =\t', list(map(lambda x : x + 1, mci)))
print('<<<MODIFIED CODE>>>')
print(mc)
# JSON file output format
if JSONFILE_OUT:
d = {}
d['targetFilename'] = targetFilename
d['inputTCdirname'] = inputTCdirname
d['outputTCdirname'] = outputTCdirname
d['modifiedCode'] = mc # check 'modified code String' in 'findVarError.py'
d['modifiedCodeLines'] = mci # check 'modified codeline Indices' in 'findVarError.py'
d['returnStatus'] = rs # check 'returnStatus' in 'findVarError.py'
d['resultCodes'] = rc # check 'resultCodes' in 'findVarError.py'
d['elapsedTime'] = et # check 'elpased time' in 'findVarError.py'
d['iterCount'] = vic # check 'valid Iterate count' in 'findVarError.py'
with open(jsonOutFilename, JSONFILE_OUTOPTION) as jsonfile:
if PROGRESS_PRINT:
print('app.py : dbg: JSONFILE WRITE START')
dump(d, jsonfile, indent=JSONFILE_INDENT)
if PROGRESS_PRINT:
print('app.py : dbg: JSONFILE WRITE FINISHED')