aboutsummaryrefslogtreecommitdiffstats
path: root/lib/megaco/test/megaco_examples_test.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/megaco/test/megaco_examples_test.erl')
-rw-r--r--lib/megaco/test/megaco_examples_test.erl341
1 files changed, 268 insertions, 73 deletions
diff --git a/lib/megaco/test/megaco_examples_test.erl b/lib/megaco/test/megaco_examples_test.erl
index 45a6c5011a..fdf9fe29ff 100644
--- a/lib/megaco/test/megaco_examples_test.erl
+++ b/lib/megaco/test/megaco_examples_test.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2001-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2001-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -25,12 +25,27 @@
-module(megaco_examples_test).
--compile(export_all).
+-export([
+ all/0,
+ groups/0,
+
+ init_per_group/2,
+ end_per_group/2,
+ init_per_testcase/2,
+ end_per_testcase/2,
+
+ simple/1,
+
+ t/0, t/1
+ ]).
+
-include("megaco_test_lib.hrl").
-include_lib("megaco/include/megaco.hrl").
-include_lib("megaco/include/megaco_message_v1.hrl").
+-define(LIB, megaco_test_lib).
+
t() -> megaco_test_lib:t(?MODULE).
t(Case) -> megaco_test_lib:t({?MODULE, Case}).
@@ -56,9 +71,19 @@ load_examples() ->
{error, Reason} ->
{error, Reason};
Dir ->
- [code:load_abs(filename:join([Dir, examples, simple, M])) || M <- example_modules()]
+ SimpleDir = filename:join([Dir, examples, simple]),
+ case code:add_path(SimpleDir) of
+ true ->
+ ok;
+ {error, What} ->
+ error_logger:error_msg("failed adding examples path: "
+ "~n ~p"
+ "~n", [What]),
+ {error, {failed_add_path, What}}
+ end
end.
+
purge_examples() ->
case code:lib_dir(megaco) of
{error, Reason} ->
@@ -67,6 +92,7 @@ purge_examples() ->
[code:purge(M) || M <- example_modules()]
end.
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Top test case
@@ -87,94 +113,263 @@ end_per_group(_GroupName, Config) ->
simple(suite) ->
[];
simple(Config) when is_list(Config) ->
- ?ACQUIRE_NODES(1, Config),
- d("simple -> proxy start",[]),
- ProxyPid = megaco_test_lib:proxy_start({?MODULE, ?LINE}),
+ process_flag(trap_exit, true),
+ d("simple -> create node name(s)"),
+ [_Local, MGC, MG] = ?LIB:mk_nodes(3), %% Grrr
+ Nodes = [MGC, MG],
- d("simple -> start megaco",[]),
- ?VERIFY(ok, megaco:start()),
+ d("simple -> start nodes"),
+ ok = ?LIB:start_nodes(Nodes, ?MODULE, ?LINE),
- d("simple -> start mgc",[]),
- ?APPLY(ProxyPid, fun() -> megaco_simple_mgc:start() end),
+ MGCId = "MGC",
+ MGId = "MG",
+
+ d("simple -> MGC proxy start (on ~p)", [MGC]),
+ MGCProxy = megaco_test_lib:proxy_start(MGC, "MGC"),
+ ?SLEEP(1000),
+
+ d("simple -> MG proxy start (on ~p)", [MG]),
+ MGProxy = megaco_test_lib:proxy_start(MG, "MG"),
+ ?SLEEP(1000),
+
+ MegacoStart = fun() -> megaco:start() end,
+ MegacoStartVerify =
+ fun(_, ok) -> ok;
+ (Id, Else) -> ?ERROR({failed_starting_megaco, Id, Else})
+ end,
+
+ d("simple -> start MGC megaco"),
+ exec(MGCProxy, MGCId, MegacoStart,
+ fun(Res) -> MegacoStartVerify(MGCId, Res) end),
+ %% ?APPLY(MGCProxy, fun() -> ok = megaco:start() end),
+ ?SLEEP(1000),
+
+ d("simple -> start MG megaco"),
+ exec(MGProxy, MGId, MegacoStart,
+ fun(Res) -> MegacoStartVerify(MGId, Res) end),
+ %% ?APPLY(MGProxy, fun() -> ok = megaco:start() end),
+ ?SLEEP(1000),
+
+ d("simple -> start mgc"),
+ start_mgc(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC info (no mg)"),
+ info(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC system_info(users) (no mg)"),
+ users(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> start mg"),
+ start_mg(MGProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC info (mg)"),
+ info(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC system_info(users) (mg)"),
+ users(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MG info"),
+ info(MGProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MG system_info(users)"),
+ users(MGProxy),
+ ?SLEEP(1000),
+
+ d("simple -> stop mgc"),
+ exec(MGCProxy, MGCId,
+ fun() -> megaco_simple_mgc:stop() end,
+ fun([_]) -> ok;
+ (L) when is_list(L) ->
+ ?ERROR({invalid_users, L});
+ (X) ->
+ ?ERROR({invalid_result, X})
+ end),
+ %% ?VERIFY(5, length()),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC info (no mgc)"),
+ info(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MG info (no mgc)"),
+ info(MGProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MGC system_info(users) (no mgc)",[]),
+ users(MGCProxy),
+ ?SLEEP(1000),
+
+ d("simple -> verify MG system_info(users) (no mgc)",[]),
+ users(MGProxy),
+ ?SLEEP(1000),
+
+ MegacoStop = fun() -> megaco:stop() end,
+ MegacoStopVerify =
+ fun(_, ok) -> ok;
+ (Id, Else) -> ?ERROR({failed_stop_megaco, Id, Else})
+ end,
+
+ d("simple -> stop MG megaco",[]),
+ exec(MGProxy, MGId, MegacoStop,
+ fun(Res) -> MegacoStopVerify(MGId, Res) end),
+ %% ?VERIFY(ok, megaco:stop()),
+ ?SLEEP(1000),
+
+ d("simple -> stop MGC megaco",[]),
+ exec(MGCProxy, MGCId, MegacoStop,
+ fun(Res) -> MegacoStopVerify(MGCId, Res) end),
+ %% ?VERIFY(ok, megaco:stop()),
+ ?SLEEP(1000),
+
+ d("simple -> kill (exit) MG Proxy: ~p", [MGProxy]),
+ MGProxy ! {stop, self(), normal},
+ receive
+ {'EXIT', MGProxy, _} ->
+ d("simple -> MG Proxy terminated"),
+ ok
+ end,
+
+ d("simple -> kill (exit) MGC Proxy: ~p", [MGCProxy]),
+ MGCProxy ! {stop, self(), normal},
+ receive
+ {'EXIT', MGCProxy, _} ->
+ d("simple -> MGC Proxy terminated"),
+ ok
+ end,
+
+ d("simple -> stop ~p", [MGC]),
+ slave:stop(MGC),
+
+ d("simple -> stop ~p", [MG]),
+ slave:stop(MG),
+
+ d("simple -> done", []),
+ ok.
+
+
+exec(Proxy, Id, Cmd, Verify) ->
+ ?APPLY(Proxy, Cmd),
+ receive
+ {res, Id, Res} ->
+ Verify(Res)
+ end.
+
+
+start_mgc(Proxy) ->
+ ?APPLY(Proxy,
+ fun() ->
+ try megaco_simple_mgc:start() of
+ Res ->
+ Res
+ catch
+ C:E:S ->
+ {error, {{catched, C, E, S}}, code:get_path()}
+ end
+ end),
receive
{res, _, {ok, MgcAll}} when is_list(MgcAll) ->
MgcBad = [MgcRes || MgcRes <- MgcAll, element(1, MgcRes) /= ok],
?VERIFY([], MgcBad),
- %% MgcGood = MgcAll -- MgcBad,
- %% MgcRecHandles = [MgcRH || {ok, _MgcPort, MgcRH} <- MgcGood],
-
- d("simple -> start mg",[]),
- ?APPLY(ProxyPid, fun() -> megaco_simple_mg:start() end),
- receive
- {res, _, MgList} when is_list(MgList) andalso (length(MgList) =:= 4) ->
- d("simple -> received res: ~p",[MgList]),
- Verify =
- fun({_MgMid, {TransId, Res}}) when TransId =:= 1 ->
- case Res of
- {ok, [AR]} when is_record(AR, 'ActionReply') ->
- case AR#'ActionReply'.commandReply of
- [{serviceChangeReply, SCR}] ->
- case SCR#'ServiceChangeReply'.serviceChangeResult of
- {serviceChangeResParms, MgcMid} when MgcMid /= asn1_NOVALUE ->
- ok;
- Error ->
- ?ERROR(Error)
- end;
- Error ->
- ?ERROR(Error)
- end;
- Error ->
- ?ERROR(Error)
- end;
- (Error) ->
- ?ERROR(Error)
- end,
- lists:map(Verify, MgList);
- Error ->
- ?ERROR(Error)
- end;
+ ok;
Error ->
?ERROR(Error)
- end,
- d("simple -> verify info()",[]),
- info(),
- d("simple -> verify system_info(users)",[]),
- users(),
- d("simple -> stop mgc",[]),
- ?VERIFY(5, length(megaco_simple_mgc:stop())),
- d("simple -> verify system_info(users)",[]),
- users(),
- d("simple -> stop megaco",[]),
- ?VERIFY(ok, megaco:stop()),
- d("simple -> kill (exit) ProxyPid: ~p",[ProxyPid]),
- exit(ProxyPid, shutdown), % Controlled kill of transport supervisors
+ end.
- ok.
+start_mg(Proxy) ->
+ ?APPLY(Proxy, fun() ->
+ try megaco_simple_mg:start() of
+ Res ->
+ Res
+ catch
+ C:E:S ->
+ {error, {{catched, C, E, S}}, code:get_path()}
+ end
+ end),
+ receive
+ {res, _, MGs} when is_list(MGs) andalso (length(MGs) =:= 4) ->
+ verify_mgs(MGs);
+ Error ->
+ ?ERROR(Error)
+ end.
-info() ->
- case (catch megaco:info()) of
- {'EXIT', _} = Error ->
- ?ERROR(Error);
- Info ->
- ?LOG("Ok, ~p~n", [Info])
+verify_mgs(MGs) ->
+ Verify =
+ fun({_MgMid, {TransId, Res}}) when (TransId =:= 1) ->
+ case Res of
+ {ok, [AR]} when is_record(AR, 'ActionReply') ->
+ case AR#'ActionReply'.commandReply of
+ [{serviceChangeReply, SCR}] ->
+ case SCR#'ServiceChangeReply'.serviceChangeResult of
+ {serviceChangeResParms, MgcMid}
+ when (MgcMid =/= asn1_NOVALUE) ->
+ ok;
+ Error ->
+ ?ERROR(Error)
+ end;
+ Error ->
+ ?ERROR(Error)
+ end;
+ Error ->
+ ?ERROR(Error)
+ end;
+ (Error) ->
+ ?ERROR(Error)
+ end,
+ lists:map(Verify, MGs).
+
+
+info(Proxy) ->
+ ?APPLY(Proxy,
+ fun() ->
+ try megaco:info() of
+ I -> I
+ catch
+ C:E:S ->
+ {error, {C, E, S}}
+ end
+ end),
+ receive
+ {res, _, Info} when is_list(Info) ->
+ ?LOG("Ok, ~p~n", [Info]);
+ {res, _, Error} ->
+ ?ERROR(Error)
end.
-users() ->
- case (catch megaco:system_info(users)) of
- {'EXIT', _} = Error ->
- ?ERROR(Error);
- Users ->
- ?LOG("Ok, ~p~n", [Users])
+
+users(Proxy) ->
+ ?APPLY(Proxy,
+ fun() ->
+ try megaco:system_info(users) of
+ I -> I
+ catch
+ C:E:S ->
+ {error, {C, E, S}}
+ end
+ end),
+ receive
+ {res, _, Info} when is_list(Info) ->
+ ?LOG("Ok, ~p~n", [Info]);
+ {res, _, Error} ->
+ ?ERROR(Error)
end.
-d(F,A) ->
- d(get(dbg),F,A).
+d(F) ->
+ d(F, []).
+d(F, A) ->
+ d(get(dbg), F, A).
-d(true,F,A) ->
- io:format("DBG: " ++ F ++ "~n",A);
+d(true, F, A) ->
+ io:format("DBG: ~s " ++ F ++ "~n", [?FTS() | A]);
d(_, _F, _A) ->
ok.