1
1
module Test.Kore.Exec
2
2
( test_exec
3
3
, test_search
4
+ , test_execGetExitCode
4
5
) where
5
6
6
7
import Test.Tasty
7
8
( TestTree , testGroup )
8
9
import Test.Tasty.HUnit
9
- ( testCase )
10
+ ( assertEqual , testCase )
10
11
11
12
import Control.Applicative
12
13
( liftA2 )
@@ -19,6 +20,8 @@ import Data.Set
19
20
import qualified Data.Set as Set
20
21
import Data.Text
21
22
( Text )
23
+ import System.Exit
24
+ ( ExitCode (.. ) )
22
25
23
26
import Kore.AST.Kore
24
27
import Kore.AST.Sentence
@@ -29,7 +32,9 @@ import Kore.ASTVerifier.DefinitionVerifier
29
32
import qualified Kore.Attribute.Axiom as Attribute
30
33
import Kore.Attribute.Constructor
31
34
import Kore.Attribute.Functional
35
+ import Kore.Attribute.Hook
32
36
import qualified Kore.Builtin as Builtin
37
+ import qualified Kore.Builtin.Int as Int
33
38
import Kore.Exec
34
39
import Kore.IndexedModule.IndexedModule
35
40
( VerifiedModule )
@@ -280,3 +285,87 @@ applyToNoArgs sort name =
280
285
, symbolOrAliasParams = []
281
286
}
282
287
[]
288
+
289
+ test_execGetExitCode :: TestTree
290
+ test_execGetExitCode =
291
+ testGroup " execGetExitCode"
292
+ [ makeTestCase " No getExitCode symbol => ExitSuccess"
293
+ testModuleNoSymbol 42 ExitSuccess
294
+ , makeTestCase " No getExitCode simplification axiom => ExitFailure 111"
295
+ testModuleNoAxiom 42 $ ExitFailure 111
296
+ , makeTestCase " Exit cell contains 0 => ExitSuccess"
297
+ testModuleSuccessfulSimplification 0 ExitSuccess
298
+ , makeTestCase " Exit cell contains 42 => ExitFailure 42"
299
+ testModuleSuccessfulSimplification 42 $ ExitFailure 42
300
+ ]
301
+ where
302
+ unlimited :: Limit Integer
303
+ unlimited = Unlimited
304
+
305
+ makeTestCase name testModule inputInteger expectedCode =
306
+ testCase name
307
+ $ actual testModule inputInteger >>= assertEqual " " expectedCode
308
+
309
+ actual testModule exitCode =
310
+ SMT. runSMT SMT. defaultConfig
311
+ $ evalSimplifier emptyLogger
312
+ $ execGetExitCode
313
+ (verifiedMyModule testModule)
314
+ (Limit. replicate unlimited . anyRewrite)
315
+ $ Int. asInternal myIntSort exitCode
316
+
317
+ -- Module with no getExitCode symbol
318
+ testModuleNoSymbol = Module
319
+ { moduleName = ModuleName " MY-MODULE"
320
+ , moduleSentences = []
321
+ , moduleAttributes = Attributes []
322
+ }
323
+ -- simplification of the exit code pattern will not produce an integer
324
+ -- (no axiom present for the symbol)
325
+ testModuleNoAxiom = Module
326
+ { moduleName = ModuleName " MY-MODULE"
327
+ , moduleSentences =
328
+ [ asSentence intSortDecl
329
+ , asSentence getExitCodeDecl
330
+ ]
331
+ , moduleAttributes = Attributes []
332
+ }
333
+ -- simplification succeeds
334
+ testModuleSuccessfulSimplification = Module
335
+ { moduleName = ModuleName " MY-MODULE"
336
+ , moduleSentences =
337
+ [ asSentence intSortDecl
338
+ , asSentence getExitCodeDecl
339
+ , mockGetExitCodeAxiom
340
+ ]
341
+ , moduleAttributes = Attributes []
342
+ }
343
+
344
+ myIntSortId = testId " Int"
345
+
346
+ myIntSort = SortActualSort $ SortActual myIntSortId []
347
+
348
+ intSortDecl :: VerifiedKoreSentenceSort Object
349
+ intSortDecl = SentenceSort
350
+ { sentenceSortName = myIntSortId
351
+ , sentenceSortParameters = []
352
+ , sentenceSortAttributes = Attributes [hookAttribute Int. sort]
353
+ }
354
+
355
+ getExitCodeId = testId " LblgetExitCode"
356
+
357
+ getExitCodeDecl :: VerifiedKoreSentenceSymbol Object
358
+ getExitCodeDecl =
359
+ ( mkSymbol_ getExitCodeId [myIntSort] myIntSort )
360
+ { sentenceSymbolAttributes = Attributes [functionalAttribute] }
361
+
362
+ mockGetExitCodeAxiom =
363
+ mkEqualityAxiom
364
+ (mkApp myIntSort getExitCodeSym [mkVar v]) (mkVar v) Nothing
365
+ where
366
+ v = Variable
367
+ { variableName = testId " V"
368
+ , variableCounter = mempty
369
+ , variableSort = myIntSort
370
+ }
371
+ getExitCodeSym = SymbolOrAlias getExitCodeId []
0 commit comments