Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogma-core: Spec2Copilot translator does not sanitize handler names #127

Closed
ivanperez-keera opened this issue Mar 4, 2024 · 6 comments
Closed
Assignees
Labels
CR:Status:Closed Admin only: Change request that has been completed CR:Type:Bug Admin only: Change request pertaining to error detected
Milestone

Comments

@ivanperez-keera
Copy link
Member

ivanperez-keera commented Mar 4, 2024

Description

The Spec to Copilot translator is not sanitizing handler names. This causes the Copilot generated code not to compile if the property identifiers have a hyphen.

Type

  • Bug: backend generates incorrect code.

Additional context

None.

Requester

  • Tage Andersen and Elias Evjen Hartmark (NMBU, Norway)

Method to check presence of bug

Compiling a specification with a hyphen in a requirement name produces Copilot code that does not compile:

{
  "test_componentSpec": {
    "Functions": [
    ],
    "Internal_variables": [
    ],
    "Other_variables": [
    ],
    "Requirements": [
      {
        "CoCoSpecCode": "true",
        "fretish": "unimportant",
        "name": "testCopilot-001",
        "ptLTL": "TRUE"
      }
    ]
  }
}
Monitor.hs: '-' is not a nondigit
CallStack (from HasCallStack):
  error, called at src/Language/C99/Util/Expr.hs:78:10 in language-c99-util-0.2.0-987ZdxxqOvYC4hudkeZk8i:Language.C99.Util.Expr

Expected result

The execution above should produce a Copilot specification that can be compiled and where - has been converted to an underscore.

Desired result

The execution above should produce a Copilot specification that can be compiled and where - has been converted to an underscore.

Proposed solution

Modify the Spec translator to sanitize handler names the same way that the ROS backend does.

Further notes

None.

@ivanperez-keera ivanperez-keera added CR:Status:Initiated Admin only: Change request that has been initiated CR:Type:Bug Admin only: Change request pertaining to error detected labels Mar 5, 2024
@ivanperez-keera
Copy link
Member Author

Change Manager: Confirmed that the issue exists.

@ivanperez-keera ivanperez-keera added CR:Status:Confirmed Admin only: Change request that has been acknowledged by the change manager and removed CR:Status:Initiated Admin only: Change request that has been initiated labels Mar 5, 2024
@ivanperez-keera
Copy link
Member Author

Technical Lead: Confirmed that the issue should be addressed.

@ivanperez-keera ivanperez-keera added CR:Status:Accepted Admin only: Change request accepted by technical lead and removed CR:Status:Confirmed Admin only: Change request that has been acknowledged by the change manager labels Mar 5, 2024
@ivanperez-keera
Copy link
Member Author

Technical Lead: Issue scheduled for fixing in Ogma 1.3.

Fix assigned to: @ivanperez-keera.

@ivanperez-keera ivanperez-keera added CR:Status:Scheduled Admin only: Change requested scheduled and removed CR:Status:Accepted Admin only: Change request accepted by technical lead labels Mar 5, 2024
@ivanperez-keera ivanperez-keera added this to the 1.3.0 milestone Mar 5, 2024
@ivanperez-keera ivanperez-keera self-assigned this Mar 5, 2024
@ivanperez-keera ivanperez-keera added CR:Status:Implementation Admin only: Change request that is currently being implemented and removed CR:Status:Scheduled Admin only: Change requested scheduled labels Mar 14, 2024
ivanperez-keera added a commit that referenced this issue Mar 14, 2024
The Spec to Copilot translator is not sanitizing handler names. This
causes the Copilot generated code not to compile if the property
identifiers have a hyphen.

This commit modifies the handler association in the trigger definitions
in the generated Copilot code so that the handler names are sanitized.
@ivanperez-keera
Copy link
Member Author

Implementor: Solution implemented, review requested.

@ivanperez-keera ivanperez-keera added CR:Status:Verification Admin only: Change request that is currently being verified and removed CR:Status:Implementation Admin only: Change request that is currently being implemented labels Mar 14, 2024
@ivanperez-keera
Copy link
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles passes the tests. Details:
      Docker image:

      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 apt-get install --yes git
      
      # We install the application first and then test it, in case any tests need to
      # run the tool.
      CMD git clone $REPO && \
          cd $NAME && \
          git checkout $COMMIT && \
          cd .. && \
          cabal v1-install $NAME/$PAT**/ --enable-tests && \
          cabal v1-install $NAME/$PAT**/ --enable-tests --run-tests -j1

      Command:

      $ docker run -e "REPO=https://github.com/nasa/ogma" -e "NAME=ogma" -e PAT="ogma-" -e "COMMIT=7ce5a4058a1f0527d1051b84406446a15a0ba31d" -it ogma-test
    • The solution proposed fixes the issues described. Details:
      The following Dockerfile uses the spec containing an equivalence operator in the SMV property, and it compiles the resulting Copilot code.

      --- Dockerfile-verify-127
      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.19
      RUN apt-get install --yes git
      
      ADD reqs.json /tmp/reqs.json
      
      CMD git clone $REPO && \
          cd $NAME && \
          git checkout $COMMIT && \
          cd .. && \
          cabal v1-install --force-reinstall $NAME/$PAT**/ && \
          ogma fret-component-spec --fret-file-name /tmp/reqs.json --target-file-name monitor > CS.hs && \
          cabal v1-exec -- runhaskell CS.hs && \
          gcc -c monitor.c && \
          echo "Success"
      
      --- reqs.json
      {
        "test_componentSpec": {
          "Functions": [
          ],
          "Internal_variables": [
          ],
          "Other_variables": [
          ],
          "Requirements": [
            {
              "CoCoSpecCode": "true",
              "fretish": "unimportant",
              "name": "testCopilot-001",
              "ptLTL": "TRUE"
            }
          ]
        }
      }

      Command:

      $ docker run -e "REPO=https://github.com/nasa/ogma" -e "NAME=ogma" -e PAT="ogma-" -e "COMMIT=7ce5a4058a1f0527d1051b84406446a15a0ba31d" -it ogma-verify-127
  • Implementation is documented. Details:
    No changes needed.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No examples affected.
  • Required version bumps are evaluated. Details:
    No bump needed (bug fix).

@ivanperez-keera
Copy link
Member Author

Change Manager: Implementation ready to be merged.

@ivanperez-keera ivanperez-keera added CR:Status:Closed Admin only: Change request that has been completed and removed CR:Status:Verification Admin only: Change request that is currently being verified labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CR:Status:Closed Admin only: Change request that has been completed CR:Type:Bug Admin only: Change request pertaining to error detected
Projects
None yet
Development

No branches or pull requests

1 participant