diff options
author | Peter Andersson <[email protected]> | 2011-11-14 17:02:22 +0100 |
---|---|---|
committer | Peter Andersson <[email protected]> | 2011-11-14 17:02:22 +0100 |
commit | be0c9a73c891a8d12a249abf558770f540f316e9 (patch) | |
tree | 3a43efe972c55b451d39781c3f797abc4e61453c /lib | |
parent | 2cacf6885cafa276985324924a038618b0bb10fd (diff) | |
download | otp-be0c9a73c891a8d12a249abf558770f540f316e9.tar.gz otp-be0c9a73c891a8d12a249abf558770f540f316e9.tar.bz2 otp-be0c9a73c891a8d12a249abf558770f540f316e9.zip |
Copy default CSS file to log directory before test run
The log files should be independent of the Common Test installation.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common_test/priv/ct_default.css | 25 | ||||
-rw-r--r-- | lib/common_test/src/ct_logs.erl | 93 | ||||
-rw-r--r-- | lib/test_server/src/test_server.erl | 1 | ||||
-rw-r--r-- | 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,"</pre>",[]), + io:format(Fd,"\n</pre>\n",[]), io:format(Fd,footer(),[]), file:close(Fd). @@ -1126,8 +1156,7 @@ header1(Title, SubTitle) -> xhtml("</center>\n<br>\n", "</center>\n<br />\n")]; true -> xhtml("<br>\n", "<br />\n") end, - CTPath = code:lib_dir(common_test), - CSSFile = filename:join(filename:join(CTPath, "priv"), "ct_default.css"), + CSSFile = locate_default_css_file(), [xhtml(["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", "<html>\n"], ["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n", @@ -1956,12 +1985,48 @@ basic_html() -> 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, ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", "<html>\n", - "<head><title>Test ", TestName1, " results</title>\n", + "<head><title>", TestName1, "</title>\n", "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", "</head>\n", "<body", Bgr, " bgcolor=\"white\" text=\"black\" ", @@ -2014,12 +2079,12 @@ get_ts_html_wrapper(TestName, PrintLabel) -> "Open Telecom Platform</a><br />\n", "Updated: <!date>", current_time(), "<!/date>", "<br />\n</div>\n"], - CSSFile = filename:join(filename:join(CTPath, "priv"), "ct_default.css"), + CSSFile = locate_default_css_file(), {xhtml, ["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n", "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n", - "<head>\n<title>Test ", TestName1, " results</title>\n", + "<head>\n<title>", TestName1, "</title>\n", "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", "<link rel=\"stylesheet\" href=\"file:///", CSSFile, "\" type=\"text/css\">", "</head>\n","<body>\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), {["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", "<!-- autogenerated by '", atom_to_list(?MODULE), "'. -->\n", "<html>\n", - "<head><title>Test ", TestName, " results</title>\n", + "<head><title>", TestDescr, "</title>\n", "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", "</head>\n", "<body bgcolor=\"white\" text=\"black\" ", @@ -1731,14 +1732,16 @@ do_test_cases(TopCases, SkipCases, print_timestamp(html, "Test started at "), print(html, xhtml("</p>", "</h4>")), - print(html, xhtml("<p>HOST:<br>\n", "<p>HOST:<br />\n")), + print(html, xhtml("\n<p><b>Host info:</b><br>\n", + "\n<p><b>Host info:</b><br />\n")), print_who(test_server_sup:hoststr(), test_server_sup:get_username()), print(html, xhtml("<br>Used Erlang v~s in <tt>~s</tt></p>\n", "<br />Used Erlang v~s in \"~s\"</p>\n"), [erlang:system_info(version), code:root_dir()]), if FwMod == ?MODULE -> - print(html, xhtml("<p>TARGET:<br>\n", "<p>TARGET:<br />\n")), + print(html, xhtml("\n<p><b>Target Info:</b><br>\n", + "\n<p><b>Target Info:</b><br />\n")), print_who(TI#target_info.host, TI#target_info.username), print(html, xhtml("<br>Used Erlang v~s in <tt>~s</tt></p>\n", "<br />Used Erlang v~s in \"~s\"</p>\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("<p>TARGET:<br>\n", "<p>TARGET:<br />\n")), + print(html, xhtml("\n<p><b>Target info:</b><br>\n", + "\n<p><b>Target info:</b><br />\n")), print(html, "~s</p>\n", [TargetInfo]); _ -> ok @@ -1755,9 +1759,9 @@ do_test_cases(TopCases, SkipCases, end, print(html, - "<ul>\n" + "<p><ul>\n" "<li><a href=\"~s\">Full textual log</a></li>\n" - "<li><a href=\"~s\">Coverage log</a></li>\n</ul>\n", + "<li><a href=\"~s\">Coverage log</a></li>\n</ul></p>\n", [?suitelog_name,?coverlog_name]), print(html, "<p>~s</p>\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), {["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", "<!-- autogenerated by '", atom_to_list(?MODULE), "'. -->\n", "<html>\n", - "<head><title>Test ", TestName, "</title>\n", + "<head><title>", TestDescr, "</title>\n", "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", "</head>\n", "<body bgcolor=\"white\" text=\"black\" ", @@ -2038,14 +2042,15 @@ html_possibly_convert(Src, SrcInfo, Dest) -> 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) == "") -> ["<!DOCTYPE HTML PUBLIC", "\"-//W3C//DTD HTML 3.2 Final//EN\">\n", - "<!-- autogenerated by 'er2html2' -->\n", + "<!-- autogenerated by 'erl2html2' -->\n", "<html>\n", - "<head><title>Test ", Src, "</title>\n", + "<head><title>Module ", Src, "</title>\n", "<meta http-equiv=\"cache-control\" ", "content=\"no-cache\">\n", "</head>\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, "<a name=top></a>", []), + print(minor, "<a name=\"top\"></a>", []), 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, "<a name=end></a>", []), + print(minor, "<a name=\"end\"></a>", []), print_timestamp(minor, "Ended at "), print(major, "=ended ~s", [lists:flatten(timestamp_get(""))]), |