Skip to content

Commit

Permalink
WIP: add functiondefinitionsChecker to git workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bischof committed Oct 11, 2023
1 parent 22e3393 commit b2aaf95
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/configs-apitracing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Config CI ApiTracing

on:
push:
branches:
- "main"
paths:
- 'plugins/apitracing/**.py'
- 'plugins/apitracing/configuration/functiondefinitions/*.{yml,yaml}'
pull_request:
branches:
- "main"
paths:
- 'plugins/apitracing/**.py'
- 'plugins/apitracing/configuration/functiondefinitions/*.{yml,yaml}'

jobs:
check_definitions:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v3
- name: execute py script
run: python FunctionDefinitionsChecker.py
working-directory: plugins/apitracing/tools
31 changes: 28 additions & 3 deletions plugins/apitracing/tools/FunctionDefinitionsChecker.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,84 @@
import sys
import yaml


def check_parameter_translation(function_definitions_yaml):
modules_node = function_definitions_yaml["Modules"]
parameter_types = get_parameter_types(modules_node)
structures_node = function_definitions_yaml["Structures"]

struct_names = set()
for struct in structures_node:
struct_names.add(struct)

struct_parameter_types = get_struct_parameter_types(struct_names, structures_node)
# Replace structs as parameters with the extracted struct parameters
parameter_types = parameter_types.union(struct_parameter_types) - struct_names

highlevel_parameter_node = function_definitions_yaml["HighLevelParameterTypes"]
highlevel_parameter_names, highlevel_parameter_types = get_high_level_parameter_names_and_types(
highlevel_parameter_node)
find_ring_in_highlevel_parameter_types(highlevel_parameter_node)
backing_parameter_node = function_definitions_yaml["BackingParameterTypes"]
backing_parameter_names = get_backing_parameter_names(backing_parameter_node)

# Sets error default value
error = find_ring_in_highlevel_parameter_types(highlevel_parameter_node)

missing_function_parameters = (
parameter_types - struct_names - highlevel_parameter_names - backing_parameter_names)
if missing_function_parameters:
print("Function parameters with missing definitions:", missing_function_parameters)
error = 1

missing_struct_parameters = (
struct_parameter_types - struct_names - highlevel_parameter_names - backing_parameter_names)
if missing_struct_parameters:
print("Used struct parameters with missing definitions: ", missing_struct_parameters)
error = 1

missing_high_level_parameters = (
highlevel_parameter_types - highlevel_parameter_names - backing_parameter_names)
if missing_high_level_parameters:
print("Highlevel parameter types with missing definitions: ", missing_high_level_parameters)
error = 1

multiple_parameter_definitions = highlevel_parameter_names & backing_parameter_names
if multiple_parameter_definitions:
print("Parameters which are defined as both a high level parameter and a backing parameter",
multiple_parameter_definitions)
error = 1

multiple_parameter_definitions = (highlevel_parameter_names & struct_names)
if multiple_parameter_definitions:
print("Parameters which are defined as both a high level parameter and a struct",
multiple_parameter_definitions)
error = 1

multiple_parameter_definitions = (struct_names & backing_parameter_names)
if multiple_parameter_definitions:
print("Parameters which are defined as both a struct and a backing parameter", multiple_parameter_definitions)
error = 1

return error


def find_ring_in_highlevel_parameter_types(highlevel_parameter_node):
error = 0
for address_width, param_types in highlevel_parameter_node.items():
for param in param_types.keys():
visited_high_level_params = set(param)
current_node = param
while current_node in param_types.keys():
current_node = param_types[current_node]
if current_node in visited_high_level_params:
error = 1
print("Highlevelparameter resolution for address width:", address_width, "starting from:",
param, "contains ring between",
param_types[current_node],
"and", current_node)
break
visited_high_level_params.add(current_node)
return error


def get_parameter_types(modules_node):
Expand Down Expand Up @@ -96,13 +119,15 @@ def get_backing_parameter_names(backing_parameter_node):


def main():
error = 1
with open("../configuration/functiondefinitions/functionDefinitions.yaml", "r") as stream:
try:
function_definitions_yaml = yaml.safe_load(stream)
check_parameter_translation(function_definitions_yaml)
error = check_parameter_translation(function_definitions_yaml)
except yaml.YAMLError as exc:
print(exc)
return error


if __name__ == '__main__':
main()
sys.exit(main())

0 comments on commit b2aaf95

Please sign in to comment.