diff options
author | Peter Andersson <peppe@erlang.org> | 2014-03-03 21:45:34 +0100 |
---|---|---|
committer | Peter Andersson <peppe@erlang.org> | 2014-03-12 17:04:59 +0100 |
commit | ffa2475adee774d0fced95d47fffe4528d436dd0 (patch) | |
tree | 4a4ee57b53b7ad7355ad9877022ba3bb368dd35e /lib | |
parent | c9ef7945d7c1621ba6d51bb24dc1853f47e30cc5 (diff) | |
download | otp-ffa2475adee774d0fced95d47fffe4528d436dd0.tar.gz otp-ffa2475adee774d0fced95d47fffe4528d436dd0.tar.bz2 otp-ffa2475adee774d0fced95d47fffe4528d436dd0.zip |
Update event protocol and CT Hooks API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common_test/src/ct_framework.erl | 52 | ||||
-rw-r--r-- | lib/common_test/src/ct_hooks.erl | 13 | ||||
-rw-r--r-- | lib/test_server/src/test_server_ctrl.erl | 40 |
3 files changed, 61 insertions, 44 deletions
diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 1358ad1f60..94de9a3425 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -1277,28 +1277,35 @@ report(What,Data) -> ct_util:set_testdata({What,Data}), ok; tc_start -> - %% Data = {{Suite,GroupName,Func},LogFileName} + %% Data = {Suite,{Func,GroupName}},LogFileName} + Data1 = case Data of + {{Suite,{Func,undefined}},LFN} -> {{Suite,Func},LFN}; + _ -> Data + end, ct_event:sync_notify(#event{name=tc_logfile, node=node(), - data=Data}), + data=Data1}), ok; tc_done -> - {_Suite,_GroupName,Case,Result} = Data, + {Suite,{Func,GrName},Result} = Data, + Data1 = if GrName == undefined -> {Suite,Func,Result}; + true -> Data + end, case Result of {failed, _} -> - ct_hooks:on_tc_fail(What, Data); + ct_hooks:on_tc_fail(What, Data1); {skipped,{failed,{_,init_per_testcase,_}}} -> - ct_hooks:on_tc_skip(tc_auto_skip, Data); + ct_hooks:on_tc_skip(tc_auto_skip, Data1); {skipped,{require_failed,_}} -> - ct_hooks:on_tc_skip(tc_auto_skip, Data); + ct_hooks:on_tc_skip(tc_auto_skip, Data1); {skipped,_} -> - ct_hooks:on_tc_skip(tc_user_skip, Data); + ct_hooks:on_tc_skip(tc_user_skip, Data1); {auto_skipped,_} -> - ct_hooks:on_tc_skip(tc_auto_skip, Data); + ct_hooks:on_tc_skip(tc_auto_skip, Data1); _Else -> ok end, - case {Case,Result} of + case {Func,Result} of {init_per_suite,_} -> ok; {end_per_suite,_} -> @@ -1327,12 +1334,17 @@ report(What,Data) -> tc_user_skip -> %% test case or config function specified as skipped in testspec, %% or init config func for suite/group has returned {skip,Reason} - %% Data = {Suite,GroupName,Func,Comment} + %% Data = {Suite,{Func,GroupName},Comment} + {Func,Data1} = case Data of + {Suite,{F,undefined},Comment} -> + {F,{Suite,F,Comment}}; + D = {_,{F,_},_} -> + {F,D} + end, ct_event:sync_notify(#event{name=tc_user_skip, node=node(), - data=Data}), - ct_hooks:on_tc_skip(What, Data), - Func = element(3, Data), + data=Data1}), + ct_hooks:on_tc_skip(What, Data1), if Func /= init_per_suite, Func /= init_per_group, Func /= end_per_suite, Func /= end_per_group -> add_to_stats(user_skipped); @@ -1342,15 +1354,19 @@ report(What,Data) -> tc_auto_skip -> %% test case skipped because of error in config function, or %% config function skipped because of error in info function - %% Data = {Suite,GroupName,Func,Comment} - + %% Data = {Suite,{Func,GroupName},Comment} + {Func,Data1} = case Data of + {Suite,{F,undefined},Comment} -> + {F,{Suite,F,Comment}}; + D = {_,{F,_},_} -> + {F,D} + end, %% this test case does not have a log, so printouts %% from event handlers should end up in the main log ct_event:sync_notify(#event{name=tc_auto_skip, node=node(), - data=Data}), - ct_hooks:on_tc_skip(What, Data), - Func = element(3, Data), + data=Data1}), + ct_hooks:on_tc_skip(What, Data1), if Func /= end_per_suite, Func /= end_per_group -> add_to_stats(auto_skipped); diff --git a/lib/common_test/src/ct_hooks.erl b/lib/common_test/src/ct_hooks.erl index fa8d36392c..2e667030a9 100644 --- a/lib/common_test/src/ct_hooks.erl +++ b/lib/common_test/src/ct_hooks.erl @@ -121,12 +121,13 @@ end_tc(_Mod, TC, Config, Result, _Return) -> call(fun call_generic/3, Result, [post_end_per_testcase, TC, Config], '$ct_no_change'). -on_tc_skip(How, {Suite, GroupName, Case, Reason}) -> - call(fun call_cleanup/3, {How, Reason}, - [on_tc_skip, Suite, GroupName, Case]). +%% Case = TestCase | {TestCase,GroupName} +on_tc_skip(How, {Suite, Case, Reason}) -> + call(fun call_cleanup/3, {How, Reason}, [on_tc_skip, Suite, Case]). -on_tc_fail(_How, {Suite, GroupName, Case, Reason}) -> - call(fun call_cleanup/3, Reason, [on_tc_fail, Suite, GroupName, Case]). +%% Case = TestCase | {TestCase,GroupName} +on_tc_fail(_How, {Suite, Case, Reason}) -> + call(fun call_cleanup/3, Reason, [on_tc_fail, Suite, Case]). %% ------------------------------------------------------------------------- %% Internal Functions @@ -246,7 +247,7 @@ scope([post_init_per_suite, SuiteName|_]) -> scope(init) -> none. -terminate_if_scope_ends(HookId, [on_tc_skip,_Suite,Name,end_per_group], +terminate_if_scope_ends(HookId, [on_tc_skip,_Suite,{end_per_group,Name}], Hooks) -> terminate_if_scope_ends(HookId, [post_end_per_group, Name], Hooks); terminate_if_scope_ends(HookId, [on_tc_skip,Suite,end_per_suite], Hooks) -> diff --git a/lib/test_server/src/test_server_ctrl.erl b/lib/test_server/src/test_server_ctrl.erl index 58f1a21665..ec7aea1e8c 100644 --- a/lib/test_server/src/test_server_ctrl.erl +++ b/lib/test_server/src/test_server_ctrl.erl @@ -2293,7 +2293,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], set_io_buffering(undefined), {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, false, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), run_test_cases_loop(Cases, Config, TimetrapData, ParentMode, @@ -2304,7 +2304,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], wait_for_cases(Ref), {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, true, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), case CurrIOHandler of {Ref,_} -> @@ -2324,7 +2324,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], %% nested under a parallel group {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, false, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), %% Check if this group is auto skipped because of error in the @@ -2358,7 +2358,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], %% a parallel group (io buffering is active) {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, true, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), case CurrIOHandler of {Ref,_} -> @@ -2376,7 +2376,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], %% under a parallel group {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, false, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), run_test_cases_loop(Cases, Config, TimetrapData, [conf(Ref,[])|Mode], Status); @@ -2391,7 +2391,7 @@ run_test_cases_loop([{SkipTag,{Type,Ref,Case,Comment},SkipMode}|Cases], end, {Mod,Func} = skip_case(AutoOrUser, Ref, 0, Case, Comment, true, SkipMode), - ConfData = {Mod,get_name(SkipMode),Func,Comment}, + ConfData = {Mod,{Func,get_name(SkipMode)},Comment}, test_server_sup:framework_call(report, [ReportTag,ConfData]), run_test_cases_loop(Cases, Config, TimetrapData, [conf(Ref,[])|Mode], Status) @@ -2402,8 +2402,8 @@ run_test_cases_loop([{auto_skip_case,{Case,Comment},SkipMode}|Cases], {Mod,Func} = skip_case(auto, undefined, get(test_server_case_num)+1, Case, Comment, is_io_buffered(), SkipMode), test_server_sup:framework_call(report, [tc_auto_skip, - {Mod,get_name(SkipMode), - Func,Comment}]), + {Mod,{Func,get_name(SkipMode)}, + Comment}]), run_test_cases_loop(Cases, Config, TimetrapData, Mode, update_status(skipped, Mod, Func, Status)); @@ -2411,7 +2411,7 @@ run_test_cases_loop([{skip_case,{{Mod,all}=Case,Comment}}|Cases], Config, TimetrapData, Mode, Status) -> skip_case(user, undefined, 0, Case, Comment, false, Mode), test_server_sup:framework_call(report, [tc_user_skip, - {Mod,undefined,all,Comment}]), + {Mod,{all,undefined},Comment}]), run_test_cases_loop(Cases, Config, TimetrapData, Mode, Status); run_test_cases_loop([{skip_case,{Case,Comment},SkipMode}|Cases], @@ -2419,8 +2419,8 @@ run_test_cases_loop([{skip_case,{Case,Comment},SkipMode}|Cases], {Mod,Func} = skip_case(user, undefined, get(test_server_case_num)+1, Case, Comment, is_io_buffered(), SkipMode), test_server_sup:framework_call(report, [tc_user_skip, - {Mod,get_name(SkipMode), - Func,Comment}]), + {Mod,{Func,get_name(SkipMode)}, + Comment}]), run_test_cases_loop(Cases, Config, TimetrapData, Mode, update_status(skipped, Mod, Func, Status)); @@ -2429,8 +2429,8 @@ run_test_cases_loop([{skip_case,{Case,Comment}}|Cases], {Mod,Func} = skip_case(user, undefined, get(test_server_case_num)+1, Case, Comment, is_io_buffered(), []), test_server_sup:framework_call(report, [tc_user_skip, - {Mod,undefined, - Func,Comment}]), + {Mod,{Func,undefined}, + Comment}]), run_test_cases_loop(Cases, Config, TimetrapData, Mode, update_status(skipped, Mod, Func, Status)); @@ -3689,7 +3689,7 @@ run_test_case1(Ref, Num, Mod, Func, Args, RunInit, end, GrName = get_name(Mode), test_server_sup:framework_call(report, - [tc_start,{{Mod,GrName,Func}, + [tc_start,{{Mod,{Func,GrName}}, MinorName}]), print_props((RunInit==skip_init), get_props(Mode)), @@ -3880,7 +3880,7 @@ progress(skip, CaseNum, Mod, Func, GrName, Loc, Reason, Time, print(major, "=result ~w: ~p", [ReportTag,Reason1]), print(1, "*** SKIPPED ~ts ***", [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), - test_server_sup:framework_call(report, [tc_done,{Mod,GrName,Func, + test_server_sup:framework_call(report, [tc_done,{Mod,{Func,GrName}, {ReportTag,Reason1}}]), ReasonStr = reason_to_string(Reason1), ReasonStr1 = lists:flatten([string:strip(S,left) || @@ -3911,7 +3911,7 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, timetrap_timeout, T, print(1, "*** FAILED ~ts ***", [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), test_server_sup:framework_call(report, - [tc_done,{Mod,GrName,Func, + [tc_done,{Mod,{Func,GrName}, {failed,timetrap_timeout}}]), FormatLastLoc = test_server_sup:format_loc(get_last_loc(Loc)), ErrorReason = io_lib:format("{timetrap_timeout,~ts}", [FormatLastLoc]), @@ -3937,7 +3937,7 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, {testcase_aborted,Reason}, _T, print(1, "*** FAILED ~ts ***", [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), test_server_sup:framework_call(report, - [tc_done,{Mod,GrName,Func, + [tc_done,{Mod,{Func,GrName}, {failed,testcase_aborted}}]), FormatLastLoc = test_server_sup:format_loc(get_last_loc(Loc)), ErrorReason = io_lib:format("{testcase_aborted,~ts}", [FormatLastLoc]), @@ -3962,7 +3962,7 @@ progress(failed, CaseNum, Mod, Func, GrName, unknown, Reason, Time, print(major, "=result failed: ~p, ~w", [Reason,unknown]), print(1, "*** FAILED ~ts ***", [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), - test_server_sup:framework_call(report, [tc_done,{Mod,GrName,Func, + test_server_sup:framework_call(report, [tc_done,{Mod,{Func,GrName}, {failed,Reason}}]), TimeStr = io_lib:format(if is_float(Time) -> "~.3fs"; true -> "~w" @@ -3998,7 +3998,7 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, Reason, Time, print(major, "=result failed: ~p, ~p", [Reason,Loc]), print(1, "*** FAILED ~ts ***", [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), - test_server_sup:framework_call(report, [tc_done,{Mod,GrName,Func, + test_server_sup:framework_call(report, [tc_done,{Mod,{Func,GrName}, {failed,Reason}}]), TimeStr = io_lib:format(if is_float(Time) -> "~.3fs"; true -> "~w" @@ -4023,7 +4023,7 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, Reason, Time, progress(ok, _CaseNum, Mod, Func, GrName, _Loc, RetVal, Time, Comment0, {St0,St1}) -> print(minor, "successfully completed test case", []), - test_server_sup:framework_call(report, [tc_done,{Mod,GrName,Func,ok}]), + test_server_sup:framework_call(report, [tc_done,{Mod,{Func,GrName},ok}]), Comment = case RetVal of {comment,RetComment} -> |