Debian Codegraph @

tools/antithesis-go-instrumentor/scanners/assertions/assertion_hints.go

raw
1 package assertions
2
3 // A type for writing raw assertions.
4 // GuidanceFnType allows the assertion to provide guidance to
5 // the Antithesis platform when testing in Antithesis.
6 // Regular users of the assert package should not use it.
7 type GuidanceFnType int
8
9 const (
10 GuidanceFnMaximize GuidanceFnType = iota // Maximize (left - right) values
11 GuidanceFnMinimize // Minimize (left - right) values
12 GuidanceFnWantAll // Encourages fuzzing explorations where boolean values are true
13 GuidanceFnWantNone // Encourages fuzzing explorations where boolean values are false
14 GuidanceFnExplore
15 )
16
17 // --------------------------------------------------------------------------------
18 // Assertion Hints
19 // --------------------------------------------------------------------------------
20 type AssertionFuncInfo struct {
21 TargetFunc string
22 AssertType string
23 MustHit bool
24 Condition bool
25 MessageArg int
26 }
27
28 type AssertionHints map[string]*AssertionFuncInfo
29
30 func SetupHintMap() AssertionHints {
31 hintMap := make(AssertionHints)
32
33 hintMap["Always"] = &AssertionFuncInfo{
34 TargetFunc: "Always",
35 MustHit: true,
36 AssertType: "always",
37 Condition: false,
38 MessageArg: 1,
39 }
40
41 hintMap["AlwaysOrUnreachable"] = &AssertionFuncInfo{
42 TargetFunc: "AlwaysOrUnreachable",
43 MustHit: false,
44 AssertType: "always",
45 Condition: false,
46 MessageArg: 1,
47 }
48
49 hintMap["Sometimes"] = &AssertionFuncInfo{
50 TargetFunc: "Sometimes",
51 MustHit: true,
52 AssertType: "sometimes",
53 Condition: false,
54 MessageArg: 1,
55 }
56
57 hintMap["Unreachable"] = &AssertionFuncInfo{
58 TargetFunc: "Unreachable",
59 MustHit: false,
60 AssertType: "reachability",
61 Condition: false,
62 MessageArg: 0,
63 }
64
65 hintMap["Reachable"] = &AssertionFuncInfo{
66 TargetFunc: "Reachable",
67 MustHit: true,
68 AssertType: "reachability",
69 Condition: true,
70 MessageArg: 0,
71 }
72
73 return hintMap
74 }
75
76 // --------------------------------------------------------------------------------
77 // Guidance Hints
78 // --------------------------------------------------------------------------------
79 type GuidanceFuncInfo struct {
80 AssertionFuncInfo
81 GuidanceFn GuidanceFnType
82 }
83
84 type GuidanceHints map[string]*GuidanceFuncInfo
85
86 func SetupGuidanceHintMap() GuidanceHints {
87 hintMap := make(GuidanceHints)
88
89 hintMap["AlwaysGreaterThan"] = &GuidanceFuncInfo{
90 AssertionFuncInfo: AssertionFuncInfo{
91 TargetFunc: "AlwaysGreaterThan",
92 AssertType: "always",
93 MustHit: true,
94 Condition: false,
95 MessageArg: 2,
96 },
97 GuidanceFn: GuidanceFnMinimize,
98 }
99
100 hintMap["AlwaysGreaterThanOrEqualTo"] = &GuidanceFuncInfo{
101 AssertionFuncInfo: AssertionFuncInfo{
102 TargetFunc: "AlwaysGreaterThanOrEqualTo",
103 AssertType: "always",
104 MustHit: true,
105 Condition: false,
106 MessageArg: 2,
107 },
108 GuidanceFn: GuidanceFnMinimize,
109 }
110
111 hintMap["SometimesGreaterThan"] = &GuidanceFuncInfo{
112 AssertionFuncInfo: AssertionFuncInfo{
113 TargetFunc: "SometimesGreaterThan",
114 AssertType: "sometimes",
115 MustHit: true,
116 Condition: false,
117 MessageArg: 2,
118 },
119 GuidanceFn: GuidanceFnMaximize,
120 }
121
122 hintMap["SometimesGreaterThanOrEqualTo"] = &GuidanceFuncInfo{
123 AssertionFuncInfo: AssertionFuncInfo{
124 TargetFunc: "SometimesGreaterThanOrEqualTo",
125 AssertType: "sometimes",
126 MustHit: true,
127 Condition: false,
128 MessageArg: 2,
129 },
130 GuidanceFn: GuidanceFnMaximize,
131 }
132
133 hintMap["AlwaysLessThan"] = &GuidanceFuncInfo{
134 AssertionFuncInfo: AssertionFuncInfo{
135 TargetFunc: "AlwaysLessThan",
136 AssertType: "always",
137 MustHit: true,
138 Condition: false,
139 MessageArg: 2,
140 },
141 GuidanceFn: GuidanceFnMaximize,
142 }
143
144 hintMap["AlwaysLessThanOrEqualTo"] = &GuidanceFuncInfo{
145 AssertionFuncInfo: AssertionFuncInfo{
146 TargetFunc: "AlwaysLessThanOrEqualTo",
147 AssertType: "always",
148 MustHit: true,
149 Condition: false,
150 MessageArg: 2,
151 },
152 GuidanceFn: GuidanceFnMaximize,
153 }
154
155 hintMap["SometimesLessThan"] = &GuidanceFuncInfo{
156 AssertionFuncInfo: AssertionFuncInfo{
157 TargetFunc: "SometimesLessThan",
158 AssertType: "sometimes",
159 MustHit: true,
160 Condition: false,
161 MessageArg: 2,
162 },
163 GuidanceFn: GuidanceFnMinimize,
164 }
165
166 hintMap["SometimesLessThanOrEqualTo"] = &GuidanceFuncInfo{
167 AssertionFuncInfo: AssertionFuncInfo{
168 TargetFunc: "SometimesLessThanOrEqualTo",
169 AssertType: "sometimes",
170 MustHit: true,
171 Condition: false,
172 MessageArg: 2,
173 },
174 GuidanceFn: GuidanceFnMinimize,
175 }
176
177 hintMap["AlwaysSome"] = &GuidanceFuncInfo{
178 AssertionFuncInfo: AssertionFuncInfo{
179 TargetFunc: "AlwaysSome",
180 AssertType: "always",
181 MustHit: true,
182 Condition: false,
183 MessageArg: 1,
184 },
185 GuidanceFn: GuidanceFnWantNone,
186 }
187
188 hintMap["SometimesAll"] = &GuidanceFuncInfo{
189 AssertionFuncInfo: AssertionFuncInfo{
190 TargetFunc: "SometimesAll",
191 AssertType: "sometimes",
192 MustHit: true,
193 Condition: false,
194 MessageArg: 1,
195 },
196 GuidanceFn: GuidanceFnWantAll,
197 }
198
199 return hintMap
200 }
201
202 func (m AssertionHints) HintsForName(name string) *AssertionFuncInfo {
203 if v, ok := m[name]; ok {
204 return v
205 }
206 return nil
207 }
208
209 func (m GuidanceHints) GuidanceHintsForName(name string) *GuidanceFuncInfo {
210 if v, ok := m[name]; ok {
211 return v
212 }
213 return nil
214 }