Skip to content

Commit 3618709

Browse files
authored
[CN-Test-Gen] Note if error comes from cn-exec (#734)
1 parent 3a7897a commit 3618709

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

backend/cn/bin/main.ml

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,19 @@ let verify
342342
Typing.run_from_pause check paused)
343343

344344

345+
let handle_error_with_user_guidance ~(label : string) (e : exn) : unit =
346+
let msg = Printexc.to_string e in
347+
let stack = Printexc.get_backtrace () in
348+
Printf.eprintf "cn: internal error, uncaught exception:\n %s\n" msg;
349+
let lines = String.split_on_char '\n' stack in
350+
List.iter (fun line -> Printf.eprintf " %s\n" line) lines;
351+
Printf.eprintf
352+
"Issues can be made at https://github.com/rems-project/cerberus/issues.\n";
353+
Printf.eprintf "Prefix your issue with \"[%s]\". " label;
354+
Printf.eprintf "Check that there isn't already one for this error.\n";
355+
exit 1
356+
357+
345358
let generate_executable_specs
346359
filename
347360
macros
@@ -404,16 +417,19 @@ let generate_executable_specs
404417
~f:(fun ~prog5 ~ail_prog ~statement_locs ~paused:_ ->
405418
Cerb_colour.without_colour
406419
(fun () ->
407-
Executable_spec.main
408-
~without_ownership_checking
409-
~with_test_gen
410-
~copy_source_dir
411-
filename
412-
ail_prog
413-
output_decorated
414-
output_decorated_dir
415-
prog5
416-
statement_locs;
420+
(try
421+
Executable_spec.main
422+
~without_ownership_checking
423+
~with_test_gen
424+
~copy_source_dir
425+
filename
426+
ail_prog
427+
output_decorated
428+
output_decorated_dir
429+
prog5
430+
statement_locs
431+
with
432+
| e -> handle_error_with_user_guidance ~label:"CN-Exec" e);
417433
Resultat.return ())
418434
())
419435

@@ -489,25 +505,28 @@ let run_tests
489505
Option.is_some inst.internal)
490506
|> List.is_empty
491507
then (
492-
print_endline "No testable functions, aborting";
493-
exit 1);
508+
print_endline "No testable functions, trivially passing";
509+
exit 0);
494510
if not (Sys.file_exists output_dir) then (
495511
print_endline ("Directory \"" ^ output_dir ^ "\" does not exist.");
496512
Sys.mkdir output_dir 0o777;
497513
print_endline
498514
("Created directory \"" ^ output_dir ^ "\" with full permissions."));
499515
let _, sigma = ail_prog in
500516
Cn_internal_to_ail.augment_record_map (BaseTypes.Record []);
501-
Executable_spec.main
502-
~without_ownership_checking
503-
~with_test_gen:true
504-
~copy_source_dir:false
505-
filename
506-
ail_prog
507-
None
508-
(Some output_dir)
509-
prog5
510-
statement_locs;
517+
(try
518+
Executable_spec.main
519+
~without_ownership_checking
520+
~with_test_gen:true
521+
~copy_source_dir:false
522+
filename
523+
ail_prog
524+
None
525+
(Some output_dir)
526+
prog5
527+
statement_locs
528+
with
529+
| e -> handle_error_with_user_guidance ~label:"CN-Exec" e);
511530
let config : TestGeneration.config =
512531
{ num_samples;
513532
max_backtracks;
@@ -529,13 +548,16 @@ let run_tests
529548
disable_passes
530549
}
531550
in
532-
TestGeneration.run
533-
~output_dir
534-
~filename
535-
~without_ownership_checking
536-
config
537-
sigma
538-
prog5;
551+
(try
552+
TestGeneration.run
553+
~output_dir
554+
~filename
555+
~without_ownership_checking
556+
config
557+
sigma
558+
prog5
559+
with
560+
| e -> handle_error_with_user_guidance ~label:"CN-Test-Gen" e);
539561
if not dont_run then
540562
Unix.execv (Filename.concat output_dir "run_tests.sh") (Array.of_list []))
541563
();

0 commit comments

Comments
 (0)