Commit 46cf061a authored by Daniel Tuulik's avatar Daniel Tuulik
Browse files

Call sdl-parser, add out file comparison

The out file comparison is taken from QGen,
it still needs some adjustments to work
Calling sdl-parser assumes the following:
#export JAR_DIR=~/esa/esa-ic-proj/parser/ee.ibk.sdl.parser/target/export/
#export JAR_NAME=ee.ibk.sdl.parser-full.jar
parent 945050ab
......@@ -15,7 +15,7 @@ work3 = ['python', 'testqgen.py']
testsWork = {
'all': work1,
'test-parse' : work1,
'test-qgen-parse' : work3,
'test-qgen-parse' : work1,
'test-ada' : work1,
'test-c' : work1,
'test-llvm' : work1,
......@@ -60,12 +60,8 @@ def make(rule, path):
work=testsWork[rule]
''' Compose the command based on the rule'''
if rule=='test-qgen-parse':
cmd=[work[0], work[1], rule, path]
else:
cmd=[work[0], work[1], path, rule]
cmd=[work[0], work[1], path, rule]
print (cmd)
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
......
......@@ -10,13 +10,17 @@ import sys
import logging
import argparse
import subprocess
import unittest
import difflib
import re
import string
__version__ = '1.0.0'
LOG = logging.getLogger(__name__)
def parse_args():
''' Parse command line arguments '''
parser = argparse.ArgumentParser(version=__version__)
parser.add_argument('rule', metavar='Rule', type=str)
parser.add_argument('files', metavar='file.pr', type=str, nargs='*',
help='SDL file(s)')
parser.add_argument('-u', '--update', action='store_true')
......@@ -43,27 +47,103 @@ def getSizeFiles(list,size):
return err
def diff(expected, actual, msg=None, count=1, case_sensitive=True,
update=None, silent=False, directory=''):
"""Compare EXPECTED and str2. If not equal, display a diff and raise an
error.
"""
# try looking in self.directory
full_expected = os.path.join(directory, expected)
if isinstance(expected, file):
str1 = expected.read()
frm = expected.name
elif os.path.isfile(expected):
str1 = file(expected).read()
frm = expected
elif os.path.isfile(full_expected):
expected = full_expected
str1 = file(expected).read()
frm = expected
elif update:
# Check if it's a valid file path, in which case use it. Because of
# --update, the file will be created and filled with the expected
# output further below.
try:
file(full_expected, 'w')
expected = full_expected
str1 = ''
frm = expected
except:
str1 = expected
frm = "Expected"
else:
str1 = expected
frm = "Expected"
if os.path.isfile(actual):
actual = file(actual).read()
string.replace(actual, "\r", "")
expected = str1 * count
diff = colored_unified_diff(
expected, actual, fromfile=frm, tofile="Output")
if diff:
if msg:
msg = msg + "\n"
else:
msg = ""
msg = msg + "------- EXPECTED: ----\n" \
+ expected + "\n" \
+ "------- ACTUAL: --------\n" + actual + "\n"
if update:
# If updating baselines, do not stop at the first difference
if frm != "Expected":
f = file(frm, "w")
f.close()
else:
d = re.sub("\n", "$\n", "\n".join(diff))
if not silent:
unittest.TestCase.fail(msg + "\n" + d)
else:
return msg + "\n" + d
def colored_unified_diff(a, b, fromfile='', tofile='',
fromfiledate='', tofiledate='', n=3, lineterm='\n',
onequal=None, onreplaceA=None, onreplaceB=None):
for line in difflib.unified_diff(a, b, fromfile, tofile):
yield line
def main():
options = parse_args()
init_logging(options)
files=''
jar_dir = os.environ.get('JAR_DIR')
jar_name = os.environ.get('JAR_NAME')
jar_path = os.path.join (jar_dir,jar_name)
for file in options.files:
files = files + file + ' '
cmd = ['make ', files, ' --check']
print (cmd)
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()
errcode = proc.wait()
#expected = file + '.out'
cmd = ['java', '-jar', jar_path, os.path.abspath(file)]
print (cmd)
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
errcode = proc.wait()
#diff(expected=expected, actual=proc.stdout)
return (errcode, stdout, stderr)
if __name__ == '__main__':
ret = main()
sys.exit(ret)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment