From fd55862c24edbb47e7c632395d21bd1aeefd6d42 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Tue, 15 Nov 2011 13:43:36 +0100 Subject: Make absolute paths in log files relative --- lib/common_test/src/ct_framework.erl | 8 ++--- lib/common_test/src/ct_logs.erl | 62 ++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 14 deletions(-) (limited to 'lib/common_test') diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 26c71dfb42..0897675591 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -27,7 +27,7 @@ -export([init_tc/3, end_tc/3, end_tc/4, get_suite/2, get_all_cases/1]). -export([report/2, warn/1, error_notification/4]). --export([get_logopts/0, format_comment/1, get_html_wrapper/2]). +-export([get_logopts/0, format_comment/1, get_html_wrapper/3]). -export([error_in_suite/1, ct_init_per_group/2, ct_end_per_group/2]). @@ -1411,6 +1411,6 @@ format_comment(Comment) -> "" ++ Comment ++ "". %%%----------------------------------------------------------------- -%%% @spec get_html_wrapper(TestName, PrintLabel) -> Header -get_html_wrapper(TestName, PrintLabel) -> - ct_logs:get_ts_html_wrapper(TestName, PrintLabel). +%%% @spec get_html_wrapper(TestName, PrintLabel, Cwd) -> Header +get_html_wrapper(TestName, PrintLabel, Cwd) -> + ct_logs:get_ts_html_wrapper(TestName, PrintLabel, Cwd). diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index eea03b1db4..d66a31d9a5 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -35,7 +35,7 @@ -export([add_external_logs/1,add_link/3]). -export([make_last_run_index/0]). -export([make_all_suites_index/1,make_all_runs_index/1]). --export([get_ts_html_wrapper/2]). +-export([get_ts_html_wrapper/3]). %% Logging stuff directly from testcase -export([tc_log/3,tc_print/3,tc_pal/3,ct_log/3, @@ -213,6 +213,7 @@ cast(Msg) -> %%%

This function is called by ct_framework:init_tc/3

init_tc(RefreshLog) -> call({init_tc,self(),group_leader(),RefreshLog}), + io:format(xhtml("", "
")), ok. %%%----------------------------------------------------------------- @@ -222,6 +223,7 @@ init_tc(RefreshLog) -> %%% %%%

This function is called by ct_framework:end_tc/3

end_tc(TCPid) -> + io:format(xhtml("
", "
")), %% use call here so that the TC process will wait and receive %% possible exit signals from ct_logs before end_tc returns ok call({end_tc,TCPid}). @@ -1159,7 +1161,8 @@ header1(Title, SubTitle) -> xhtml("\n
\n", "\n
\n")]; true -> xhtml("
\n", "
\n") end, - CSSFile = locate_default_css_file(), + CSSFile = xhtml(fun() -> "" end, + fun() -> make_relative(locate_default_css_file()) end), [xhtml(["\n", "\n"], [" "" ++ Title ++ " " ++ SubTitle ++ "\n", "\n", xhtml("", - [""]), + [""]), "\n", body_tag(), "
\n", @@ -1953,10 +1956,16 @@ last_test([], Latest) -> %%% %%% @doc %%% +xhtml(HTML, XHTML) when is_function(HTML), + is_function(XHTML) -> + case get(basic_html) of + true -> HTML(); + _ -> XHTML() + end; xhtml(HTML, XHTML) -> case get(basic_html) of true -> HTML; - _ -> XHTML + _ -> XHTML end. %%%----------------------------------------------------------------- @@ -2020,11 +2029,41 @@ locate_default_css_file() -> end. %%%----------------------------------------------------------------- -%%% @spec get_ts_html_wrapper(TestName, PrintLabel) -> {Mode,Header,Footer} +%%% @spec make_relative(AbsDir, Cwd) -> RelDir +%%% +%%% @doc Return directory path to File (last element of AbsDir), which +%%% is the path relative to Cwd. Examples when Cwd == "/ldisk/test/logs": +%%% make_relative("/ldisk/test/logs/run/trace.log") -> "run/trace.log" +%%% make_relative("/ldisk/test/trace.log") -> "../trace.log" +%%% make_relative("/ldisk/test/logs/trace.log") -> "trace.log" +make_relative(AbsDir) -> + {ok,Cwd} = file:get_cwd(), + make_relative(AbsDir, Cwd). + +make_relative(AbsDir, Cwd) -> + DirTokens = filename:split(AbsDir), + CwdTokens = filename:split(Cwd), + filename:join(make_relative1(DirTokens, CwdTokens)). + +make_relative1([T | DirTs], [T | CwdTs]) -> + make_relative1(DirTs, CwdTs); +make_relative1(Last = [_File], []) -> + Last; +make_relative1(Last = [_File], CwdTs) -> + Ups = ["../" || _ <- CwdTs], + Ups ++ Last; +make_relative1(DirTs, []) -> + DirTs; +make_relative1(DirTs, CwdTs) -> + Ups = ["../" || _ <- CwdTs], + Ups ++ DirTs. + +%%%----------------------------------------------------------------- +%%% @spec get_ts_html_wrapper(TestName, PrintLabel, Cwd) -> {Mode,Header,Footer} %%% %%% @doc %%% -get_ts_html_wrapper(TestName, PrintLabel) -> +get_ts_html_wrapper(TestName, PrintLabel, Cwd) -> TestName1 = if is_list(TestName) -> lists:flatten(TestName); true -> @@ -2046,8 +2085,10 @@ get_ts_html_wrapper(TestName, PrintLabel) -> end, CTPath = code:lib_dir(common_test), {ok,CtLogdir} = get_log_dir(true), - AllRuns = filename:join(filename:dirname(CtLogdir), ?all_runs_name), - TestIndex = filename:join(filename:dirname(CtLogdir), ?index_name), + AllRuns = make_relative(filename:join(filename:dirname(CtLogdir), + ?all_runs_name), Cwd), + TestIndex = make_relative(filename:join(filename:dirname(CtLogdir), + ?index_name), Cwd), case Basic of true -> TileFile = filename:join(filename:join(CTPath,"priv"),"tile1.jpg"), @@ -2082,14 +2123,15 @@ get_ts_html_wrapper(TestName, PrintLabel) -> "Open Telecom Platform
\n", "Updated: ", current_time(), "", "
\n\n"], - CSSFile = locate_default_css_file(), + CSSFile = xhtml(fun() -> "" end, + fun() -> make_relative(locate_default_css_file(), Cwd) end), {xhtml, ["\n", "\n", "\n", TestName1, "\n", "\n", - "", + "", "\n","\n", LabelStr, "\n"], ["
\n

\n", -- cgit v1.2.3