Commit 54ca28be authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Call gnuplot-rif at the beginning of the test run.

nb : the gnuplot window needs to be refresed manually ('a' keystroke).
I should find a way to refresh it automatically.
parent a3d4bb30
......@@ -4,7 +4,7 @@ LTOP=../../../bin/lurettetop
LURETTETOP=$(LTOP) \
--test-length 100 --thick-draw 1 \
--draw-inside 0 --draw-edges 0 --draw-vertices 0 --draw-all-vertices \
--step-mode Inside --local-var --no-sim2chro --seed 3 \
--step-mode Inside --local-var --no-gnuplot --no-sim2chro --seed 3 \
--do-not-show-step
EXPDIR=`$(LTOP) --ocaml-version`
......
......@@ -9,7 +9,7 @@ LURETTETOP=$(LTOP) --precision 2 \
-rp "env:lutin:env.lut:main" \
--thick-draw 1 \
--draw-inside 0 --draw-edges 0 --draw-vertices 0 --draw-all-vertices \
--step-mode Inside --local-var --no-sim2chro --seed 3 \
--step-mode Inside --local-var --no-gnuplot --no-sim2chro --seed 3 \
--do-not-show-step
EXPDIR=`$(LTOP) --ocaml-version`
......
......@@ -55,7 +55,7 @@ Command-line options are handled afterwards.
(********************************************************************************)
(* To make gnuplot-rif dynamic, I should stop as soon as no data is availi*)
(* To make gnuplot-rif dynamic, I should stop as soon as no data is available *)
let (readfile: string -> string) =
fun name ->
let chanin = open_in_bin name in
......@@ -90,14 +90,14 @@ let (readfile: string -> string) =
let lexer = make_lexer ["#"; "columns"; ":"; "|"; ")";"("]
type tok = token Stream.t
let debug_parsing = false
let verbose = ref false
let debug_msg msg =
if debug_parsing then (output_string stdout msg; flush stdout)
if !verbose then (output_string stdout ("gnuplot-rif: "^msg); flush stdout)
let (print_debug : string -> tok -> unit) =
fun msg tok ->
if debug_parsing then (
if !verbose then (
output_string stdout ((string_of_int (Stream.count tok)) ^ ": " ^ msg);
flush stdout)
else
......@@ -170,8 +170,8 @@ let min_step = ref "0"
let max_step = ref ""
let min_val = ref "xxx"
let max_val = ref "xxx"
let min_val = ref 0
let max_val = ref 0
let vars_to_hide = ref []
let vars_to_show = ref []
......@@ -203,8 +203,7 @@ let (read_ressource_file : string -> unit) =
| _ -> ()
)
strll;
print_string "read .gnuplot-rif: ok.\n";
flush stdout;
debug_msg "read .gnuplot-rif: ok.\n";
vars_to_hide:= !vars_to_hide @ (List.flatten (List.map List.tl hide_strll));
vars_to_show:= !vars_to_show @ (List.flatten (List.map List.tl show_strll))
with _ ->
......@@ -227,11 +226,11 @@ let is_num str =
str = "True" || str = "False" || str = "t" || str = "f"
(* set debut and cdelta references according to data values *)
let (calibrate_plot : (string -> bool) -> (int -> bool) -> string -> vtypes_tbl -> unit) =
fun to_hide to_hide_pos rif_file tbl ->
let lines = Str.split (Str.regexp "\n") rif_file in
let _ = step_nb := List.length lines in
(* update debut and cdelta references according to data values *)
let (calibrate_plot : (string -> bool) -> (int -> bool) -> string -> int -> unit) =
fun to_hide to_hide_pos rif_data nbb_vars ->
let lines = Str.split (Str.regexp "\n") rif_data in
let _ = step_nb := !step_nb + List.length lines in
let lines = List.map (fun line -> Str.split (Str.regexp "[ \t]+") line) lines in
let lines = List.filter (fun line -> line <> []) lines in
let lines = List.filter (fun line -> is_num (List.hd line)) lines in
......@@ -256,23 +255,17 @@ let (calibrate_plot : (string -> bool) -> (int -> bool) -> string -> vtypes_tb
in
let all_values = List.flatten lines in
let vmin,vmax = get_range all_values in
let nbb_vars =
List.fold_left
(fun cpt (vn, (t,_)) -> if (t="bool" && not (to_hide vn)) then cpt+1 else cpt)
0
tbl
let _ =
max_val := max !max_val vmax ;
min_val := min !min_val vmin ;
in
let delta' = (vmax - vmin) / (max 1 nbb_vars) in
let delta' = (!max_val - !min_val) / (max 1 nbb_vars) in
let cdelta = max 1 delta' in
let cdebut = vmin + (-vmin mod (1+cdelta)) in
max_val := string_of_int vmax ;
min_val := string_of_int vmin ;
if debug_parsing then (
let cdebut = !min_val + (- !min_val mod (1+cdelta)) in
if !verbose then (
print_string ("delta = " ^ (string_of_int cdelta) ^ "\n ");
print_string ("vmin = " ^ (string_of_int vmin) ^ "\n ");
print_string ("vmax = " ^ (string_of_int vmax) ^
"\n ");
print_string ("vmax = " ^ (string_of_int vmax) ^ "\n ");
print_string ("debut = " ^ (string_of_int cdebut) ^ "\n ");
flush stdout
);
......@@ -338,7 +331,6 @@ and (get_names_in_gp3 : string list -> tok -> string -> string list) =
print_debug msg s;
get_names_in_gp s ""
(********************************************************************************)
type terminal_kind = Jpg | Ps | Cps | Eps | Latex | X11| Wxt | NoDisplay
......@@ -352,7 +344,7 @@ let terminal_kind_to_string tk file =
| Latex -> "set term solid latex\nset output \"" ^ base_fn ^ ".tex\"\n"
| X11 -> "set terminal x11 persist"
| Wxt -> "set terminal wxt persist font \"Arial,12\" "
| NoDisplay -> ""
| NoDisplay -> "set terminal wxt persist font \"Arial,12\" "
let gen_plot_file rif_file vars to_hide ttbl file tk =
let file_name = (Filename.chop_extension file) ^ ".plot" in
......@@ -387,8 +379,7 @@ let gen_plot_file rif_file vars to_hide ttbl file tk =
string_of_int (max 1 ((!step_nb / (log_step_nb * 100))*10))
in
let cpt = ref (!debut + (!delta/2)) in
output_string stderr ("Generating "^ file_name ^ " file...\n");
flush stderr;
debug_msg ("Generating "^ file_name ^ " file...\n");
put ("
# defaults
set title \""^(Filename.chop_extension file)^".rif\"
......@@ -405,7 +396,7 @@ set key right top title \"Numeric variables\" box 3
");
List.iter
(fun (id, (t,pos)) ->
if (to_hide id) then output_string stderr ("Hidding " ^ id ^ "\n");
if (to_hide id) then debug_msg ("Hidding " ^ id ^ "\n");
if t = "bool" then (
if (to_hide id) then
()
......@@ -468,25 +459,17 @@ let (scale_bool : (int -> bool) -> string list -> string list) =
let (transform_bools : (int -> bool) -> vtypes_tbl -> string -> string) =
fun to_hide tbl str ->
let lines = Str.split (Str.regexp "\n") str in
let lines = List.map (fun line -> Str.split (Str.regexp "[ \t]+") line) lines in
let lines = List.filter (fun line -> line <> []) lines in
let lines = List.map (scale_bool to_hide) lines in
let lines = List.map (String.concat " ") lines in
String.concat "\n" lines
(*
Takes a ".rif" file name and generates a ".gp" file that contains
the same info in a format suitable for gnuplot
*)
let (rif_to_gp : (int -> bool) -> vtypes_tbl -> string -> string) =
fun to_hide_pos tbl rif_file ->
let gp_file = ((Filename.chop_extension rif_file) ^ ".gp") in
let oc = open_out gp_file in
let put str = output_string oc str in
let rif_file_content = readfile rif_file in
let lines = Str.split (Str.regexp "\n") str in
let lines = List.map (fun line -> Str.split (Str.regexp "[ \t]+") line) lines in
let lines = List.filter (fun line -> line <> []) lines in
let lines = List.map (scale_bool to_hide) lines in
let lines = List.map (String.concat " ") lines in
String.concat "\n" lines
let (clean_rif_string: string -> string) =
fun str ->
let subst =
[
(Str.regexp_string ":bool"), " | " ;
......@@ -531,30 +514,31 @@ let (rif_to_gp : (int -> bool) -> vtypes_tbl -> string -> string) =
(Str.regexp_string "@"), "#"
]
in
let gp_file_content =
try
List.fold_left
(fun str (regexp, temp) -> Str.global_replace regexp temp str)
rif_file_content
subst
(* replaces "," by "." ins floats *)
(* Str.string_match (Str.regexp "\([0-9]*\)\(,\)\([0-9]*\)") s 0; *)
(* Str.replace_matched "\1.\3" s *)
with e ->
print_string ("*** gnuplot-rif error: " ^ (Printexc.to_string e) ^ "\n");
flush stdout;
exit 2
in
try
List.fold_left
(fun str (regexp, temp) -> Str.global_replace regexp temp str)
str
subst
with e ->
print_string ("*** gnuplot-rif error: " ^ (Printexc.to_string e) ^ "\n");
flush stdout;
exit 2
(* Takes a ".rif" file name and generates a ".gp" file that contains
the same info in a format suitable for gnuplot *)
let (gen_gp_file : (int -> bool) -> vtypes_tbl -> string -> string -> unit) =
fun to_hide_pos tbl gp_file rif_file ->
let oc = open_out gp_file in
let put str = output_string oc str in
let rif_file_content = readfile rif_file in
let gp_file_content = clean_rif_string rif_file_content in
let gp_file_content = transform_bools to_hide_pos tbl gp_file_content in
output_string stdout ("Generating "^ gp_file ^ " file...\n");
flush stdout;
debug_msg ("Generating "^ gp_file ^ " file...\n");
put gp_file_content;
flush oc;
close_out oc;
gp_file
close_out oc
(********************************************************************************)
......@@ -564,55 +548,53 @@ let (my_create_process : string -> string list -> bool) =
fun prog args ->
try
let pid =
List.iter (fun x -> output_string stderr (x ^ " ")) (prog::args);
output_string stderr "\n";
flush stderr;
Unix.create_process
prog
(Array.of_list (prog::args))
(Unix.stdin)
(Unix.stdout)
(Unix.stderr)
List.iter (fun x -> debug_msg (x ^ " ")) (prog::args);
debug_msg "\n";
Unix.create_process
prog
(Array.of_list (prog::args))
(Unix.stdin)
(Unix.stdout)
(Unix.stderr)
in
let (_,status) = (Unix.waitpid [Unix.WUNTRACED] pid) in
( match status with
Unix.WEXITED i ->
if i = 0 || i = 1 then
(
output_string stderr (" ... " ^ prog ^ " exited normally.\n");
flush stderr;
true
)
else
(
output_string stderr ("*** Error: " ^ prog ^ " exited abnormally.\n");
flush stderr;
false
)
| _ ->
output_string stderr ("*** Error: " ^ prog ^ " exited ABnormally!\n");
flush stderr;
true
)
( match status with
Unix.WEXITED i ->
if i = 0 || i = 1 then
(
debug_msg (" ... " ^ prog ^ " exited normally.\n");
true
)
else
(
output_string stderr ("*** Error: " ^ prog ^ " exited abnormally.\n");
flush stderr;
false
)
| _ ->
output_string stderr ("*** Error: " ^ prog ^ " exited ABnormally!\n");
flush stderr;
true
)
with
| Unix.Unix_error(error, name, arg) ->
let msg = ( "*** << " ^
(Unix.error_message error) ^
" >> in the system call: << " ^ name ^ " " ^ arg ^ " >>\n")
in
output_string stdout msg;
flush stdout;
output_string stderr msg;
flush stderr;
false
let msg = ( "*** << " ^
(Unix.error_message error) ^
" >> in the system call: << " ^ name ^ " " ^ arg ^ " >>\n")
in
output_string stdout msg;
flush stdout;
output_string stderr msg;
flush stderr;
false
| e ->
output_string stdout (Printexc.to_string e);
flush stdout;
output_string stderr (Printexc.to_string e);
flush stderr;
false
output_string stdout (Printexc.to_string e);
flush stdout;
output_string stderr (Printexc.to_string e);
flush stderr;
false
(********************************************************************************)
......@@ -621,18 +603,6 @@ let gnuplot =
with _ ->
"gnuplot"
let (gv: string -> unit) =
fun ps_file ->
let ps_viewer =
try Unix.getenv "PS_VIEWER"
with _ ->
print_string "*** Can not find PS_VIEWER env variable.\n";
flush stdout;
""
in
ignore (my_create_process ps_viewer [ps_file])
(********************************************************************************)
let terminal = ref Wxt
......@@ -646,6 +616,9 @@ let rec speclist =
"-no-display",Arg.Unit (fun _ -> (terminal := NoDisplay)),
"\t do not launch gnuplot once the gnuplot file are generated";
"-verbose",Arg.Unit (fun _ -> (verbose := true)),
"\t set on a verbose mode";
"-wxt",Arg.Unit (fun _ -> (terminal := Wxt)),
"\t launch gnuplot with the wxt terminal (default)";
......@@ -690,25 +663,20 @@ let rec speclist =
let main () =
if
(Array.length Sys.argv) <= 1
then
(Arg.usage speclist usage; flush stdout; exit 2)
else
(
try
Arg.parse speclist (fun s -> rif_file := s) usage
with
Failure(e) ->
print_string e; flush stdout; flush stderr; exit 2
| e ->
print_string (Printexc.to_string e);
flush stdout; flush stderr; exit 2
);
if (Array.length Sys.argv) <= 1
then (Arg.usage speclist usage; flush stdout; exit 2)
else (
try Arg.parse speclist (fun s -> rif_file := s) usage
with
| Failure(e) ->
print_string e; flush stdout; flush stderr; exit 2
| e ->
print_string (Printexc.to_string e);
flush stdout; flush stderr; exit 2
);
let rif_file_content = readfile !rif_file in
let ttbl = get_var_types rif_file_content in
let to_hide v =
if !vars_to_show = [] then
List.exists
......@@ -730,22 +698,26 @@ let main () =
try List.assoc i to_hide_pos_tbl
with Not_found -> false
in
let _ = calibrate_plot to_hide to_hide_pos rif_file_content ttbl in
let gp_file = rif_to_gp to_hide_pos ttbl !rif_file in
let nbb_vars =
List.fold_left
(fun cpt (vn, (t,_)) -> if (t="bool" && not (to_hide vn)) then cpt+1 else cpt)
0
ttbl
in
let _ = calibrate_plot to_hide to_hide_pos rif_file_content nbb_vars in
let recalibrate str = calibrate_plot to_hide to_hide_pos str nbb_vars in
let gp_file = ((Filename.chop_extension !rif_file) ^ ".gp") in
let _ = gen_gp_file to_hide_pos ttbl gp_file !rif_file in
let gp_s =
if not (Sys.file_exists gp_file) then
(
print_string (gp_file ^ " does not exist.\n");
print_string usage;
flush stdout;
exit 2
);
(print_string (gp_file ^ " does not exist.\n" ^ usage); flush stdout; exit 2);
lexer (Stream.of_string (readfile gp_file))
in
let vars = List.rev (get_names_in_gp gp_s "start") in
let _ = plot_file := gen_plot_file rif_file_content vars to_hide ttbl gp_file !terminal in
if debug_parsing then
if !verbose then
(
output_string stderr "\nvar names are :\n";
List.iter (fun x -> output_string stderr (x ^ "\n")) vars;
......@@ -754,8 +726,7 @@ let main () =
if !terminal <> NoDisplay then
let pid =
output_string stderr ("Launching "^ gnuplot ^ " " ^ !plot_file ^ "...\n");
flush stderr;
debug_msg ("Launching "^ gnuplot ^ " " ^ !plot_file ^ "...\n");
Unix.create_process
gnuplot
......
......@@ -140,6 +140,7 @@ type t = {
mutable step_by_step : int option ;
mutable display_local_var : bool ;
mutable display_sim2chro : bool;
mutable display_gnuplot : bool;
mutable seed : int option ;
mutable precision : int ;
mutable verbose : verbose_level ;
......@@ -217,6 +218,7 @@ let (args : t) = {
show_step = false ;
display_local_var = false ;
display_sim2chro = true ;
display_gnuplot = true ;
seed = None ;
precision = 2;
verbose = 0 ;
......@@ -283,7 +285,8 @@ let (to_string : t -> (string * string * string) list) =
bool_opt args.all_vertices "set_draw_all_vertices" "--draw-all-vertices";
bool_opt args.display_local_var "set_display_local_var true" "--local-var";
bool_opt args.display_sim2chro "set_display_sim2chro" "--sim2chro";
bool_opt (not args.display_sim2chro) "set_display_sim2chro" "--no-sim2chro";
bool_opt (not args.display_gnuplot) "set_display_gnuplot" "--no-gnuplot";
bool_opt args.log "log" "--log";
bool_opt args.compute_volume "set_fair_mode" "--compute-poly-volume";
......@@ -717,11 +720,18 @@ let rec speclist =
"--log", Arg.Unit (fun _ -> args.log <- true),
"\t\tRedirect stdout to a log file (lurette_stdout.log)\n";
"--gnuplot", Arg.Unit (fun () -> args.display_gnuplot <- true),
"\t\tCall gnuplot.";
"--no-gnuplot", Arg.Unit (fun () -> args.display_gnuplot <- false),
"\tDo not call gnuplot.";
"-ngp", Arg.Unit (fun () -> args.display_gnuplot <- false), "\n";
"--sim2chro", Arg.Unit (fun () -> args.display_sim2chro <- true),
"\t\tCall sim2chro when lurette resumes.";
"\t\tCall sim2chro.";
"--no-sim2chro", Arg.Unit (fun () -> args.display_sim2chro <- false),
"\tDo not call sim2chro when lurette resumes.";
"\tDo not call sim2chro.";
"-ns2c", Arg.Unit (fun () -> args.display_sim2chro <- false), "\n";
"--local-var", Arg.Unit (fun () -> args.display_local_var <- true),
......
......@@ -105,9 +105,10 @@ type cov_opt =
exception OracleError of string
exception SutStop of cov_opt
let gnuplot_time = ref 0.0
let (f : unit -> int) =
fun () ->
gnuplot_time := 0.0;
(* Get sut info (var names, step func, etc.) *)
let _ = if args.debug_ltop then LustreRun.debug := args.debug_ltop in
let sut_in_l, sut_out_l, sut_kill_l, sut_step_sl_l, sut_init_in_l, sut_init_out_l =
......@@ -184,6 +185,8 @@ let (f : unit -> int) =
in
let oc = open_out args.output in
let sim2chro_oc = if args.display_sim2chro then Util2.sim2chro_dyn () else open_out "/dev/null" in
let gnuplot_oc = ref (open_out "/dev/null") in
let filter vals vars =
List.map (fun (n,t) -> n,
try List.assoc n vals
......@@ -216,6 +219,15 @@ let (f : unit -> int) =
"The oracle first output should be a bool; but %s has type %s" vn vv in
failwith msg
in
(* update gnuplot-rif files less and less often... *)
if
args.display_gnuplot
&& Unix.time () -. !gnuplot_time > (log (float_of_int i) /. log 10.)
then (
gnuplot_time := Unix.time ();
Util2.gnuplotrif_update (args.verbose>1) args.output
);
match cov with
NO -> NO
| OO -> ignore (List.map check_one_oracle oracle_out_vals_l); OO
......@@ -229,7 +241,6 @@ let (f : unit -> int) =
cov_ref := Some cov;
OC cov
in
(* The main loop *)
let rec loop cov env_in_vals pre_env_out_vals i =
if i > args.step_nb then cov, 0 else
......@@ -276,6 +287,9 @@ let (f : unit -> int) =
output_string sim2chro_oc (String.concat " " (List.map print_val sut_out_vals));
output_string sim2chro_oc "\n";
flush sim2chro_oc;
if args.display_gnuplot && !gnuplot_time = 0.0
then gnuplot_oc := Util2.gnuplotrif_dyn (args.verbose>1) args.output;
loop (check_oracles oracle_in_vals i oracle_out_l oracle_out_vals_l cov)
sut_out_vals env_out_vals (i+1)
......@@ -340,6 +354,7 @@ let (f : unit -> int) =
oracle_kill msg;
close_out oc;
close_out sim2chro_oc;
if args.display_gnuplot then Util2.gnuplotrif_update (args.verbose>1) args.output;
res
let (terminate : unit -> unit) =
......
......@@ -203,7 +203,7 @@ $(LUCKY_RELEASE_NAME).tgz:strip
mkdir /tmp/$(LUCKY_RELEASE_NAME)/include
mkdir /tmp/$(LUCKY_RELEASE_NAME)/doc
cp -rf $(LURETTE_PATH)/$(HOSTTYPE)/lib/* /tmp/$(LUCKY_RELEASE_NAME)/lib
cp -rf $(LURETTE_PATH)/$(HOSTTYPE)/include /tmp/$(LUCKY_RELEASE_NAME)/include
cp -rf $(LURETTE_PATH)/$(HOSTTYPE)/include /tmp/$(LUCKY_RELEASE_NAME)/
cp $(LURETTE_PATH)/$(HOSTTYPE)/bin/lucky$(EXE) /tmp/$(LUCKY_RELEASE_NAME)/bin/
cp $(LURETTE_PATH)/utils/lucky_cpp /tmp/$(LUCKY_RELEASE_NAME)/utils
cp $(LURETTE_PATH)/$(HOSTTYPE)/bin/luc2luciole$(EXE) /tmp/$(LUCKY_RELEASE_NAME)/bin/
......@@ -306,7 +306,7 @@ $(LUC4OCAML_RELEASE_NAME).tgz:
$(RANLIB) ../$(HOSTTYPE)/lib/*.a
cp ../README-luc4ocaml /tmp/$(LUC4OCAML_RELEASE_NAME)/
ifeq ($(HOSTTYPE),cygwin)
cp ../$(HOSTTYPE)/include/fenv.h /tmp/$(LUC4OCAML_RELEASE_NAME)/include
cp ../$(HOSTTYPE)/include/fenv.h /tmp/$(LUC4OCAML_RELEASE_NAME)/include/
endif
cp ../$(HOSTTYPE)/lib/liblucky_nc.a /tmp/$(LUC4OCAML_RELEASE_NAME)/lib
cp ../$(HOSTTYPE)/lib/libluc4c_nc.a /tmp/$(LUC4OCAML_RELEASE_NAME)/lib
......@@ -368,7 +368,7 @@ $(LUC4C_RELEASE_NAME).tgz:
cp ../$(HOSTTYPE)/lib/libgmp.a /tmp/$(LUC4C_RELEASE_NAME)/lib || true
cp ../$(HOSTTYPE)/lib/*luc4c*.* /tmp/$(LUC4C_RELEASE_NAME)/lib
\
cp ../$(HOSTTYPE)/include/luc4c_stubs.h /tmp/$(LUC4C_RELEASE_NAME)/include
cp ../$(HOSTTYPE)/include/luc4c_stubs.h /tmp/$(LUC4C_RELEASE_NAME)/include/
\
cp -rf $(HOME)/SYNCHRON/lurette/doc/lucky-man.pdf \
/tmp/$(LUC4C_RELEASE_NAME)/doc || true
......
......@@ -294,6 +294,30 @@ let (lv62ec: string -> string -> string -> bool) =
flush stdout;
false
let (gnuplotrif_update : bool -> string -> unit) =
fun verb riffile ->
let gnuplotrif = mygetenv "GNUPLOTRIF" in
let cmd = (gnuplotrif ^ " -no-display " ^ riffile) in
let cmd = if verb then cmd ^ " -verbose" else cmd in
let res = Sys.command cmd in
if res > 0 then (
output_string stderr ("'"^ cmd ^ "' has been launched but failed.\n");
flush stderr
)
let (gnuplotrif_dyn : bool -> string -> out_channel) =
fun verb riffile ->
let _ = gnuplotrif_update verb riffile in
let gnuplot = mygetenv "GNUPLOT" in
let plotfile = (Filename.chop_extension riffile) ^ ".plot" in
let cmd = gnuplot ^ " \"" ^ plotfile ^ "\"" in
let oc = Unix.open_process_out cmd in
let str = readfile plotfile in
output_string oc str;
flush oc;