Commit f30a385e authored by Daniel Tuulik's avatar Daniel Tuulik
Browse files

Update testqgen.py, generate gpr file and compile

parent c0e72f21
......@@ -5,6 +5,7 @@
Run some tests using QGen components
"""
from string import Template
import os
import sys
import logging
......@@ -128,7 +129,7 @@ def main():
def run_test(op):
''' Call a SDL parser with the required arguments '''
jar_dir = os.environ.get('JAR_DIR')
jar_name = os.environ.get('JAR_NAME')
jar_path = os.path.join (jar_dir,jar_name)
......@@ -146,16 +147,117 @@ def run_test(op):
#expected = file + '.out'
cmd = ['java', '-jar', jar_path, op.root_model,
'--language', lang]
proc = subprocess.Popen(cmd,
'--language', lang, '--generate-types',
'--output', 'generated_' + lang]
p1 = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
errcode = proc.wait()
stdout, stderr = p1.communicate()
errcode = p1.wait()
if errcode != 0:
return (errcode, stdout, stderr, op.root_model, op.rule)
#diff(expected=expected, actual=proc.stdout
return (errcode, stdout, stderr, op.root_model, op.rule)
if lang in ('ada', 'c'):
p2 = _compile (lang)
stdout, stderr = p2.communicate()
errcode = p2.wait()
return (errcode, stdout, stderr, op.root_model, op.rule)
def _run_gprbuild(gprfile):
args = ["gprbuild",
"-p", # Create obj dirs
"-j1", # when tests run in parallel, CPUs are already
# being used by other tests.
"-k", # Do not stop on first error
"-P%s" % gprfile,
"-gnatwa", "-gnatyg-dm", "-gnateE"]
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return proc
def _compile (lang):
source_dirs = '"."'
main_file = ""
compiler_pkg = ""
linker_pkg = ""
binder_pkg = ""
do_c = lang == "c"
do_ada = lang == "ada"
c_prj = ""
ada_prj = ""
src_path = 'generated_' + lang
flags = ''
c_std = 'c99'
languages = """for Languages use ({0});"""
compiler_pkg = """package Compiler is
for Default_Switches ("{0}") use ("-g"{1});
end Compiler;"""
linker_pkg = """package Linker is
for Default_Switches ("{0}") use ("-lm");
end Linker;"""
binder_pkg = """package Binder is
for Default_Switches ("{0}") use ("-E");
end Binder;"""
template_ada = Template("""with "Prj_C";
project Prj_Ada is
for Source_Dirs use (${source_dirs});
for Object_Dir use "obj_ada";
for Exec_Dir use "exec";
${main}
${lang}
${compiler_pkg}
${linker_pkg}
${binder_pkg}
end Prj_Ada;""")
ada_prj = template_ada.substitute(
source_dirs=source_dirs,
main=main_file.format("main.adb"),
lang=languages.format('"Ada"'),
compiler_pkg=compiler_pkg.format(
"Ada", ', "-gnata"%s' % flags),
linker_pkg=linker_pkg.format("Ada"),
binder_pkg=binder_pkg.format("Ada"))
gpr_filename_ada = os.path.join(src_path, 'Prj_Ada.gpr')
with open(gpr_filename_ada, 'w') as f:
f.write(ada_prj)
template_c = Template("""project Prj_C is
for Source_Dirs use (${source_dirs});
for Object_Dir use "obj";
for Exec_Dir use "exec";
${main}
${lang}
${compiler_pkg}
${linker_pkg}
${binder_pkg}
end Prj_C;""")
c_prj = template_c.substitute(
source_dirs=source_dirs,
main=main_file.format("main.c"), lang=languages.format('"C"'),
compiler_pkg=compiler_pkg.format("C", ', "-std=%s"%s' %
(c_std, flags)),
linker_pkg=linker_pkg.format("C"),
binder_pkg=binder_pkg.format("C"))
gpr_filename_c = os.path.join(src_path, 'Prj_C.gpr')
with open(gpr_filename_c, 'w') as f:
f.write(c_prj)
if do_ada:
return _run_gprbuild(gpr_filename_ada)
if do_c:
return _run_gprbuild(gpr_filename_c)
if __name__ == '__main__':
ret = main()
sys.exit(ret)
Supports Markdown
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