From 40014d4b190c86044df5f1aa70dad7138d531b7b Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 4 Jan 2012 16:09:01 +0100 Subject: [reltool] Add more test cases and fix bugs OTP-9794 The following test cases are added for the inteface from GUI to reltool_server: * get_config * get_apps * set_app_and_undo * set_apps_and_undo * load_config_and_undo * reset_config_and_undo * save_config The following bugs were found and corrected: * If set_apps failed, then the state of reltool_server would not be reset to how it was before the failing operation - and every operation done afterwards would also (seem to) fail. * undo_config did not work after reset_config - since faulty #sys record was stored as old_sys. * undo_config did not work after set_app (used when changing the content of an application from the GUI) - since old_sys was not set. Also old_status was not set causing possible warnings to disappear. * undo_config did not work after set_apps (used e.g. when excluding or including an application from the GUI) - since old_sys was not set. Also old_status was not set causing possible warnings to disappear. --- lib/reltool/src/reltool.hrl | 6 ++-- lib/reltool/src/reltool_server.erl | 59 +++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 29 deletions(-) (limited to 'lib/reltool/src') diff --git a/lib/reltool/src/reltool.hrl b/lib/reltool/src/reltool.hrl index 93f47f6381..8e80c80e10 100644 --- a/lib/reltool/src/reltool.hrl +++ b/lib/reltool/src/reltool.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009-2011. All Rights Reserved. +%% Copyright Ericsson AB 2009-2012. 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 @@ -199,8 +199,8 @@ used_by_mods :: [mod_name()], uses_apps :: [app_name()], used_by_apps :: [app_name()], - is_pre_included :: boolean(), - is_included :: boolean(), + is_pre_included :: boolean() | undefined, + is_included :: boolean() | undefined, rels :: [rel_name()] }). diff --git a/lib/reltool/src/reltool_server.erl b/lib/reltool/src/reltool_server.erl index 692baea0a4..fdb9e08a90 100644 --- a/lib/reltool/src/reltool_server.erl +++ b/lib/reltool/src/reltool_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009-2011. All Rights Reserved. +%% Copyright Ericsson AB 2009-2012. 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 @@ -254,7 +254,7 @@ loop(#state{common = C, sys = Sys} = S) -> {S2, Status} = parse_options(S#state.options), S3 = shrink_sys(S2), {S4, Status2} = refresh(S3, true, Status), - {S5, Status3} = analyse(S4#state{old_sys = S4#state.sys}, Status2), + {S5, Status3} = analyse(S4#state{old_sys = S#state.sys}, Status2), S6 = case Status3 of {ok, _Warnings} -> @@ -266,11 +266,11 @@ loop(#state{common = C, sys = Sys} = S) -> reltool_utils:reply(ReplyTo, Ref, Status3), ?MODULE:loop(S6); {call, ReplyTo, Ref, undo_config} -> - reltool_utils:reply(ReplyTo, Ref, ok), S2 = S#state{sys = S#state.old_sys, old_sys = S#state.sys, status = S#state.old_status, old_status = S#state.status}, + reltool_utils:reply(ReplyTo, Ref, ok), ?MODULE:loop(S2); {call, ReplyTo, Ref, {get_rel, RelName}} -> Sys = S#state.sys, @@ -319,19 +319,21 @@ loop(#state{common = C, sys = Sys} = S) -> ?MODULE:loop(S); {call, ReplyTo, Ref, {set_app, App}} -> {S2, Status} = do_set_app(S, App, {ok, []}), - {S3, Status2} = analyse(S2, Status), - case Status2 of - {ok, Warnings} -> - App2 = ?KEYSEARCH(App#app.name, - #app.name, - (S3#state.sys)#sys.apps), - reltool_utils:reply(ReplyTo, Ref, {ok, App2, Warnings}), - ?MODULE:loop(S3); - {error, Reason} -> - %% Keep old state - reltool_utils:reply(ReplyTo, Ref, {error, Reason}), - ?MODULE:loop(S) - end; + {S3, Status2} = analyse(S2#state{old_sys=S#state.sys}, Status), + {S4, Reply} = + case Status2 of + {ok, Warnings} -> + App2 = ?KEYSEARCH(App#app.name, + #app.name, + (S3#state.sys)#sys.apps), + {S3#state{status=Status2, old_status=S#state.status}, + {ok, App2, Warnings}}; + {error, _} -> + %% Keep old state + {S, Status2} + end, + reltool_utils:reply(ReplyTo, Ref, Reply), + ?MODULE:loop(S4); {call, ReplyTo, Ref, {get_apps, Kind}} -> AppNames = case Kind of @@ -361,9 +363,17 @@ loop(#state{common = C, sys = Sys} = S) -> lists:foldl(fun(A, {X, Y}) -> do_set_app(X, A, Y) end, {S, {ok, []}}, Apps), - {S3, Status2} = analyse(S2, Status), + {S3, Status2} = analyse(S2#state{old_sys = S#state.sys}, Status), + S4 = + case Status2 of + {ok, _Warnings} -> + S3#state{status=Status2, old_status=S#state.status}; + {error, _} -> + %% Keep old state + S + end, reltool_utils:reply(ReplyTo, Ref, Status2), - ?MODULE:loop(S3); + ?MODULE:loop(S4); {call, ReplyTo, Ref, get_sys} -> reltool_utils:reply(ReplyTo, Ref, {ok, Sys#sys{apps = undefined}}), ?MODULE:loop(S); @@ -374,19 +384,16 @@ loop(#state{common = C, sys = Sys} = S) -> (Sys2#sys.lib_dirs =/= Sys#sys.lib_dirs) orelse (Sys2#sys.escripts =/= Sys#sys.escripts), {S3, Status} = refresh(S2, Force, {ok, []}), - {S4, Status2} = - analyse(S3#state{old_sys = S#state.sys}, Status), - {S5, Status3} = + {S4, Status2} = analyse(S3#state{old_sys = S#state.sys}, Status), + S5 = case Status2 of {ok, _Warnings} -> % BUGBUG: handle warnings - {S4#state{status = Status2, - old_status = S#state.status}, - Status2}; + S4#state{status = Status2, old_status = S#state.status}; {error, _} -> %% Keep old state - {S, Status2} + S end, - reltool_utils:reply(ReplyTo, Ref, Status3), + reltool_utils:reply(ReplyTo, Ref, Status2), ?MODULE:loop(S5); {call, ReplyTo, Ref, get_status} -> reltool_utils:reply(ReplyTo, Ref, S#state.status), -- cgit v1.2.3