diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-08-16 12:19:27 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-08-16 12:33:36 +0200 |
commit | 1574e66bfd7f6cfa6d88ff59ed2d540f178fd99d (patch) | |
tree | 757b7a139170bbc766e0628e6aa96e4f19712d2b /rtemsspec | |
parent | 54e9530b503a0d5fc800c013df9263e621f5adab (diff) |
validation: Move parts of loop body to a function
Diffstat (limited to 'rtemsspec')
-rw-r--r-- | rtemsspec/tests/test_validation.py | 41 | ||||
-rw-r--r-- | rtemsspec/validation.py | 25 |
2 files changed, 42 insertions, 24 deletions
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py index 287ee3a2..43a2cd79 100644 --- a/rtemsspec/tests/test_validation.py +++ b/rtemsspec/tests/test_validation.py @@ -698,6 +698,16 @@ static inline Directive_Entry Directive_PopEntry( Directive_Context *ctx ) ]; } +static void Directive_TestVariant( Directive_Context *ctx ) +{ + Directive_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] ); + Directive_Pre_Node_Prepare( ctx, ctx->Map.pcs[ 1 ] ); + Directive_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 2 ] ); + Directive_Action( ctx ); + Directive_Post_Status_Check( ctx, ctx->Map.entry.Post_Status ); + Directive_Post_Id_Check( ctx, ctx->Map.entry.Post_Id ); +} + /** * @fn void T_case_body_Directive( void ) */ @@ -725,13 +735,7 @@ T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture ) ++ctx->Map.pcs[ 2 ] ) { ctx->Map.entry = Directive_PopEntry( ctx ); - - Directive_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] ); - Directive_Pre_Node_Prepare( ctx, ctx->Map.pcs[ 1 ] ); - Directive_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 2 ] ); - Directive_Action( ctx ); - Directive_Post_Status_Check( ctx, ctx->Map.entry.Post_Status ); - Directive_Post_Id_Check( ctx, ctx->Map.entry.Post_Id ); + Directive_TestVariant( ctx ); } } } @@ -2219,6 +2223,19 @@ static inline Action2_Entry Action2_PopEntry( Action2_Context *ctx ) ]; } +static void Action2_TestVariant( Action2_Context *ctx ) +{ + Action2_Pre_A_Prepare( + ctx, + ctx->Map.entry.Pre_A_NA ? Action2_Pre_A_NA : ctx->Map.pcs[ 0 ] + ); + Action2_Pre_B_Prepare( ctx, ctx->Map.pcs[ 1 ] ); + Action2_Pre_C_Prepare( ctx, ctx->Map.pcs[ 2 ] ); + Action2_Action( ctx ); + Action2_Post_A_Check( ctx, ctx->Map.entry.Post_A ); + Action2_Post_B_Check( ctx, ctx->Map.entry.Post_B ); +} + static T_fixture_node Action2_Node; void Action2_Run( int *a, int b, int *c ) @@ -2256,15 +2273,7 @@ void Action2_Run( int *a, int b, int *c ) } Action2_Prepare( ctx ); - Action2_Pre_A_Prepare( - ctx, - ctx->Map.entry.Pre_A_NA ? Action2_Pre_A_NA : ctx->Map.pcs[ 0 ] - ); - Action2_Pre_B_Prepare( ctx, ctx->Map.pcs[ 1 ] ); - Action2_Pre_C_Prepare( ctx, ctx->Map.pcs[ 2 ] ); - Action2_Action( ctx ); - Action2_Post_A_Check( ctx, ctx->Map.entry.Post_A ); - Action2_Post_B_Check( ctx, ctx->Map.entry.Post_B ); + Action2_TestVariant( ctx ); Action2_Cleanup( ctx ); } } diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py index 48c65077..c743b1c0 100644 --- a/rtemsspec/validation.py +++ b/rtemsspec/validation.py @@ -561,15 +561,9 @@ class _ActionRequirementTestItem(_TestItem): content.gap = False content.call_function(None, f"{self.ident}_{name}", ["ctx"]) - def _add_loop_body(self, content: CContent, - transition_map: TransitionMap) -> None: + def _add_test_variant(self, content: CContent, + transition_map: TransitionMap) -> None: entry = "ctx->Map.entry" - content.call_function(f"{entry} =", f"{self.ident}_PopEntry", ["ctx"]) - if transition_map.pre_co_summary[0]: - with content.condition(f"{entry}.Skip"): - content.append("continue;") - content.add_blank_line() - self._add_call(content, "test-prepare", "Prepare") for index, pre_co in enumerate(self._item["pre-conditions"]): content.gap = False state = f"ctx->Map.pcs[ {index} ]" @@ -585,6 +579,18 @@ class _ActionRequirementTestItem(_TestItem): content.call_function(None, f"{enum[0]}_Check", [ "ctx", f"{entry}.{transition_map.get_post_entry_member(index)}" ]) + + def _add_loop_body(self, content: CContent, + transition_map: TransitionMap) -> None: + entry = "ctx->Map.entry" + content.call_function(f"{entry} =", f"{self.ident}_PopEntry", ["ctx"]) + if transition_map.pre_co_summary[0]: + with content.condition(f"{entry}.Skip"): + content.append("continue;") + content.add_blank_line() + self._add_call(content, "test-prepare", "Prepare") + content.gap = False + content.call_function(None, f"{self.ident}_TestVariant", ["ctx"]) self._add_call(content, "test-cleanup", "Cleanup") def _add_for_loops(self, content: CContent, transition_map: TransitionMap, @@ -610,6 +616,9 @@ class _ActionRequirementTestItem(_TestItem): "ctx->Map.index = index + 1;", f"return {self.ident}_Entries[", f" {self.ident}_Map[ index ]", "];" ]) + with content.function("static void", f"{self.ident}_TestVariant", + [f"{self.context} *ctx"]): + self._add_test_variant(content, transition_map) fixture = f"{self.ident}_Fixture" prologue = CContent() epilogue = CContent() |