@@ -144,3 +144,100 @@ count_properties(const propertiest &properties, property_statust status)
144
144
}
145
145
return count;
146
146
}
147
+
148
+ // / Update with the preference order
149
+ // / 1. old non-UNKNOWN/non-NOT_CHECKED status
150
+ // / 2. new non-UNKNOWN/non-NOT_CHECKED status
151
+ // / 3. UNKNOWN
152
+ // / 4. NOT_CHECKED
153
+ // / Suitable for updating property status
154
+ property_statust &operator |=(property_statust &a, property_statust const &b)
155
+ {
156
+ // non-monotonic use is likely a bug
157
+ PRECONDITION (
158
+ a == property_statust::NOT_CHECKED ||
159
+ (a == property_statust::UNKNOWN && b != property_statust::NOT_CHECKED) ||
160
+ a == b);
161
+ switch (a)
162
+ {
163
+ case property_statust::NOT_CHECKED:
164
+ case property_statust::UNKNOWN:
165
+ a = b;
166
+ return a;
167
+ case property_statust::ERROR:
168
+ case property_statust::PASS:
169
+ case property_statust::NOT_REACHABLE:
170
+ case property_statust::FAIL:
171
+ return a;
172
+ }
173
+ UNREACHABLE;
174
+ }
175
+
176
+ // / Update with the preference order
177
+ // / 1. ERROR
178
+ // / 2. FAIL
179
+ // / 3. UNKNOWN
180
+ // / 4. NOT_CHECKED
181
+ // / 5. NOT_REACHABLE
182
+ // / 6. PASS
183
+ // / Suitable for computing overall results
184
+ property_statust &operator &=(property_statust &a, property_statust const &b)
185
+ {
186
+ switch (a)
187
+ {
188
+ case property_statust::ERROR:
189
+ a = b;
190
+ return a;
191
+ case property_statust::FAIL:
192
+ a = (b == property_statust::ERROR ? b : a);
193
+ return a;
194
+ case property_statust::UNKNOWN:
195
+ a = (b == property_statust::ERROR || b == property_statust::FAIL ? b : a);
196
+ return a;
197
+ case property_statust::NOT_CHECKED:
198
+ a =
199
+ (b != property_statust::PASS && b != property_statust::NOT_REACHABLE ? b
200
+ : a);
201
+ return a;
202
+ case property_statust::NOT_REACHABLE:
203
+ a = (b != property_statust::PASS ? b : a);
204
+ return a;
205
+ case property_statust::PASS:
206
+ a = (b == property_statust::PASS ? a : b);
207
+ return a;
208
+ }
209
+ UNREACHABLE;
210
+ }
211
+
212
+ // / Determines the overall result corresponding from the given properties
213
+ // / That is PASS if all properties are PASS or NOT_CHECKED,
214
+ // / FAIL if at least one property is FAIL and no property is ERROR,
215
+ // / UNKNOWN if no property is FAIL or ERROR and
216
+ // / at least one property is UNKNOWN,
217
+ // / ERROR if at least one property is error.
218
+ resultt determine_result (const propertiest &properties)
219
+ {
220
+ property_statust status = property_statust::PASS;
221
+ for (const auto &property_pair : properties)
222
+ {
223
+ status &= property_pair.second .status ;
224
+ }
225
+ switch (status)
226
+ {
227
+ case property_statust::NOT_CHECKED:
228
+ // If we have unchecked properties then we don't know.
229
+ return resultt::UNKNOWN;
230
+ case property_statust::UNKNOWN:
231
+ return resultt::UNKNOWN;
232
+ case property_statust::NOT_REACHABLE:
233
+ // If a property is not reachable then overall it's still a PASS.
234
+ return resultt::PASS;
235
+ case property_statust::PASS:
236
+ return resultt::PASS;
237
+ case property_statust::FAIL:
238
+ return resultt::FAIL;
239
+ case property_statust::ERROR:
240
+ return resultt::ERROR;
241
+ }
242
+ UNREACHABLE;
243
+ }
0 commit comments