Skip to content

Commit

Permalink
ogma-core: Adjust tests to provide target directory to standalone com…
Browse files Browse the repository at this point in the history
…mand. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

A prior commit introduced, in the standalone command, support for custom
templates. Unlike the prior implementation of the standalone command,
which printed the output to standard output, the new interface puts the
result in a file (or several files) included with the template.  To
implement this new functionality, we have added an argument to specify a
target directory for the generated standalone application,
where the files will be copied to.

This commit modifies the tests for the standalone command to provide a
temporary directory as destination. We default to the temporary
directory of the host system. Since this is only used for testing and
not during normal operation, and the ogma implementation is open source,
we consider this safe from a security standpoint.
  • Loading branch information
ivanperez-keera committed Dec 24, 2024
1 parent 1ee00ed commit 8408589
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions ogma-core/ogma-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ test-suite unit-tests

build-depends:
base
, directory
, HUnit
, QuickCheck
, test-framework
Expand Down
5 changes: 5 additions & 0 deletions ogma-core/tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Data.Monoid ( mempty )
import Test.Framework ( Test, defaultMainWithOpts )
import Test.Framework.Providers.HUnit ( testCase )
import Test.HUnit ( assertBool )
import System.Directory ( getTemporaryDirectory )

-- Internal imports
import Command.CStructs2Copilot (cstructs2Copilot)
Expand Down Expand Up @@ -101,11 +102,13 @@ testFretComponentSpec2Copilot :: FilePath -- ^ Path to a FRET/JSON requirements
-> Bool
-> IO ()
testFretComponentSpec2Copilot file success = do
targetDir <- getTemporaryDirectory
let opts = StandaloneOptions
{ standaloneFormat = "fcs"
, standalonePropFormat = "smv"
, standaloneTypeMapping = [("int", "Int64"), ("real", "Float")]
, standaloneFilename = "fret"
, standaloneTargetDir = targetDir
}
result <- standalone file opts

Expand Down Expand Up @@ -133,11 +136,13 @@ testFretReqsDBCoCoSpec2Copilot :: FilePath -- ^ Path to a FRET/JSON
-> Bool
-> IO ()
testFretReqsDBCoCoSpec2Copilot file success = do
targetDir <- getTemporaryDirectory
let opts = StandaloneOptions
{ standaloneFormat = "fdb"
, standalonePropFormat = "cocospec"
, standaloneTypeMapping = []
, standaloneFilename = "fret"
, standaloneTargetDir = targetDir
}
result <- standalone file opts

Expand Down

0 comments on commit 8408589

Please sign in to comment.