summaryrefslogtreecommitdiffstats
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-02-04 10:51:12 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-02-04 14:23:33 +0100
commita95eaf1e8163bdd0e974ea55066e014d6f99d8a3 (patch)
tree01cfb3d1d62a571b20bd910073c629bc129d67f5 /rtemsspec
parentvalidation: Remove prologue/epilogue in test cases (diff)
downloadrtems-central-a95eaf1e8163bdd0e974ea55066e014d6f99d8a3.tar.bz2
validation: Move actions to separate functions
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/tests/spec-validation/tc7.yml30
-rw-r--r--rtemsspec/tests/test_validation.py156
-rw-r--r--rtemsspec/validation.py75
3 files changed, 209 insertions, 52 deletions
diff --git a/rtemsspec/tests/spec-validation/tc7.yml b/rtemsspec/tests/spec-validation/tc7.yml
new file mode 100644
index 00000000..bdcf1e04
--- /dev/null
+++ b/rtemsspec/tests/spec-validation/tc7.yml
@@ -0,0 +1,30 @@
+SPDX-License-Identifier: CC-BY-SA-6.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links: []
+test-actions:
+- action: |
+ /* ${step} */
+ checks: []
+ description: |
+ Action.
+ links: []
+test-brief: null
+test-context: []
+test-context-support: null
+test-description: null
+test-header:
+ code: null
+ includes: []
+ local-includes: []
+ run-params: []
+ target: tc7.h
+test-includes: []
+test-local-includes: []
+test-setup: null
+test-stop: null
+test-support: null
+test-target: tc34.c
+test-teardown: null
+type: test-case
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index 93242cb5..7269a0ef 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -858,22 +858,35 @@ T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture )
/* Test case support code */
-/**
- * @fn void T_case_body_Tc( void )
- */
-T_TEST_CASE( Tc )
+static void Tc_Action_0( void *ctx )
{
- T_plan( 125 );
-
/* Test case action 0 code */
/* Test case action 0 check 0 code: Accounts for 123 test plan steps */
/* Test case action 0 check 1 code; step 123 */
+}
+static void Tc_Action_1( void *ctx )
+{
/* Test case action 1 code */
/* Test case action 1 check 0 code; step 124 */
/* Test case action 1 check 1 code */
}
+/**
+ * @fn void T_case_body_Tc( void )
+ */
+T_TEST_CASE( Tc )
+{
+ void *ctx;
+
+ ctx = T_fixture_context();
+
+ T_plan( 125 );
+
+ Tc_Action_0( ctx );
+ Tc_Action_1( ctx );
+}
+
/** @} */
/**
@@ -939,18 +952,31 @@ static T_fixture Tc2_Fixture = {
.initial_context = &Tc2_Instance
};
-/**
- * @fn void T_case_body_Tc2( void )
- */
-T_TEST_CASE_FIXTURE( Tc2, &Tc2_Fixture )
+static void Tc2_Action_0( Tc2_Context *ctx )
{
/* Test case 2 action 0 code */
/* Test case 2 action 0 check 0 code */
/* Test case 2 action 0 check 1 code */
+}
+static void Tc2_Action_1( Tc2_Context *ctx )
+{
/* Test case 2 action 1 code */
}
+/**
+ * @fn void T_case_body_Tc2( void )
+ */
+T_TEST_CASE_FIXTURE( Tc2, &Tc2_Fixture )
+{
+ Tc2_Context *ctx;
+
+ ctx = T_fixture_context();
+
+ Tc2_Action_0( ctx );
+ Tc2_Action_1( ctx );
+}
+
/** @} */
"""
assert content == src.read()
@@ -965,10 +991,11 @@ T_TEST_CASE_FIXTURE( Tc2, &Tc2_Fixture )
* @ingroup RTEMSTestCaseTc4
* @ingroup RTEMSTestCaseTc5
* @ingroup RTEMSTestCaseTc6
+ * @ingroup RTEMSTestCaseTc7
*/
/*
- * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ * Copyright (C) 2020, 2021 embedded brains GmbH (http://www.embedded-brains.de)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1232,15 +1259,24 @@ T_TEST_CASE_FIXTURE( Rtm, &Rtm_Fixture )
* @{
*/
+static void Tc3_Action_0( void *ctx )
+{
+ /* Test case 3 action 0 code */
+ /* Test case 3 action 0 check 0 code; step 0 */
+}
+
/**
* @fn void T_case_body_Tc3( void )
*/
T_TEST_CASE( Tc3 )
{
+ void *ctx;
+
+ ctx = T_fixture_context();
+
T_plan( 1 );
- /* Test case 3 action 0 code */
- /* Test case 3 action 0 check 0 code; step 0 */
+ Tc3_Action_0( ctx );
}
/** @} */
@@ -1262,6 +1298,9 @@ T_TEST_CASE( Tc3 )
*/
T_TEST_CASE( Tc4 )
{
+ void *ctx;
+
+ ctx = T_fixture_context();
}
/** @} */
@@ -1292,14 +1331,49 @@ T_TEST_CASE( Tc4 )
* @{
*/
-static void Tc5_Wrap( int *a, int b, int *c )
-{
- T_plan( 2 );
+/**
+ * @brief Test context for spec:/tc5 test case.
+ */
+typedef struct {
+ /**
+ * @brief This member contains a copy of the corresponding Tc5_Run()
+ * parameter.
+ */
+ int *a;
+
+ /**
+ * @brief This member contains a copy of the corresponding Tc5_Run()
+ * parameter.
+ */
+ int b;
+
+ /**
+ * @brief This member contains a copy of the corresponding Tc5_Run()
+ * parameter.
+ */
+ int *c;
+} Tc5_Context;
+
+static Tc5_Context
+ Tc5_Instance;
+static T_fixture Tc5_Fixture = {
+ .setup = NULL,
+ .stop = NULL,
+ .teardown = NULL,
+ .scope = NULL,
+ .initial_context = &Tc5_Instance
+};
+
+static void Tc5_Action_0( Tc5_Context *ctx )
+{
/* Test case action 0 code */
/* Test case action 0 check 0 code */
/* Test case action 0 check 1 code; step 0 */
+}
+static void Tc5_Action_1( Tc5_Context *ctx )
+{
/* Test case action 1 code */
/* Test case action 1 check 0 code; step 1 */
/* Test case action 1 check 1 code */
@@ -1309,8 +1383,19 @@ static T_fixture_node Tc5_Node;
void Tc5_Run( int *a, int b, int *c )
{
- T_push_fixture( &Tc5_Node, &T_empty_fixture );
- Tc5_Wrap( a, b, c );
+ Tc5_Context *ctx;
+
+ ctx = T_push_fixture( &Tc5_Node, &Tc5_Fixture );
+
+ ctx->a = a;
+ ctx->b = b;
+ ctx->c = c;
+
+ T_plan( 2 );
+
+ Tc5_Action_0( ctx );
+ Tc5_Action_1( ctx );
+
T_pop_fixture();
}
@@ -1326,6 +1411,41 @@ void Tc5_Run( int *a, int b, int *c )
void Tc6_Run( void )
{
+ void *ctx;
+}
+
+/** @} */
+
+/**
+ * @defgroup RTEMSTestCaseTc7 spec:/tc7
+ *
+ * @ingroup RTEMSTestSuiteTs
+ *
+ * This test case performs the following actions:
+ *
+ * - Action.
+ *
+ * @{
+ */
+
+static void Tc7_Action_0( void *ctx )
+{
+ /* 0 */
+}
+
+static T_fixture_node Tc7_Node;
+
+void Tc7_Run( void )
+{
+ void *ctx;
+
+ ctx = T_push_fixture( &Tc7_Node, &T_empty_fixture );
+
+ T_plan( 1 );
+
+ Tc7_Action_0( ctx );
+
+ T_pop_fixture();
}
/** @} */
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index 33724c26..ea263d88 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -188,13 +188,18 @@ class _TestItem:
initial_indent=" - ",
subsequent_indent=" ")
- def _generate_test_case_actions(self) -> CContent:
- content = CContent()
- for action in self["test-actions"]:
- content.add(self.substitute_code(action["action"]))
- for check in action["checks"]:
- content.append(self.substitute_text(check["check"]))
- return content
+ def _add_test_case_actions(self, content: CContent) -> CContent:
+ actions = CContent()
+ for index, action in enumerate(self["test-actions"]):
+ method = f"{self._ident}_Action_{index}"
+ actions.gap = False
+ actions.call_function(None, method, ["ctx"])
+ params = [f"{self.context} *ctx"]
+ with content.function("static void", method, params):
+ content.add(self.substitute_code(action["action"]))
+ for check in action["checks"]:
+ content.append(self.substitute_text(check["check"]))
+ return actions
def _get_run_params(self, header: Optional[Dict[str, Any]]) -> List[str]:
if not header:
@@ -280,11 +285,18 @@ class _TestItem:
def add_default_context_members(self, content: CContent) -> None:
""" Adds the default context members to the content """
+ for param in self._get_run_params(self["test-header"]):
+ content.add_description_block(
+ "This member contains a copy of the corresponding "
+ f"{self.ident}_Run() parameter.", None)
+ content.add(f"{param.strip()};")
def add_context(self, content: CContent) -> str:
""" Adds the context to the content. """
content.add(self.substitute_code(self["test-context-support"]))
- if not self["test-context"]:
+ if not self["test-context"] and (
+ not self["test-header"]
+ or not self["test-header"]["run-params"]):
return "NULL"
with content.doxygen_block():
content.add_brief_description(
@@ -355,22 +367,29 @@ class _TestItem:
""" Generates the content. """
self.add_test_case_description(content, test_case_to_suites)
fixture = self._add_context_and_fixture(content)
+ content.add(self.substitute_code(self["test-support"]))
self._mapper.reset()
- actions = self._generate_test_case_actions()
+ actions = self._add_test_case_actions(content)
header = self["test-header"]
+ prologue = CContent()
+ prologue.add([f"{self.context} *ctx;"])
+ epilogue = CContent()
if header:
self.generate_header(base_directory, header)
- if self._mapper.steps > 0 and not fixture:
- fixture = "T_empty_fixture"
- content.add(self.substitute_code(self["test-support"]))
- if header:
+ ret = "void"
+ name = f"{self.ident}_Run"
params = self._get_run_params(header)
+ if self._mapper.steps > 0 and not fixture:
+ fixture = "&T_empty_fixture"
if fixture:
- ret = "static void"
- name = f"{self.ident}_Wrap"
- else:
- ret = "void"
- name = f"{self.ident}_Run"
+ content.add(f"static T_fixture_node {self.ident}_Node;")
+ prologue.call_function("ctx =", "T_push_fixture",
+ [f"&{self.ident}_Node", fixture])
+ prologue.add([
+ f"ctx->{param['name']} = {param['name']};"
+ for param in header["run-params"]
+ ])
+ epilogue.add("T_pop_fixture();")
align = True
else:
ret = ""
@@ -380,26 +399,18 @@ class _TestItem:
name = "T_TEST_CASE_FIXTURE"
else:
name = "T_TEST_CASE"
+ prologue.add("ctx = T_fixture_context();")
align = False
with content.function_block(
f"void T_case_body_{self.ident}( void )"):
pass
content.gap = False
with content.function(ret, name, params, align=align):
+ content.add(prologue)
if self._mapper.steps > 0:
content.add(f"T_plan( {self._mapper.steps} );")
content.add(actions)
- if header and fixture:
- run = f"{self.ident}_Run"
- content.add(f"static T_fixture_node {self.ident}_Node;")
- with content.function("void", run, params, align=align):
- content.call_function(None, "T_push_fixture",
- [f"&{self.ident}_Node", f"&{fixture}"])
- content.gap = False
- content.call_function(
- None, name,
- [param["name"] for param in header["run-params"]])
- content.append("T_pop_fixture();")
+ content.add(epilogue)
content.add("/** @} */")
@@ -501,11 +512,7 @@ class _ActionRequirementTestItem(_TestItem):
content.add("};")
def add_default_context_members(self, content: CContent) -> None:
- for param in self._get_run_params(self["test-header"]):
- content.add_description_block(
- "This member contains a copy of the corresponding "
- f"{self.ident}_Run() parameter.", None)
- content.add(f"{param.strip()};")
+ super().add_default_context_members(content)
content.add_description_block(
"This member defines the pre-condition states "
"for the next action.", None)