-
Notifications
You must be signed in to change notification settings - Fork 42
/
Clobber.hs
187 lines (171 loc) · 7.86 KB
/
Clobber.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{-
Copyright : (c) Galois, Inc 2021
License : BSD3
Maintainer : Langston Barrett <[email protected]>
Stability : provisional
-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-partial-type-signatures -fno-warn-incomplete-uni-patterns #-}
module Clobber (clobberTests) where
{- ORMOLU_DISABLE -}
import Control.Lens ((^.))
import Data.Functor.Compose (Compose(Compose))
import qualified Data.IORef as IORef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Test.Tasty as TT
import qualified Test.Tasty.HUnit as TH
import Text.LLVM.AST as L
import qualified Data.Parameterized.Context as Ctx
import Data.Parameterized.NatRepr (knownNat)
import Lang.Crucible.LLVM.Translation (transContext, llvmTypeCtx)
import qualified Crux.LLVM.Config as CruxLLVM
import UCCrux.LLVM.Constraints (ConstrainedShape(..))
import UCCrux.LLVM.Context.Module (moduleTranslation, declTypes)
import qualified UCCrux.LLVM.Cursor as Cursor
import qualified UCCrux.LLVM.FullType.Type as FT
import UCCrux.LLVM.Module (FuncSymbol(FuncDeclSymbol), makeDeclSymbol)
import qualified UCCrux.LLVM.Run.Simulate as Sim
import qualified UCCrux.LLVM.Overrides.Skip as Skip
import qualified UCCrux.LLVM.Shape as Shape
-- Tests
import qualified Utils
{- ORMOLU_ENABLE -}
clobberTests :: TT.TestTree
clobberTests =
TT.testGroup
"clobbering"
[ TH.testCase
"clobbers_arg.c"
( Utils.simulateFunc
"clobbers_arg.c"
"calls_clobbers_arg"
( \_appCtx modCtx _halloc _cruxOpts llOpts _funCtx ->
do let Just callee =
makeDeclSymbol
(L.Symbol "clobbers_arg")
(modCtx ^. declTypes)
let ?memOpts = CruxLLVM.memOpts llOpts
let ?lc = modCtx ^. moduleTranslation . transContext . llvmTypeCtx
let
i32p = FT.FTPtrRepr (FT.toPartType (FT.FTIntRepr (knownNat @32)))
specs =
Skip.makeClobberSpecs
[ Skip.SomeClobberSpec $
Skip.ClobberSpec
{ Skip.clobberSelector =
Skip.ClobberSelectArgument
Ctx.baseIndex
(Cursor.Here i32p)
, Skip.clobberType = i32p
, Skip.clobberShape =
ConstrainedShape
(Shape.ShapeInt (Compose []))
}
]
Map.empty
msg = "Test failure: 'clobbers_arg'"
get = either (error msg) id
return $
Sim.SimulatorCallbacks $
do nameRef <- IORef.newIORef Set.empty
annRef <- IORef.newIORef Map.empty
return $
Sim.SimulatorHooks
{ Sim.createOverrideHooks =
[ Sim.SymCreateOverrideFn $
\bak ->
return $
get $
Skip.createSkipOverride
modCtx
bak
nameRef
annRef
specs
Nothing
(FuncDeclSymbol callee)
]
, Sim.resultHook =
\_bak _mem _args _cruxResult ucCruxResult ->
do calls <- IORef.readIORef nameRef
TH.assertEqual
"The override for 'clobbers_arg' was exec'd"
1
(length calls)
TH.assertBool
"No read of uninitialized memory"
(null (Sim.explanations ucCruxResult))
return ()
}
)
)
, TH.testCase
"clobbers_arg_void_ptr.c"
( Utils.simulateFunc
"clobbers_arg_void_ptr.c"
"calls_clobbers_arg_void_ptr"
( \_appCtx modCtx _halloc _cruxOpts llOpts _funCtx ->
do let Just callee =
makeDeclSymbol
(L.Symbol "clobbers_arg_void_ptr")
(modCtx ^. declTypes)
let ?memOpts = CruxLLVM.memOpts llOpts
let ?lc = modCtx ^. moduleTranslation . transContext . llvmTypeCtx
let
i32p = FT.FTPtrRepr (FT.toPartType (FT.FTIntRepr (knownNat @32)))
specs =
Skip.makeClobberSpecs
[ Skip.SomeClobberSpec $
Skip.ClobberSpec
{ Skip.clobberSelector =
Skip.ClobberSelectArgument
Ctx.baseIndex
(Cursor.Here i32p)
, Skip.clobberType = i32p
, Skip.clobberShape =
ConstrainedShape
(Shape.ShapeInt (Compose []))
}
]
Map.empty
msg = "Test failure: 'clobbers_arg'"
get = either (error msg) id
return $
Sim.SimulatorCallbacks $
do nameRef <- IORef.newIORef Set.empty
annRef <- IORef.newIORef Map.empty
return $
Sim.SimulatorHooks
{ Sim.createOverrideHooks =
[ Sim.SymCreateOverrideFn $
\sym ->
return $
get $
Skip.createSkipOverride
modCtx
sym
nameRef
annRef
specs
Nothing
(FuncDeclSymbol callee)
]
, Sim.resultHook =
\_sym _mem _args _cruxResult ucCruxResult ->
do calls <- IORef.readIORef nameRef
TH.assertEqual
"The override for 'clobbers_arg' was exec'd"
1
(length calls)
TH.assertBool
"No read of uninitialized memory"
(null (Sim.explanations ucCruxResult))
return ()
}
)
)
]