Skip to content

Commit

Permalink
Merge branch 'develop-fix-ne' into develop. Close #71.
Browse files Browse the repository at this point in the history
**Description**

Requirements that contain inequalities in conditions in the TL formulas fail to
be parsed correctly by Ogma.

**Type**

- Bug: valid FRET file cannot be parsed by Ogma.

**Additional context**

None.

**Requester**

- Alexander Will (Virginia Commonwealth University).

**Method to check presence of bug**

The following command reports an error instead of producing a monitor
specification.
```sh
$ ogma fret-component-spec --fret-file-name file.json
```
where `file.json` contains the following:
```json
{
  "mySpec": {
    "Internal_variables": [ ],
    "Other_variables": [ {"name":"input", "type":"real"} ],
    "Functions": [ ],
    "Requirements": [
      { "name": "REQ",
        "ptLTL": "(H (input != 30.0))",
        "CoCoSpecCode": "(H( input <> 30.0 ))",
        "fretish": "Irrelevant for the example"
      }
    ]
  }
}
```

The error produced is:
```
$ ogma fret-component-spec --fret-file-name file.json
file.json: error: syntax error at line 1, column 10 before `!'
$ ogma fret-component-spec --cocospec --fret-file-name file.json
file.json: error: syntax error at line 1, column 11 before `>'
```

The following dockerfile uses the accompanying FRET component specification
containing inequalities in the TL formulas to generate the Copilot monitors
both for the SMV and CoCoSpec cases, and it compiles the resulting Copilot
code:

```Dockerfile
--- Dockerfile-verify-71
FROM ubuntu:trusty

RUN apt-get update

RUN apt-get install --yes software-properties-common
RUN add-apt-repository ppa:hvr/ghc
RUN apt-get update

RUN apt-get install --yes ghc-8.6.5 cabal-install-2.4
RUN apt-get install --yes libz-dev

ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:$PWD/.cabal-sandbox/bin:$PATH

RUN cabal update
RUN cabal v1-sandbox init
RUN cabal v1-install alex happy
RUN cabal v1-install copilot-3.13
RUN apt-get install --yes git

ADD file.json /tmp/file.json

CMD git clone $REPO && \
    cd $NAME && \
    git checkout $COMMIT && \
    cd .. && \
    cabal v1-install $NAME/$PAT**/ && \
    ogma fret-component-spec --fret-file-name /tmp/file.json > SMV.hs && \
    cabal v1-exec -- runhaskell SMV.hs && \
    gcc -c fret.c && \
    ogma fret-component-spec --fret-file-name /tmp/file.json --cocospec > CoCoSpec.hs && \
    cabal v1-exec -- runhaskell CoCoSpec.hs && \
    gcc -c fret.c && \
    echo "Success"

--- file.json
{
  "mySpec": {
    "Internal_variables": [ ],
    "Other_variables": [ {"name":"input", "type":"real"} ],
    "Functions": [ ],
    "Requirements": [
      { "name": "REQ",
        "ptLTL": "(H (input != 30.0))",
        "CoCoSpecCode": "(H( input <> 30.0 ))",
        "fretish": "Irrelevant for the example"
      }
    ]
  }
}
```

Command (substitute variables based on new path after merge):
```sh
$ docker run -e "REPO=https://github.com/NASA/ogma" -e "NAME=ogma" -e PAT="ogma-" -e "COMMIT=<HASH>" -it ogma-verify-71
```

**Expected result**

The json file above should be usable with Ogma and produce a valid Copilot
monitor. Running the Docker image with the associated file in scope should
produce correct Copilot code which can be executed. The resulting C99
code can be compiled correctly. The word "Success" is printed after a
successful execution.

**Solution implemented**

Modify SMV grammar to accept inequality. Adjust Ogma accordingly to translate
the operator into Copilot's (/=).

Modify CoCoSpec grammar to accept inequality. Adjust Ogma accordingly to
translate the operator into Copilot's (/=).

Modify the general Copilot code generator to hide the (/=) operator imported by
default from the Prelude.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed Feb 2, 2023
2 parents 0d67c6b + 393cb1e commit 04802db
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-core

## [1.X.Y] - 2023-02-01

* Support inequality operator in SMV and CoCoSpec (#71).

## [1.0.7] - 2023-01-21
* Version bump 1.0.7 (#69).
* Introduce new ROS2 backend (#56).
Expand Down
1 change: 1 addition & 0 deletions ogma-core/src/Language/Trans/CoCoSpec2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ numOpTwoIn2Copilot NumOp2Mult = "*"
-- operator.
opTwoNum2Copilot :: BoolNumOp -> String
opTwoNum2Copilot BoolNumOp2Eq = "=="
opTwoNum2Copilot BoolNumOp2Ne = "/="
opTwoNum2Copilot BoolNumOp2Le = "<="
opTwoNum2Copilot BoolNumOp2Lt = "<"
opTwoNum2Copilot BoolNumOp2Gt = ">="
Expand Down
2 changes: 1 addition & 1 deletion ogma-core/src/Language/Trans/FRETComponentSpec2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fretComponentSpec2Copilot' prefs fretComponentSpec =
, "import qualified Copilot.Library.MTL as MTL"
, "import Language.Copilot (reify)"
, "import Prelude hiding ((&&), (||), (++),"
++ " (<=), (>=), (<), (>), (==), not)"
++ " (<=), (>=), (<), (>), (==), (/=), not)"
, ""
]

Expand Down
2 changes: 1 addition & 1 deletion ogma-core/src/Language/Trans/FRETReqsDB2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fret2CopilotModule' prefs smvSpec cocoSpec = unlines $ concat sections
, "import qualified Copilot.Library.PTLTL as PTLTL"
, "import Language.Copilot (reify)"
, "import Prelude hiding ((&&), (||), (++), (<=), (>=),"
++ " (<), (>), (==), not)"
++ " (<), (>), (==), (/=), not)"
, ""
]

Expand Down
1 change: 1 addition & 0 deletions ogma-core/src/Language/Trans/SMV2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ ordOp2Copilot :: OrdOp -> String
ordOp2Copilot OrdOpLT = "<"
ordOp2Copilot OrdOpLE = "<="
ordOp2Copilot OrdOpEQ = "=="
ordOp2Copilot OrdOpNE = "/="
ordOp2Copilot OrdOpGT = ">"
ordOp2Copilot OrdOpGE = ">="

Expand Down
4 changes: 4 additions & 0 deletions ogma-language-cocospec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-language-cocospec

## [1.X.Y] - 2023-02-01

* Support inequality operator (#71).

## [1.0.7] - 2023-01-21
* Version bump 1.0.7 (#69).
* Specify upper bound constraint for Cabal. Refs #69.
Expand Down
1 change: 1 addition & 0 deletions ogma-language-cocospec/grammar/CoCoSpec.cf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ NumOp2Minus. NumOp2In ::= "-" ;
NumOp2Mult . NumOp2In ::= "*" ;

BoolNumOp2Eq . BoolNumOp ::= "=" ;
BoolNumOp2Ne . BoolNumOp ::= "<>" ;
BoolNumOp2Le . BoolNumOp ::= "<=" ;
BoolNumOp2Lt . BoolNumOp ::= "<" ;
BoolNumOp2Gt . BoolNumOp ::= ">" ;
Expand Down
4 changes: 4 additions & 0 deletions ogma-language-smv/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-language-smv

## [1.X.Y] - 2023-02-01

* Support inequality operator (#71).

## [1.0.7] - 2023-01-21
* Version bump 1.0.7 (#69).
* Specify upper bound constraint for Cabal. Refs #69.
Expand Down
1 change: 1 addition & 0 deletions ogma-language-smv/grammar/SMV.cf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ _ . Number ::= "<i>" Number "</i>";
OrdOpLT . OrdOp ::= "<";
OrdOpLE . OrdOp ::= "<=";
OrdOpEQ . OrdOp ::= "=";
OrdOpNE . OrdOp ::= "!=";
OrdOpGT . OrdOp ::= ">";
OrdOpGE . OrdOp ::= ">=";

Expand Down

0 comments on commit 04802db

Please sign in to comment.