Skip to content

Commit

Permalink
Add erbb unit test target type feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmtech-rdi committed Dec 6, 2024
1 parent ab4ce00 commit dd338ab
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 2 deletions.
1 change: 1 addition & 0 deletions build-system/build-system.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
# generators/vcvrack
'erbb/generators/vcvrack/project_template.gyp',
'erbb/generators/vcvrack/project.py',
'erbb/generators/vcvrack/test_unit_template.gyp',

# generators/daisy
'erbb/generators/daisy/Makefile_template',
Expand Down
39 changes: 39 additions & 0 deletions build-system/erbb/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def is_data (self): return isinstance (self, Data)
@property
def is_stream (self): return isinstance (self, Stream)

@property
def is_test (self): return isinstance (self, Test)

@property
def is_faust_address (self): return isinstance (self, FaustAddress)

Expand Down Expand Up @@ -207,6 +210,11 @@ def resources (self):
entities = [e for e in self.entities if e.is_resources]
return entities

@property
def tests (self):
entities = [e for e in self.entities if e.is_test]
return entities

@property
def bases (self):
entities = [e for e in self.entities if e.is_base]
Expand Down Expand Up @@ -492,6 +500,37 @@ def source_context_part (self, part):



# -- Test --------------------------------------------------------------------

class Test (Scope):
def __init__ (self, name_identifier):
assert isinstance (name_identifier, adapter.Identifier)
super (Test, self).__init__ ()
self.name_identifier = name_identifier

@staticmethod
def typename (): return 'test'

@property
def name (self): return self.name_identifier.name

@property
def source_context (self):
return self.source_context_part ('name')

def source_context_part (self, part):
if part == 'name':
return adapter.SourceContext.from_token (self.name_identifier)

return super (Test, self).source_context_part (part) # pragma: no cover

@property
def files (self):
entities = [e for e in self.entities if e.is_file]
return entities



# -- Faust -------------------------------------------------------------------

class Faust (Scope):
Expand Down
39 changes: 39 additions & 0 deletions build-system/erbb/generators/vcvrack/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def generate_module (self, path, module, strict):
template = self.replace_bases (template, module, module.bases, path);
template = self.replace_sources (template, module, module.sources, path)
template = self.replace_actions (template, module, path)
template = self.replace_tests (template, module, path)

with open (path_cpp, 'w', encoding='utf-8') as file:
file.write (template)
Expand Down Expand Up @@ -400,3 +401,41 @@ def replace_actions_data (self, module, path):
lines += ' },\n'

return lines


#--------------------------------------------------------------------------

def replace_tests (self, template, module, path):

lines = ''
for test in module.tests:
lines += self.replace_test (module, test, path)

return template.replace ('% tests%', lines)


#--------------------------------------------------------------------------

def replace_test (self, module, test, path):
path_template = os.path.join (PATH_THIS, 'test_unit_template.gyp')
with open (path_template, 'r', encoding='utf-8') as file:
template = file.read ()

template = template.replace ('%test.name%', test.name)
template = self.replace_includes (template, module, path);
template = self.replace_defines (template, module.defines)
template = self.replace_bases (template, module, module.bases, path);
template = self.replace_test_sources (template, test, path)
return template


#--------------------------------------------------------------------------

def replace_test_sources (self, template, test, path):
lines = ''

for file in test.files:
file_path = os.path.relpath (file.path, path)
lines += ' \'%s\',\n' % file_path

return template.replace ('% test.sources%', lines)
1 change: 1 addition & 0 deletions build-system/erbb/generators/vcvrack/project_template.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
},
],
},
% tests%
],
}
17 changes: 17 additions & 0 deletions build-system/erbb/generators/vcvrack/test_unit_template.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
'target_name': '%test.name%',
'type': 'executable',

'defines': [
% defines.entities%
],

'include_dirs': [
'.',
% bases.entities%
],

'sources': [
% test.sources%
],
},
10 changes: 8 additions & 2 deletions build-system/erbb/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
KEYWORDS = (
'module',
'import', 'define', 'sources', 'resources', 'section',
'file', 'data', 'flash', 'qspi', 'sram', 'stream', 'mono', 'interleaved', 'planar'
'file', 'data', 'test', 'flash', 'qspi', 'sram', 'stream', 'mono', 'interleaved', 'planar'
)

SYMBOLS = (',', '{', '}', '=')
Expand Down Expand Up @@ -71,6 +71,12 @@ def resources_entities (): return ZeroOrMore (data_declaration)
def resources_body (): return '{', resources_entities, '}'
def resources_declaration (): return 'resources', resources_body

# Tests
def test_entities (): return ZeroOrMore (file_declaration)
def test_body (): return '{', test_entities, '}'
def test_name (): return name
def test_declaration (): return 'test', test_name, test_body

# Base
def base_declaration (): return 'base', string_literal

Expand All @@ -79,7 +85,7 @@ def section_name (): return ['flash', 'qspi', 'sram']
def section_declaration (): return 'section', section_name

# Module
def module_entities (): return ZeroOrMore ([section_declaration, import_declaration, define_declaration, sources_declaration, resources_declaration, base_declaration])
def module_entities (): return ZeroOrMore ([section_declaration, import_declaration, define_declaration, sources_declaration, resources_declaration, test_declaration, base_declaration])
def module_body (): return '{', module_entities, '}'
def module_name (): return name
def module_declaration (): return 'module', module_name, module_body
Expand Down
23 changes: 23 additions & 0 deletions build-system/erbb/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ def visit_resources_entities (self, node, children):
return list (children)


#-- Test ------------------------------------------------------------------

def visit_test_declaration (self, node, children):
test_name_identifier = children.test_name [0]

test = ast.Test (test_name_identifier)

if children.test_body:
entities = children.test_body [0]
test.add (entities)

return test

def visit_test_name (self, node, children):
return self.visit_identifier (node, children)

def visit_test_body (self, node, children):
return children [0] if children else []

def visit_test_entities (self, node, children):
return list (children)


#-- Base ------------------------------------------------------------------

def visit_base_declaration (self, node, children):
Expand Down

0 comments on commit dd338ab

Please sign in to comment.