Permalink
Browse files

fix bug in lookup_pids and update quickcheck test model

git-svn-id: http://svn.ulf.wiger.net/gproc/branches/experimental-0906/gproc@28 f3948e33-8234-0410-8a80-a07eae3b6c4d
  • Loading branch information...
1 parent 1e02602 commit dedacd15616dfe6d5ef5ac801baf83e380a92218 jwnorton committed Aug 24, 2009
Showing with 40 additions and 482 deletions.
  1. +30 −3 src/Unit-Quick-Files/gproc_eqc.erl
  2. +9 −7 src/gproc.erl
  3. +0 −471 src/gproc_eqc.erl
  4. +1 −1 src/gproc_lib.erl
@@ -24,7 +24,6 @@
%%
%% - add non integer to value() generator
%% - implement mreg
-%% - implement lookup_pid/lookup_pids
%%
%%
@@ -96,9 +95,9 @@ command(S) ->
%% get_value
, {call,?MODULE,get_value, [elements(S#state.pids), key()]}
%% lookup_pid
- %%, {call,gproc,lookup_pid, [key()]}
+ , {call,?MODULE,lookup_pid, [key()]}
%% lookup_pids
- %%, {call,gproc,lookup_pids, [key()]}
+ , {call,?MODULE,lookup_pids, [key()]}
])
|| S#state.pids/=[] ]
).
@@ -343,6 +342,26 @@ postcondition(S,{call,_,get_value,[Pid,Key]},Res) ->
[Value] ->
Res == Value
end;
+%% lookup_pid
+postcondition(S,{call,_,lookup_pid,[#key{class=Class}=Key]},Res)
+ when Class == n; Class == a ->
+ case [ Pid1 || #reg{pid=Pid1,key=Key1} <- S#state.regs
+ , Key==Key1 ] of
+ [] ->
+ case Res of {'EXIT', {badarg, _}} -> true; _ -> false end;
+ [Pid] ->
+ Res == Pid
+ end;
+postcondition(_S,{call,_,lookup_pid,[_Key]},Res) ->
+ case Res of {'EXIT', {badarg, _}} -> true; _ -> false end;
+%% lookup_pids
+postcondition(S,{call,_,lookup_pids,[#key{class=Class}=Key]},Res)
+ when Class == n; Class == a; Class == c ->
+ Pids = [ Pid1 || #reg{pid=Pid1,key=Key1} <- S#state.regs
+ , Key==Key1 ],
+ lists:sort(Res) == lists:sort(Pids);
+postcondition(_S,{call,_,lookup_pids,[_Key]},Res) ->
+ case Res of {'EXIT', {badarg, _}} -> true; _ -> false end;
%% otherwise
postcondition(_S,{call,_,_,_},_Res) ->
false.
@@ -456,6 +475,14 @@ update_counter(Pid, #key{class=Class,scope=Scope,name=Name},Incr) ->
get_value(Pid,#key{class=Class,scope=Scope,name=Name}) ->
do(Pid, fun() -> catch gproc:get_value({Class,Scope,Name}) end).
+%% lookup_pid
+lookup_pid(#key{class=Class,scope=Scope,name=Name}) ->
+ catch gproc:lookup_pid({Class,Scope,Name}).
+
+%% lookup_pids
+lookup_pids(#key{class=Class,scope=Scope,name=Name}) ->
+ catch gproc:lookup_pids({Class,Scope,Name}).
+
%% do
do(Pid, F) ->
Ref = erlang:monitor(process, Pid),
View
@@ -185,7 +185,7 @@ get_value(Key) ->
get_value(Key, self()).
get_value({T,_,_} = Key, Pid) when is_pid(Pid) ->
- if T==n; T==a ->
+ if T==n orelse T==a ->
case ets:lookup(?TAB, {Key, T}) of
[{_, P, Value}] when P == Pid -> Value;
_ -> erlang:error(badarg)
@@ -208,7 +208,7 @@ lookup_pid({_T,_,_} = Key) ->
where({T,_,_}=Key) ->
- if T==n; T==a ->
+ if T==n orelse T==a ->
case ets:lookup(?TAB, {Key,T}) of
[] ->
undefined;
@@ -220,8 +220,10 @@ where({T,_,_}=Key) ->
end.
lookup_pids({T,_,_} = Key) ->
- if T==n; T==a; T==c ->
+ if T==n orelse T==a ->
ets:select(?TAB, [{{{Key,T}, '$1', '_'},[],['$1']}]);
+ T==c ->
+ ets:select(?TAB, [{{{Key,'_'}, '$1', '_'},[],['$1']}]);
true ->
erlang:error(badarg)
end.
@@ -239,14 +241,14 @@ update_counter(_, _) ->
send({T,C,_} = Key, Msg) when C==l; C==g ->
- if T == n; T == a ->
+ if T == n orelse T == a ->
case ets:lookup(?TAB, {Key, T}) of
[{_, Pid, _}] ->
Pid ! Msg;
[] ->
erlang:error(badarg)
end;
- T==p; T==c ->
+ T==p orelse T==c ->
%% BUG - if the key part contains select wildcards, we may end up
%% sending multiple messages to the same pid
Head = {{Key,'$1'},'_'},
@@ -483,7 +485,7 @@ headpat(T, C, V1,V2,V3) ->
Rf = fun(Pos) ->
{element,Pos,{element,1,{element,1,'$_'}}}
end,
- K2 = if T==n; T==a -> T;
+ K2 = if T==n orelse T==a -> T;
true -> '_'
end,
{Kp,Vars} = case V1 of
@@ -644,7 +646,7 @@ qlc_lookup(Scope, 2, Pids) ->
[], ['$_']}]),
lists:flatmap(
fun({{_,{T,_,_}=K}}) ->
- K2 = if T==n; T==a -> T;
+ K2 = if T==n orelse T==a -> T;
true -> Pid
end,
case ets:lookup(?TAB, {K,K2}) of
Oops, something went wrong.

0 comments on commit dedacd1

Please sign in to comment.