nasa / ogma

Other
329 stars 24 forks source link

`ogma-core`: equivalence operator should be translated to `(==)` #126

Closed Andersen0 closed 6 months ago

Andersen0 commented 7 months ago

When using an equivalence operator (as used in, for example, FRETISH requirements as <=>) the returned Monitor will not be able to properly run because the Haskell Monitor cannot use the <==> operator that is defined in the code.

The command used for generation of the Monitor was: _ogma fret-component-spec --fret-file-name fretspecifications.json > Monitor.hs

The command used for compiling and linking: ghc -package copilot-c99 -package copilot-language -package copilot-libraries Monitor.hs

Acquired error message:

Variable not in scope:
      (<==>) :: Stream Bool -> Stream Bool -> Stream Bool
    Suggested fix: Perhaps use ‘==>’ (imported from Copilot.Language)

Suggested fix: Defining a custom infix operator that compares two boolean arguments and returns true if they are both true or both false

infix 4 <==>
(<==>) :: Stream (Bool) -> Stream (Bool) -> Stream (Bool)
a <==> b = a == b
ivanperez-keera commented 6 months ago

Thank you @Andersen0 . I can confirm that the issue is there. This will be an easy fix.

ivanperez-keera commented 6 months ago

Description

The SMV to Copilot translator translates equivalences as (<==>). However, that operator does not exist in Copilot, it is simply (==) for Bools.

Type

Additional context

None.

Requester

Method to check presence of bug

Compiling a specification with <-> in the ptLTL field produces Copilot code that does not compile:

{
  "test_componentSpec": {
    "Functions": [
    ],
    "Internal_variables": [
    ],
    "Other_variables": [
      {
        "name": "a",
        "type": "bool"
      }
    ],
    "Requirements": [
      {
        "CoCoSpecCode": "true",
        "fretish": "unimportant",
        "name": "testCopilot001",
        "ptLTL": "a <-> a"
      }
    ]
  }
}
    • Variable not in scope:
        (<==>) :: Stream Bool -> Stream Bool -> Stream Bool
    • Perhaps you meant ‘==>’ (imported from Copilot.Language)
   |
20 | propTestCopilot001 = (a <==> a)

Expected result

The execution above should produce a Copilot specification that can be compiled and where == is used in Copilot where an equivalence between booleans needs to be expressed.

Desired result

The execution above should produce a Copilot specification that can be compiled and where == is used in Copilot where an equivalence between booleans needs to be expressed.

Proposed solution

Modify the SMV translator to use (==) instead of <==>.

Further notes

None.

ivanperez-keera commented 6 months ago

Change Manager: Confirmed that the issue exists.

ivanperez-keera commented 6 months ago

Technical Lead: Confirmed that the issue should be addressed.

ivanperez-keera commented 6 months ago

Technical Lead: Issue scheduled for fixing in Ogma 1.3.

Fix assigned to: @ivanperez-keera.

ivanperez-keera commented 6 months ago

Implementor: Solution implemented, review requested.

ivanperez-keera commented 6 months ago

Change Manager: Verified that:

ivanperez-keera commented 6 months ago

Change Manager: Implementation ready to be merged.