1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 2004-2011. All Rights Reserved. 5: %% 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/. 11: %% 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 15: %% under the License. 16: %% 17: %% %CopyrightEnd% 18: %% 19: %% 20: 21: %%---------------------------------------------------------------------- 22: %% Purpose : Test suite for c-client/erl-server 23: %%---------------------------------------------------------------------- 24: 25: -module(c_client_erl_server_proto_tmo_SUITE). 26: -include_lib("common_test/include/ct.hrl"). 27: 28: -export([init_per_testcase/2, end_per_testcase/2, 29: all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 30: init_per_group/2,end_per_group/2, 31: void_test/1, long_test/1, long_long_test/1, 32: unsigned_short_test/1, unsigned_long_test/1, 33: unsigned_long_long_test/1, double_test/1, char_test/1, 34: wchar_test/1, octet_test/1, bool_test/1, struct_test/1, 35: struct2_test/1, seq1_test/1, seq2_test/1, seq3_test/1, 36: seq4_test/1, seq5_test/1, array1_test/1, array2_test/1, 37: enum_test/1, string1_test/1, string2_test/1, string3_test/1, 38: string4_test/1, pid_test/1, port_test/1, ref_test/1, term_test/1, 39: typedef_test/1, inline_sequence_test/1, term_sequence_test/1, 40: term_struct_test/1, wstring1_test/1]). 41: 42: -define(DEFAULT_TIMEOUT, 20000). 43: -define(PORT_TIMEOUT, 15000). 44: -define(ERLANG_SERVER_NAME, idl_erlang_server). 45: -define(C_CLIENT_NODE_NAME, c_client_idl_test). 46: 47: %% Add/remove code path and watchdog before/after each test case. 48: %% 49: init_per_testcase(_Case, Config) -> 50: DataDir = ?config(data_dir, Config), 51: code:add_patha(DataDir), 52: 53: %% Since other test suites use the module m_i, we have 54: %% to make sure we are using the right m_i module. 55: code:purge(m_i), 56: code:load_file(m_i), 57: 58: WatchDog = test_server:timetrap(?DEFAULT_TIMEOUT), 59: [{watchdog, WatchDog}| Config]. 60: 61: end_per_testcase(_Case, Config) -> 62: DataDir = ?config(data_dir, Config), 63: code:del_path(DataDir), 64: WatchDog = ?config(watchdog, Config), 65: test_server:timetrap_cancel(WatchDog). 66: 67: suite() -> [{ct_hooks,[ts_install_cth]}]. 68: 69: all() -> 70: [void_test, long_test, long_long_test, 71: unsigned_short_test, unsigned_long_test, 72: unsigned_long_long_test, double_test, char_test, 73: wchar_test, octet_test, bool_test, struct_test, 74: struct2_test, seq1_test, seq2_test, seq3_test, 75: seq4_test, seq5_test, array1_test, array2_test, 76: enum_test, string1_test, string2_test, string3_test, 77: string4_test, pid_test, port_test, ref_test, term_test, 78: typedef_test, inline_sequence_test, term_sequence_test, 79: term_struct_test, wstring1_test]. 80: 81: groups() -> 82: []. 83: 84: init_per_suite(Config) -> 85: Config. 86: 87: end_per_suite(_Config) -> 88: ok. 89: 90: init_per_group(_GroupName, Config) -> 91: Config. 92: 93: end_per_group(_GroupName, Config) -> 94: Config. 95: 96: 97: 98: array1_test(doc) -> ""; 99: array1_test(suite) -> []; 100: array1_test(Config) -> 101: do_test(array1_test, Config). 102: 103: array2_test(doc) -> ""; 104: array2_test(suite) -> []; 105: array2_test(Config) -> 106: do_test(array2_test, Config). 107: 108: bool_test(doc) -> ""; 109: bool_test(suite) -> []; 110: bool_test(Config) -> 111: do_test(bool_test, Config). 112: 113: char_test(doc) -> ""; 114: char_test(suite) -> []; 115: char_test(Config) -> 116: do_test(char_test, Config). 117: 118: double_test(doc) -> ""; 119: double_test(suite) -> []; 120: double_test(Config) -> 121: do_test(double_test, Config). 122: 123: enum_test(doc) -> ""; 124: enum_test(suite) -> []; 125: enum_test(Config) -> 126: do_test(enum_test, Config). 127: 128: inline_sequence_test(doc) -> ""; 129: inline_sequence_test(suite) -> []; 130: inline_sequence_test(Config) -> 131: do_test(inline_sequence_test, Config). 132: 133: long_long_test(doc) -> ""; 134: long_long_test(suite) -> []; 135: long_long_test(Config) -> 136: do_test(long_long_test, Config). 137: 138: long_test(doc) -> ""; 139: long_test(suite) -> []; 140: long_test(Config) -> 141: do_test(long_test, Config). 142: 143: octet_test(doc) -> ""; 144: octet_test(suite) -> []; 145: octet_test(Config) -> 146: do_test(octet_test, Config). 147: 148: pid_test(doc) -> ""; 149: pid_test(suite) -> []; 150: pid_test(Config) -> 151: do_test(pid_test, Config). 152: 153: port_test(doc) -> ""; 154: port_test(suite) -> []; 155: port_test(Config) -> 156: do_test(port_test, Config). 157: 158: ref_test(doc) -> ""; 159: ref_test(suite) -> []; 160: ref_test(Config) -> 161: do_test(ref_test, Config). 162: 163: seq1_test(doc) -> ""; 164: seq1_test(suite) -> []; 165: seq1_test(Config) -> 166: do_test(seq1_test, Config). 167: 168: seq2_test(doc) -> ""; 169: seq2_test(suite) -> []; 170: seq2_test(Config) -> 171: do_test(seq2_test, Config). 172: 173: seq3_test(doc) -> ""; 174: seq3_test(suite) -> []; 175: seq3_test(Config) -> 176: do_test(seq3_test, Config). 177: 178: seq4_test(doc) -> ""; 179: seq4_test(suite) -> []; 180: seq4_test(Config) -> 181: do_test(seq4_test, Config). 182: 183: seq5_test(doc) -> ""; 184: seq5_test(suite) -> []; 185: seq5_test(Config) -> 186: do_test(seq5_test, Config). 187: 188: string1_test(doc) -> ""; 189: string1_test(suite) -> []; 190: string1_test(Config) -> 191: do_test(string1_test, Config). 192: 193: string2_test(doc) -> ""; 194: string2_test(suite) -> []; 195: string2_test(Config) -> 196: do_test(string2_test, Config). 197: 198: string3_test(doc) -> ""; 199: string3_test(suite) -> []; 200: string3_test(Config) -> 201: do_test(string3_test, Config). 202: 203: string4_test(doc) -> ""; 204: string4_test(suite) -> []; 205: string4_test(Config) -> 206: do_test(string4_test, Config). 207: 208: struct2_test(doc) -> ""; 209: struct2_test(suite) -> []; 210: struct2_test(Config) -> 211: do_test(struct2_test, Config). 212: 213: struct_test(doc) -> ""; 214: struct_test(suite) -> []; 215: struct_test(Config) -> 216: do_test(struct_test, Config). 217: 218: term_sequence_test(doc) -> ""; 219: term_sequence_test(suite) -> []; 220: term_sequence_test(Config) -> 221: do_test(term_sequence_test, Config). 222: 223: term_struct_test(doc) -> ""; 224: term_struct_test(suite) -> []; 225: term_struct_test(Config) -> 226: do_test(term_struct_test, Config). 227: 228: term_test(doc) -> ""; 229: term_test(suite) -> []; 230: term_test(Config) -> 231: do_test(term_test, Config). 232: 233: typedef_test(doc) -> ""; 234: typedef_test(suite) -> []; 235: typedef_test(Config) -> 236: do_test(typedef_test, Config). 237: 238: unsigned_long_long_test(doc) -> ""; 239: unsigned_long_long_test(suite) -> []; 240: unsigned_long_long_test(Config) -> 241: do_test(unsigned_long_long_test, Config). 242: 243: unsigned_long_test(doc) -> ""; 244: unsigned_long_test(suite) -> []; 245: unsigned_long_test(Config) -> 246: do_test(unsigned_long_test, Config). 247: 248: unsigned_short_test(doc) -> ""; 249: unsigned_short_test(suite) -> []; 250: unsigned_short_test(Config) -> 251: do_test(unsigned_short_test, Config). 252: 253: void_test(doc) -> ""; 254: void_test(suite) -> []; 255: void_test(Config) -> 256: do_test(void_test, Config). 257: 258: wchar_test(doc) -> ""; 259: wchar_test(suite) -> []; 260: wchar_test(Config) -> 261: do_test(wchar_test, Config). 262: 263: wstring1_test(doc) -> ""; 264: wstring1_test(suite) -> []; 265: wstring1_test(Config) -> 266: do_test(wstring1_test, Config). 267: 268: 269: %% It is here that all tests really are done. 270: %% 271: 272: do_test(Case, Config) -> 273: %% Trap exits 274: process_flag(trap_exit, true), 275: %% Start the server 276: {ok, _Pid} = m_i:oe_create_link([], {local, ?ERLANG_SERVER_NAME}), 277: Node = atom_to_list(node()), 278: %% [NodeName, HostName] = string:tokens(Node, "@"), 279: DataDir = ?config(data_dir, Config), 280: %% io:format("~p: data directory: ~p~n", [?MODULE, DataDir]), 281: Cookie = atom_to_list(erlang:get_cookie()), 282: %% Start C-client node as a port program. 283: Cmd = filename:join([DataDir, "c_client"]) ++ 284: " -this-node-name " ++ atom_to_list(?C_CLIENT_NODE_NAME) ++ 285: " -peer-node " ++ Node ++ 286: " -peer-process-name " ++ atom_to_list(?ERLANG_SERVER_NAME) ++ 287: " -cookie " ++ Cookie ++ 288: " -test-case " ++ atom_to_list(Case), 289: Port = open_port({spawn, Cmd}, [exit_status, eof, stderr_to_stdout]), 290: Res = wait_for_completion(Port), 291: %% Kill off node if there was timeout 292: case Res of 293: {error, timeout} -> 294: catch rpc:cast(?C_CLIENT_NODE_NAME, erlang, halt, [1]); 295: _ -> 296: ok 297: end, 298: process_flag(trap_exit, false), 299: catch m_i:stop(?ERLANG_SERVER_NAME), 300: ok = Res. 301: 302: 303: %% Wait for eof *and* exit status, but return if exit status indicates 304: %% an error, or we have been waiting more than PORT_TIMEOUT seconds. 305: %% 306: wait_for_completion(Port) -> 307: wait_for_completion(Port, 0). 308: 309: wait_for_completion(Port, N) when N < 2 -> 310: receive 311: {Port, {data, Bytes}} -> 312: %% Relay output 313: io:format("~s", [Bytes]), 314: wait_for_completion(Port, N); 315: {Port, {exit_status, 0}} -> 316: wait_for_completion(Port, N + 1); 317: {Port, {exit_status, Status}} -> 318: {error, Status}; 319: {Port, eof} -> 320: wait_for_completion(Port, N + 1); 321: {'EXIT', Port, Reason} -> 322: io:format("Port exited with reason: ~w~n", [Reason]), 323: wait_for_completion(Port, N); 324: {'EXIT', From, Reason} -> 325: io:format("Got unexpected exit: ~p~n", [{'EXIT', From, Reason}]), 326: wait_for_completion(Port, N) 327: after ?PORT_TIMEOUT -> 328: {error, timeout} 329: end; 330: wait_for_completion(_, _) -> 331: ok. 332: 333: 334: