lurette.ml 3.55 KB
Newer Older
1
(* Time-stamp: <modified the 29/03/2019 (at 14:53) by Erwan Jahier> *)
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
(* Mimick the behavior of 'rdbg -lurette', but without the dependency
   on ocaml *)
open Event

open RdbgWrapperArgs

let url_doc="http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/lustre-v6/"

let _ =
  lurette := true;
  usage := (Sys.argv.(0) ^
               " is equivalent to 'rdbg -lurette', except that the lustre-v6
and the lutin plugins are statically linked to it, to avoid the need of an 
ocaml compiler. One can not use other language plugins as 'rdbg -lurette'
would allow.
cf also "^url_doc^"

usage: "^ Sys.argv.(0) ^" [<options>] 
     where <options> are:")

             
let get_extension f =
  try
    let bf = Filename.chop_extension f in
    let lf,lbf = String.length f, String.length bf in
    String.sub f (lbf+1) (lf - lbf - 1)
  with _ -> ""

let args= ref []
let ml_files = ref []

let add_args arg = 
  if get_extension arg = "ml" 
  then 
    ml_files := arg::!ml_files 
  else
    args := (arg::!args)

let others = ref []
let (add_other : string -> unit) =
  fun s -> 
    others := s:: !others

let other_args:string =
  mkoptab ();
  Arg.parse_argv Sys.argv !arg_options add_args !usage;
  String.concat " " (List.rev !others)

(**********************************************************************************)
let (gen_reactive_program : string -> RdbgArg.reactive_program) =
  fun str -> 
  let args = Str.split (Str.regexp "[ \t]+") str in
  let tool = Filename.basename (List.hd args) in
  let plugin =
    match tool with
    | "lutin"   -> LutinRun.make (Array.of_list args)
    | "lv6" | "lus2lic" -> Lv6Run.make  (Array.of_list (args@["--expand-io-type"]))
59
    | "ocaml" -> OcamlRun.make (List.nth args 1)
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    | _ -> StdioRun.make str
  in
  Ocaml(plugin)

open RdbgArg    
let _ =        
  let sut_plugins = List.map gen_reactive_program (!suts @ !suts_nd) in
  let env_plugins = List.map gen_reactive_program (!envs @ !envs_nd) in
  let oracle_plugins = List.map gen_reactive_program (!oracles @ !oracles_nd) in

  args.suts <- sut_plugins;
  args.envs <- env_plugins;
  args.oracles <- oracle_plugins;

  args.step_nb <- !test_length;
  args.display_sim2chro <- !display_sim2chro ;
  args.display_gnuplot <- !display_gnuplot ;
  args.verbose <- if !verbose then 1 else 0 ;
  args.output <- !output_file ;
79
80
81
82
83
84
85

  args.overwrite_output = !overwrite_output;
  args.stop_on_oracle_error = not !dont_stop_on_oracle_error;
  args.log = !log;
  args.cov_file = !cov_file;
  args.reset_cov_file = !reset_cov_file;

86
87
88
89
  args.debug_rdbg <- !drdbg;
  args.rdbg <- false;

  args.cov_file <- "lurette.cov";
90
  args.stop_on_oracle_error <- not !dont_stop_on_oracle_error;
91
92
93
94
95
96
97
  ()

(**********************************************************************************)

   

let _ =
98
99
100
101
102
103
  if args.suts = [] then (
    Printf.printf "\027[35mW: Please set at least one sut \027[00m\n\n" ;
    flush stdout;
    help()
  )
  else
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
  try RdbgRun.lurette_start()
  with
  | RdbgRun.OracleError str ->
     Printf.printf "\027[35m %s \027[00m\n"  str;
     flush stdout
                     
  | Dynlink.Error msg -> (* deadcode *)
     Printf.eprintf "\n*** error in lurette (Dynlink.loadfile %s).\n*** %s.\n" 
       (List.fold_left (fun acc x -> acc^" "^x) "" args._others)
       (Dynlink.error_message msg);
     RdbgRun.clean_terminate(); 
     flush stderr;
     exit 2
  | Event.End(i) ->
     RdbgRun.clean_terminate();
     exit i
  | pb ->
     RdbgRun.clean_terminate();
     output_string args.ocr (Printexc.to_string pb);
     Printf.printf "bye\n"; flush stdout; exit 2
;;

let _ =
  Printf.printf "lurette: bye\n"; flush stdout; exit 0