From 847ed46699dc7e2992b941da13bb99e812e03a0c Mon Sep 17 00:00:00 2001 From: Ulf Bjorkengren Date: Tue, 19 Dec 2023 15:52:20 +0100 Subject: [PATCH 1/5] Binary parser bug fix. Signed-off-by: Ulf Bjorkengren --- binary/c_parser/cparserlib.c | 21 +++++++++++++++++++-- binary/c_parser/cparserlib.h | 2 ++ binary/go_parser/parserlib/parser.go | 20 ++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/binary/c_parser/cparserlib.c b/binary/c_parser/cparserlib.c index 17f9f73a..95302236 100644 --- a/binary/c_parser/cparserlib.c +++ b/binary/c_parser/cparserlib.c @@ -50,7 +50,24 @@ typedef struct SearchContext_t { FILE* listFp; } SearchContext_t; -uint8_t validationMatrix[4][4] = {{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}}; +// Access control values: none=0, write-only=1. read-write=2, consent +=10 +// matrix preserving inherited value with read-write having priority over write-only and consent over no consent +uint8_t validationMatrix[5][5] = {{0,1,2,11,12}, {1,1,2,11,12}, {2,2,2,12,12}, {11,11,12,11,12}, {12,12,12,12,12}}; + +uint8_t getMaxValidation(uint8_t newValidation, uint8_t currentMaxValidation) { + return validationMatrix[translateToMatrixIndex(newValidation)][translateToMatrixIndex(currentMaxValidation)]; +} + +uint8_t translateToMatrixIndex(uint8_t index) { + switch (index) { + case 0: return 0; + case 1: return 1; + case 2: return 2; + case 11: return 3; + case 12: return 4; + } + return 0; +} void initReadMetadata() { readTreeMetadata.currentDepth = 0; @@ -219,7 +236,7 @@ int saveMatchingNode(long thisNode, SearchContext_t* context, bool* done) { if (strcmp(getPathSegment(0, context), "*") == 0) { context->speculationIndex++; } - context->maxValidation = validationMatrix[VSSgetValidation(thisNode)][context->maxValidation]; + context->maxValidation = getMaxValidation(VSSgetValidation(thisNode), context->maxValidation); if (VSSgetType(thisNode) != BRANCH && VSSgetType(thisNode) != STRUCT || context->leafNodesOnly == false) { if ( isGetLeafNodeList == false && isGetUuidList == false) { strcpy(context->searchData[context->numOfMatches].responsePaths, context->matchPath); diff --git a/binary/c_parser/cparserlib.h b/binary/c_parser/cparserlib.h index cca94bdf..782d02cf 100644 --- a/binary/c_parser/cparserlib.h +++ b/binary/c_parser/cparserlib.h @@ -72,3 +72,5 @@ char* VSSgetDescr(long nodeHandle); int VSSgetNumOfAllowedElements(long nodeHandle); char* VSSgetAllowedElement(long nodeHandle, int index); char* VSSgetUnit(long nodeHandle); +uint8_t getMaxValidation(uint8_t newValidation, uint8_t currentMaxValidation); +uint8_t translateToMatrixIndex(uint8_t index); diff --git a/binary/go_parser/parserlib/parser.go b/binary/go_parser/parserlib/parser.go index 4a282ea1..53667277 100644 --- a/binary/go_parser/parserlib/parser.go +++ b/binary/go_parser/parserlib/parser.go @@ -53,8 +53,24 @@ type SearchContext_t struct { ListFp *os.File } -var validationMatrix [4][4]int = [4][4]int{{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}} +// Access control values: none=0, write-only=1. read-write=2, consent +=10 +// matrix preserving inherited value with read-write having priority over write-only and consent over no consent +var validationMatrix [5][5]int = [5][5]int{{0,1,2,11,12}, {1,1,2,11,12}, {2,2,2,12,12}, {11,11,12,11,12}, {12,12,12,12,12}} +func getMaxValidation(newValidation int, currentMaxValidation int) int { + return validationMatrix[translateToMatrixIndex(newValidation)][translateToMatrixIndex(currentMaxValidation)] +} + +func translateToMatrixIndex(index int) int { + switch index { + case 0: return 0 + case 1: return 1 + case 2: return 2 + case 11: return 3 + case 12: return 4 + } + return 0 +} func initReadMetadata() { readTreeMetadata.CurrentDepth = 0 @@ -179,7 +195,7 @@ func saveMatchingNode(thisNode *def.Node_t, context *SearchContext_t, done *bool if (getPathSegment(0, context) == "*") { context.SpeculationIndex++ } - context.MaxValidation = validationMatrix[VSSgetValidation(thisNode)][context.MaxValidation] + context.MaxValidation = getMaxValidation(VSSgetValidation(thisNode), context.MaxValidation) if (VSSgetType(thisNode) != def.BRANCH && VSSgetType(thisNode) != def.STRUCT || context.LeafNodesOnly == false) { if ( isGetLeafNodeList == false && isGetUuidList == false) { context.SearchData[context.NumOfMatches].NodePath = context.MatchPath From f3ac54ec42f264b8142e68a998833f5596ef6a5e Mon Sep 17 00:00:00 2001 From: Ulf Bjorkengren Date: Wed, 23 Oct 2024 16:22:47 +0200 Subject: [PATCH 2/5] Binary exporter support for structs. Signed-off-by: Ulf Bjorkengren --- src/vss_tools/exporters/binary.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vss_tools/exporters/binary.py b/src/vss_tools/exporters/binary.py index 844984f4..9f8c3a19 100644 --- a/src/vss_tools/exporters/binary.py +++ b/src/vss_tools/exporters/binary.py @@ -115,6 +115,9 @@ def export_node(node: VSSNode, generate_uuid, f: BinaryIO): @clo.overlays_opt @clo.quantities_opt @clo.units_opt +@clo.types_opt +@clo.types_output_opt +@clo.extend_all_attributes_opt def cli( vspec: Path, output: Path, @@ -126,12 +129,15 @@ def cli( overlays: tuple[Path], quantities: tuple[Path], units: tuple[Path], + types: tuple[Path], + types_output: Path, + extend_all_attributes: bool, ): """ Export to Binary. """ - tree, _ = get_trees( + tree, datatype_tree = get_trees( vspec=vspec, include_dirs=include_dirs, aborts=aborts, @@ -140,9 +146,17 @@ def cli( uuid=uuid, quantities=quantities, units=units, + types=types, overlays=overlays, ) + log.info("Generating binary output...") + if datatype_tree: + if types_output: + with open(str(types_output), "wb") as f: + export_node(datatype_tree, uuid, f) + log.info("Binary datatype tree output generated in %s", types_output) + with open(str(output), "wb") as f: export_node(tree, uuid, f) - log.info("Binary output generated in %s", output) + log.info("Binary main tree output generated in %s", output) From 4c64632175df3cad643fb393065dac9265e15c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulf=20Bj=C3=B6rkengren?= Date: Thu, 24 Oct 2024 14:18:07 +0200 Subject: [PATCH 3/5] Update binary.py --- src/vss_tools/exporters/binary.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vss_tools/exporters/binary.py b/src/vss_tools/exporters/binary.py index 078507a1..b48d438b 100644 --- a/src/vss_tools/exporters/binary.py +++ b/src/vss_tools/exporters/binary.py @@ -150,4 +150,5 @@ def cli( with open(str(output), "wb") as f: export_node(tree, f) - log.info("Binary main tree output generated in %s", output) \ No newline at end of file + log.info("Binary main tree output generated in %s", output) + From 4a8c9a3a9f6001f6d89592c14ae16a12655075fb Mon Sep 17 00:00:00 2001 From: Ulf Bjorkengren Date: Thu, 24 Oct 2024 16:08:28 +0200 Subject: [PATCH 4/5] Build chck error fix. Signed-off-by: Ulf Bjorkengren --- src/vss_tools/exporters/binary.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/vss_tools/exporters/binary.py b/src/vss_tools/exporters/binary.py index 9f8c3a19..6a7de2f3 100644 --- a/src/vss_tools/exporters/binary.py +++ b/src/vss_tools/exporters/binary.py @@ -19,7 +19,7 @@ # The order of fields (where each field is composed of # fieldlength + fielddata) is: # -# name (vsspath), type, uuid, description, datatype, min, max, unit, +# name (vsspath), type, description, datatype, min, max, unit, # allowed, default, validate # # if a field is not present (e.g. min, max, unit, allowed, default, validate), @@ -73,16 +73,13 @@ def create_l16v_string(s: str) -> bytes: return pack -def export_node(node: VSSNode, generate_uuid, f: BinaryIO): +def export_node(node: VSSNode, f: BinaryIO): data = node.get_vss_data().as_dict() f.write(create_l8v_string(node.name)) f.write(create_l8v_string(data.get("type", ""))) - if node.uuid is None: - log.debug(("No UUID for node %s", node.name)) - f.write(struct.pack("B", 0)) - else: - f.write(create_l8v_string(node.uuid)) + # Keeping UUID field in output for now (always 0) + f.write(struct.pack("B", 0)) f.write(create_l16v_string(data.get("description", ""))) f.write(create_l8v_string(data.get("datatype", ""))) @@ -101,7 +98,7 @@ def export_node(node: VSSNode, generate_uuid, f: BinaryIO): f.write(struct.pack("B", len(node.children))) for child in node.children: - export_node(child, generate_uuid, f) + export_node(child, f) @click.command() @@ -111,13 +108,11 @@ def export_node(node: VSSNode, generate_uuid, f: BinaryIO): @clo.extended_attributes_opt @clo.strict_opt @clo.aborts_opt -@clo.uuid_opt @clo.overlays_opt @clo.quantities_opt @clo.units_opt @clo.types_opt @clo.types_output_opt -@clo.extend_all_attributes_opt def cli( vspec: Path, output: Path, @@ -125,13 +120,11 @@ def cli( extended_attributes: tuple[str], strict: bool, aborts: tuple[str], - uuid: bool, overlays: tuple[Path], quantities: tuple[Path], units: tuple[Path], types: tuple[Path], - types_output: Path, - extend_all_attributes: bool, + types_output: Path | None, ): """ Export to Binary. @@ -142,8 +135,6 @@ def cli( include_dirs=include_dirs, aborts=aborts, strict=strict, - extended_attributes=extended_attributes, - uuid=uuid, quantities=quantities, units=units, types=types, @@ -154,9 +145,10 @@ def cli( if datatype_tree: if types_output: with open(str(types_output), "wb") as f: - export_node(datatype_tree, uuid, f) + export_node(datatype_tree, f) log.info("Binary datatype tree output generated in %s", types_output) with open(str(output), "wb") as f: - export_node(tree, uuid, f) + export_node(tree, f) log.info("Binary main tree output generated in %s", output) + From fc2f3b30faef9cbd4f27624047492dbd348c8e4c Mon Sep 17 00:00:00 2001 From: Ulf Bjorkengren Date: Mon, 11 Nov 2024 10:03:59 +0100 Subject: [PATCH 5/5] binary.py cleanup. Signed-off-by: Ulf Bjorkengren --- src/vss_tools/exporters/binary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vss_tools/exporters/binary.py b/src/vss_tools/exporters/binary.py index 6a7de2f3..7f8ed612 100644 --- a/src/vss_tools/exporters/binary.py +++ b/src/vss_tools/exporters/binary.py @@ -147,8 +147,8 @@ def cli( with open(str(types_output), "wb") as f: export_node(datatype_tree, f) log.info("Binary datatype tree output generated in %s", types_output) - + else: + log.warning("Ignoring type tree generation as no file name specified") with open(str(output), "wb") as f: export_node(tree, f) log.info("Binary main tree output generated in %s", output) -