From 31b52954dc667861a2e7cd4edba100132499cd5f Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Tue, 29 Jun 2010 17:13:05 +0200 Subject: Add new option to label test runs With the option 'label', the test run gets a user defined name that Common Test prints in the overview log files. --- lib/common_test/src/ct_logs.erl | 66 +++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 13 deletions(-) (limited to 'lib/common_test/src/ct_logs.erl') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 5683d06aa7..3ed0ea5c40 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -716,7 +716,7 @@ make_last_run_index1(StartTime,IndexName) -> [Log]; Logs -> case read_totals_file(?totals_name) of - {_Node,Logs0,_Totals} -> + {_Node,_Lbl,Logs0,_Totals} -> insert_dirs(Logs,Logs0); _ -> %% someone deleted the totals file!? @@ -728,10 +728,15 @@ make_last_run_index1(StartTime,IndexName) -> {ok,Bin} -> binary_to_term(Bin); _ -> [] end, - {ok,Index0,Totals} = make_last_run_index(Logs1, index_header(StartTime), + Label = case application:get_env(common_test, test_label) of + {ok,Lbl} -> Lbl; + _ -> undefined + end, + {ok,Index0,Totals} = make_last_run_index(Logs1, + index_header(Label,StartTime), 0, 0, 0, 0, 0, Missing), %% write current Totals to file, later to be used in all_runs log - write_totals_file(?totals_name,Logs1,Totals), + write_totals_file(?totals_name,Label,Logs1,Totals), Index = [Index0|index_footer()], case force_write_file(IndexName, Index) of ok -> @@ -937,8 +942,16 @@ term_to_text(Term) -> %%% Headers and footers. -index_header(StartTime) -> - [header("Test Results " ++ format_time(StartTime)) | +index_header(Label, StartTime) -> + Head = + case Label of + undefined -> + header("Test Results", format_time(StartTime)); + _ -> + header("Test Results for \"" ++ Label ++ "\"", + format_time(StartTime)) + end, + [Head | ["
\n", "

Common Test Framework Log

", " "BGCOLOR=\"",?table_color1,"\">\n" "\n" "\n" + "\n" "\n" "\n" "\n" @@ -987,12 +1001,23 @@ all_runs_header() -> "\n"]]. header(Title) -> + header1(Title, ""). +header(Title, SubTitle) -> + header1(Title, SubTitle). + +header1(Title, SubTitle) -> + SubTitleHTML = if SubTitle =/= "" -> + ["
\n", + "

" ++ SubTitle ++ "

\n", + "
\n
\n"]; + true -> "
\n" + end, ["\n" "\n" "\n", "\n", - "" ++ Title ++ "\n", + "" ++ Title ++ " " ++ SubTitle ++ "\n", "\n", "\n", @@ -1004,6 +1029,7 @@ header(Title) -> "
\n", "

" ++ Title ++ "

\n", "
\n", + SubTitleHTML, "\n"]. @@ -1217,7 +1243,7 @@ runentry(Dir, BasicHtml) -> TotalsFile = filename:join(Dir,?totals_name), TotalsStr = case read_totals_file(TotalsFile) of - {Node,Logs,{TotSucc,TotFail,UserSkip,AutoSkip,NotBuilt}} -> + {Node,Label,Logs,{TotSucc,TotFail,UserSkip,AutoSkip,NotBuilt}} -> TotFailStr = if TotFail > 0 -> ["", @@ -1263,6 +1289,7 @@ runentry(Dir, BasicHtml) -> end, Total = TotSucc+TotFail+AllSkip, A = ["\n", + "\n", "\n"], B = if BasicHtml -> ["\n"]; @@ -1286,14 +1313,16 @@ runentry(Dir, BasicHtml) -> "\n" "\n"]. -write_totals_file(Name,Logs,Totals) -> +write_totals_file(Name,Label,Logs,Totals) -> AbsName = ?abs(Name), notify_and_lock_file(AbsName), force_write_file(AbsName, term_to_binary({atom_to_list(node()), - Logs,Totals})), + Label,Logs,Totals})), notify_and_unlock_file(AbsName). +%% this function needs to convert from old formats to new so that old +%% test results (prev ct versions) can be listed together with new read_totals_file(Name) -> AbsName = ?abs(Name), notify_and_lock_file(AbsName), @@ -1303,12 +1332,23 @@ read_totals_file(Name) -> case catch binary_to_term(Bin) of {'EXIT',_Reason} -> % corrupt file {"-",[],undefined}; - R = {Node,Ls,Tot} -> + {Node,Label,Ls,Tot} -> % all info available + Label1 = case Label of + undefined -> "-"; + _ -> Label + end, + case Tot of + {_Ok,_Fail,_USkip,_ASkip,_NoBuild} -> % latest format + {Node,Label1,Ls,Tot}; + {TotSucc,TotFail,AllSkip,NotBuilt} -> + {Node,Label1,Ls,{TotSucc,TotFail,AllSkip,undefined,NotBuilt}} + end; + {Node,Ls,Tot} -> % no label found case Tot of - {_,_,_,_,_} -> % latest format - R; + {_Ok,_Fail,_USkip,_ASkip,_NoBuild} -> % latest format + {Node,"-",Ls,Tot}; {TotSucc,TotFail,AllSkip,NotBuilt} -> - {Node,Ls,{TotSucc,TotFail,AllSkip,undefined,NotBuilt}} + {Node,"-",Ls,{TotSucc,TotFail,AllSkip,undefined,NotBuilt}} end; %% for backwards compatibility {Ls,Tot} -> {"-",Ls,Tot}; -- cgit v1.2.3 From 79851b599df5caf5e2101d834a843e3837c6a6ae Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Tue, 29 Jun 2010 18:03:09 +0200 Subject: Improve handling of test case group specifications --- lib/common_test/src/ct_logs.erl | 51 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'lib/common_test/src/ct_logs.erl') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 3ed0ea5c40..bb859d3b72 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -57,7 +57,7 @@ -define(table_color2,"#E4F0FE"). -define(table_color3,"#F0F8FF"). --define(testname_width, 70). +-define(testname_width, 55). -define(abs(Name), filename:absname(Name)). @@ -766,7 +766,7 @@ make_last_run_index([Name|Rest], Result, TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuilt, Missing); LastLogDir -> SuiteName = filename:rootname(filename:basename(Name)), - case make_one_index_entry(SuiteName, LastLogDir, false, Missing) of + case make_one_index_entry(SuiteName, LastLogDir, "-", false, Missing) of {Result1,Succ,Fail,USkip,ASkip,NotBuilt} -> %% for backwards compatibility AutoSkip1 = case catch AutoSkip+ASkip of @@ -785,18 +785,18 @@ make_last_run_index([], Result, TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuil {ok, [Result|total_row(TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuilt, false)], {TotSucc,TotFail,UserSkip,AutoSkip,TotNotBuilt}}. -make_one_index_entry(SuiteName, LogDir, All, Missing) -> +make_one_index_entry(SuiteName, LogDir, Label, All, Missing) -> case count_cases(LogDir) of {Succ,Fail,UserSkip,AutoSkip} -> NotBuilt = not_built(SuiteName, LogDir, All, Missing), - NewResult = make_one_index_entry1(SuiteName, LogDir, Succ, Fail, + NewResult = make_one_index_entry1(SuiteName, LogDir, Label, Succ, Fail, UserSkip, AutoSkip, NotBuilt, All), {NewResult,Succ,Fail,UserSkip,AutoSkip,NotBuilt}; error -> error end. -make_one_index_entry1(SuiteName, Link, Success, Fail, UserSkip, AutoSkip, +make_one_index_entry1(SuiteName, Link, Label, Success, Fail, UserSkip, AutoSkip, NotBuilt, All) -> LogFile = filename:join(Link, ?suitelog_name ++ ".html"), CrashDumpName = SuiteName ++ "_erl_crash.dump", @@ -857,6 +857,7 @@ make_one_index_entry1(SuiteName, Link, Success, Fail, UserSkip, AutoSkip, end, ["\n", "\n", + Label, Timestamp, "\n", "\n", @@ -956,7 +957,7 @@ index_header(Label, StartTime) -> "

Common Test Framework Log

", "
HistoryNodeLabelTestsNamesTotal",Node,"",Label,"",NoOfTests,"",TestNamesTrunc,"",timestamp(Dir),"",TotalsStr,"
",SuiteName,"",CrashDumpLink,"",integer_to_list(Success),"",FailStr,"
\n" - "\n", + "\n", "\n" "\n", @@ -965,13 +966,17 @@ index_header(Label, StartTime) -> "\n"]]. all_suites_index_header() -> + {ok,Cwd} = file:get_cwd(), + LogDir = filename:basename(Cwd), + AllRuns = "All test runs in \"" ++ LogDir ++ "\"", [header("Test Results") | ["
\n", - "All Test Runs in this directory\n", + "",AllRuns,"\n", "

\n", "
NameTest Name_Ok" "_Failed
\n" - "\n", + "\n", + "\n", "\n", "\n" @@ -984,14 +989,17 @@ all_suites_index_header() -> "\n"]]. all_runs_header() -> - [header("All test runs in current directory") | + {ok,Cwd} = file:get_cwd(), + LogDir = filename:basename(Cwd), + Title = "All test runs in \"" ++ LogDir ++ "\"", + [header(Title) | ["
NameTest NameLabelTest Run Started_Ok" "_
\n" "\n" "\n" "\n" "\n" - "\n" + "\n" "\n" "\n" @@ -1451,7 +1459,7 @@ make_all_suites_index1(When,AllSuitesLogDirs) -> make_all_suites_index2(IndexName,AllSuitesLogDirs) -> {ok,Index0,_Totals} = make_all_suites_index3(AllSuitesLogDirs, all_suites_index_header(), - 0, 0, 0, 0, 0), + 0, 0, 0, 0, 0, []), Index = [Index0|index_footer()], case force_write_file(IndexName, Index) of ok -> @@ -1461,14 +1469,25 @@ make_all_suites_index2(IndexName,AllSuitesLogDirs) -> end. make_all_suites_index3([{SuiteName,[LastLogDir|OldDirs]}|Rest], - Result, TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuilt) -> + Result, TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuilt, + Labels) -> [EntryDir|_] = filename:split(LastLogDir), Missing = case file:read_file(filename:join(EntryDir,?missing_suites_info)) of {ok,Bin} -> binary_to_term(Bin); _ -> [] end, - case make_one_index_entry(SuiteName, LastLogDir, {true,OldDirs}, Missing) of + {Label,Labels1} = + case proplists:get_value(EntryDir, Labels) of + undefined -> + case read_totals_file(filename:join(EntryDir,?totals_name)) of + {_,Lbl,_,_} -> {Lbl,[{EntryDir,Lbl}|Labels]}; + _ -> {"-",[{EntryDir,"-"}|Labels]} + end; + Lbl -> + {Lbl,Labels} + end, + case make_one_index_entry(SuiteName, LastLogDir, Label, {true,OldDirs}, Missing) of {Result1,Succ,Fail,USkip,ASkip,NotBuilt} -> %% for backwards compatibility AutoSkip1 = case catch AutoSkip+ASkip of @@ -1477,13 +1496,13 @@ make_all_suites_index3([{SuiteName,[LastLogDir|OldDirs]}|Rest], end, make_all_suites_index3(Rest, [Result|Result1], TotSucc+Succ, TotFail+Fail, UserSkip+USkip, AutoSkip1, - TotNotBuilt+NotBuilt); + TotNotBuilt+NotBuilt,Labels1); error -> make_all_suites_index3(Rest, Result, TotSucc, TotFail, - UserSkip, AutoSkip, TotNotBuilt) + UserSkip, AutoSkip, TotNotBuilt,Labels1) end; make_all_suites_index3([], Result, TotSucc, TotFail, UserSkip, AutoSkip, - TotNotBuilt) -> + TotNotBuilt,_) -> {ok, [Result|total_row(TotSucc, TotFail, UserSkip, AutoSkip, TotNotBuilt,true)], {TotSucc,TotFail,UserSkip,AutoSkip,TotNotBuilt}}. -- cgit v1.2.3 From afbd6fa341f89211697a3c3f59f888b8247aa7f4 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Thu, 1 Jul 2010 15:46:13 +0200 Subject: Add textured backgound to html log files The overview html log files now have a textured background. This default new look can be switched off with the 'basic_html' option. --- lib/common_test/src/ct_logs.erl | 68 +++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'lib/common_test/src/ct_logs.erl') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index bb859d3b72..004d0d2540 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -36,7 +36,8 @@ -export([make_all_suites_index/1,make_all_runs_index/1]). %% Logging stuff directly from testcase --export([tc_log/3,tc_print/3,tc_pal/3]). +-export([tc_log/3,tc_print/3,tc_pal/3, + basic_html/0]). %% Simulate logger process for use without ct environment running -export([simulate/0]). @@ -57,7 +58,7 @@ -define(table_color2,"#E4F0FE"). -define(table_color3,"#F0F8FF"). --define(testname_width, 55). +-define(testname_width, 60). -define(abs(Name), filename:absname(Name)). @@ -808,7 +809,7 @@ make_one_index_entry1(SuiteName, Link, Label, Success, Fail, UserSkip, AutoSkip, false -> "" end, - {Timestamp,Node,AllInfo} = + {Lbl,Timestamp,Node,AllInfo} = case All of {true,OldRuns} -> [_Prefix,NodeOrDate|_] = string:tokens(Link,"."), @@ -816,20 +817,21 @@ make_one_index_entry1(SuiteName, Link, Label, Success, Fail, UserSkip, AutoSkip, 0 -> "-"; _ -> NodeOrDate end, - N = ["\n"], + N = ["\n"], CtRunDir = filename:dirname(filename:dirname(Link)), - T = ["\n"], + L = ["\n"], + T = ["\n"], CtLogFile = filename:join(CtRunDir,?ct_log_name), OldRunsLink = case OldRuns of [] -> "none"; _ -> "Old Runs" end, - A=["\n", - "\n"], - {T,N,A}; + A=["\n", + "\n"], + {L,T,N,A}; false -> - {"","",""} + {"","","",""} end, NotBuiltStr = if NotBuilt == 0 -> @@ -856,8 +858,8 @@ make_one_index_entry1(SuiteName, Link, Label, Success, Fail, UserSkip, AutoSkip, {UserSkip+AutoSkip,integer_to_list(UserSkip),ASStr} end, ["\n", - "\n", - Label, + "\n", + Lbl, Timestamp, "\n", "\n", @@ -868,12 +870,14 @@ make_one_index_entry1(SuiteName, Link, Label, Success, Fail, UserSkip, AutoSkip, AllInfo, "\n"]. total_row(Success, Fail, UserSkip, AutoSkip, NotBuilt, All) -> - {TimestampCell,AllInfo} = + {Label,TimestampCell,AllInfo} = case All of - true -> - {"\n","\n\n"}; + true -> + {"\n", + "\n", + "\n\n"}; false -> - {"",""} + {"","",""} end, {AllSkip,UserSkipStr,AutoSkipStr} = @@ -883,6 +887,7 @@ total_row(Success, Fail, UserSkip, AutoSkip, NotBuilt, All) -> end, ["\n", "", + Label, TimestampCell, "\n", "\n", @@ -1047,19 +1052,28 @@ index_footer() -> footer() -> ["

\n" - "
\n" - "

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

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

\n" + "
\n" + "

\n" + "Copyright © ", year(), + " Open Telecom Platform
\n" + "Updated: ", current_time(), "
\n" + "
\n" + "\n" + "\n"]. body_tag() -> - "\n". + case basic_html() of + true -> + "\n"; + false -> + CTPath = ct_util:get_ct_root(), + TileFile = filename:join(filename:join(filename:join(CTPath),"priv"),"tile1.jpg"), + "\n" + end. current_time() -> format_time(calendar:local_time()). @@ -1297,7 +1311,7 @@ runentry(Dir, BasicHtml) -> end, Total = TotSucc+TotFail+AllSkip, A = ["

\n", - "\n", + "\n", "\n"], B = if BasicHtml -> ["\n"]; @@ -1318,7 +1332,7 @@ runentry(Dir, BasicHtml) -> end, Index = filename:join(Dir,?index_name), ["\n" - "\n" + "\n" "\n"]. write_totals_file(Name,Label,Logs,Totals) -> -- cgit v1.2.3 From 311ed3490b2b9dc93433827a3941c14e40f41a2e Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Mon, 5 Jul 2010 23:38:58 +0200 Subject: Fix bug that crashes common_test when running cover --- lib/common_test/src/ct_logs.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/common_test/src/ct_logs.erl') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 004d0d2540..f8ae7202e6 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -1069,8 +1069,8 @@ body_tag() -> "\n"; false -> - CTPath = ct_util:get_ct_root(), - TileFile = filename:join(filename:join(filename:join(CTPath),"priv"),"tile1.jpg"), + CTPath = code:lib_dir(common_test), + TileFile = filename:join(filename:join(CTPath,"priv"),"tile1.jpg"), "\n" end. -- cgit v1.2.3
HistoryNodeLabelTestsNamesTest NamesTotal_Ok" "_",Node1,"",Node1,"",timestamp(CtRunDir),"",Label,"",timestamp(CtRunDir),"CT Log",OldRunsLink,"CT Log",OldRunsLink,"
",SuiteName,"",CrashDumpLink,"",SuiteName,"",CrashDumpLink,"",integer_to_list(Success),"",FailStr,"
       
Total",integer_to_list(Success),"",integer_to_list(Fail),"",Node,"",Label,"",Label,"",NoOfTests,"",TestNamesTrunc,"
",timestamp(Dir),"",TotalsStr,"",timestamp(Dir),"",TotalsStr,"