GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of hst/hst
Description: An open-source refinement checker for the CSP process algebra
Homepage: http://dcreager.lighthouseapp.com/projects/9982-hst/overview
Clone URL: git://github.com/dcreager/hst.git
Adding failures refinement option to csp0 script

A previous patch added support for failures refinement, but I hadn't
yet made this functionality available in the csp0 command-line script.
This patch does so.

Lighthouse: [#3 state:resolved]
dcreager (author)
Sun Jul 06 10:30:56 -0700 2008
commit  8317134761619c5c0b768c2c2d0493936913e5db
tree    9614134343319783de0fe4c885a0c7451cf291ea
parent  d9c7dc294b48e2f3a5009e26a27a96b33f562db8
...
96
97
98
 
99
100
101
...
180
181
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
184
185
...
240
241
242
243
 
 
 
244
245
 
246
247
248
249
250
251
252
253
254
 
255
256
257
 
258
259
260
 
261
262
 
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
 
 
 
313
 
 
 
314
315
316
...
96
97
98
99
100
101
102
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
...
415
416
417
 
418
419
420
421
 
422
423
 
 
 
 
 
 
 
 
424
425
 
 
426
427
 
 
428
429
 
430
431
432
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
434
435
436
437
438
439
440
441
442
0
@@ -96,6 +96,7 @@ void print_assert_usage(ostream &stream)
0
            << "be of the following form:" << endl
0
            << endl
0
            << " --traces-refinement [spec] [impl]" << endl
0
+ << " --failures-refinement [spec] [impl]" << endl
0
         ;
0
 }
0
 
0
@@ -180,6 +181,180 @@ int do_lts(int argc, const char **argv)
0
  * The “assert” command tests assertions on a CSP0 script.
0
  */
0
 
0
+int do_traces_refinement(csp_t &csp,
0
+ const char *spec_name,
0
+ const char *impl_name)
0
+{
0
+ // Look up the process names in the CSP script.
0
+
0
+ state_t spec, impl;
0
+
0
+ spec = csp.get_process(spec_name);
0
+ if (spec == HST_ERROR_STATE)
0
+ {
0
+ cerr << "Specification process "
0
+ << spec_name << " does not exist."
0
+ << endl;
0
+ return 3;
0
+ }
0
+
0
+ impl = csp.get_process(impl_name);
0
+ if (impl == HST_ERROR_STATE)
0
+ {
0
+ cerr << "Implementation process "
0
+ << impl_name << " does not exist."
0
+ << endl;
0
+ return 3;
0
+ }
0
+
0
+ // Normalize the spec process.
0
+
0
+ csp.normalized_lts()->clear(TRACES);
0
+ csp.normalized_lts()->prenormalize(spec);
0
+ csp.normalized_lts()->normalize();
0
+ spec = csp.normalized_lts()->initial_normal_state(spec);
0
+
0
+ // Check the refinement.
0
+
0
+ trace_counterexample_t counter;
0
+ bool result = trace_refines(counter,
0
+ *csp.normalized_lts(), spec,
0
+ *csp.lts(), impl);
0
+
0
+ cout << spec_name << " [T= " << impl_name
0
+ << ": " << (result? "true": "false")
0
+ << endl;
0
+
0
+ if (!result)
0
+ {
0
+ cout << "After trace <";
0
+
0
+ trace_t::const_iterator tit;
0
+ bool first = true;
0
+
0
+ for (tit = counter.trace.begin();
0
+ tit != counter.trace.end();
0
+ ++tit)
0
+ {
0
+ event_t event = *tit;
0
+
0
+ if (event != csp.tau())
0
+ {
0
+ if (first)
0
+ first = false;
0
+ else
0
+ cout << ",";
0
+
0
+ cout << csp.lts()->get_event_name(*tit);
0
+ }
0
+ }
0
+
0
+ cout << ">," << endl
0
+ << impl_name << " can execute "
0
+ << csp.lts()->get_event_name(counter.event)
0
+ << " but " << spec_name << " cannot."
0
+ << endl;
0
+ }
0
+
0
+ return 0;
0
+}
0
+
0
+int do_failures_refinement(csp_t &csp,
0
+ const char *spec_name,
0
+ const char *impl_name)
0
+{
0
+ // Look up the process names in the CSP script.
0
+
0
+ state_t spec, impl;
0
+
0
+ spec = csp.get_process(spec_name);
0
+ if (spec == HST_ERROR_STATE)
0
+ {
0
+ cerr << "Specification process "
0
+ << spec_name << " does not exist."
0
+ << endl;
0
+ return 3;
0
+ }
0
+
0
+ impl = csp.get_process(impl_name);
0
+ if (impl == HST_ERROR_STATE)
0
+ {
0
+ cerr << "Implementation process "
0
+ << impl_name << " does not exist."
0
+ << endl;
0
+ return 3;
0
+ }
0
+
0
+ // Normalize the spec process.
0
+
0
+ csp.normalized_lts()->clear(FAILURES);
0
+ csp.normalized_lts()->prenormalize(spec);
0
+ csp.normalized_lts()->normalize();
0
+ spec = csp.normalized_lts()->initial_normal_state(spec);
0
+
0
+ // Check the refinement.
0
+
0
+ failures_counterexample_t counter;
0
+ bool result = failures_refines(counter,
0
+ *csp.normalized_lts(), spec,
0
+ *csp.lts(), impl);
0
+
0
+ cout << spec_name << " [F= " << impl_name
0
+ << ": " << (result? "true": "false")
0
+ << endl;
0
+
0
+ if (!result)
0
+ {
0
+ cout << "After trace <";
0
+
0
+ bool first = true;
0
+
0
+ for (trace_t::const_iterator tit = counter.trace.begin();
0
+ tit != counter.trace.end();
0
+ ++tit)
0
+ {
0
+ event_t event = *tit;
0
+
0
+ if (event != csp.tau())
0
+ {
0
+ if (first)
0
+ first = false;
0
+ else
0
+ cout << ",";
0
+
0
+ cout << csp.lts()->get_event_name(event);
0
+ }
0
+ }
0
+
0
+ cout << ">," << endl
0
+ << impl_name << " can accept {";
0
+
0
+ first = true;
0
+
0
+ for (alphabet_t::iterator ait = counter.acceptance.begin();
0
+ ait != counter.acceptance.end();
0
+ ++ait)
0
+ {
0
+ event_t event = *ait;
0
+
0
+ if (event != csp.tau())
0
+ {
0
+ if (first)
0
+ first = false;
0
+ else
0
+ cout << ",";
0
+
0
+ cout << csp.lts()->get_event_name(event);
0
+ }
0
+ }
0
+
0
+ cout << "} but " << spec_name << " cannot."
0
+ << endl;
0
+ }
0
+
0
+ return 0;
0
+}
0
+
0
 int do_assert(int argc, const char **argv)
0
 {
0
     if (argc < 1)
0
@@ -240,77 +415,28 @@ int do_assert(int argc, const char **argv)
0
             const char *impl_name = *argv++;
0
             argc -= 2;
0
 
0
- // Look up the process names in the CSP script.
0
+ int result = do_traces_refinement(csp, spec_name, impl_name);
0
+ if (result != 0)
0
+ return result;
0
 
0
- state_t spec, impl;
0
+ } else if (strcmp(flag, "--failures-refinement") == 0) {
0
 
0
- spec = csp.get_process(spec_name);
0
- if (spec == HST_ERROR_STATE)
0
- {
0
- cerr << "Specification process "
0
- << spec_name << " does not exist."
0
- << endl;
0
- return 3;
0
- }
0
+ // We need two process names
0
 
0
- impl = csp.get_process(impl_name);
0
- if (impl == HST_ERROR_STATE)
0
+ if (argc < 2)
0
             {
0
- cerr << "Implementation process "
0
- << impl_name << " does not exist."
0
+ cerr << "Need two processes for a failures refinement!"
0
                      << endl;
0
- return 3;
0
+ return 2;
0
             }
0
 
0
- // Normalize the spec process.
0
-
0
- csp.normalized_lts()->clear(TRACES);
0
- csp.normalized_lts()->prenormalize(spec);
0
- csp.normalized_lts()->normalize();
0
- spec = csp.normalized_lts()->initial_normal_state(spec);
0
-
0
- // Check the refinement.
0
-
0
- trace_counterexample_t counter;
0
- bool result = trace_refines(counter,
0
- *csp.normalized_lts(), spec,
0
- *csp.lts(), impl);
0
-
0
- cout << spec_name << " [T= " << impl_name
0
- << ": " << (result? "true": "false")
0
- << endl;
0
-
0
- if (!result)
0
- {
0
- cout << "After trace <";
0
-
0
- trace_t::const_iterator tit;
0
- bool first = true;
0
-
0
- for (tit = counter.trace.begin();
0
- tit != counter.trace.end();
0
- ++tit)
0
- {
0
- event_t event = *tit;
0
-
0
- if (event != csp.tau())
0
- {
0
- if (first)
0
- first = false;
0
- else
0
- cout << ",";
0
-
0
- cout << csp.lts()->get_event_name(*tit);
0
- }
0
- }
0
-
0
- cout << ">," << endl
0
- << impl_name << " can execute "
0
- << csp.lts()->get_event_name(counter.event)
0
- << " but " << spec_name << " cannot."
0
- << endl;
0
- }
0
+ const char *spec_name = *argv++;
0
+ const char *impl_name = *argv++;
0
+ argc -= 2;
0
 
0
+ int result = do_failures_refinement(csp, spec_name, impl_name);
0
+ if (result != 0)
0
+ return result;
0
         } else {
0
             cerr << "Unknown assertion flag " << flag << endl;
0
             return 2;

Comments

    No one has commented yet.