Skip to content

Commit

Permalink
WiP: test for AAA API interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed May 7, 2019
1 parent 80e38f4 commit 5c05c9a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/ergw_test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
-export([has_ipv6_test_config/0]).
-export([query_usage_report/2]).
-export([match_map/4]).
-export([classify_list/3]).
-export([check_aaa_invoke/8]).

-include("ergw_test_lib.hrl").
-include_lib("common_test/include/ct.hrl").
Expand Down Expand Up @@ -561,3 +563,47 @@ match_map(Match, Map, File, Line) ->
end
end, true, Match) orelse error(badmatch),
ok.

classify_list(Pred, Classes, List)
when is_function(Pred, 1), is_integer(Classes), is_list(List) ->
Init = array:new([{size, Classes}, {fixed, true}, {default, []}]),
Result = do_classify_list(Pred, List, Init),
list_to_tuple(array:to_list(Result)).

do_classify_list(_Pred, [], Init) ->
Init;
do_classify_list(Pred, [H|T], Init) ->
Next = do_classify_list(Pred, T, Init),
case Pred(H) of
Class when is_integer(Class) ->
array:set(Class, [H | array:get(Class, Next)], Next);
false ->
Next
end.

check_aaa_invoke(AuthC, GxC, GyC, RfC, AcctC, OtherC, File, Line) ->
{Auth, Gx, Gy, Rf, Acct, Other} =
classify_list(
fun({_, {ergw_aaa_session, invoke, [_, _, authenticate, _]}, _}) ->
0;
({_, {ergw_aaa_session, invoke, [_, _, {gx, _}, _]}, _}) ->
1;
({_, {ergw_aaa_session, invoke, [_, _, {gy, _}, _]}, _}) ->
2;
({_, {ergw_aaa_session, invoke, [_, _, {rf, _}, _]}, _}) ->
3;
({_, {ergw_aaa_session, invoke, [_, _, Ev, _]}, _})
when Ev == start; Ev == stop ->
4;
({_, {ergw_aaa_session, invoke, _}, _}) ->
5;
(_) ->
false
end, 6, meck:history(ergw_aaa_session)),
?equal_loc(AuthC, length(Auth), File, Line),
?equal_loc(GxC, length(Gx), File, Line),
?equal_loc(GyC, length(Gy), File, Line),
?equal_loc(RfC, length(Rf), File, Line),
?equal_loc(AcctC, length(Acct), File, Line),
?equal_loc(OtherC, length(Other), File, Line),
ok.
22 changes: 22 additions & 0 deletions test/ergw_test_lib.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
false
end)(Expected, Actual) orelse error(badmatch)).

-define(equal_loc(Expected, Actual, File, Line),
(fun (Expected@@@, Expected@@@) -> true;
(Expected@@@, Actual@@@) ->
ct:pal("MISMATCH(~s:~b, ~s)~nExpected: ~p~nActual: ~p~n",
[File, Line, ??Actual, Expected@@@, Actual@@@]),
false
end)(Expected, Actual) orelse error(badmatch)).

-define(not_equal(A, B),
(fun (A@@@, A@@@) ->
ct:pal("SHOULD NOT BE EQUAL(~s:~b, ~s, ~s)~nGot: ~p~n",
Expand All @@ -123,4 +131,18 @@
end
end)())).

-define(match_loc(Guard, Expr, File, Line),
((fun () ->
case (Expr) of
Guard -> ok;
V -> ct:pal("MISMATCH(~s:~b, ~s)~nExpected: ~p~nActual: ~s~n",
[File, Line, ??Expr, ??Guard,
ergw_test_lib:pretty_print(V)]),
error(badmatch)
end
end)())).

-define(match_map(Expected, Actual), ergw_test_lib:match_map(Expected, Actual, ?FILE, ?LINE)).

-define(check_aaa_invoke(AuthC, GxC, GyC, RfC, AcctC, OtherC),
ergw_test_lib:check_aaa_invoke(AuthC, GxC, GyC, RfC, AcctC, OtherC, ?FILE, ?LINE)).
2 changes: 2 additions & 0 deletions test/ggsn_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ create_pdp_context_request_pool_exhausted(Config) ->
end),
create_pdp_context(pool_exhausted, Config),

?check_aaa_invoke(3, 0, 0, 0, 0, 0),
?equal([], outstanding_requests()),
meck_validate(Config),
ok.
Expand Down Expand Up @@ -726,6 +727,7 @@ simple_pdp_context_request(Config) ->
MetricsAfter = socket_counter_metrics(),
delete_pdp_context(GtpC),

?check_aaa_invoke(1, 2, 2, 2, 2, 0),
?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
Expand Down
5 changes: 5 additions & 0 deletions test/pgw_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ create_session_request_aaa_reject() ->
create_session_request_aaa_reject(Config) ->
create_session(aaa_reject, Config),

?check_aaa_invoke(1, 0, 0, 0, 0, 0),
meck_validate(Config),
ok.

Expand All @@ -633,6 +634,7 @@ create_session_request_gx_fail() ->
create_session_request_gx_fail(Config) ->
create_session(gx_fail, Config),

?check_aaa_invoke(1, 1, 0, 0, 0, 0),
meck_validate(Config),
ok.

Expand All @@ -642,6 +644,7 @@ create_session_request_gy_fail() ->
create_session_request_gy_fail(Config) ->
create_session(gy_fail, Config),

?check_aaa_invoke(1, 2, 1, 0, 0, 0),
meck_validate(Config),
ok.

Expand Down Expand Up @@ -694,6 +697,7 @@ create_session_request_pool_exhausted(Config) ->
end),
create_session(pool_exhausted, Config),

?check_aaa_invoke(3, 0, 0, 0, 0, 0),
?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
Expand Down Expand Up @@ -903,6 +907,7 @@ simple_session_request(Config) ->
}
}, URR),

?check_aaa_invoke(1, 2, 2, 2, 2, 0),
meck_validate(Config),
ok.

Expand Down
2 changes: 2 additions & 0 deletions test/saegw_s11_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ create_session_request_pool_exhausted(Config) ->
end),
create_session(pool_exhausted, Config),

?check_aaa_invoke(3, 0, 0, 0, 0, 0),
?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
Expand All @@ -558,6 +559,7 @@ simple_session_request(Config) ->
{GtpC2, _, _} = modify_bearer(enb_u_tei, GtpC1),
delete_session(GtpC2),

?check_aaa_invoke(1, 2, 2, 2, 2, 0),
?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
Expand Down

0 comments on commit 5c05c9a

Please sign in to comment.