Skip to content

Commit

Permalink
Add tests for enum image
Browse files Browse the repository at this point in the history
Part of R601-023

Change-Id: Id7e37273c41ed91b11251ef95bfa71e1595eca53
  • Loading branch information
Nikokrock committed Jun 27, 2018
1 parent c4f809b commit d32516a
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1 +1,2 @@
sqlite/amalgamation/* no-precommit-check
testsuite/** no-precommit-check
60 changes: 52 additions & 8 deletions testsuite/drivers/__init__.py
Expand Up @@ -9,19 +9,57 @@
TESTSUITE_ROOT_DIR = os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))
GNATCOLL_ROOT_DIR = os.path.dirname(TESTSUITE_ROOT_DIR)

# List of default components. By default postgres is not included
COMPONENTS = ['sql', 'sqlite', 'xref', 'gnatinspect',
'gnatcoll_db2ada', 'postgres']
'gnatcoll_db2ada', 'gnatcoll_sqlite2ada']

# Properties to help compilation, and dependency resolution
COMPONENT_PROPERTIES = {
'xref': {},
'gnatinspect': {'is_bin': True},
'xref': {
'requires': ['sqlite']},
'gnatinspect': {
'is_bin': True,
'requires': ['xref']},
'sql': {},
'gnatcoll_db2ada': {'is_bin': True},
'postgres': {},
'sqlite': {}
'gnatcoll_db2ada': {
'is_bin': True,
'requires': ['sql']},
'gnatcoll_sqlite2ada': {
'is_bin': True,
'component': 'gnatcoll_db2ada',
'make_args': ['DB_BACKEND=sqlite'],
'requires': ['sqlite']},
'postgres': {
'requires': ['sql']},
'sqlite': {
'requires': ['sql']}
}


def get_components_closure(components):
"""Compute the component closure needed for the run.
:param components: list of component passed to run-tests
:type components: list[str]
:return: the closure of needed gnatcoll-db components
:rtype: list[str]
"""
result = set(components)
current_len = len(result)
while True:
for component in list(result):
assert component in COMPONENT_PROPERTIES, \
"invalid component: %s" % component
properties = COMPONENT_PROPERTIES[component]
result |= set(properties.get('requires', set()))
if len(result) == current_len:
break
current_len = len(result)
logging.info('Component closure: %s', ",".join(result))
return list(result)


def make_gnatcoll_for_gcov(work_dir, components):
"""Build gnatcoll core with gcov instrumentation.
Expand All @@ -44,16 +82,21 @@ def make_gnatcoll_for_gcov(work_dir, components):
Env().add_path(os.path.join(install_dir, 'bin'))

for component in components:
logging.info('Compiling: %s', component)
gcov_options = '-cargs -fprofile-arcs -ftest-coverage -gargs'
component_dir = COMPONENT_PROPERTIES[component].get('component',
component)

if COMPONENT_PROPERTIES[component].get('is_bin'):
gcov_options += ' -largs -lgcov -gargs'

make_gnatcoll_cmd = [
'make', '-f',
os.path.join(GNATCOLL_ROOT_DIR, component, 'Makefile'),
os.path.join(GNATCOLL_ROOT_DIR, component_dir, 'Makefile'),
'BUILD=DEBUG',
'GPRBUILD_OPTIONS=%s' % gcov_options,
'ENABLE_SHARED=no']
'ENABLE_SHARED=no'] + \
COMPONENT_PROPERTIES[component].get('make_args', [])

p = Run(make_gnatcoll_cmd, cwd=build_dir)
assert p.status == 0, "gnatcoll build failed:\n%s" % p.out
Expand Down Expand Up @@ -119,6 +162,7 @@ def gprbuild(driver,
fd.write('with "%s";\n' % project)
fd.write(content)
scenario['TEST_SOURCES'] = driver.test_env['test_dir']
scenario['SUPPORT_SOURCES'] = os.path.join(TESTSUITE_ROOT_DIR, 'support')

gprbuild_cmd = [
'gprbuild', '--relocate-build-tree', '-p', '-P', project_file]
Expand Down
20 changes: 19 additions & 1 deletion testsuite/drivers/db2ada.py
Expand Up @@ -22,10 +22,15 @@ class DB2AdaTestDriver(TestDriver):
Example of test.yaml:
description: SQL test 1
sqlite_db: db.sql
db2ada:
- "-api=DB"
- "-dbmodel=descr.txt"
driver: db2ada
if sqlite_db is set then a sql file is loaded into a sqlite database and
then gnatcoll_sqlite2ada is used instead of gnatcoll_db2ada with the
resulting database (no need to specify -dbname in the db2ada arguments)
"""

def add_test(self, dag):
Expand All @@ -49,6 +54,19 @@ def db2ada(self, previous_values):
"""Run db2ada."""
mkdir(self.test_env['working_dir'])
db2ada_args = []
db2ada = 'gnatcoll_db2ada'

# If necessary initialize an sqlite database
if 'sqlite_db' in self.test_env:
check_call(self,
['sqlite3', 'db.db', '-cmd',
".read %s" % os.path.join(self.test_env['test_dir'],
self.test_env['sqlite_db'])],
input="|")
db2ada = 'gnatcoll_sqlite2ada'
db2ada_args.append(
'-dbname=%s' % os.path.join(self.test_env['working_dir'],
'db.db'))

# Compute db2ada arguments
for value in self.test_env.get('db2ada', []):
Expand All @@ -59,7 +77,7 @@ def db2ada(self, previous_values):
else:
db2ada_args.append(value)

check_call(self, ['gnatcoll_db2ada'] + db2ada_args)
check_call(self, [db2ada] + db2ada_args)

def build(self, previous_values):
"""Build fragment."""
Expand Down
2 changes: 2 additions & 0 deletions testsuite/e3-test.yaml
@@ -0,0 +1,2 @@
main: run-tests
default_args: []
11 changes: 8 additions & 3 deletions testsuite/run-tests
@@ -1,5 +1,7 @@
#!/usr/bin/env python
from drivers import make_gnatcoll_for_gcov, TESTSUITE_ROOT_DIR, COMPONENTS
from drivers import (make_gnatcoll_for_gcov,
TESTSUITE_ROOT_DIR, COMPONENTS,
COMPONENT_PROPERTIES, get_components_closure)
from drivers.basic import BasicTestDriver
from drivers.db2ada import DB2AdaTestDriver
from e3.testsuite import Testsuite
Expand All @@ -25,14 +27,17 @@ class MyTestsuite(Testsuite):
action="store_true")
self.main.argument_parser.add_argument(
'--components',
help="list of component to test",
help="list of component to test in %s (default: %s)"
% (",".join(COMPONENT_PROPERTIES.keys()),
",".join(COMPONENTS)),
default=','.join(COMPONENTS))

def tear_up(self):
logging.info('running testsuite for components: %s' %
self.main.args.components)
self.env.gcov = self.main.args.gcov
self.env.components = self.main.args.components.split(',')
self.env.components = get_components_closure(
self.main.args.components.split(','))
self.env.enable_cleanup = self.main.args.enable_cleanup
if self.main.args.gcov:
work_dir = os.path.join(TESTSUITE_ROOT_DIR, 'gcov')
Expand Down
3 changes: 2 additions & 1 deletion testsuite/support/test.gpr
Expand Up @@ -6,7 +6,8 @@ with "gnatcoll";

project Test is
Test_Sources := External("TEST_SOURCES");
for Source_Dirs use (".", Test_Sources);
Support_Sources := External("SUPPORT_SOURCES");
for Source_Dirs use (".", Support_Sources, Test_Sources);
for Main use ("test.adb");
for Languages use ("Ada");
for Object_Dir use "obj";
Expand Down
3 changes: 3 additions & 0 deletions testsuite/tests/db2ada/enums/db.sql
@@ -0,0 +1,3 @@
CREATE TABLE colors (name text, value int);
INSERT INTO colors (name, value) VALUES ('red', 1), ('green', 2), ('dark gray', 3);
.quit
8 changes: 8 additions & 0 deletions testsuite/tests/db2ada/enums/test.adb
@@ -0,0 +1,8 @@
with Colorspkg; use Colorspkg;
with Test_Assert;
function Test return Integer is
package A renames Test_Assert;
begin
A.Assert (Image_Color_Id (Color_Dark_Gray) = "dark gray");
return A.Report;
end Test;
5 changes: 5 additions & 0 deletions testsuite/tests/db2ada/enums/test.yaml
@@ -0,0 +1,5 @@
description: Do not quote original names in enum image function
sqlite_db: "db.sql"
db2ada: ["-enum", "colors,value,name,Color,Integer",
"-enum-image", "-api-enums", "colorspkg"]
driver: db2ada

0 comments on commit d32516a

Please sign in to comment.