Skip to content

Commit

Permalink
add 'if' statement in session (TSUN-77)
Browse files Browse the repository at this point in the history
SVN Revision: 948
  • Loading branch information
nniclausse committed Nov 15, 2008
1 parent 4ce6945 commit f89961a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/tsung/ts_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,18 @@ ctrl_struct_impl({for_end,VarName,EndValue,Increment,Target},DynData=#dyndata{dy
{jump,Target,DynData#dyndata{dynvars=NewDynVars}}
end;

ctrl_struct_impl({if_start,Rel, VarName, Value, Target},DynData=#dyndata{dynvars=DynVars}) ->
case ts_dynvars:lookup(VarName,DynVars) of
{ok,VarValue} ->
?DebugF("If found ~p; value is ~p~n",[VarName,VarValue]),
?DebugF("Calling need_jump with args ~p ~p ~p~n",[Rel,Value,VarValue]),
Jump = need_jump('if',rel(Rel,Value,VarValue)),
jump_if(Jump,Target,DynData#dyndata{dynvars=DynVars});
false ->
ts_mon:add({ count, 'error_if_undef'}),
{next,DynData}
end;

ctrl_struct_impl({repeat,RepeatName, _,_,_,_,_,_},DynData=#dyndata{dynvars=[]}) ->
Msg= list_to_atom("error_repeat_"++atom_to_list(RepeatName)++"_undef"),
ts_mon:add({ count, Msg}),
Expand Down Expand Up @@ -448,7 +460,8 @@ rel('eq',A,B) -> A == B;
rel('neq',A,B) -> A /= B.

need_jump('while',F) -> F;
need_jump('until',F) -> not F.
need_jump('until',F) -> not F;
need_jump('if',F) -> not F.

jump_if(true,Target,DynData) -> {jump,Target,DynData};
jump_if(false,_Target,DynData) -> {next,DynData}.
Expand Down
18 changes: 18 additions & 0 deletions src/tsung_controller/ts_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ parse(Element = #xmlElement{name=transaction, attributes=Attrs},
ets:insert(Tab, {{CurS#session.id, NewId+1}, {transaction,stop,Name}}),
NewConf#config{curid=NewId+1} ;

%%%% Parsing the 'if' element
parse(_Element = #xmlElement{name='if', attributes=Attrs,content=Content},
Conf = #config{session_tab = Tab, sessions=[CurS|_], curid=Id}) ->
VarName = getAttr(atom,Attrs,var),
{Rel,Value} = case getAttr(string,Attrs,eq,none) of
none -> {neq,getAttr(string,Attrs,neq)};
X -> {eq,X}
end,
?LOGF("Add if_start action in session ~p as id ~p",
[CurS#session.id,Id+1],?INFO),
NewConf = lists:foldl(fun parse/2, Conf#config{curid=Id+1}, Content),
NewId = NewConf#config.curid,
?LOGF("endif in session ~p as id ~p",[CurS#session.id,NewId+1],?INFO),
InitialAction = {ctrl_struct, {if_start, Rel, VarName, Value , NewId+1}},
%%NewId+1 -> id of the first action after the if
ets:insert(Tab,{{CurS#session.id,Id+1},InitialAction}),
NewConf;

%%%% Parsing the 'for' element
parse(_Element = #xmlElement{name=for, attributes=Attrs,content=Content},
Conf = #config{session_tab = Tab, sessions=[CurS|_], curid=Id}) ->
Expand Down
14 changes: 11 additions & 3 deletions tsung-1.0.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<!ELEMENT sessions (session+)>
<!ELEMENT session ( request | thinktime | transaction | setdynvars | for |
repeat)*>
repeat | if )*>
<!ATTLIST session
name CDATA #REQUIRED
bidi CDATA #IMPLIED
Expand Down Expand Up @@ -225,19 +225,27 @@ repeat)*>
<!ATTLIST var
name CDATA #REQUIRED>

<!ELEMENT for (request | thinktime | transaction | setdynvars | for | repeat)+>
<!ELEMENT for (request | thinktime | transaction | setdynvars | for |
if | repeat)+>
<!ATTLIST for
var CDATA #REQUIRED
from NMTOKEN #REQUIRED
to NMTOKEN #REQUIRED
incr NMTOKEN "1">

<!ELEMENT repeat (request | thinktime | transaction | setdynvars | for | repeat
| while | until)+>
| while | if | until)+>
<!ATTLIST repeat
name NMTOKEN #REQUIRED
max_repeat NMTOKEN "20">

<!ELEMENT if (request | thinktime | transaction | setdynvars | for | repeat
| while | if | until)+>
<!ATTLIST if
var CDATA #REQUIRED
eq CDATA #IMPLIED
neq CDATA #IMPLIED >

<!ELEMENT while EMPTY>
<!ATTLIST while
var CDATA #REQUIRED
Expand Down

0 comments on commit f89961a

Please sign in to comment.