1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2009-2018. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19 20-module(reltool_wx_SUITE). 21 22-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, 23 init_per_suite/1, end_per_suite/1, 24 init_per_testcase/2, end_per_testcase/2]). 25 26-export([start_all_windows/1, check_no_win_crash/0, wait_terminate/1]). 27 28-include("reltool_test_lib.hrl"). 29 30%% Initialization functions. 31init_per_suite(Config) -> 32 reltool_test_lib:wx_init_per_suite(Config). 33 34end_per_suite(Config) -> 35 reltool_test_lib:wx_end_per_suite(Config). 36 37init_per_testcase(Func,Config) -> 38 reltool_test_lib:init_per_testcase(Func,Config). 39end_per_testcase(Func,Config) -> 40 reltool_test_lib:end_per_testcase(Func,Config). 41 42%% SUITE specification 43suite() -> [{ct_hooks,[ts_install_cth]}]. 44 45all() -> 46 [start_all_windows]. 47 48groups() -> 49 []. 50 51init_per_group(_GroupName, Config) -> 52 Config. 53 54end_per_group(_GroupName, Config) -> 55 Config. 56 57 58%% The test cases 59 60%% Display all windows and see if something crashes 61start_all_windows(TestInfo) when is_atom(TestInfo) -> 62 reltool_test_lib:tc_info(TestInfo); 63start_all_windows(_Config) -> 64 {ok, SysPid} = ?msym({ok, _}, reltool:start([{trap_exit, false}])), 65 erlang:monitor(process,SysPid), 66 {ok, AppPid} = ?msym({ok, _}, reltool_sys_win:open_app(SysPid, stdlib)), 67 erlang:monitor(process,AppPid), 68 {ok, ModPid} = ?msym({ok, _}, reltool_app_win:open_mod(AppPid, escript)), 69 erlang:monitor(process,ModPid), 70 71 %% Let all windows get started 72 timer:sleep(timer:seconds(10)), 73 74 %% Test that server pid can be fetched, and that server is alive 75 {ok, Server} = ?msym({ok,_}, reltool:get_server(SysPid)), 76 ?m(true, erlang:is_process_alive(Server)), 77 Sys = 78 case reltool_test_lib:erl_libs() of 79 [] -> []; 80 Libs -> [{lib_dirs,Libs}] 81 end, 82 ?m({ok,{sys,Sys}}, reltool:get_config(Server)), 83 84 %% Terminate 85 check_no_win_crash(), 86 ?m(ok, reltool:stop(SysPid)), 87 wait_terminate([{sys,SysPid},{app,AppPid},{mod,ModPid}]), 88 89 ok. 90 91 92%%%----------------------------------------------------------------- 93%%% Internal functions 94check_no_win_crash() -> 95 receive {'DOWN',_,_,_,_} = Down -> 96 ct:log("Unexpected termination of window:~n~p",[Down]), 97 ct:fail("window crashed") 98 after 0 -> 99 ok 100 end. 101 102wait_terminate([]) -> 103 ok; 104wait_terminate([{Win,P}|Rest]) -> 105 receive 106 {'DOWN',_,process,P,shutdown} -> 107 wait_terminate(Rest); 108 {'DOWN',_,process,P,Reason} -> 109 ct:log("~p window terminated with unexpected reason:~n~p", 110 [Win,Reason]), 111 ct:fail("unexpected exit reason from window") 112 end. 113