From be0c9a73c891a8d12a249abf558770f540f316e9 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Mon, 14 Nov 2011 17:02:22 +0100 Subject: Copy default CSS file to log directory before test run The log files should be independent of the Common Test installation. --- lib/common_test/priv/ct_default.css | 25 ++++----- lib/common_test/src/ct_logs.erl | 93 +++++++++++++++++++++++++++----- lib/test_server/src/test_server.erl | 1 + lib/test_server/src/test_server_ctrl.erl | 47 ++++++++-------- 4 files changed, 119 insertions(+), 47 deletions(-) diff --git a/lib/common_test/priv/ct_default.css b/lib/common_test/priv/ct_default.css index 94baf1f6f9..a64e1ec576 100644 --- a/lib/common_test/priv/ct_default.css +++ b/lib/common_test/priv/ct_default.css @@ -16,25 +16,25 @@ a:visited { h1 { font-family: verdana, arial, sans-serif; font-size: 200%; - letter-spacing: -2.5px; word-spacing: 2px; font-weight: bold; + letter-spacing: -2px; word-spacing: 2px; font-weight: bold; color: #3F3F3F; } h2 { font-family: verdana, arial, sans-serif; font-size: 175%; - letter-spacing: -2.5px; word-spacing: 2px; font-weight: normal; + letter-spacing: -2px; word-spacing: 2px; font-weight: normal; color: #3F3F3F; } h3 { font-family: verdana, arial, sans-serif; font-size: 140%; - letter-spacing: -2.5px; word-spacing: 2px; font-weight: bold; + letter-spacing: -2px; word-spacing: 2px; font-weight: bold; color: #3F3F3F; } h4 { font-family: verdana, arial, sans-serif; font-size: 120%; - letter-spacing: -2.5px; word-spacing: 2px; font-weight: normal; + letter-spacing: -2px; word-spacing: 2px; font-weight: normal; color: #3F3F3F; } @@ -49,9 +49,8 @@ ul { margin: 1em; } li { - font-family: "Trebuchet MS", "Lucida Sans Unicode", verdana, arial, sans-serif; - font-size: .9em; color: #000000; - margin: .4em 0; + font-size: 0.95em; color: #000000; + margin: .3em 0; } pre { @@ -67,31 +66,33 @@ code { } div.mono_sm { - font-family: "Courier New", monospace; font-size: 80%; + font-family: "Courier New", monospace; font-size: .75em; word-spacing: 1px; color: #000000; } div.mono_la { - font-family: "Courier New", monospace; font-size: 100%; + font-family: "Courier New", monospace; font-size: .8em; color: #000000; } div.copyright { padding: 20px 0px 0px 0px; - font-family: "Courier New", monospace; font-size: 80%; + font-family: "Courier New", monospace; font-size: .7em; color: #000000; } div.ct_internal { background: lightgrey; color: black; font-family: "Monaco", "Andale Mono", "Consolas", monospace; - font-size: 90%; + font-size: .95em; + margin: .2em 0 0 0; } div.default { background: lightgreen; color: black; font-family: "Monaco", "Andale Mono", "Consolas", monospace; - font-size: 90%; + font-size: 1.05em; + margin: .2em 0 0 0; } div.label { diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index af45ecf235..6ad962469f 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -55,6 +55,7 @@ -define(all_runs_name, "all_runs.html"). -define(index_name, "index.html"). -define(totals_name, "totals.info"). +-define(css_default, "ct_default.css"). -define(table_color1,"#ADD8E6"). -define(table_color2,"#E4F0FE"). @@ -167,9 +168,9 @@ get_log_dir() -> call({get_log_dir,false}). %%%----------------------------------------------------------------- -%%% @spec get_log_dir(Abs) -> {ok,Dir} | {error,Reason} -get_log_dir(Abs) -> - call({get_log_dir,Abs}). +%%% @spec get_log_dir(ReturnAbsName) -> {ok,Dir} | {error,Reason} +get_log_dir(ReturnAbsName) -> + call({get_log_dir,ReturnAbsName}). %%%----------------------------------------------------------------- %%% make_last_run_index() -> ok @@ -444,8 +445,6 @@ log_timestamp({MS,S,US}) -> logger(Parent,Mode) -> register(?MODULE,self()), - put(basic_html, basic_html()), - %%! Below is a temporary workaround for the limitation of %%! max one test run per second. %%! ---> @@ -457,7 +456,6 @@ logger(Parent,Mode) -> timer:sleep(1000), Time1 = calendar:local_time(), Dir1 = make_dirname(Time1), - {Time1,Dir1}; false -> {Time0,Dir0} @@ -466,6 +464,38 @@ logger(Parent,Mode) -> file:make_dir(Dir), AbsDir = ?abs(Dir), + put(ct_run_dir, AbsDir), + + 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(".", ?css_default), + CSSFileDestRun = filename:join(Dir, ?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", [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", [CSSFileDestRun, Reason1]), + exit({css_file_error,CSSFileDestRun}); + _ -> + ok + end + end + end, ct_event:notify(#event{name=start_logging,node=node(), data=AbsDir}), make_all_runs_index(start), @@ -670,7 +700,7 @@ set_evmgr_gl(GL) -> open_ctlog() -> {ok,Fd} = file:open(?ct_log_name,[write]), - io:format(Fd,header("Common Test Framework Log"),[]), + io:format(Fd, header("Common Test Framework Log"), []), case file:consult(ct_run:variables_file_name("../")) of {ok,Vars} -> io:format(Fd, config_table(Vars), []); @@ -741,7 +771,7 @@ print_style_error(Fd,StyleSheet,Reason) -> print_style(Fd,undefined). close_ctlog(Fd) -> - io:format(Fd,"",[]), + io:format(Fd,"\n\n",[]), io:format(Fd,footer(),[]), file:close(Fd). @@ -1126,8 +1156,7 @@ header1(Title, SubTitle) -> xhtml("\n
\n", "\n
\n")]; true -> xhtml("
\n", "
\n") end, - CTPath = code:lib_dir(common_test), - CSSFile = filename:join(filename:join(CTPath, "priv"), "ct_default.css"), + CSSFile = locate_default_css_file(), [xhtml(["\n", "\n"], [" false end. +%%%----------------------------------------------------------------- +%%% @spec locate_default_css_file() -> CSSFile +%%% +%%% @doc +%%% +locate_default_css_file() -> + {ok,CWD} = file:get_cwd(), + CSSFileInCwd = filename:join(CWD, ?css_default), + case filelib:is_file(CSSFileInCwd) of + true -> + CSSFileInCwd; + false -> + CSSResultFile = + case {whereis(?MODULE),self()} of + {Self,Self} -> + %% executed on the ct_logs process + filename:join(get(ct_run_dir), ?css_default); + _ -> + %% executed on other process than ct_logs + {ok,RunDir} = get_log_dir(true), + filename:join(RunDir, ?css_default) + end, + case filelib:is_file(CSSResultFile) of + true -> + CSSResultFile; + false -> + %% last resort, try use css file in CT installation + CTPath = code:lib_dir(common_test), + filename:join(filename:join(CTPath, "priv"), ?css_default) + end + end. + %%%----------------------------------------------------------------- %%% @spec get_ts_html_wrapper(TestName, PrintLabel) -> {Mode,Header,Footer} %%% %%% @doc %%% get_ts_html_wrapper(TestName, PrintLabel) -> - TestName1 = lists:flatten(io_lib:format("~p", [TestName])), + TestName1 = if is_list(TestName) -> + lists:flatten(TestName); + true -> + lists:flatten(io_lib:format("~p", [TestName])) + end, Basic = basic_html(), LabelStr = if not PrintLabel -> @@ -1994,7 +2059,7 @@ get_ts_html_wrapper(TestName, PrintLabel) -> {basic_html, ["\n", "\n", - "Test ", TestName1, " results\n", + "", TestName1, "\n", "\n", "\n", " "Open Telecom Platform
\n", "Updated: ", current_time(), "", "
\n\n"], - CSSFile = filename:join(filename:join(CTPath, "priv"), "ct_default.css"), + CSSFile = locate_default_css_file(), {xhtml, ["\n", "\n", - "\nTest ", TestName1, " results\n", + "\n", TestName1, "\n", "\n", "", "\n","\n", diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl index 0026b95872..2287d0fd5b 100644 --- a/lib/test_server/src/test_server.erl +++ b/lib/test_server/src/test_server.erl @@ -611,6 +611,7 @@ do_run_test_case_apply(Mod, Func, Args, Name, RunInit, TimetrapData) -> print(minor, "Test case started with:\n~s:~s(~p)\n", [Mod,Func,Args2Print]), print(minor, "Current directory is ~p\n", [Cwd]), print_timestamp(minor,"Started at "), + print(minor, "\n", []), TCCallback = get(test_server_testcase_callback), LogOpts = get(test_server_logopts), Ref = make_ref(), diff --git a/lib/test_server/src/test_server_ctrl.erl b/lib/test_server/src/test_server_ctrl.erl index 49cce9c429..14a77f5785 100644 --- a/lib/test_server/src/test_server_ctrl.erl +++ b/lib/test_server/src/test_server_ctrl.erl @@ -1692,23 +1692,24 @@ do_test_cases(TopCases, SkipCases, [print_if_known(N, {", ~w test cases",[N]}, {" (with repeated test cases)",[]})]), Test = get(test_server_name), - TestName = if is_list(Test) -> - lists:flatten(io_lib:format("~s", [Test])); - true -> - lists:flatten(io_lib:format("~p", [Test])) - end, + TestName = if is_list(Test) -> + lists:flatten(io_lib:format("~s", [Test])); + true -> + lists:flatten(io_lib:format("~p", [Test])) + end, + TestDescr = "Test " ++ TestName ++ " results", test_server_sup:framework_call(report, [tests_start,{Test,N}]), {Header,Footer} = case test_server_sup:framework_call(get_html_wrapper, - [Test,true], "") of + [TestDescr,true], "") of Empty when (Empty == "") ; (element(2,Empty) == "") -> put(basic_html, true), {["\n", "\n", "\n", - "Test ", TestName, " results\n", + "", TestDescr, "\n", "\n", "\n", "", "")), - print(html, xhtml("

HOST:
\n", "

HOST:
\n")), + print(html, xhtml("\n

Host info:
\n", + "\n

Host info:
\n")), print_who(test_server_sup:hoststr(), test_server_sup:get_username()), print(html, xhtml("
Used Erlang v~s in ~s

\n", "
Used Erlang v~s in \"~s\"

\n"), [erlang:system_info(version), code:root_dir()]), if FwMod == ?MODULE -> - print(html, xhtml("

TARGET:
\n", "

TARGET:
\n")), + print(html, xhtml("\n

Target Info:
\n", + "\n

Target Info:
\n")), print_who(TI#target_info.host, TI#target_info.username), print(html, xhtml("
Used Erlang v~s in ~s

\n", "
Used Erlang v~s in \"~s\"

\n"), @@ -1747,7 +1750,8 @@ do_test_cases(TopCases, SkipCases, case test_server_sup:framework_call(target_info, []) of TargetInfo when is_list(TargetInfo), length(TargetInfo) > 0 -> - print(html, xhtml("

TARGET:
\n", "

TARGET:
\n")), + print(html, xhtml("\n

Target info:
\n", + "\n

Target info:
\n")), print(html, "~s

\n", [TargetInfo]); _ -> ok @@ -1755,9 +1759,9 @@ do_test_cases(TopCases, SkipCases, end, print(html, - "

\n", [?suitelog_name,?coverlog_name]), print(html, "

~s

\n" ++ @@ -1908,16 +1912,16 @@ start_minor_log_file1(Mod, Func, LogDir, AbsName) -> Lev = get(test_server_minor_level)+1000, %% far down in the minor levels put(test_server_minor_fd, Fd), - TestName = io_lib:format("~p:~p", [Mod,Func]), + TestDescr = io_lib:format("Test ~p:~p result", [Mod,Func]), {Header,Footer} = case test_server_sup:framework_call(get_html_wrapper, - [TestName,false], "") of + [TestDescr,false], "") of Empty when (Empty == "") ; (element(2,Empty) == "") -> put(basic_html, true), {["\n", "\n", "\n", - "Test ", TestName, "\n", + "", TestDescr, "\n", "\n", "\n", " ok; % dest file up to date _ -> Header = - case test_server_sup:framework_call(get_html_header, - [Src,false], "") of + case test_server_sup:framework_call(get_html_wrapper, + ["Module "++Src,false], + "") of Empty when (Empty == "") ; (element(2,Empty) == "") -> ["\n", - "\n", + "\n", "\n", - "Test ", Src, "\n", + "Module ", Src, "\n", "\n", "\n", @@ -3618,7 +3623,7 @@ run_test_case1(Ref, Num, Mod, Func, Args, RunInit, Where, test_server_sup:framework_call(report, [tc_start,{?pl2a(Mod),Func}]), print(major, "=case ~p:~p", [Mod, Func]), MinorName = start_minor_log_file(Mod, Func), - print(minor, "", []), + print(minor, "", []), MinorBase = filename:basename(MinorName), print(major, "=logfile ~s", [filename:basename(MinorName)]), print_props((RunInit==skip_init), get_props(Mode)), @@ -3642,7 +3647,7 @@ run_test_case1(Ref, Num, Mod, Func, Args, RunInit, Where, {died,DReason,DLoc,DCmt} -> {died,DReason,DLoc,[],DCmt} end, - print(minor, "", []), + print(minor, "", []), print_timestamp(minor, "Ended at "), print(major, "=ended ~s", [lists:flatten(timestamp_get(""))]), -- cgit v1.2.3