Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file rdbgArg.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408(* Time-stamp: <modified the 03/05/2018 (at 10:02) by Erwan Jahier> *)openMypervasivesletcmxs_or_cma=ifDynlink.is_nativethen"cmxs"else"cma"letusage_msg=("usage: "^Sys.argv.(0)^" [<option>] ["^cmxs_or_cma^" file]
use --help to see the available options.
")letprint_usage()=Printf.printf"%s\n"usage_msg;flushstdouttypeverbose_level=inttypeprogram_kind=SUT|Env|Oracletypereactive_program=|Stdioofstring|StdioInitofstring|Sockofstring*int|SockInitofstring*int|OcamlofRdbgPlugin.tletprogram_kind_of_string=function|"sut"->SUT|"oracle"->Oracle|"env"->Env|s->assertfalseletprogram_kind_to_string=function|SUT->"sut"|Oracle->"oracle"|Env->"env"letreactive_program_to_string=function|Stdio(cmd)->cmd|StdioInit(cmd)->"init:"^cmd|Sock(addr,port)->Printf.sprintf"%s:%i"addrport|SockInit(addr,port)->Printf.sprintf"init:%s:%i"addrport|Ocaml(plugin)->plugin.RdbgPlugin.idtypet={mutable_args:(string*Arg.spec*string)list;(* classical Arg option tab used by Arg.parse *)mutable_user_man:(string*stringlist)list;mutable_hidden_man:(string*stringlist)list;mutablesuts:reactive_programlist;mutableenvs:reactive_programlist;mutableoracles:reactive_programlist;mutablestep_nb:int;(* nb : thick tests is not possible if one rp works via stdio *)mutabledraw_nb:int;mutabledraw_inside:int;mutabledraw_edges:int;mutabledraw_vertices:int;mutableall_formula:bool;mutableall_vertices:bool;mutableluciole_mode:bool;mutabledelay_env_outputs:bool;(* clutch for comon *)mutabledisplay_sim2chro:bool;mutabledisplay_gnuplot:bool;mutableprecision:int;mutableverbose:verbose_level;(* RIF output control *)mutabledisplay_local_var:bool;mutableshow_step:bool;mutableoutput:string;mutableoverwrite_output:bool;mutableprompt:stringoption;mutablego:bool;(* obselete ? *)mutablelog:bool;mutabletmp_dir:string;mutabletmp_dir_provided:stringoption;(* to call rdbg via a socket *)mutablesocket_inet_addr:stringoption;(* if None, we use stdin/stdout *)mutablesocket_port:intoption;mutablesocket_err_port:intoption;mutabledebug_rdbg:bool;mutablerdbg:bool;(* if false, well, basically, it's lurette! *)mutablecov_file:string;mutablereset_cov_file:bool;mutablestop_on_oracle_error:bool;(*
I am using references for that in order to be able to replace them
by sockets if necessary (i.e., once the sockets are connected) *)mutableicr:Pervasives.in_channel;mutableocr:Pervasives.out_channel;mutableecr:Pervasives.out_channel;(* unknown args*)mutable_others:stringlist;mutable_margin:int;}let(make_args:unit->t)=fun()->{_args=[];_user_man=[];_hidden_man=[];suts=[];oracles=[];envs=[];step_nb=100;draw_nb=1;draw_inside=0;draw_edges=0;draw_vertices=0;all_formula=false;all_vertices=false;luciole_mode=true;delay_env_outputs=false;show_step=false;display_local_var=false;display_sim2chro=false;display_gnuplot=false;precision=2;verbose=0;output="rdbg.rif";overwrite_output=false;prompt=None;tmp_dir=".";tmp_dir_provided=None;go=false;log=false;socket_inet_addr=None;socket_port=None;socket_err_port=None;debug_rdbg=false;rdbg=false;cov_file="lurette.cov";reset_cov_file=false;stop_on_oracle_error=false;ocr=stdout;icr=stdin;ecr=stderr;_others=[];_margin=12;}let(args:t)=make_args()letpspecos(c,ml)=(let(m1,oth)=matchmlwith|h::t->(h,t)|_->("",[])inlett2=String.makeargs._margin' 'inletcl=String.lengthcinlett1=if(cl<args._margin)thenString.make(args._margin-cl)' 'else"\n"^t2inPrintf.fprintfos"%s%s%s"ct1m1;List.iter(functionx->Printf.fprintfos"\n%s%s"t2x)oth;Printf.fprintfos"\n";)letoptionsoc=(letl=List.revargs._user_manin(* let str = Arg.usage_string args._args usage_msg in *)(* output_string oc str; flush oc; *)List.iter(pspecoc)l)letmore_optionsoc=(letl=List.rev(args._hidden_man)inList.iter(pspecoc)l)letmyexiti=ifargs.rdbgthenfailwith"error in rdbg"elseexitiletunexpecteds=(prerr_string("unexpected argument \""^s^"\"");prerr_newline();myexit1)letfile_notfoundf=(prerr_string("File not found: \""^f^"\"");prerr_newline();myexit1)let(parse_stdio_string:string->reactive_program)=funstr->(* try *)letl=(Str.split(Str.regexp":")str)inletrp=matchlwith|[cmd]->Stdio(cmd)|["init";cmd]->StdioInit(cmd)|_->failwith("*** Error: in --*-stdio arguments: \""^str^"\"\n")inrpletmy_int_of_stringport=tryint_of_stringportwith_->failwith("*** Error: in --*-socket arguments: \""^port^"\" should be an int\n")let(parse_sock_string:string->reactive_program)=funstr->(* try *)letl=(Str.split(Str.regexp":")str)inletrp=matchlwith|[addr;port]->Sock(addr,my_int_of_stringport)|["init";addr;port]->SockInit(addr,my_int_of_stringport)|_->failwith("*** Error: in --*-socket arguments: \""^str^"\"\n")inrp(************************************************************************)let(mkopt:t->stringlist->?hide:bool->?arg:string->Arg.spec->stringlist->unit)=funoptol?(hide=false)?(arg="")seml->lettretoo=opt._args<-(o,se,"")::opt._argsinList.itertretool;letcol1=(String.concat", "ol)^arginifhidethenopt._hidden_man<-(col1,ml)::opt._hidden_manelseopt._user_man<-(col1,ml)::opt._user_man(*** User Options Tab **)let(mkoptab:t->unit)=funopt->letnl="\n"^(String.makeargs._margin' ')in(mkoptopt["--sut-stdio"]~arg:" \"{init:}sys call\" "(Arg.String(funs->args.suts<-args.suts@[parse_stdio_strings]))["the sut read/writes its I/O on stdin/stdout in RIF."^nl^" if 'init' is present, the process first"^nl^" read values to initialiase its I/O values sequence."];mkoptopt["--env-stdio"]~arg:" \"{init:}sys call\" "(Arg.String(funs->args.envs<-args.envs@[parse_stdio_strings]))["ditto for env"];mkoptopt["--oracle-stdio"]~arg:" \"{init:}sys call\" "(Arg.String(funs->args.oracles<-args.oracles@[parse_stdio_strings]))["ditto for oracle"];mkoptopt["--sut-socket"]~arg:" \"{init:}sockadr:port\" "(Arg.String(funs->args.suts<-args.suts@[parse_sock_strings]))["the sut read/writes its I/O on a socket in RIF."^nl^" if 'init' is present, the process first"^nl^" read values to initialiase its I/O values sequence."];mkoptopt["--env-socket"]~arg:" \"{init:}sockadr:port\" "(Arg.String(funs->args.envs<-args.envs@[parse_sock_strings]))["ditto for env"];mkoptopt["--oracle-socket"]~arg:" \"{init:}sockadr:port\" "(Arg.String(funs->args.oracles<-args.oracles@[parse_sock_strings]))["ditto for oracle"];mkoptopt["--test-length";"-l"]~arg:" <int>"(Arg.Int(funi->args.step_nb<-i))["Number of steps to be done ("^(string_of_intargs.step_nb)^" by default).\n"];mkoptopt["--output";"-o"]~arg:" <string>"(Arg.String(funs->args.output<-s))["Set the output file name (currently, \""^args.output^"\")."];mkoptopt~hide:true["--precision";"-p"]~arg:" <int>"(Arg.Int(funi->args.precision<-i))["number of digit after the dot used for floating points."];mkoptopt["--lurette";"-lurette"](Arg.Unit(fun()->args.rdbg<-false))["Remove debugging stuff and thus behaves as lurette"];mkoptopt~hide:true["--debug-me"](Arg.Unit(fun()->args.debug_rdbg<-true))["debug rdbg mode (to debug rdbg)\n"];mkoptopt~hide:true["--overwrite-rif-file";"-orf"](Arg.Unit(fun()->args.overwrite_output<-true))["Overwrite \""^args.output^"\" if it exists without trying to invent a new name"];(*
mkopt opt ~hide:true ["--socket-inet-addr"] ~arg:" <string>"
(Arg.String (fun i -> args.socket_inet_addr <- Some i))
["Set the socket address"];
mkopt opt ~hide:true ["--socket-io-port"] ~arg:" <int>"
(Arg.Int (fun i -> args.socket_port <- Some i))
["Set the socket io port"];
mkopt opt ~hide:true ["--socket-err-port"] ~arg:" <int>"
(Arg.Int (fun i -> args.socket_err_port <- Some i))
["Set the socket error port"];
*)mkoptopt~hide:true["--stop-on-oracle-error"](Arg.Unit(fun_->args.stop_on_oracle_error<-true))["Stop if one oracle is violated"];mkoptopt~hide:true["--delay-env-outputs"](Arg.Unit(fun_->args.delay_env_outputs<-true))["Delay the outputs of the environements before transmitting them to the oracles"];mkoptopt~hide:true["--log";"-log"](Arg.Unit(fun_->args.log<-true))["Redirect stdout to a log file (rdbg_stdout.log)"];mkoptopt["--gnuplot";"-gp"](Arg.Unit(fun()->args.display_gnuplot<-true))["Call gnuplot to display data"];mkoptopt["--sim2chro"](Arg.Unit(fun()->args.display_sim2chro<-true))["Call sim2chro to display data"];mkoptopt["--no-luciole"](Arg.Unit(fun()->args.luciole_mode<-false))["Use stdin/stdout instead of luciole when some inputs are missing"];mkoptopt~hide:true["--ocaml-version"](Arg.Unit(fun_->(print_string(Sys.ocaml_version);flushstdout;exit0)))["Display the version ocaml version lurette was compiled with and exit."];mkoptopt["--version";"-version";"-v"](Arg.Unit(fun_->(print_string(RdbgVersion.str^"-"^RdbgVersion.sha);exit0)))["Display the version and exit"];mkoptopt~hide:true["--cov-file"]~arg:" <string>"(Arg.String(funs->args.cov_file<-s))["file name coverage info will be put into"];mkoptopt~hide:true["--reset-cov-file"](Arg.Unit(fun_->args.reset_cov_file<-true))["Reset coverage file data"];mkoptopt["--verbose";"-vl"]~arg:" <int>"(Arg.Int(funi->args.verbose<-i))["Set the verbose level"];mkoptopt["--help";"-help";"-h"](Arg.Unit(fun_->print_usage();optionsstdout;exit0))["Display main options"];mkoptopt["--more";"-m"](Arg.Unit(fun()->more_optionsstdout;exit0))["Display more options"])(* all unrecognized options are accumulated *)let(add_other:t->string->unit)=funopts->args._others<-s::args._othersletcurrent=ref0;;letfirst_lineb=(try(letf=String.indexb'\n'inString.subb0f)withNot_found->b)letparseargv=(letsave_current=!currentintry(mkoptabargs;Arg.parse_argv~current:currentargvargs._args(add_otherargs)usage_msg;(List.iter(funf->if(String.subf01="-")thenunexpectedfelseifnot(Sys.file_existsf)thenfile_notfoundfelse())args._others);current:=save_current;)with(* only 1rst line is interesting ! *)|Arg.Badmsg->Printf.fprintfstderr"*** Error when calling '%s': %s\n%s\n"(Sys.argv.(0))(first_linemsg)usage_msg;exit2;|Arg.Helpmsg->Printf.fprintfstdout"%s\n%s\n"msgusage_msg;optionsstdout;exit0)