Skip to content

Commit

Permalink
Merge branch 'develop-cocospec-ytopre' into develop. Close #86.
Browse files Browse the repository at this point in the history
**Description**

Ogma cannot handle CoCoSpec boolean specifications containing the unary
operators `ZtoPre` or `YtoPre`. This makes some of the specifications produced
by FRET not parseable.

**Type**

- Bug: FRET specification cannot be parsed or converted to Copilot monitor.

**Additional context**

None.

**Requester**

- Ivan Perez

**Method to check presence of bug**

Compiling a specification with `ZtoPre` or `YtoPre` in the CoCoSpec property
produces an error message instead of a correct Copilot specification:

```json
{
  "test_componentSpec": {
    "Functions": [
    ],
    "Internal_variables": [
    ],
    "Other_variables": [
      {
        "name": "signal",
        "type": "bool"
      }
    ],
    "Requirements": [
      {
        "CoCoSpecCode": "ZtoPre(signal)",
        "fretish": "unimportant",
        "name": "testCopilot-001",
        "ptLTL": "signal"
      }
    ]
  }
}
```

```sh
$ ogma fret-component-spec --cocospec --fret-file-name fret-reqs-full.json
fret-reqs-full.json: error: syntax error at line 1, column 7 before `('
```

The following Dockerfile runs the FRET to Copilot translators on the
accompanying FRET component specification and FRET requirements DB, which
contain ZtoPre and YtoPre in the CoCoSpec formulas.

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

ENV DEBIAN_FRONTEND=noninteractive

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.15
RUN apt-get install --yes git

ADD fret-reqs-db.json /tmp/fret-reqs-db.json
ADD fret-reqs-cs.json /tmp/fret-reqs-cs.json

CMD git clone $REPO && \
    cd $NAME && \
    git checkout $COMMIT && \
    cd .. && \
    cabal v1-install $NAME/$PAT**/ && \
    ogma fret-reqs-db --fret-file-name /tmp/fret-reqs-db.json --cocospec > DB.hs && \
    cabal v1-exec -- ghc --make DB.hs && \
    ogma fret-component-spec --fret-file-name /tmp/fret-reqs-cs.json --cocospec > CS.hs && \
    cabal v1-exec -- ghc --make CS.hs && \
    echo "Success"

--- fret-reqs-cs.json
{
  "test_componentSpec": {
    "Functions": [
    ],
    "Internal_variables": [
    ],
    "Other_variables": [
      {
        "name": "signal",
        "type": "bool"
      }
    ],
    "Requirements": [
      {
        "CoCoSpecCode": "ZtoPre(signal) and YtoPre(signal)",
        "fretish": "unimportant",
        "name": "testCopilot-001",
        "ptLTL": "TRUE"
      }
    ]
  }
}

--- fret-reqs-db.json
[
    {
        "reqid": "test_req1",
        "parent_reqid": "",
        "project": "Test",
        "rationale": "",
        "fulltext": "",
        "semantics": {
            "type": "test",
            "ptExpanded": "TRUE",
            "CoCoSpecCode": "ZtoPre(signal) and YtoPre(signal)"
        }
    }
]
```

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-86
```

**Expected result**

The execution above should produce a Copilot specification that translates
`ZtoPre` to delay initialized to `True`. If modified to use `YtoPre`, the
operator should be translated to a delay initialized to `False`.

Running the docker script prints Success, indicating that specifications
containing both ZtoPre and YtoPre can be translated and the resulting Copilot
files can be compiled, both in requirements DBs and in Component Specs.

**Solution implemented**

Modify CoCoSpec grammar to allow the unary operators `ZtoPre` and `YtoPre`.

Modify translator in `ogma-core` to perform the translation of `ZtoPre` to a
delay initialized to `True`, and `YtoPre` to a delay initialized to `False`.
Include the necessary auxiliary definitions in the generated Copilot modules.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed May 21, 2023
2 parents 702f27e + 6a1054f commit 8ba5f4e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Revision history for ogma-core

## [1.X.Y] - 2023-05-20
## [1.X.Y] - 2023-05-21

* Allow customizing the names of the C files generated by Copilot (#80).
* Translate ZtoPre and YtoPre to Copilot (#86).

## [1.0.8] - 2023-03-21

Expand Down
2 changes: 2 additions & 0 deletions ogma-core/src/Language/Trans/CoCoSpec2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const2Copilot BoolConstFTP = "ftp"
-- operator.
opOnePre2Copilot :: Op1Pre -> String
opOnePre2Copilot Op1Pre = "pre"
opOnePre2Copilot Op1YtoPre = "pre"
opOnePre2Copilot Op1ZtoPre = "tpre"
opOnePre2Copilot Op1Once = "PTLTL.eventuallyPrev"
opOnePre2Copilot Op1Hist = "PTLTL.alwaysBeen"
opOnePre2Copilot Op1Y = "PTLTL.previous"
Expand Down
7 changes: 7 additions & 0 deletions ogma-core/src/Language/Trans/FRETComponentSpec2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fretComponentSpec2Copilot' prefs fretComponentSpec =
, pure clock
, pure ftp
, pure pre
, pure tpre
, pure spec
, pure main'
]
Expand Down Expand Up @@ -223,6 +224,12 @@ fretComponentSpec2Copilot' prefs fretComponentSpec =
, "pre = ([False] ++)"
]

-- Auxiliary streams: tpre
tpre = [ ""
, "tpre :: Stream Bool -> Stream Bool"
, "tpre = ([True] ++)"
]

-- Main specification
spec :: [String]
spec = [ ""
Expand Down
11 changes: 9 additions & 2 deletions ogma-core/src/Language/Trans/FRETReqsDB2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ fret2CopilotModule' prefs smvSpec cocoSpec = unlines $ concat sections
else SMV.boolSpecNames smvSpec

sections | fretReqsDB2CopilotUseCoCoSpec prefs
= [ imports, propDef, externs, clock, ftp, undef, spec, main' ]
= [ imports, propDef, externs, clock, ftp, undef, tpre, spec
, main'
]

| otherwise
= [ imports, propDef, externs, clock, ftp, spec, main' ]
= [ imports, propDef, externs, clock, ftp, tpre, spec, main' ]

imports :: [String]
imports =
Expand Down Expand Up @@ -145,6 +147,11 @@ fret2CopilotModule' prefs smvSpec cocoSpec = unlines $ concat sections
, "pre = undefined"
]

tpre = [ ""
, "tpre :: Stream Bool -> Stream Bool"
, "tpre = ([True] ++)"
]

spec = [ ""
, "-- | Complete specification. Calls the C function void handler(); when"
, "-- the property is violated."
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-05-21

* Add unary operators ZtoPre, YtoPre (#86).

## [1.0.8] - 2023-03-21

* Version bump 1.0.8 (#81).
Expand Down
14 changes: 8 additions & 6 deletions ogma-language-cocospec/grammar/CoCoSpec.cf
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ BoolSpecOp2ST. BoolSpec ::= "ST" "(" NumExpr "," NumExpr "," BoolSpec "," BoolS

-- Boolean Operators

Op1Once. Op1Pre ::= "O" ;
Op1Pre. Op1Pre ::= "pre" ;
Op1Hist. Op1Pre ::= "H" ;
Op1Y. Op1Pre ::= "Y" ;
Op1Not. Op1Pre ::= "not" ;
Op1Bang. Op1Pre ::= "!" ;
Op1Once. Op1Pre ::= "O" ;
Op1Pre. Op1Pre ::= "pre" ;
Op1YtoPre. Op1Pre ::= "YtoPre" ;
Op1ZtoPre. Op1Pre ::= "ZtoPre" ;
Op1Hist. Op1Pre ::= "H" ;
Op1Y. Op1Pre ::= "Y" ;
Op1Not. Op1Pre ::= "not" ;
Op1Bang. Op1Pre ::= "!" ;

Op2And. Op2In ::= "and" ;
Op2Amp. Op2In ::= "&" ;
Expand Down

0 comments on commit 8ba5f4e

Please sign in to comment.