From 70be956dafd2f9514946ed6aa5cc2863e553ad04 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 22 Mar 2013 11:20:08 +0100 Subject: Preliminary test case updates --- lib/megaco/test/megaco_test_lib.erl | 41 +++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'lib/megaco/test/megaco_test_lib.erl') diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl index 03c04831e8..0018f4c247 100644 --- a/lib/megaco/test/megaco_test_lib.erl +++ b/lib/megaco/test/megaco_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. +%% Copyright Ericsson AB 1999-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -114,7 +114,7 @@ os_based_skip(_) -> tickets(Case) -> Res = lists:flatten(tickets(Case, default_config())), - %% io:format("Res: ~p~n", [Res]), + io:format("~w:tickets(Case = ~w) -> Res: ~p~n", [?MODULE, Case, Res]), display_result(Res), Res. @@ -122,16 +122,25 @@ tickets(Cases, Config) when is_list(Cases) -> [tickets(Case, Config) || Case <- Cases]; tickets(Mod, Config) when is_atom(Mod) -> Res = tickets(Mod, tickets, Config), + io:format("~w:tickets(Mod = ~w) -> Res: ~p~n", [?MODULE, Mod, Res]), Res; tickets(Bad, _Config) -> [{badarg, Bad, ok}]. tickets(Mod, Func, Config) -> + io:format("~w:tickets -> entry with" + "~n Mod: ~p" + "~n Func: ~p" + "~n Config: ~p" + "~n", [?MODULE, Mod, Func, Config]), case (catch Mod:Func(suite)) of [] -> io:format("Eval: ~p:", [{Mod, Func}]), Res = eval(Mod, Func, Config), - {R, _, _} = Res, + io:format("~w:tickets -> evaluated" + "~n Res: ~p" + "~n", [?MODULE, Res]), + {R, _, _, _} = Res, io:format(" ~p~n", [R]), Res; @@ -147,17 +156,37 @@ tickets(Mod, Func, Config) -> lists:map(Map, Cases); {req, _, {conf, Init, Cases, Finish}} -> + io:format("~w:tickets -> suite result req-conf: " + "~n Init: ~p" + "~n Cases: ~p" + "~n Finish: ~p" + "~n", [?MODULE, Init, Cases, Finish]), case (catch Mod:Init(Config)) of Conf when is_list(Conf) -> io:format("Expand: ~p:~p ...~n", [Mod, Func]), Map = fun({M,_}) when is_atom(M) -> - tickets(M, tickets, Config); + io:format("~w:tickets -> " + "~n M: ~p" + "~n", [?MODULE, M]), + tickets(M, tickets, Conf); (F) when is_atom(F) -> - tickets(Mod, F, Config); - (Case) -> Case + io:format("~w:tickets -> " + "~n F: ~p" + "~n", [?MODULE, F]), + tickets(Mod, F, Conf); + (Case) -> + io:format("~w:tickets -> " + "~n Case: ~p" + "~n", [?MODULE, Case]), + Case end, Res = lists:map(Map, Cases), + io:format("~w:tickets -> and now finish when: " + "~n Res: ~p" + "~n", [?MODULE, Res]), (catch Mod:Finish(Conf)), + io:format("~w:tickets -> finished" + "~n", [?MODULE]), Res; {'EXIT', {skipped, Reason}} -> -- cgit v1.2.3 From aec630d41b13e31c7732513457a54e19937c7a75 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 22 Mar 2013 14:13:46 +0100 Subject: Test case cleanup --- lib/megaco/test/megaco_test_lib.erl | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'lib/megaco/test/megaco_test_lib.erl') diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl index 0018f4c247..55eee97443 100644 --- a/lib/megaco/test/megaco_test_lib.erl +++ b/lib/megaco/test/megaco_test_lib.erl @@ -114,7 +114,7 @@ os_based_skip(_) -> tickets(Case) -> Res = lists:flatten(tickets(Case, default_config())), - io:format("~w:tickets(Case = ~w) -> Res: ~p~n", [?MODULE, Case, Res]), + %% io:format("~w:tickets(Case = ~w) -> Res: ~p~n", [?MODULE, Case, Res]), display_result(Res), Res. @@ -122,24 +122,24 @@ tickets(Cases, Config) when is_list(Cases) -> [tickets(Case, Config) || Case <- Cases]; tickets(Mod, Config) when is_atom(Mod) -> Res = tickets(Mod, tickets, Config), - io:format("~w:tickets(Mod = ~w) -> Res: ~p~n", [?MODULE, Mod, Res]), + %% io:format("~w:tickets(Mod = ~w) -> Res: ~p~n", [?MODULE, Mod, Res]), Res; tickets(Bad, _Config) -> [{badarg, Bad, ok}]. tickets(Mod, Func, Config) -> - io:format("~w:tickets -> entry with" - "~n Mod: ~p" - "~n Func: ~p" - "~n Config: ~p" - "~n", [?MODULE, Mod, Func, Config]), + %% io:format("~w:tickets -> entry with" + %% "~n Mod: ~p" + %% "~n Func: ~p" + %% "~n Config: ~p" + %% "~n", [?MODULE, Mod, Func, Config]), case (catch Mod:Func(suite)) of [] -> io:format("Eval: ~p:", [{Mod, Func}]), Res = eval(Mod, Func, Config), - io:format("~w:tickets -> evaluated" - "~n Res: ~p" - "~n", [?MODULE, Res]), + %% io:format("~w:tickets -> evaluated" + %% "~n Res: ~p" + %% "~n", [?MODULE, Res]), {R, _, _, _} = Res, io:format(" ~p~n", [R]), Res; @@ -156,37 +156,37 @@ tickets(Mod, Func, Config) -> lists:map(Map, Cases); {req, _, {conf, Init, Cases, Finish}} -> - io:format("~w:tickets -> suite result req-conf: " - "~n Init: ~p" - "~n Cases: ~p" - "~n Finish: ~p" - "~n", [?MODULE, Init, Cases, Finish]), + %% io:format("~w:tickets -> suite result req-conf: " + %% "~n Init: ~p" + %% "~n Cases: ~p" + %% "~n Finish: ~p" + %% "~n", [?MODULE, Init, Cases, Finish]), case (catch Mod:Init(Config)) of Conf when is_list(Conf) -> io:format("Expand: ~p:~p ...~n", [Mod, Func]), Map = fun({M,_}) when is_atom(M) -> - io:format("~w:tickets -> " - "~n M: ~p" - "~n", [?MODULE, M]), + %% io:format("~w:tickets -> " + %% "~n M: ~p" + %% "~n", [?MODULE, M]), tickets(M, tickets, Conf); (F) when is_atom(F) -> - io:format("~w:tickets -> " - "~n F: ~p" - "~n", [?MODULE, F]), + %% io:format("~w:tickets -> " + %% "~n F: ~p" + %% "~n", [?MODULE, F]), tickets(Mod, F, Conf); (Case) -> - io:format("~w:tickets -> " - "~n Case: ~p" - "~n", [?MODULE, Case]), + %% io:format("~w:tickets -> " + %% "~n Case: ~p" + %% "~n", [?MODULE, Case]), Case end, Res = lists:map(Map, Cases), - io:format("~w:tickets -> and now finish when: " - "~n Res: ~p" - "~n", [?MODULE, Res]), + %% io:format("~w:tickets -> and now finish when: " + %% "~n Res: ~p" + %% "~n", [?MODULE, Res]), (catch Mod:Finish(Conf)), - io:format("~w:tickets -> finished" - "~n", [?MODULE]), + %% io:format("~w:tickets -> finished" + %% "~n", [?MODULE]), Res; {'EXIT', {skipped, Reason}} -> -- cgit v1.2.3 From 817843f31e613ca1648965d360229cdf56c88787 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 17 Apr 2013 12:04:49 +0200 Subject: [megaco] Misc fixes of the (internal) megaco test server --- lib/megaco/test/megaco_test_lib.erl | 79 ++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 31 deletions(-) (limited to 'lib/megaco/test/megaco_test_lib.erl') diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl index f4f922bd5f..f64743f32a 100644 --- a/lib/megaco/test/megaco_test_lib.erl +++ b/lib/megaco/test/megaco_test_lib.erl @@ -112,12 +112,14 @@ os_based_skip(_) -> %% {Mod, Fun, ExpectedRes, ActualRes} %%---------------------------------------------------------------------- -tickets(Mod) -> - %% io:format("~w:tickets -> entry with" - %% "~n Mod: ~p", [?MODULE, Mod]), +tickets([Mod]) -> + tickets(Mod); +tickets(Mod) when is_atom(Mod) -> + %% p("tickets -> entry with" + %% "~n Mod: ~p", [Mod]), Res0 = t({Mod, {group, tickets}, Mod:groups()}, default_config()), Res = lists:flatten(Res0), - %% io:format("~w:tickets(Mod = ~w) -> Res: ~p~n", [?MODULE, Mod, Res]), + %% p("tickets(~w) -> Res: ~p~n", [Mod, Res]), display_result(Res), Res. @@ -196,12 +198,12 @@ alloc_instance_mem_info(Key, InstanceInfo) -> t([Case]) when is_atom(Case) -> - io:format("~w:t -> entry with" - "~n [Case]: [~p]", [?MODULE, Case]), + %% p("t -> entry with" + %% "~n [Case]: [~p]", [Case]), t(Case); t(Case) -> - io:format("~w:t -> entry with" - "~n Case: ~p", [?MODULE, Case]), + %% p("t -> entry with" + %% "~n Case: ~p", [Case]), process_flag(trap_exit, true), MEM = fun() -> case (catch erlang:memory()) of {'EXIT', _} -> @@ -263,7 +265,7 @@ t({Mod, {group, Name} = Group, Groups}, Config) exit:{skipped, SkipReason} -> io:format(" => skipping group: ~p~n", [SkipReason]), [{skipped, {Mod, Group}, SkipReason, 0}]; - exit:{undef, _} -> + error:undef -> [t({Mod, Case, Groups}, Config) || Case <- GroupsAndCases]; T:E -> @@ -274,7 +276,7 @@ t({Mod, {group, Name} = Group, Groups}, Config) end; t({Mod, Fun, _}, Config) when is_atom(Mod) andalso is_atom(Fun) -> - case catch apply(Mod, Fun, [suite]) of + try apply(Mod, Fun, [suite]) of [] -> io:format("Eval: ~p:", [{Mod, Fun}]), Res = eval(Mod, Fun, Config), @@ -289,22 +291,24 @@ t({Mod, Fun, _}, Config) end, t(lists:map(Map, Cases), Config); - {'EXIT', {undef, _}} -> - io:format("Undefined: ~p~n", [{Mod, Fun}]), - [{nyi, {Mod, Fun}, ok, 0}]; - Error -> io:format("Ignoring: ~p: ~p~n", [{Mod, Fun}, Error]), [{failed, {Mod, Fun}, Error, 0}] + + catch + error:undef -> + io:format("Undefined: ~p~n", [{Mod, Fun}]), + [{nyi, {Mod, Fun}, ok, 0}] + + end; t(Mod, Config) when is_atom(Mod) -> - io:format("~w:t -> entry with" - "~n Mod: ~p" - "~n Config: ~p" - "~n", [?MODULE, Mod, Config]), + %% p("t -> entry with" + %% "~n Mod: ~p" + %% "~n Config: ~p", [Mod, Config]), %% This is assumed to be a test suite, so we start by calling %% the top test suite function(s) (all/0 and groups/0). - case (catch Mod:all()) of + try Mod:all() of Cases when is_list(Cases) -> %% The list may contain atoms (actual test cases) and %% group-tuples (a tuple naming a group of test cases). @@ -322,17 +326,21 @@ t(Mod, Config) when is_atom(Mod) -> exit:{skipped, SkipReason} -> io:format(" => skipping suite: ~p~n", [SkipReason]), [{skipped, {Mod, init_per_suite}, SkipReason, 0}]; - exit:{undef, _} -> + error:undef -> [t({Mod, Case, Groups}, Config) || Case <- Cases]; T:E -> + io:format(" => failed suite: ~p~n", [{T,E}]), [{failed, {Mod, init_per_suite}, {T,E}, 0}] end; - {'EXIT', {undef, _}} -> - io:format("Undefined: ~p~n", [{Mod, all}]), - [{nyi, {Mod, all}, ok, 0}]; - + Crap -> Crap + + catch + error:undef -> + io:format("Undefined: ~p~n", [{Mod, all}]), + [{nyi, {Mod, all}, ok, 0}] + end; t(Bad, _Config) -> [{badarg, Bad, ok, 0}]. @@ -397,15 +405,24 @@ wait_for_evaluator(Pid, Mod, Fun, Config, Errors, AccTime) -> do_eval(ReplyTo, Mod, Fun, Config) -> display_system_info("before", Mod, Fun), - case timer:tc(Mod, Fun, [Config]) of - {Time, {'EXIT', {skipped, Reason}}} -> - display_tc_time(Time), - display_system_info("after (skipped)", Mod, Fun), - ReplyTo ! {'EXIT', self(), {skipped, Reason}, Time}; - {Time, Other} -> + T1 = os:timestamp(), + try Mod:Fun(Config) of + Res -> + T2 = os:timestamp(), + Time = timer:now_diff(T2, T1), display_tc_time(Time), display_system_info("after", Mod, Fun), - ReplyTo ! {done, self(), Other, Time} + ReplyTo ! {done, self(), Res, Time} + catch + error:undef -> + ReplyTo ! {'EXIT', self(), undef, 0}; + exit:{skipped, Reason} -> + T2 = os:timestamp(), + Time = timer:now_diff(T2, T1), + display_tc_time(Time), + display_system_info("after (skipped)", Mod, Fun), + ReplyTo ! {'EXIT', self(), {skipped, Reason}, Time} + end, unlink(ReplyTo), exit(shutdown). -- cgit v1.2.3