From c2a3647e471bb08de24d867bc7c3f541e2f7a15d Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Tue, 20 Mar 2012 01:29:02 +0100 Subject: Implement support for user controlled timetraps OTP-9988 --- lib/common_test/src/ct.erl | 14 +++++++++++--- lib/common_test/src/ct_framework.erl | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 63a8adbc63..296416737f 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -993,13 +993,21 @@ remove_config(Callback, Config) -> %%%----------------------------------------------------------------- %%% @spec timetrap(Time) -> ok -%%% Time = {hours,Hours} | {minutes,Mins} | {seconds,Secs} | Millisecs | infinity +%%% Time = {hours,Hours} | {minutes,Mins} | {seconds,Secs} | Millisecs | infinity | Func %%% Hours = integer() %%% Mins = integer() %%% Secs = integer() %%% Millisecs = integer() | float() -%%% -%%% @doc

Use this function to set a new timetrap for the running test case.

+%%% Func = {M,F,A} | fun() +%%% M = atom() +%%% F = atom() +%%% A = list() +%%% +%%% @doc

Use this function to set a new timetrap for the running test case. +%%% If the argument is Func, the timetrap will be triggered +%%% when this function returns. Func may also return a new +%%% Time value, which in that case will be the value for the +%%% new timetrap.

timetrap(Time) -> test_server:timetrap_cancel(), test_server:timetrap(Time). diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 187794e78b..c8aff3c039 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -212,7 +212,7 @@ init_tc2(Mod,Suite,Func,SuiteInfo,MergeResult,Config) -> {auto_skip,{require_failed,Reason}}; {'EXIT',Reason} -> {auto_skip,Reason}; - {ok,FinalConfig} -> + {ok,Config1} -> case MergeResult of {error,Reason} -> %% suite0 configure finished now, report that @@ -221,9 +221,9 @@ init_tc2(Mod,Suite,Func,SuiteInfo,MergeResult,Config) -> _ -> case get('$test_server_framework_test') of undefined -> - ct_suite_init(Suite, FuncSpec, FinalConfig); + ct_suite_init(Mod, FuncSpec, Config1); Fun -> - case Fun(init_tc, FinalConfig) of + case Fun(init_tc, Config1) of NewConfig when is_list(NewConfig) -> {ok,NewConfig}; Else -> -- cgit v1.2.3 From 07481665da8b71ce75e70eca62f8b980179d360c Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 21 Mar 2012 12:01:37 +0100 Subject: Fix dialyzer reported errors --- lib/common_test/src/ct_framework.erl | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 187794e78b..1ed707fcb0 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -213,22 +213,15 @@ init_tc2(Mod,Suite,Func,SuiteInfo,MergeResult,Config) -> {'EXIT',Reason} -> {auto_skip,Reason}; {ok,FinalConfig} -> - case MergeResult of - {error,Reason} -> - %% suite0 configure finished now, report that - %% first test case actually failed - {skip,Reason}; - _ -> - case get('$test_server_framework_test') of - undefined -> - ct_suite_init(Suite, FuncSpec, FinalConfig); - Fun -> - case Fun(init_tc, FinalConfig) of - NewConfig when is_list(NewConfig) -> - {ok,NewConfig}; - Else -> - Else - end + case get('$test_server_framework_test') of + undefined -> + ct_suite_init(Suite, FuncSpec, FinalConfig); + Fun -> + case Fun(init_tc, FinalConfig) of + NewConfig when is_list(NewConfig) -> + {ok,NewConfig}; + Else -> + Else end end end. @@ -346,16 +339,12 @@ get_suite_name(Mod, _) -> Mod. %% Check that alias names are not already in use -check_for_clashes(TCInfo, GrPathInfo, SuiteInfo) -> - {CurrGrInfo,SearchIn} = case GrPathInfo of - [] -> {[],[SuiteInfo]}; - [Curr|Path] -> {Curr,[SuiteInfo|Path]} - end, +check_for_clashes(TCInfo, [CurrGrInfo|Path], SuiteInfo) -> ReqNames = fun(Info) -> [element(2,R) || R <- Info, size(R) == 3, require == element(1,R)] end, - ExistingNames = lists:flatten([ReqNames(L) || L <- SearchIn]), + ExistingNames = lists:flatten([ReqNames(L) || L <- [SuiteInfo|Path]]), CurrGrReqNs = ReqNames(CurrGrInfo), GrClashes = [Name || Name <- CurrGrReqNs, true == lists:member(Name, ExistingNames)], -- cgit v1.2.3 From 390843117229d7d6e1e5f167aca9ea2ebe6df5f2 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 21 Mar 2012 16:03:46 +0100 Subject: Update ct_master to use the Common Test CSS file for the logs OTP-9973 --- lib/common_test/src/ct_logs.erl | 25 ++--- lib/common_test/src/ct_master.erl | 13 ++- lib/common_test/src/ct_master_logs.erl | 175 +++++++++++++++++++++------------ 3 files changed, 137 insertions(+), 76 deletions(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 0cd9b5f7cb..012f947fdd 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -36,6 +36,7 @@ -export([make_last_run_index/0]). -export([make_all_suites_index/1,make_all_runs_index/1]). -export([get_ts_html_wrapper/3]). +-export([xhtml/2, locate_default_css_file/0, make_relative/1]). %% Logging stuff directly from testcase -export([tc_log/3,tc_log/4,tc_log_async/3,tc_print/3,tc_pal/3,ct_log/3, @@ -1246,18 +1247,18 @@ header1(Title, SubTitle) -> ["\n", "\n"]), - "\n", - "\n", - "" ++ Title ++ " " ++ SubTitle ++ "\n", - "\n", - xhtml("", - [""]), - "\n", - body_tag(), - "
\n", - "

" ++ Title ++ "

\n", - "
\n", - SubTitleHTML,"\n"]. + "\n", + "\n", + "" ++ Title ++ " " ++ SubTitle ++ "\n", + "\n", + xhtml("", + [""]), + "\n", + body_tag(), + "
\n", + "

" ++ Title ++ "

\n", + "
\n", + SubTitleHTML,"\n"]. index_footer() -> ["\n" diff --git a/lib/common_test/src/ct_master.erl b/lib/common_test/src/ct_master.erl index 2ea2ba106a..0d32bb0072 100644 --- a/lib/common_test/src/ct_master.erl +++ b/lib/common_test/src/ct_master.erl @@ -25,6 +25,7 @@ -export([run/1,run/3,run/4]). -export([run_on_node/2,run_on_node/3]). -export([run_test/1,run_test/2]). +-export([basic_html/1]). -export([abort/0,abort/1,progress/0]). @@ -277,7 +278,17 @@ abort(Node) when is_atom(Node) -> progress() -> call(progress). - +%%%----------------------------------------------------------------- +%%% @spec basic_html(Bool) -> ok +%%% Bool = true | false +%%% +%%% @doc If set to true, the ct_master logs will be written on a +%%% primitive html format, not using the Common Test CSS style +%%% sheet. +basic_html(Bool) -> + application:set_env(common_test_master, basic_html, Bool), + ok. + %%%----------------------------------------------------------------- %%% MASTER, runs on central controlling node. %%%----------------------------------------------------------------- diff --git a/lib/common_test/src/ct_master_logs.erl b/lib/common_test/src/ct_master_logs.erl index 244faace06..8fd346670f 100644 --- a/lib/common_test/src/ct_master_logs.erl +++ b/lib/common_test/src/ct_master_logs.erl @@ -23,7 +23,8 @@ %%% node.

-module(ct_master_logs). --export([start/2, make_all_runs_index/0, log/3, nodedir/2, stop/0]). +-export([start/2, make_all_runs_index/0, log/3, nodedir/2, + stop/0]). -record(state, {log_fd, start_time, logdir, rundir, nodedir_ix_fd, nodes, nodedirs=[]}). @@ -32,6 +33,7 @@ -define(all_runs_name, "master_runs.html"). -define(nodedir_index_name, "index.html"). -define(details_file_name,"details.info"). +-define(css_default, "ct_default.css"). -define(table_color,"lightblue"). %%%-------------------------------------------------------------------- @@ -87,6 +89,40 @@ init(Parent,LogDir,Nodes) -> RunDirAbs = filename:join(LogDir,RunDir), file:make_dir(RunDirAbs), write_details_file(RunDirAbs,{node(),Nodes}), + + case basic_html() of + true -> + put(basic_html, true); + BasicHtml -> + put(basic_html, BasicHtml), + %% copy stylesheet to log dir (both top dir and test run + %% dir) so logs are independent of Common Test installation + CTPath = code:lib_dir(common_test), + CSSFileSrc = filename:join(filename:join(CTPath, "priv"), + ?css_default), + CSSFileDestTop = filename:join(LogDir, ?css_default), + CSSFileDestRun = filename:join(RunDirAbs, ?css_default), + case file:copy(CSSFileSrc, CSSFileDestTop) of + {error,Reason0} -> + io:format(user, "ERROR! "++ + "CSS file ~p could not be copied to ~p. "++ + "Reason: ~p~n", + [CSSFileSrc,CSSFileDestTop,Reason0]), + exit({css_file_error,CSSFileDestTop}); + _ -> + case file:copy(CSSFileSrc, CSSFileDestRun) of + {error,Reason1} -> + io:format(user, "ERROR! "++ + "CSS file ~p could not be copied to ~p. "++ + "Reason: ~p~n", + [CSSFileSrc,CSSFileDestRun,Reason1]), + exit({css_file_error,CSSFileDestRun}); + _ -> + ok + end + end + end, + make_all_runs_index(LogDir), CtLogFd = open_ct_master_log(RunDirAbs), NodeStr = @@ -164,8 +200,9 @@ open_ct_master_log(Dir) -> "\n", []), io:format(Fd, - "

Progress Log

\n" - "
\n",[]),
+	      xhtml("

Progress Log

\n
\n",
+		    "

Progress Log

\n
\n"),
+	      []),
     Fd.
 
 close_ct_master_log(Fd) ->
@@ -178,18 +215,10 @@ config_table(Vars) ->
 
 config_table_header() ->
     ["

Configuration

\n", - "\n"), "\n"]. -%% -%% keep for possible later use -%% -%%config_table1([{Key,Value}|Vars]) -> -%% ["\n", -%% "\n" | -%% config_table1(Vars)]; - config_table1([]) -> ["
KeyValue
", atom_to_list(Key), "
",io_lib:format("~p",[Value]),"
\n"]. @@ -210,10 +239,10 @@ open_nodedir_index(Dir,StartTime) -> print_nodedir(Node,RunDir,Fd) -> Index = filename:join(RunDir,"index.html"), io:format(Fd, - ["\n" - "",atom_to_list(Node),"\n", - "",Index,"\n", - "\n"],[]), + ["\n" + "",atom_to_list(Node),"\n", + "",Index,"\n", + "\n"],[]), ok. close_nodedir_index(Fd) -> @@ -222,12 +251,12 @@ close_nodedir_index(Fd) -> nodedir_index_header(StartTime) -> [header("Log Files " ++ format_time(StartTime)) | - ["
\n", - "

Common Test Master Log

", - "\n", - "\n", - "\n", + ["
\n", + "

Common Test Master Log

", + xhtml(["
NodeLog
\n"], "
\n"), + "\n", + "\n", "\n"]]. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -279,20 +308,20 @@ runentry(Dir) -> {"unknown",""} end, Index = filename:join(Dir,?nodedir_index_name), - ["\n" - "\n", - "\n", - "\n", - "\n"]. + ["\n" + "\n", + "\n", + "\n", + "\n"]. all_runs_header() -> [header("Master Test Runs") | - ["
\n", - "
NodeLog
",timestamp(Dir),"",MasterStr,"",NodesStr,"
",timestamp(Dir),"",MasterStr,"",NodesStr,"
\n" - "\n" - "\n" - "\n" + ["
\n", + xhtml(["
HistoryMaster HostTest Nodes
\n"], "
\n"), + "\n" + "\n" + "\n" "\n"]]. timestamp(Dir) -> @@ -318,44 +347,46 @@ read_details_file(Dir) -> %%%-------------------------------------------------------------------- header(Title) -> - ["\n" - "\n" - "\n", - "\n", - - "" ++ Title ++ "\n", - "\n", - - "\n", - + CSSFile = xhtml(fun() -> "" end, + fun() -> make_relative(locate_default_css_file()) end), + [xhtml(["\n", + "\n"], + ["\n", + "\n"]), + "\n", + "\n", + "" ++ Title ++ "\n", + "\n", + xhtml("", + [""]), + "\n", body_tag(), - - "\n", - - "
\n", - "

" ++ Title ++ "

\n", - "
\n", - - "\n"]. + "
\n", + "

" ++ Title ++ "

\n", + "
\n"]. index_footer() -> - ["
HistoryMaster HostTest Nodes
\n" - "
\n" | footer()]. + ["\n" + "\n" | footer()]. footer() -> - ["

\n" - "
\n" - "

\n" + ["

\n", + xhtml("

\n", "
\n"), + xhtml("

\n", "

"), "Copyright © ", year(), - " Open Telecom Platform
\n" - "Updated: ", current_time(), "
\n" - "
\n" - "
\n" + " Open Telecom Platform", + xhtml("
\n", "
\n"), + "Updated: ", current_time(), "", + xhtml("
\n", "
\n"), + xhtml("

\n", "\n"), + "
\n" "\n"]. body_tag() -> - "\n". + xhtml("\n", + "\n"). current_time() -> format_time(calendar:local_time()). @@ -404,6 +435,23 @@ log_timestamp(Now) -> lists:flatten(io_lib:format("~2.2.0w:~2.2.0w:~2.2.0w", [H,M,S])). +basic_html() -> + case application:get_env(common_test_master, basic_html) of + {ok,true} -> + true; + _ -> + false + end. + +xhtml(HTML, XHTML) -> + ct_logs:xhtml(HTML, XHTML). + +locate_default_css_file() -> + ct_logs:locate_default_css_file(). + +make_relative(Dir) -> + ct_logs:make_relative(Dir). + force_write_file(Name,Contents) -> force_delete(Name), file:write_file(Name,Contents). @@ -452,3 +500,4 @@ cast(Msg) -> _Pid -> ?MODULE ! Msg end. + -- cgit v1.2.3 From c75d6ef4e32affebd6e5a3a03bbbb18532940030 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 21 Mar 2012 18:09:30 +0100 Subject: Document the create_priv_dir option for ct:run_test/1 --- lib/common_test/src/ct.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 63a8adbc63..68ddce8068 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -146,7 +146,8 @@ run(TestDirs) -> %%% {silent_connections,Conns} | {stylesheet,CSSFile} | %%% {cover,CoverSpecFile} | {step,StepOpts} | %%% {event_handler,EventHandlers} | {include,InclDirs} | -%%% {auto_compile,Bool} | {multiply_timetraps,M} | {scale_timetraps,Bool} | +%%% {auto_compile,Bool} | {create_priv_dir,CreatePrivDir} | +%%% {multiply_timetraps,M} | {scale_timetraps,Bool} | %%% {repeat,N} | {duration,DurTime} | {until,StopTime} | %%% {force_stop,Bool} | {decrypt,DecryptKeyOrFile} | %%% {refresh_logs,LogDir} | {logopts,LogOpts} | {basic_html,Bool} | @@ -171,6 +172,7 @@ run(TestDirs) -> %%% EH = atom() | {atom(),InitArgs} | {[atom()],InitArgs} %%% InitArgs = [term()] %%% InclDirs = [string()] | string() +%%% CreatePrivDir = auto_per_run | auto_per_tc | manual_per_tc %%% M = integer() %%% N = integer() %%% DurTime = string(HHMMSS) -- cgit v1.2.3