Skip to content

Implemented Consistency checks for safety for trlc requirements - #414

Open
ishakulkarni1012 wants to merge 2 commits into
eclipse-score:mainfrom
ishakulkarni1012:consistency-checks-for-safety-in-requirements
Open

Implemented Consistency checks for safety for trlc requirements#414
ishakulkarni1012 wants to merge 2 commits into
eclipse-score:mainfrom
ishakulkarni1012:consistency-checks-for-safety-in-requirements

Conversation

@ishakulkarni1012

Copy link
Copy Markdown

PR: ASIL Non-Degradation Safety Checks for Requirements

Purpose

Add automated ASIL (Automotive Safety Integrity Level) non-degradation checks to the S-CORE requirements model. These checks enforce that when a requirement is derived from an upstream requirement, its ASIL safety level must be at least as high as the upstream — it must not be degraded. This is a fundamental safety rule: a derived requirement cannot weaken the safety guarantees of its upstream.

ASIL ordering enforced: QM < B < D


Changes Made

1. bazel/rules/rules_score/trlc/config/score_requirements_model.rsl

Added FeatReqSourceId tuple:

tuple FeatReqSourceId {
    item    RequirementSafety
    separator @
    version Integer
}
  • FeatReq.derived_from previously used AssumedSystemReqId (item type = AssumedSystemReq, a concrete type).
  • TRLC 3.0.0 does not resolve inherited fields when the tuple item is a single concrete type — attempting to access upstream.item.safety in a check block caused a semantic error.
  • Changed item type to the abstract base RequirementSafety (which directly declares the safety field), so TRLC can resolve the field. At runtime, every instance is still an AssumedSystemReq.

Changed FeatReq.derived_from:

derived_from "..." FeatReqSourceId[1 .. *]   // was AssumedSystemReqId

Added checks FeatReq block:

checks FeatReq {
    (forall upstream in derived_from =>
        not ((upstream.item.safety == Asil.B and safety == Asil.QM) or
             (upstream.item.safety == Asil.D and safety != Asil.D))),
      error "ASIL level of derived requirement must be at least the same as the upstream requirement",
      safety
}

Added checks CompReq block:

checks CompReq {
    derived_from == null or
    (forall upstream in derived_from =>
        not ((upstream.item.safety == Asil.B and safety == Asil.QM) or
             (upstream.item.safety == Asil.D and safety != Asil.D))),
      error "ASIL level of derived requirement must be at least the same as the upstream requirement",
      safety
}
  • CompReq.derived_from already used a union type [FeatReq, AssumedSystemReq] — TRLC resolves safety via their common ancestor RequirementSafety, so no tuple change was needed.
  • derived_from == null guard added because CompReq.derived_from is optional.

2. bazel/rules/rules_score/trlc/config/test/trlc_check_test.bzl (new file)

Custom Bazel macro that runs TRLC without --verify. The standard trlc_requirements_test rule always adds --verify, which triggers TRLC 3.0.0's CVC5/VCG static analysis. That analysis crashes with a KeyError when processing forall over union or abstract tuple item fields. Runtime check evaluation (what actually validates requirement instances) still works correctly without --verify.


3. bazel/rules/rules_score/trlc/config/BUILD

  • Loaded trlc_check_test macro.
  • Changed score_requirements_model_test from trlc_requirements_test to trlc_check_test — the existing model test was broken by the newly added checks because --verify crashed.

4. bazel/rules/rules_score/trlc/config/test/BUILD (new file)

Bazel targets for ASIL check test fixtures:

Target Purpose
asil_check_valid_test Passes — valid ASIL assignments (no degradation)
asil_check_invalid_feat_test Fails (expected) — FeatReqs with degraded ASIL
asil_check_invalid_comp_test Fails (expected) — CompReqs with degraded ASIL

Invalid tests are tagged manual so they don't run in CI by default.


5. TRLC Test Fixture Files (new files in bazel/rules/rules_score/trlc/config/test/)

File Package Contents
valid_asr.trlc AssilCheckValid AssumedSystemReq instances at QM / B / D
valid_feat_req.trlc AssilCheckValid FeatReq instances with maintained or raised ASIL
valid_comp_req.trlc AssilCheckValidComp CompReq instances with maintained or raised ASIL
invalid_feat_req.trlc AssilCheckInvalidFeat FeatReq instances with degraded ASIL (QM←B, B←D, QM←D)
invalid_comp_req.trlc AssilCheckInvalidComp CompReq instances with degraded ASIL

Why trlc_check_test instead of trlc_requirements_test

TRLC 3.0.0 has a bug: the VCG (Verification Condition Generator) that runs with --verify crashes when statically analyzing forall expressions over tuple items typed as union or abstract types. Since the checks require these patterns (for field resolution), --verify cannot be used. The custom macro skips VCG while still running all runtime checks against actual requirement instances.


Test Results

Test Result
score_requirements_model_test PASSES
asil_check_valid_test PASSES
asil_check_invalid_feat_test FAILS with 3 violations (expected)
asil_check_invalid_comp_test FAILS with 4 violations (expected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant