[rtems-central commit] validation: Avoid duplicated variants

Sebastian Huber sebh at rtems.org
Fri Mar 19 14:24:30 UTC 2021


Module:    rtems-central
Branch:    master
Commit:    83bc022d4e72e6612cae6037e5a5b0be2ae1ed73
Changeset: http://git.rtems.org/rtems-central/commit/?id=83bc022d4e72e6612cae6037e5a5b0be2ae1ed73

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Mar 17 20:26:06 2021 +0100

validation: Avoid duplicated variants

---

 rtemsspec/tests/spec-validation/action2.yml | 11 +++++++++++
 rtemsspec/tests/test_validation.py          |  6 ++++++
 rtemsspec/validation.py                     | 24 ++++++++++++++++--------
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/rtemsspec/tests/spec-validation/action2.yml b/rtemsspec/tests/spec-validation/action2.yml
index 4875bad..822a470 100644
--- a/rtemsspec/tests/spec-validation/action2.yml
+++ b/rtemsspec/tests/spec-validation/action2.yml
@@ -261,4 +261,15 @@ transition-map:
     - else: A0
     B: B0
   pre-conditions: default
+- enabled-by: FOOBAR
+  post-conditions:
+    A: A1
+    B: B0
+  pre-conditions:
+    A:
+    - A0
+    B:
+    - B0
+    C:
+    - C0
 type: requirement
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index 032b531..35ae847 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -2401,6 +2401,12 @@ def test_validation_invalid_actions():
              "for pre-condition set {A=A2}")
     with pytest.raises(ValueError, match=match):
         generate(validation_config, item_cache)
+    action_data["transition-map"][0]["enabled-by"] = False
+    match = ("transition map descriptor 0 of spec:/a is the first "
+             "variant for {A=A0} and it is not enabled by default")
+    with pytest.raises(ValueError, match=match):
+        generate(validation_config, item_cache)
+    action_data["transition-map"][0]["enabled-by"] = True
     action_data["transition-map"][-1]["post-conditions"]["X"] = []
     match = ("cannot determine state for post-condition 'X' of transition map "
              "descriptor 1 of spec:/a for pre-condition set {A=A1}")
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index a36aa19..c3034f8 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -759,18 +759,26 @@ class TransitionMap:
                                           pre_cond_na + (0, ))
         else:
             enabled_by = desc["enabled-by"]
-            if transition_map[map_idx] and isinstance(enabled_by,
-                                                      bool) and enabled_by:
+            post_cond = self._make_post_cond(desc_idx, map_idx, skip_post_cond)
+            if transition_map[map_idx]:
+                if isinstance(enabled_by, bool) and enabled_by:
+                    raise ValueError(
+                        f"transition map descriptor {desc_idx} of "
+                        f"{self._item.spec} duplicates pre-condition set "
+                        f"{{{self._map_index_to_pre_conditions(map_idx)}}} "
+                        "defined by transition map descriptor "
+                        f"{transition_map[map_idx][0].desc_idx}")
+                if transition_map[map_idx][0].post_cond == post_cond:
+                    return
+            elif not isinstance(enabled_by, bool) or not enabled_by:
                 raise ValueError(
                     f"transition map descriptor {desc_idx} of "
-                    f"{self._item.spec} duplicates pre-condition set "
+                    f"{self._item.spec} is the first variant for "
                     f"{{{self._map_index_to_pre_conditions(map_idx)}}} "
-                    "defined by transition map descriptor "
-                    f"{transition_map[map_idx][0].desc_idx}")
+                    "and it is not enabled by default")
             transition_map[map_idx].append(
-                Transition(
-                    desc_idx, enabled_by, skip_post_cond[0], pre_cond_na,
-                    self._make_post_cond(desc_idx, map_idx, skip_post_cond)))
+                Transition(desc_idx, enabled_by, skip_post_cond[0],
+                           pre_cond_na, post_cond))
 
     def _add_default(self, transition_map: _TransitionMap, desc: Dict[str,
                                                                       Any],



More information about the vc mailing list