4
%% Copyright Ericsson AB 2002-2009. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
%%----------------------------------------------------------------------
21
%% Purpose: Verify the application specifics of the Megaco application
22
%%----------------------------------------------------------------------
23
-module(inets_appup_test).
27
-include("inets_test_lib.hrl").
30
% t() -> megaco_test_lib:t(?MODULE).
31
% t(Case) -> megaco_test_lib:t({?MODULE, Case}).
34
%% Test server callbacks
35
init_per_testcase(_Case, Config) ->
38
fin_per_testcase(_Case, Config) ->
41
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
{req, [], {conf, appup_init, Cases, appup_fin}}.
50
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
appup_init(suite) -> [];
53
appup_init(doc) -> [];
54
appup_init(Config) when is_list(Config) ->
55
AppFile = file_name(inets, ".app"),
56
AppupFile = file_name(inets, ".appup"),
57
[{app_file, AppFile}, {appup_file, AppupFile}|Config].
60
file_name(App, Ext) ->
61
LibDir = code:lib_dir(App),
62
filename:join([LibDir, "ebin", atom_to_list(App) ++ Ext]).
65
appup_fin(suite) -> [];
67
appup_fin(Config) when is_list(Config) ->
71
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
"perform a simple check of the appup file";
77
appup(Config) when is_list(Config) ->
78
AppupFile = key1search(appup_file, Config),
79
AppFile = key1search(app_file, Config),
80
Modules = modules(AppFile),
81
check_appup(AppupFile, Modules).
84
case file:consult(File) of
85
{ok, [{application,inets,Info}]} ->
86
case lists:keysearch(modules,1,Info) of
87
{value, {modules, Modules}} ->
90
fail({bad_appinfo, Info})
93
fail({bad_appfile, Error})
97
check_appup(AppupFile, Modules) ->
98
case file:consult(AppupFile) of
99
{ok, [{V, UpFrom, DownTo}]} ->
103
% "~n", [V, UpFrom, DownTo]),
104
check_appup(V, UpFrom, DownTo, Modules);
106
fail({bad_appupfile, Else})
110
check_appup(V, UpFrom, DownTo, Modules) ->
112
check_depends(up, UpFrom, Modules),
113
check_depends(down, DownTo, Modules),
117
check_depends(_, [], _) ->
119
check_depends(UpDown, [Dep|Deps], Modules) ->
120
check_depend(UpDown, Dep, Modules),
121
check_depends(UpDown, Deps, Modules).
124
check_depend(UpDown, {V, Instructions}, Modules) ->
126
case check_instructions(UpDown,
127
Instructions, Instructions, [], [], Modules) of
131
fail({bad_instructions, Bad, UpDown})
135
check_instructions(_, [], _, Good, Bad, _) ->
136
{lists:reverse(Good), lists:reverse(Bad)};
137
check_instructions(UpDown, [Instr|Instrs], AllInstr, Good, Bad, Modules) ->
138
case (catch check_instruction(UpDown, Instr, AllInstr, Modules)) of
140
check_instructions(UpDown, Instrs, AllInstr,
141
[Instr|Good], Bad, Modules);
143
check_instructions(UpDown, Instrs, AllInstr, Good,
144
[{Instr, Reason}|Bad], Modules)
146
check_instructions(UpDown, Instructions, _, _, _, _) ->
147
fail({bad_instructions, {UpDown, Instructions}}).
149
%% A new module is added
150
check_instruction(up, {add_module, Module}, _, Modules)
151
when is_atom(Module) ->
152
check_module(Module, Modules);
154
%% An old module is re-added
155
check_instruction(down, {add_module, Module}, _, Modules)
156
when is_atom(Module) ->
157
case (catch check_module(Module, Modules)) of
158
{error, {unknown_module, Module, Modules}} ->
161
error({existing_readded_module, Module})
164
%% Removing a module on upgrade:
165
%% - the module has been removed from the app-file.
166
%% - check that no module depends on this (removed) module
167
check_instruction(up, {remove, {Module, Pre, Post}}, _, Modules)
168
when is_atom(Module), is_atom(Pre), is_atom(Post) ->
169
case (catch check_module(Module, Modules)) of
170
{error, {unknown_module, Module, Modules}} ->
174
error({existing_removed_module, Module})
177
%% Removing a module on downgrade: the module exist
179
check_instruction(down, {remove, {Module, Pre, Post}}, AllInstr, Modules)
180
when is_atom(Module), is_atom(Pre), is_atom(Post) ->
181
case (catch check_module(Module, Modules)) of
185
check_no_remove_depends(Module, AllInstr);
186
{error, {unknown_module, Module, Modules}} ->
187
error({nonexisting_removed_module, Module})
190
check_instruction(up, {load_module, Module, Pre, Post, Depend}, _, Modules)
191
when is_atom(Module), is_atom(Pre), is_atom(Post), is_list(Depend) ->
192
check_module(Module, Modules),
193
check_module_depend(Module, Depend, Modules),
197
check_instruction(down, {load_module, Module, Pre, Post, Depend}, _, Modules)
198
when is_atom(Module), is_atom(Pre), is_atom(Post), is_list(Depend) ->
199
check_module(Module, Modules),
200
% Can not be sure that the the dependent module exists in the new appfile
201
%%check_module_depend(Module, Depend, Modules),
207
check_instruction(up, {delete_module, Module}, _, Modules)
208
when is_atom(Module) ->
209
case (catch check_module(Module, Modules)) of
210
{error, {unknown_module, Module, Modules}} ->
213
error({existing_module_deleted, Module})
216
check_instruction(down, {delete_module, Module}, _, Modules)
217
when is_atom(Module) ->
218
check_module(Module, Modules);
221
check_instruction(_, {apply, {Module, Function, Args}}, _, _) when is_atom(Module), is_atom(Function), is_list(Args) ->
224
check_instruction(_, {update, Module, supervisor}, _, Modules) when is_atom(Module) ->
225
check_module(Module, Modules);
227
check_instruction(_, {update, Module, {advanced, _}, DepMods}, _, Modules) when is_atom(Module), is_list(DepMods) ->
228
check_module(Module, Modules),
229
check_module_depend(Module, DepMods, Modules);
231
check_instruction(_, {update, Module, Change, Pre, Post, Depend}, _, Modules)
232
when is_atom(Module), is_atom(Pre), is_atom(Post), is_list(Depend) ->
233
check_module(Module, Modules),
234
check_module_depend(Module, Depend, Modules),
235
check_change(Change),
239
check_instruction(_, {restart_application, inets}, _AllInstr, _Modules) ->
242
check_instruction(_, {update, Module, {advanced, _}}, _, Modules) ->
243
check_module(Module, Modules);
245
check_instruction(_, Instr, _AllInstr, _Modules) ->
246
error({error, {unknown_instruction, Instr}}).
249
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251
check_version(V) when is_list(V) ->
254
error({bad_version, V}).
257
check_module(M, Modules) when is_atom(M) ->
258
case lists:member(M,Modules) of
262
error({unknown_module, M, Modules})
264
check_module(M, _) ->
265
error({bad_module, M}).
268
check_module_depend(M, [], _) when is_atom(M) ->
270
check_module_depend(M, Deps, Modules) when is_atom(M), is_list(Deps) ->
271
case [Dep || Dep <- Deps, lists:member(Dep, Modules) == false] of
275
error({unknown_depend_modules, Unknown})
277
check_module_depend(_M, D, _Modules) ->
278
error({bad_depend, D}).
281
check_no_remove_depends(_Module, []) ->
283
check_no_remove_depends(Module, [Instr|Instrs]) ->
284
check_no_remove_depend(Module, Instr),
285
check_no_remove_depends(Module, Instrs).
287
check_no_remove_depend(Module, {load_module, Mod, _Pre, _Post, Depend}) ->
288
case lists:member(Module, Depend) of
290
error({removed_module_in_depend, load_module, Mod, Module});
294
check_no_remove_depend(Module, {update, Mod, _Change, _Pre, _Post, Depend}) ->
295
case lists:member(Module, Depend) of
297
error({removed_module_in_depend, update, Mod, Module});
301
check_no_remove_depend(_, _) ->
305
check_change(soft) ->
307
check_change({advanced, _Something}) ->
309
check_change(Change) ->
310
error({bad_change, Change}).
313
check_purge(soft_purge) ->
315
check_purge(brutal_purge) ->
317
check_purge(Purge) ->
318
error({bad_purge, Purge}).
322
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325
throw({error, Reason}).
328
exit({suite_failed, Reason}).
330
key1search(Key, L) ->
331
case lists:keysearch(Key, 1, L) of
333
fail({not_found, Key, L});
334
{value, {Key, Value}} ->