%% %% %CopyrightBegin% %% %% Copyright Ericsson AB 2003-2018. 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. %% You may obtain a copy of the License at %% %% http://www.apache.org/licenses/LICENSE-2.0 %% %% Unless required by applicable law or agreed to in writing, software %% distributed under the License is distributed on an "AS IS" BASIS, %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %% See the License for the specific language governing permissions and %% limitations under the License. %% %% %CopyrightEnd% %% -module(ct). -include("ct.hrl"). -include("ct_util.hrl"). %% Command line user interface for running tests -export([install/1, run/1, run/2, run/3, run_test/1, run_testspec/1, step/3, step/4, start_interactive/0, stop_interactive/0]). %% Test suite API -export([require/1, require/2, get_config/1, get_config/2, get_config/3, reload_config/1, escape_chars/1, escape_chars/2, log/1, log/2, log/3, log/4, log/5, print/1, print/2, print/3, print/4, print/5, pal/1, pal/2, pal/3, pal/4, pal/5, set_verbosity/2, get_verbosity/1, capture_start/0, capture_stop/0, capture_get/0, capture_get/1, fail/1, fail/2, comment/1, comment/2, make_priv_dir/0, testcases/2, userdata/2, userdata/3, timetrap/1, get_timetrap_info/0, sleep/1, notify/2, sync_notify/2, break/1, break/2, continue/0, continue/1]). %% New API for manipulating with config handlers -export([add_config/2, remove_config/2]). %% Other interface functions -export([get_status/0, abort_current_testcase/1, get_event_mgr_ref/0, get_testspec_terms/0, get_testspec_terms/1, encrypt_config_file/2, encrypt_config_file/3, decrypt_config_file/2, decrypt_config_file/3]). -export([get_target_name/1]). -export([get_progname/0]). -export([parse_table/1, listenv/1]). -export([remaining_test_procs/0]). %%---------------------------------------------------------------------- %% Exported types %%---------------------------------------------------------------------- %% For ct_gen_conn -export_type([config_key/0, target_name/0, key_or_name/0]). %% For cth_conn_log -export_type([conn_log_options/0, conn_log_type/0, conn_log_mod/0]). %%------------------------------------------------------------------ %% Type declarations %% ------------------------------------------------------------------ -type config_key() :: atom(). % Config key which exists in a config file -type target_name() :: atom().% Name associated to a config_key() though 'require' -type key_or_name() :: config_key() | target_name(). %% Types used when logging connections with the 'cth_conn_log' hook -type conn_log_options() :: [conn_log_option()]. -type conn_log_option() :: {log_type,conn_log_type()} | {hosts,[key_or_name()]}. -type conn_log_type() :: raw | pretty | html | silent. -type conn_log_mod() :: ct_netconfc | ct_telnet. %%---------------------------------------------------------------------- install(Opts) -> ct_run:install(Opts). run(TestDir,Suite,Cases) -> ct_run:run(TestDir,Suite,Cases). run(TestDir,Suite) -> ct_run:run(TestDir,Suite). run(TestDirs) -> ct_run:run(TestDirs). run_test(Opts) -> ct_run:run_test(Opts). run_testspec(TestSpec) -> ct_run:run_testspec(TestSpec). step(TestDir,Suite,Case) -> ct_run:step(TestDir,Suite,Case). step(TestDir,Suite,Case,Opts) -> ct_run:step(TestDir,Suite,Case,Opts). start_interactive() -> _ = ct_util:start(interactive), ok. stop_interactive() -> ct_util:stop(normal), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% MISC INTERFACE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% require(Required) -> ct_config:require(Required). require(Name,Required) -> ct_config:require(Name,Required). get_config(Required) -> ct_config:get_config(Required,undefined,[]). get_config(Required,Default) -> ct_config:get_config(Required,Default,[]). get_config(Required,Default,Opts) -> ct_config:get_config(Required,Default,Opts). reload_config(Required)-> ct_config:reload_config(Required). get_testspec_terms() -> case ct_util:get_testdata(testspec) of undefined -> undefined; CurrSpecRec -> ct_testspec:testspec_rec2list(CurrSpecRec) end. get_testspec_terms(Tags) -> case ct_util:get_testdata(testspec) of undefined -> undefined; CurrSpecRec -> ct_testspec:testspec_rec2list(Tags, CurrSpecRec) end. escape_chars(IoList) -> ct_logs:escape_chars(IoList). escape_chars(Format, Args) -> try io_lib:format(Format, Args) of IoList -> ct_logs:escape_chars(IoList) catch _:Reason -> {error,Reason} end. log(Format) -> log(default,?STD_IMPORTANCE,Format,[],[]). log(X1,X2) -> {Category,Importance,Format,Args} = if is_atom(X1) -> {X1,?STD_IMPORTANCE,X2,[]}; is_integer(X1) -> {default,X1,X2,[]}; is_list(X1) -> {default,?STD_IMPORTANCE,X1,X2} end, log(Category,Importance,Format,Args,[]). log(X1,X2,X3) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,[],[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,[]}; is_integer(X1) -> {default,X1,X2,X3,[]}; is_list(X1), is_list(X2) -> {default,?STD_IMPORTANCE,X1,X2,X3} end, log(Category,Importance,Format,Args,Opts). log(X1,X2,X3,X4) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,X4,[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,X4}; is_integer(X1) -> {default,X1,X2,X3,X4} end, log(Category,Importance,Format,Args,Opts). log(Category,Importance,Format,Args,Opts) -> ct_logs:tc_log(Category,Importance,Format,Args,Opts). print(Format) -> print(default,?STD_IMPORTANCE,Format,[],[]). print(X1,X2) -> {Category,Importance,Format,Args} = if is_atom(X1) -> {X1,?STD_IMPORTANCE,X2,[]}; is_integer(X1) -> {default,X1,X2,[]}; is_list(X1) -> {default,?STD_IMPORTANCE,X1,X2} end, print(Category,Importance,Format,Args,[]). print(X1,X2,X3) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,[],[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,[]}; is_integer(X1) -> {default,X1,X2,X3,[]}; is_list(X1), is_list(X2) -> {default,?STD_IMPORTANCE,X1,X2,X3} end, print(Category,Importance,Format,Args,Opts). print(X1,X2,X3,X4) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,X4,[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,X4}; is_integer(X1) -> {default,X1,X2,X3,X4} end, print(Category,Importance,Format,Args,Opts). print(Category,Importance,Format,Args,Opts) -> ct_logs:tc_print(Category,Importance,Format,Args,Opts). pal(Format) -> pal(default,?STD_IMPORTANCE,Format,[]). pal(X1,X2) -> {Category,Importance,Format,Args} = if is_atom(X1) -> {X1,?STD_IMPORTANCE,X2,[]}; is_integer(X1) -> {default,X1,X2,[]}; is_list(X1) -> {default,?STD_IMPORTANCE,X1,X2} end, pal(Category,Importance,Format,Args,[]). pal(X1,X2,X3) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,[],[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,[]}; is_integer(X1) -> {default,X1,X2,X3,[]}; is_list(X1), is_list(X2) -> {default,?STD_IMPORTANCE,X1,X2,X3} end, pal(Category,Importance,Format,Args,Opts). pal(X1,X2,X3,X4) -> {Category,Importance,Format,Args,Opts} = if is_atom(X1), is_integer(X2) -> {X1,X2,X3,X4,[]}; is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,X4}; is_integer(X1) -> {default,X1,X2,X3,X4} end, pal(Category,Importance,Format,Args,Opts). pal(Category,Importance,Format,Args,Opts) -> ct_logs:tc_pal(Category,Importance,Format,Args,Opts). set_verbosity(Category, Level) -> ct_util:set_verbosity({Category,Level}). get_verbosity(Category) -> ct_util:get_verbosity(Category). capture_start() -> test_server:capture_start(). capture_stop() -> test_server:capture_stop(). capture_get() -> %% remove default log printouts (e.g. ct:log/2 printouts) capture_get([default]). capture_get([ExclCat | ExclCategories]) -> Strs = test_server:capture_get(), CatsStr = [atom_to_list(ExclCat) | [[$| | atom_to_list(EC)] || EC <- ExclCategories]], {ok,MP} = re:compile("