diff options
-rw-r--r-- | lib/ssh/test/property_test/ssh_eqc_client_server.erl | 196 |
1 files changed, 12 insertions, 184 deletions
diff --git a/lib/ssh/test/property_test/ssh_eqc_client_server.erl b/lib/ssh/test/property_test/ssh_eqc_client_server.erl index acb0faa0c7..de9e224ea6 100644 --- a/lib/ssh/test/property_test/ssh_eqc_client_server.erl +++ b/lib/ssh/test/property_test/ssh_eqc_client_server.erl @@ -102,20 +102,20 @@ %% To be called as eqc:quickcheck( ssh_eqc_client_server:prop_seq() ). prop_seq() -> error_logger:tty(false), - ?TESTINGTIME(do_prop_seq(?SSH_DIR)). + ?TESTINGTIME(do_prop_seq(?SSH_DIR,[])). %% To be called from a common_test test suite prop_seq(CT_Config) -> error_logger:tty(false), - do_prop_seq(full_path(?SSH_DIR, CT_Config)). + do_prop_seq(full_path(?SSH_DIR, CT_Config), CT_Config). -do_prop_seq(DataDir) -> +do_prop_seq(DataDir, CT_Config) -> setup_rsa(DataDir), ?FORALL(Cmds,commands(?MODULE), begin {H,Sf,Result} = run_commands(?MODULE,Cmds,[{data_dir,DataDir}]), - present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) + ct_property_test:present_result(?MODULE, Cmds, {H,Sf,Result}, CT_Config, []) end). full_path(SSHdir, CT_Config) -> @@ -124,37 +124,37 @@ full_path(SSHdir, CT_Config) -> %%%---- prop_parallel() -> error_logger:tty(false), - ?TESTINGTIME(do_prop_parallel(?SSH_DIR)). + ?TESTINGTIME(do_prop_parallel(?SSH_DIR,[])). %% To be called from a common_test test suite prop_parallel(CT_Config) -> error_logger:tty(false), - do_prop_parallel(full_path(?SSH_DIR, CT_Config)). + do_prop_parallel(full_path(?SSH_DIR, CT_Config), CT_Config). -do_prop_parallel(DataDir) -> +do_prop_parallel(DataDir, CT_Config) -> setup_rsa(DataDir), ?FORALL(Cmds,parallel_commands(?MODULE), begin {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds,[{data_dir,DataDir}]), - present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) + ct_property_test:present_result(?MODULE, Cmds, {H,Sf,Result}, CT_Config, []) end). %%%---- %% prop_parallel_multi() -> -%% ?TESTINGTIME(do_prop_parallel_multi(?SSH_DIR)). +%% ?TESTINGTIME(do_prop_parallel_multi(?SSH_DIR, [])). %% %% To be called from a common_test test suite %% prop_parallel_multi(CT_Config) -> -%% do_prop_parallel_multi(full_path(?SSH_DIR, CT_Config)). +%% do_prop_parallel_multi(full_path(?SSH_DIR, CT_Config), CT_Config). -%% do_prop_parallel_multi(DataDir) -> +%% do_prop_parallel_multi(DataDir, CT_Config) -> %% setup_rsa(DataDir), %% ?FORALL(Repetitions,?SHRINK(1,[10]), %% ?FORALL(Cmds,parallel_commands(?MODULE), %% ?ALWAYS(Repetitions, %% begin %% {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds,[{data_dir,DataDir}]), -%% present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) +%% ct_property_test:present_result(?MODULE, Cmds, {H,Sf,Result}, CT_Config, []) %% end))). %%%================================================================ @@ -476,178 +476,6 @@ is_ok(_) -> true. ensure_string({A,B,C,D}) -> lists:flatten(io_lib:format("~w.~w.~w.~w",[A,B,C,D])); ensure_string(X) -> X. -%%%---------------------------------------------------------------- -present_result(_Module, Cmds, _Triple, true) -> - aggregate(with_title("Distribution sequential/parallel"), sequential_parallel(Cmds), - aggregate(with_title("Function calls"), cmnd_names(Cmds), - aggregate(with_title("Message sizes"), empty_msgs(Cmds), - aggregate(print_frequencies(), message_sizes(Cmds), - aggregate(title("Length of command sequences",print_frequencies()), num_calls(Cmds), - true))))); - -present_result(Module, Cmds, Triple, false) -> - pretty_comands(Module, Cmds, Triple, [{show_states,true}], false), - false. % Proper dislikes non-boolean results while eqc treats non-true as false. - -pretty_comands(Module, Cmds, Triple, Opts, Bool) -> - ct:log("Module = ~p,~n Cmds = ~p,~n Triple = ~p,~n Opts = ~p,~n Bool = ~p",[Module, Cmds, Triple, Opts, Bool]). - - - -cmnd_names(Cs) -> traverse_commands(fun cmnd_name/1, Cs). -cmnd_name(L) -> [F || {set,_Var,{call,_Mod,F,_As}} <- L]. - -empty_msgs(Cs) -> traverse_commands(fun empty_msg/1, Cs). -empty_msg(L) -> [empty || {set,_,{call,_,ssh_send,[_,_,Msg]}} <- L, - size(Msg)==0]. - -message_sizes(Cs) -> traverse_commands(fun message_size/1, Cs). -message_size(L) -> [size(Msg) || {set,_,{call,_,ssh_send,[_,_,Msg]}} <- L]. - -num_calls(Cs) -> traverse_commands(fun num_call/1, Cs). -num_call(L) -> [length(L)]. - -sequential_parallel(Cs) -> - traverse_commands(fun(L) -> dup_module(L, sequential) end, - fun(L) -> [dup_module(L1, mkmod("parallel",num(L1,L))) || L1<-L] end, - Cs). -dup_module(L, ModName) -> lists:duplicate(length(L), ModName). -mkmod(PfxStr,N) -> list_to_atom(PfxStr++"_"++integer_to_list(N)). - -%% Meta functions for the aggregate functions -traverse_commands(Fun, L) when is_list(L) -> Fun(L); -traverse_commands(Fun, {Seq, ParLs}) -> Fun(lists:append([Seq|ParLs])). - -traverse_commands(Fseq, _Fpar, L) when is_list(L) -> Fseq(L); -traverse_commands(Fseq, Fpar, {Seq, ParLs}) -> lists:append([Fseq(Seq)|Fpar(ParLs)]). - -%%%---------------- -%% PrintMethod([{term(), int()}]) -> any(). -print_frequencies() -> print_frequencies(10). - -print_frequencies(Ngroups) -> fun([]) -> io:format('Empty list!~n',[]); - (L ) -> - try - M = lists:last(L), - Max = if is_integer(M) -> M; - is_tuple(M) -> element(1,L) - end, - print_frequencies(L,Ngroups,0,Max) - catch - C:E:S -> - ct:pal("~p:~p ~p:~p~n~p~n~p",[?MODULE,?LINE,C,E,S,L]) - end - end. - - -print_frequencies(Ngroups, MaxValue) -> fun(L) -> print_frequencies(L,Ngroups,0,MaxValue) end. - -print_frequencies(L, N, Min, Max) when N>Max -> print_frequencies(L++[{N,0}], N, Min, N); -print_frequencies(L, N, Min, Max0) -> - try - Interval = round((Max0-Min)/N), - Max = Max0 + (Max0 rem Interval), - IntervalUpperLimits = - lists:reverse( - [Max | tl(lists:reverse(lists:seq(Min,Max,Interval)))] - ), - {Acc0,_} = lists:mapfoldl(fun(Upper,Lower) -> - {{{Lower,Upper},0}, Upper+1} - end, hd(IntervalUpperLimits), tl(IntervalUpperLimits)), - Fs0 = get_frequencies(L, Acc0), - SumVal = lists:sum([V||{_,V}<-Fs0]), - Fs = with_percentage(Fs0, SumVal), - Mean = mean(L), - Median = median(L), - Npos_value = num_digits(SumVal), - Npos_range = num_digits(Max), - io:format("Range~*s: ~s~n",[2*Npos_range-2,"", "Number in range"]), - io:format("~*c:~*c~n",[2*Npos_range+3,$-, max(16,Npos_value+10),$- ]), - [begin - io:format("~*w - ~*w: ~*w ~5.1f%",[Npos_range,Rlow, - Npos_range,Rhigh, - Npos_value,Val, - Percent]), - [io:format(" <-- mean=~.1f",[Mean]) || in_interval(Mean, Interval)], - [io:format(" <-- median=" ++ - if - is_float(Median) -> "~.1f"; - true -> "~p" - end, [Median]) || in_interval(Median, Interval)], - io:nl() - end - || {Interval={Rlow,Rhigh},Val,Percent} <- Fs], - io:format('~*c ~*c~n',[2*Npos_range,32,Npos_value+2,$-]), - io:format('~*c ~*w~n',[2*Npos_range,32,Npos_value,SumVal]) - catch - C:E -> - io:format('*** Faild printing (~p:~p) for~n~p~n',[C,E,L]) - end. - -get_frequencies([{I,Num}|T], [{{Lower,Upper},Cnt}|Acc]) when Lower=<I,I=<Upper -> - get_frequencies(T, [{{Lower,Upper},Cnt+Num}|Acc]); -get_frequencies(L=[{I,_Num}|_], [Ah={{_Lower,Upper},_Cnt}|Acc]) when I>Upper -> - [Ah | get_frequencies(L,Acc)]; -get_frequencies([I|T], Acc) when is_integer(I) -> - get_frequencies([{I,1}|T], Acc); -get_frequencies([], Acc) -> - Acc. - -with_percentage(Fs, Sum) -> - [{Rng,Val,100*Val/Sum} || {Rng,Val} <- Fs]. - - -title(Str, Fun) -> - fun(L) -> - io:format('~s~n',[Str]), - Fun(L) - end. - -num_digits(I) -> 1+trunc(math:log(I)/math:log(10)). - -num(Elem, List) -> length(lists:takewhile(fun(E) -> E /= Elem end, List)) + 1. - -%%%---- Just for naming an operation for readability -is_odd(I) -> (I rem 2) == 1. - -in_interval(Value, {Rlow,Rhigh}) -> - try - Rlow=<round(Value) andalso round(Value)=<Rhigh - catch - _:_ -> false - end. - -%%%================================================================ -%%% Statistical functions - -%%%---- Mean value -mean(L = [X|_]) when is_number(X) -> - lists:sum(L) / length(L); -mean(L = [{_Value,_Weight}|_]) -> - SumOfWeights = lists:sum([W||{_,W}<-L]), - WeightedSum = lists:sum([W*V||{V,W}<-L]), - WeightedSum / SumOfWeights; -mean(_) -> - undefined. - -%%%---- Median -median(L = [X|_]) when is_number(X) -> - case is_odd(length(L)) of - true -> - hd(lists:nthtail(length(L) div 2, L)); - false -> - %% 1) L has at least on element (the when test). - %% 2) Length is even. - %% => Length >= 2 - [M1,M2|_] = lists:nthtail((length(L) div 2)-1, L), - (M1+M2) / 2 - end; -%% integer Weights... -median(L = [{_Value,_Weight}|_]) -> - median( lists:append([lists:duplicate(W,V) || {V,W} <- L]) ); -median(_) -> - undefined. - %%%================================================================ %%% The rest is taken and modified from ssh_test_lib.erl setup_rsa(Dir) -> |