⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 megaco_load_test.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 2 页
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id$%%%%----------------------------------------------------------------------%% Purpose: Verify the application specifics of the Megaco application%%-----------------------------------------------------------------------module(megaco_load_test).-compile(export_all).-include("megaco_test_lib.hrl").-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-define(TEST_VERBOSITY, debug).-define(MGC_VERBOSITY,  silence).-define(MG_VERBOSITY,   silence).-define(SINGLE_USER_LOAD_NUM_REQUESTS, 1000).-define(MULTI_USER_LOAD_NUM_REQUESTS,  1000).-define(MGC_START(Pid, Mid, ET, Verb),         megaco_test_mgc:start(Pid, Mid, ET, Verb)).-define(MGC_STOP(Pid), megaco_test_mgc:stop(Pid)).-define(MGC_USER_INFO(Pid,Tag), megaco_test_mgc:user_info(Pid,Tag)).-define(MGC_CONN_INFO(Pid,Tag), megaco_test_mgc:conn_info(Pid,Tag)).-define(MGC_SET_VERBOSITY(Pid, V), megaco_test_mgc:verbosity(Pid, V)).-define(MG_START(Pid, Mid, Enc, Transp, Conf, Verb),         megaco_test_mg:start(Pid, Mid, Enc, Transp, Conf, Verb)).-define(MG_STOP(Pid), megaco_test_mg:stop(Pid)).-define(MG_USER_INFO(Pid,Tag), megaco_test_mg:user_info(Pid,Tag)).-define(MG_CONN_INFO(Pid,Tag), megaco_test_mg:conn_info(Pid,Tag)).-define(MG_SERV_CHANGE(Pid), megaco_test_mg:service_change(Pid)).-define(MG_MLOAD(Pid, NL, NR), 	timer:tc(megaco_test_mg, apply_multi_load, [Pid, NL, NR])).-define(MG_LOAD(Pid, NL, NR), megaco_test_mg:apply_multi_load(Pid, NL, NR)).-define(MG_SET_VERBOSITY(Pid, V), megaco_test_mg:verbosity(Pid, V)).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t()     -> megaco_test_lib:t(?MODULE).t(Case) -> megaco_test_lib:t({?MODULE, Case}).min(M) -> timer:minutes(M).%% Test server callbacksinit_per_testcase(single_user_light_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(2)}|C]);init_per_testcase(single_user_medium_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(5)}|C]);init_per_testcase(single_user_heavy_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(10)}|C]);init_per_testcase(single_user_extreme_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(20)}|C]);init_per_testcase(multi_user_light_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(2)}|C]);init_per_testcase(multi_user_medium_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(5)}|C]);init_per_testcase(multi_user_heavy_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(10)}|C]);init_per_testcase(multi_user_extreme_load = Case, Config) ->    C = lists:keydelete(tc_timeout, 1, Config),    do_init_per_testcase(Case, [{tc_timeout, min(20)}|C]);init_per_testcase(Case, Config) ->    do_init_per_testcase(Case, Config).do_init_per_testcase(Case, Config) ->    process_flag(trap_exit, true),    megaco_test_lib:init_per_testcase(Case, Config).    fin_per_testcase(Case, Config) ->    process_flag(trap_exit, false),    megaco_test_lib:fin_per_testcase(Case, Config).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%all(suite) ->    Cases = 	[ 	 single_user_light_load, 	 single_user_medium_load, 	 single_user_heavy_load, 	 single_user_extreme_load, 	 multi_user_light_load, 	 multi_user_medium_load,  	 multi_user_heavy_load, 	 multi_user_extreme_load	],    Cases.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%single_user_light_load(suite) ->    [];single_user_light_load(doc) ->    [];single_user_light_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        single_user_light_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( single_user_load(5) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%single_user_medium_load(suite) ->    [];single_user_medium_load(doc) ->    [];single_user_medium_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        single_user_medium_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( single_user_load(15) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%single_user_heavy_load(suite) ->    [];single_user_heavy_load(doc) ->    [];single_user_heavy_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        single_user_heavy_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( single_user_load(25) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%single_user_extreme_load(suite) ->    [];single_user_extreme_load(doc) ->    [];single_user_extreme_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        single_user_extreme_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( single_user_load(100) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%multi_user_light_load(suite) ->    [];multi_user_light_load(doc) ->    [];multi_user_light_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        multi_user_light_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( multi_user_load(3,1) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%multi_user_medium_load(suite) ->    [];multi_user_medium_load(doc) ->    [];multi_user_medium_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        multi_user_medium_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( multi_user_load(3,5) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%multi_user_heavy_load(suite) ->    [];multi_user_heavy_load(doc) ->    [];multi_user_heavy_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        multi_user_heavy_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( multi_user_load(3,10) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%multi_user_extreme_load(suite) ->    [];multi_user_extreme_load(doc) ->    [];multi_user_extreme_load(Config) when list(Config) ->    put(verbosity, ?TEST_VERBOSITY),    put(tc,        multi_user_extreme_load),    put(sname,     "TEST"),    i("starting"),    load_controller(Config, 		    fun(Env) -> 			    populate(Env), 			    exit( multi_user_load(3,15) ) 		    end),    i("done", []),    ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%populate([]) ->    ok;populate([{Key,Val}|Env]) ->    put(Key, Val),    populate(Env).load_controller(Config, Fun) when is_list(Config) and is_function(Fun) ->    process_flag(trap_exit, true),    {value, {tc_timeout, TcTimeout}} = 	lists:keysearch(tc_timeout, 1, Config),    SkipTimeout = trunc(95*TcTimeout/100), % 95% of TcTimeout    Env = get(),    Loader = erlang:spawn_link(fun() -> Fun(Env) end),    receive	{'EXIT', Loader, normal} ->	    d("load_controller -> "	      "loader [~p] terminated with normal", [Loader]),	    ok;	{'EXIT', Loader, ok} ->	    d("load_controller -> "	      "loader [~p] terminated with ok~n", [Loader]),	    ok;	{'EXIT', Loader, Reason} ->	    i("load_controller -> "	      "loader [~p] terminated with"	      "~n   ~p", [Loader, Reason]),	    erlang:error({unexpected_loader_result, Reason})    after SkipTimeout ->	    i("load_controller -> "	      "loader [~p] timeout", [Loader]),	    exit(kill, Loader),	    ?SKIP({timeout, SkipTimeout, TcTimeout})    end.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%single_user_load(NumLoaders) ->    MgcNode = make_node_name(mgc),    MgNode  = make_node_name(mg),    d("Nodes: "      "~n   MgcNode: ~p"      "~n   MgNode:  ~p", [MgcNode, MgNode]),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -