From f536f86ebe3face7164c63d7455389968be94203 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 11 Sep 2014 10:12:11 +0200 Subject: Passing global var to QuickCheck statemachine The data_dir used by the tests is given at runtime. This has as a disadvantage that the generate test has a hardcoded data_dir in it (ssh_eqc_client_server_dirs below): [{set,{var,1}, {call,ssh_eqc_client_server,initial_state, [{state,false,[],[],[],[],"ssh_eqc_client_server_dirs"}]}}, {set,{var,2}, {call,ssh_eqc_client_server,ssh_server, [{{127,1,1,1}, {call,ssh_eqc_client_server,inet_port,[{127,1,1,1}]}}, "ssh_eqc_client_server_dirs", [{parallel_login,true}]]}}, Re-running this tests on another machine works, since the path is relative, but if it were absolute, it would have been hard. Instead, we may use a symbolic representation of the data_dir and fill it in each time one runs the property, thus even when one does a check or recheck. The key to this is to use a variable in the test and bind the variable in the place where one runs the commands by using the environment variable feature of run_commands. Conflicts: lib/ssh/test/property_test/ssh_eqc_client_server.erl --- .../test/property_test/ssh_eqc_client_server.erl | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib/ssh/test/property_test') 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 cf895ae85e..40782cd034 100644 --- a/lib/ssh/test/property_test/ssh_eqc_client_server.erl +++ b/lib/ssh/test/property_test/ssh_eqc_client_server.erl @@ -105,9 +105,9 @@ prop_seq(CT_Config) -> do_prop_seq(DataDir) -> - ?FORALL(Cmds,commands(?MODULE, #state{data_dir=DataDir}), + ?FORALL(Cmds,commands(?MODULE), begin - {H,Sf,Result} = run_commands(?MODULE,Cmds), + {H,Sf,Result} = run_commands(?MODULE,Cmds,[{data_dir,DataDir}]), present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) end). @@ -123,9 +123,9 @@ prop_parallel(CT_Config) -> do_prop_parallel(full_path(?SSH_DIR, CT_Config)). do_prop_parallel(DataDir) -> - ?FORALL(Cmds,parallel_commands(?MODULE, #state{data_dir=DataDir}), + ?FORALL(Cmds,parallel_commands(?MODULE), begin - {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds), + {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds,[{data_dir,DataDir}]), present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) end). @@ -139,10 +139,10 @@ prop_parallel_multi(CT_Config) -> do_prop_parallel_multi(DataDir) -> ?FORALL(Repetitions,?SHRINK(1,[10]), - ?FORALL(Cmds,parallel_commands(?MODULE, #state{data_dir=DataDir}), + ?FORALL(Cmds,parallel_commands(?MODULE), ?ALWAYS(Repetitions, begin - {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds), + {H,Sf,Result} = run_parallel_commands(?MODULE,Cmds,[{data_dir,DataDir}]), present_result(?MODULE, Cmds, {H,Sf,Result}, Result==ok) end))). @@ -151,14 +151,13 @@ do_prop_parallel_multi(DataDir) -> %%% called when using commands/1 initial_state() -> - S = initial_state(#state{}), - S#state{initialized=true}. + #state{}. %%% called when using commands/2 -initial_state(S) -> +initial_state(DataDir) -> application:stop(ssh), ssh:start(), - setup_rsa(S#state.data_dir). + setup_rsa(DataDir). %%%---------------- weight(S, ssh_send) -> 5*length([C || C<-S#state.channels, has_subsyst(C)]); @@ -172,7 +171,7 @@ weight(_S, _) -> 1. initial_state_pre(S) -> not S#state.initialized. -initial_state_args(S) -> [S]. +initial_state_args(S) -> [{var,data_dir}]. initial_state_next(S, _, _) -> S#state{initialized=true}. @@ -183,7 +182,7 @@ initial_state_next(S, _, _) -> S#state{initialized=true}. ssh_server_pre(S) -> S#state.initialized andalso length(S#state.servers) < ?MAX_NUM_SERVERS. -ssh_server_args(S) -> [?SERVER_ADDRESS, S#state.data_dir, ?SERVER_EXTRA_OPTIONS]. +ssh_server_args(S) -> [?SERVER_ADDRESS, {var,data_dir}, ?SERVER_EXTRA_OPTIONS]. ssh_server({IP,Port}, DataDir, ExtraOptions) -> ok(ssh:daemon(IP, Port, @@ -241,7 +240,7 @@ do(Pid, Fun, Timeout) when is_function(Fun,0) -> ssh_open_connection_pre(S) -> S#state.servers /= []. -ssh_open_connection_args(S) -> [oneof(S#state.servers), S#state.data_dir]. +ssh_open_connection_args(S) -> [oneof(S#state.servers), {var,data_dir}]. ssh_open_connection(#srvr{address=Ip, port=Port}, DataDir) -> ok(ssh:connect(ensure_string(Ip), Port, -- cgit v1.2.3