diff options
Diffstat (limited to 'lib/kernel')
47 files changed, 1378 insertions, 569 deletions
diff --git a/lib/kernel/doc/src/gen_sctp.xml b/lib/kernel/doc/src/gen_sctp.xml index de41178a17..3a8011e28b 100644 --- a/lib/kernel/doc/src/gen_sctp.xml +++ b/lib/kernel/doc/src/gen_sctp.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2007</year><year>2009</year> + <year>2007</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>gen_sctp</title> @@ -170,10 +170,19 @@ <p>Establishes a new association for the socket <c>Socket</c>, with the peer (SCTP server socket) given by <c>Addr</c> and <c>Port</c>. The <c>Timeout</c>, - is expressed in milliseconds.</p> - <p>A socket can be associated with multiple peers. - <marker id="record-sctp_assoc_change"></marker> + is expressed in milliseconds. A socket can be associated with multiple peers.</p> + <p><b>WARNING:</b>Using a value of <c>Timeout</c> less than + the maximum time taken by the OS to establish an association (around 4.5 minutes + if the default values from RFC 4960 are used) can result in + inconsistent or incorrect return values. This is especially + relevant for associations sharing the same <c>Socket</c> + (i.e. source address and port) since the controlling process + blocks until <c>connect/*</c> returns. + <seealso marker="#connect_init/4">connect_init/*</seealso> + provides an alternative not subject to this limitation.</p> + + <p><marker id="record-sctp_assoc_change"></marker> The result of <c>connect/*</c> is an <c>#sctp_assoc_change{}</c> event which contains, in particular, the new <seealso marker="#type-assoc_id">Association ID:</seealso></p> @@ -233,6 +242,45 @@ </desc> </func> <func> + <name>connect_init(Socket, Addr, Port, Opts) -> ok | {error, posix()}</name> + <fsummary>Same as <c>connect_init(Socket, Addr, Port, Opts, infinity)</c>.</fsummary> + <desc> + <p>Same as <c>connect_init(Socket, Addr, Port, Opts, infinity)</c>.</p> + </desc> + </func> + <func> + <name>connect_init(Socket, Addr, Port, [Opt], Timeout) -> ok | {error, posix()}</name> + <fsummary>Initiate a new association for the socket <c>Socket</c>, with a peer (SCTP server socket)</fsummary> + <type> + <v>Socket = sctp_socket()</v> + <v>Addr = ip_address() | Host</v> + <v>Port = port_number()</v> + <v>Opt = sctp_option()</v> + <v>Timeout = timeout()</v> + <v>Host = atom() | string()</v> + </type> + <desc> + <p>Initiates a new association for the socket <c>Socket</c>, + with the peer (SCTP server socket) given by + <c>Addr</c> and <c>Port</c>.</p> + <p>The fundamental difference between this API + and <c>connect/*</c> is that the return value is that of the + underlying OS connect(2) system call. If <c>ok</c> is returned + then the result of the association establishement is received + by the calling process as + an <seealso marker="#record-sctp_assoc_change"> + #sctp_assoc_change{}</seealso> + event. The calling process must be prepared to receive this, or + poll for it using <c>recv/*</c> depending on the value of the + active option.</p> + <p>The parameters are as described + in <seealso marker="#connect/5">connect/*</seealso>, with the + exception of the <c>Timeout</c> value.</p> + <p>The timer associated with <c>Timeout</c> only supervises + IP resolution of <c>Addr</c></p> + </desc> + </func> + <func> <name>controlling_process(sctp_socket(), pid()) -> ok</name> <fsummary>Assign a new controlling process pid to the socket</fsummary> <desc> @@ -1058,6 +1106,65 @@ gen_sctp:close(S). </pre> <p></p> </item> + <item> + <p>A very simple Erlang SCTP Client which uses the + connect_init API.</p> + <pre> +-module(ex3). + +-export([client/4]). +-include_lib("kernel/include/inet.hrl"). +-include_lib("kernel/include/inet_sctp.hrl"). + +client(Peer1, Port1, Peer2, Port2) + when is_tuple(Peer1), is_integer(Port1), is_tuple(Peer2), is_integer(Port2) -> + {ok,S} = gen_sctp:open(), + SctpInitMsgOpt = {sctp_initmsg,#sctp_initmsg{num_ostreams=5}}, + ActiveOpt = {active, true}, + Opts = [SctpInitMsgOpt, ActiveOpt], + ok = gen_sctp:connect(S, Peer1, Port1, Opts), + ok = gen_sctp:connect(S, Peer2, Port2, Opts), + io:format("Connections initiated~n", []), + client_loop(S, Peer1, Port1, undefined, Peer2, Port2, undefined). + +client_loop(S, Peer1, Port1, AssocId1, Peer2, Port2, AssocId2) -> + receive + {sctp, S, Peer1, Port1, {_Anc, SAC}} + when is_record(SAC, sctp_assoc_change), AssocId1 == undefined -> + io:format("Association 1 connect result: ~p. AssocId: ~p~n", + [SAC#sctp_assoc_change.state, + SAC#sctp_assoc_change.assoc_id]), + client_loop(S, Peer1, Port1, SAC#sctp_assoc_change.assoc_id, + Peer2, Port2, AssocId2); + + {sctp, S, Peer2, Port2, {_Anc, SAC}} + when is_record(SAC, sctp_assoc_change), AssocId2 == undefined -> + io:format("Association 2 connect result: ~p. AssocId: ~p~n", + [SAC#sctp_assoc_change.state, SAC#sctp_assoc_change.assoc_id]), + client_loop(S, Peer1, Port1, AssocId1, Peer2, Port2, + SAC#sctp_assoc_change.assoc_id); + + {sctp, S, Peer1, Port1, Data} -> + io:format("Association 1: received ~p~n", [Data]), + client_loop(S, Peer1, Port1, AssocId1, + Peer2, Port2, AssocId2); + + {sctp, S, Peer2, Port2, Data} -> + io:format("Association 2: received ~p~n", [Data]), + client_loop(S, Peer1, Port1, AssocId1, + Peer2, Port2, AssocId2); + + Other -> + io:format("Other ~p~n", [Other]), + client_loop(S, Peer1, Port1, AssocId1, + Peer2, Port2, AssocId2) + + after 5000 -> + ok + end. +</pre> + <p></p> + </item> </list> </section> diff --git a/lib/kernel/src/Makefile b/lib/kernel/src/Makefile index ef280058fb..9db6014a7d 100644 --- a/lib/kernel/src/Makefile +++ b/lib/kernel/src/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1996-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1996-2010. 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 # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # @@ -143,6 +143,9 @@ APPUP_TARGET= $(EBIN)/$(APPUP_FILE) # FLAGS # ---------------------------------------------------- +ifeq ($(NATIVE_LIBS_ENABLED),yes) +ERL_COMPILE_FLAGS += +native +endif ERL_COMPILE_FLAGS += -I../include # ---------------------------------------------------- @@ -154,7 +157,7 @@ debug opt: $(TARGET_FILES) # Note: In the open-source build clean must not destroyed the preloaded # beam files. clean: - rm -f $(NON_PRECIOUS_TARGETS) + rm -f $(TARGET_FILES) rm -f core diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl index fef11d7e6e..ffe58ae7a9 100644 --- a/lib/kernel/src/code.erl +++ b/lib/kernel/src/code.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(code). @@ -63,7 +63,7 @@ which/1, where_is_file/1, where_is_file/2, - set_primary_archive/2, + set_primary_archive/3, clash/0]). -include_lib("kernel/include/file.hrl"). @@ -101,7 +101,7 @@ %% unstick_dir(Dir) -> ok | error %% is_sticky(Module) -> true | false %% which(Module) -> Filename -%% set_primary_archive((FileName, Bin) -> ok | {error, Reason} +%% set_primary_archive((FileName, Bin, FileInfo) -> ok | {error, Reason} %% clash() -> -> print out %%---------------------------------------------------------------------------- @@ -420,11 +420,15 @@ where_is_file(Path, File) when is_list(Path), is_list(File) -> which(File, ".", Path) end. --spec set_primary_archive(ArchiveFile :: file:filename(), ArchiveBin :: binary()) -> 'ok' | {'error', atom()}. +-spec set_primary_archive(ArchiveFile :: file:filename(), + ArchiveBin :: binary(), + FileInfo :: #file_info{}) + -> 'ok' | {'error', atom()}. -set_primary_archive(ArchiveFile0, ArchiveBin) when is_list(ArchiveFile0), is_binary(ArchiveBin) -> +set_primary_archive(ArchiveFile0, ArchiveBin, FileInfo) + when is_list(ArchiveFile0), is_binary(ArchiveBin), is_record(FileInfo, file_info) -> ArchiveFile = filename:absname(ArchiveFile0), - case call({set_primary_archive, ArchiveFile, ArchiveBin}) of + case call({set_primary_archive, ArchiveFile, ArchiveBin, FileInfo}) of {ok, []} -> ok; {ok, _Mode, Ebins} -> @@ -461,7 +465,8 @@ search([{Dir, File} | Tail]) -> build([]) -> []; build([Dir|Tail]) -> - Files = filter(objfile_extension(), Dir, file:list_dir(Dir)), + Files = filter(objfile_extension(), Dir, + erl_prim_loader:list_dir(Dir)), [decorate(Files, Dir) | build(Tail)]. decorate([], _) -> []; diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl index 018f7f41d2..7aeddb73d1 100644 --- a/lib/kernel/src/code_server.erl +++ b/lib/kernel/src/code_server.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(code_server). @@ -384,8 +384,8 @@ handle_call(stop,{_From,_Tag}, S) -> handle_call({is_cached,_File}, {_From,_Tag}, S=#state{cache=no_cache}) -> {reply, no, S}; -handle_call({set_primary_archive, File, ArchiveBin}, {_From,_Tag}, S=#state{mode=Mode}) -> - case erl_prim_loader:set_primary_archive(File, ArchiveBin) of +handle_call({set_primary_archive, File, ArchiveBin, FileInfo}, {_From,_Tag}, S=#state{mode=Mode}) -> + case erl_prim_loader:set_primary_archive(File, ArchiveBin, FileInfo) of {ok, Files} -> {reply, {ok, Mode, Files}, S}; {error, Reason} -> @@ -1479,13 +1479,12 @@ finish_on_load(Ref, OnLoadRes, #state{on_load=OnLoad0,moddb=Db}=State) -> end. finish_on_load_1(Mod, File, OnLoadRes, WaitingPids, Db) -> - Keep = if - is_boolean(OnLoadRes) -> OnLoadRes; - true -> false - end, + Keep = OnLoadRes =:= ok, erlang:finish_after_on_load(Mod, Keep), Res = case Keep of - false -> {error,on_load_failure}; + false -> + finish_on_load_report(Mod, OnLoadRes), + {error,on_load_failure}; true -> ets:insert(Db, {Mod,File}), {module,Mod} @@ -1493,6 +1492,24 @@ finish_on_load_1(Mod, File, OnLoadRes, WaitingPids, Db) -> [reply(Pid, Res) || Pid <- WaitingPids], ok. +finish_on_load_report(_Mod, Atom) when is_atom(Atom) -> + %% No error reports for atoms. + ok; +finish_on_load_report(Mod, Term) -> + %% Play it very safe here. The error_logger module and + %% modules it depend on may not be loaded yet and there + %% would be a dead-lock if we called it directly + %% from the code_server process. + spawn(fun() -> + F = "The on_load function for module " + "~s returned ~P\n", + + %% Express the call as an apply to simplify + %% the ext_mod_dep/1 test case. + E = error_logger, + E:warning_msg(F, [Mod,Term,10]) + end). + %% ------------------------------------------------------- %% Internal functions. %% ------------------------------------------------------- diff --git a/lib/kernel/src/gen_sctp.erl b/lib/kernel/src/gen_sctp.erl index fcd1d1564a..5a31e3976f 100644 --- a/lib/kernel/src/gen_sctp.erl +++ b/lib/kernel/src/gen_sctp.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2007-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -27,7 +27,7 @@ -include("inet_sctp.hrl"). -export([open/0,open/1,open/2,close/1]). --export([listen/2,connect/4,connect/5]). +-export([listen/2,connect/4,connect/5,connect_init/4,connect_init/5]). -export([eof/2,abort/2]). -export([send/3,send/4,recv/1,recv/2]). -export([error_string/1]). @@ -80,7 +80,26 @@ listen(S, Flag) -> connect(S, Addr, Port, Opts) -> connect(S, Addr, Port, Opts, infinity). -connect(S, Addr, Port, Opts, Timeout) when is_port(S), is_list(Opts) -> +connect(S, Addr, Port, Opts, Timeout) -> + case do_connect(S, Addr, Port, Opts, Timeout, true) of + badarg -> + erlang:error(badarg, [S,Addr,Port,Opts,Timeout]); + Result -> + Result + end. + +connect_init(S, Addr, Port, Opts) -> + connect_init(S, Addr, Port, Opts, infinity). + +connect_init(S, Addr, Port, Opts, Timeout) -> + case do_connect(S, Addr, Port, Opts, Timeout, false) of + badarg -> + erlang:error(badarg, [S,Addr,Port,Opts,Timeout]); + Result -> + Result + end. + +do_connect(S, Addr, Port, Opts, Timeout, ConnWait) when is_port(S), is_list(Opts) -> case inet_db:lookup_socket(S) of {ok,Mod} -> case Mod:getserv(Port) of @@ -89,21 +108,26 @@ connect(S, Addr, Port, Opts, Timeout) when is_port(S), is_list(Opts) -> Timer -> try Mod:getaddr(Addr, Timer) of {ok,IP} -> - Mod:connect(S, IP, Port, Opts, Timer); + ConnectTimer = if ConnWait == false -> + nowait; + true -> + Timer + end, + Mod:connect(S, IP, Port, Opts, ConnectTimer); Error -> Error after inet:stop_timer(Timer) end catch error:badarg -> - erlang:error(badarg, [S,Addr,Port,Opts,Timeout]) + badarg end; Error -> Error end; Error -> Error end; -connect(S, Addr, Port, Opts, Timeout) -> - erlang:error(badarg, [S,Addr,Port,Opts,Timeout]). +do_connect(_S, _Addr, _Port, _Opts, _Timeout, _ConnWait) -> + badarg. diff --git a/lib/kernel/src/hipe_unified_loader.erl b/lib/kernel/src/hipe_unified_loader.erl index 7e26d57ced..f289b8110d 100644 --- a/lib/kernel/src/hipe_unified_loader.erl +++ b/lib/kernel/src/hipe_unified_loader.erl @@ -103,10 +103,15 @@ load_native_code(Mod, Bin) when is_atom(Mod), is_binary(Bin) -> case code:get_chunk(Bin, ChunkTag) of undefined -> no_native; NativeCode when is_binary(NativeCode) -> - OldReferencesToPatch = patch_to_emu_step1(Mod), - case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of - bad_crc -> no_native; - Result -> Result + erlang:system_flag(multi_scheduling, block), + try + OldReferencesToPatch = patch_to_emu_step1(Mod), + case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of + bad_crc -> no_native; + Result -> Result + end + after + erlang:system_flag(multi_scheduling, unblock) end end catch @@ -121,8 +126,17 @@ load_native_code(Mod, Bin) when is_atom(Mod), is_binary(Bin) -> post_beam_load(Mod) when is_atom(Mod) -> Architecture = erlang:system_info(hipe_architecture), - try chunk_name(Architecture) of _ChunkTag -> patch_to_emu(Mod) - catch _:_ -> ok + try chunk_name(Architecture) of + _ChunkTag -> + erlang:system_flag(multi_scheduling, block), + try + patch_to_emu(Mod) + after + erlang:system_flag(multi_scheduling, unblock) + end + catch + _:_ -> + ok end. %%======================================================================== @@ -141,6 +155,14 @@ version_check(Version, Mod) when is_atom(Mod) -> -spec load_module(Mod, binary(), _) -> 'bad_crc' | {'module',Mod} when is_subtype(Mod,atom()). load_module(Mod, Bin, Beam) -> + erlang:system_flag(multi_scheduling, block), + try + load_module_nosmp(Mod, Bin, Beam) + after + erlang:system_flag(multi_scheduling, unblock) + end. + +load_module_nosmp(Mod, Bin, Beam) -> load_module(Mod, Bin, Beam, []). load_module(Mod, Bin, Beam, OldReferencesToPatch) -> @@ -154,6 +176,14 @@ load_module(Mod, Bin, Beam, OldReferencesToPatch) -> -spec load(Mod, binary()) -> 'bad_crc' | {'module',Mod} when is_subtype(Mod,atom()). load(Mod, Bin) -> + erlang:system_flag(multi_scheduling, block), + try + load_nosmp(Mod, Bin) + after + erlang:system_flag(multi_scheduling, unblock) + end. + +load_nosmp(Mod, Bin) -> ?debug_msg("********* Loading funs in module ~w *********\n",[Mod]), %% Loading just some functions in a module; patch closures separately. put(hipe_patch_closures, true), diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl index b86aa1839e..eb503235d8 100644 --- a/lib/kernel/src/inet.erl +++ b/lib/kernel/src/inet.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet). @@ -45,6 +45,7 @@ %% resolve -export([gethostbyname/1, gethostbyname/2, gethostbyname/3, gethostbyname_tm/3]). +-export([gethostbyname_string/2, gethostbyname_self/2]). -export([gethostbyaddr/1, gethostbyaddr/2, gethostbyaddr_tm/2]). @@ -411,7 +412,17 @@ gethostbyname(Name,Family,Timeout) -> Res. gethostbyname_tm(Name,Family,Timer) -> - gethostbyname_tm(Name,Family,Timer,inet_db:res_option(lookup)). + Opts0 = inet_db:res_option(lookup), + Opts = + case (lists:member(native, Opts0) orelse + lists:member(string, Opts0) orelse + lists:member(nostring, Opts0)) of + true -> + Opts0; + false -> + [string|Opts0] + end, + gethostbyname_tm(Name, Family, Timer, Opts). -spec gethostbyaddr(Address :: string() | ip_address()) -> @@ -850,75 +861,61 @@ getaddrs_tm(Address, Family, Timer) -> %% %% gethostbyname with option search %% -gethostbyname_tm(Name, Type, Timer, [dns | Opts]) -> - Res = inet_res:gethostbyname_tm(Name, Type, Timer), - case Res of - {ok,_} -> Res; - {error,timeout} -> Res; - {error,formerr} -> {error,einval}; - {error,_} -> gethostbyname_tm(Name,Type,Timer,Opts) - end; -gethostbyname_tm(Name, Type, Timer, [file | Opts]) -> - case inet_hosts:gethostbyname(Name, Type) of - {error,formerr} -> {error,einval}; - {error,_} -> gethostbyname_tm(Name,Type,Timer,Opts); - Result -> Result - end; -gethostbyname_tm(Name, Type, Timer, [yp | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [string|_]=Opts) -> + Result = gethostbyname_string(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [dns|_]=Opts) -> + Result = inet_res:gethostbyname_tm(Name, Type, Timer), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [file|_]=Opts) -> + Result = inet_hosts:gethostbyname(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [yp|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [nis | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [nis|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [nisplus | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [nisplus|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [wins | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [wins|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [native | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [native|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(_, _, _, [no_default|_]) -> - %% If the native resolver has failed, we should not bother - %% to try to be smarter and parse the IP address here. - {error,nxdomain}; -gethostbyname_tm(Name, Type, Timer, [_ | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [_|_]=Opts) -> gethostbyname_tm(Name, Type, Timer, Opts); -%% Last resort - parse the hostname as address -gethostbyname_tm(Name, inet, _Timer, []) -> - case inet_parse:ipv4_address(Name) of - {ok,IP4} -> - {ok,make_hostent(Name, [IP4], [], inet)}; - _ -> - gethostbyname_self(Name) - end; -gethostbyname_tm(Name, inet6, _Timer, []) -> - case inet_parse:ipv6_address(Name) of - {ok,IP6} -> - {ok,make_hostent(Name, [IP6], [], inet6)}; - _ -> - %% Even if Name is a valid IPv4 address, we can't - %% assume it's correct to return it on a IPv6 - %% format ( {0,0,0,0,0,16#ffff,?u16(A,B),?u16(C,D)} ). - %% This host might not support IPv6. - gethostbyname_self(Name) +%% Make sure we always can look up our own hostname. +gethostbyname_tm(Name, Type, Timer, []) -> + Result = gethostbyname_self(Name, Type), + gethostbyname_tm(Name, Type, Timer, [], Result). + +gethostbyname_tm(Name, Type, Timer, Opts, Result) -> + case Result of + {ok,_} -> + Result; + {error,formerr} -> + {error,einval}; + {error,_} when Opts =:= [] -> + {error,nxdomain}; + {error,_} -> + gethostbyname_tm(Name, Type, Timer, tl(Opts)) end. gethostbyname_tm_native(Name, Type, Timer, Opts) -> %% Fixme: add (global) timeout to gethost_native - case inet_gethost_native:gethostbyname(Name, Type) of - {error,formerr} -> {error,einval}; - {error,timeout} -> {error,timeout}; - {error,_} -> gethostbyname_tm(Name, Type, Timer, Opts++[no_default]); - Result -> Result - end. + Result = inet_gethost_native:gethostbyname(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result). -%% Make sure we always can look up our own hostname. -gethostbyname_self(Name) -> - Type = case inet_db:res_option(inet6) of - true -> inet6; - false -> inet - end, + + +gethostbyname_self(Name, Type) when is_atom(Name) -> + gethostbyname_self(atom_to_list(Name), Type); +gethostbyname_self(Name, Type) + when is_list(Name), Type =:= inet; + is_list(Name), Type =:= inet6 -> case inet_db:gethostname() of Name -> - {ok,make_hostent(Name, [translate_ip(loopback, Type)], - [], Type)}; + {ok,make_hostent(Name, + [translate_ip(loopback, Type)], + [], Type)}; Self -> case inet_db:res_option(domain) of "" -> {error,nxdomain}; @@ -931,7 +928,31 @@ gethostbyname_self(Name) -> _ -> {error,nxdomain} end end - end. + end; +gethostbyname_self(_, _) -> + {error,formerr}. + +gethostbyname_string(Name, Type) when is_atom(Name) -> + gethostbyname_string(atom_to_list(Name), Type); +gethostbyname_string(Name, Type) + when is_list(Name), Type =:= inet; + is_list(Name), Type =:= inet6 -> + case + case Type of + inet -> + inet_parse:ipv4_address(Name); + inet6 -> + %% XXX should we really translate IPv4 addresses here + %% even if we do not know if this host can do IPv6? + inet_parse:ipv6_address(Name) + end of + {ok,IP} -> + {ok,make_hostent(Name, [IP], [], Type)}; + {error,einval} -> + {error,nxdomain} + end; +gethostbyname_string(_, _) -> + {error,formerr}. make_hostent(Name, Addrs, Aliases, Type) -> #hostent{h_name = Name, diff --git a/lib/kernel/src/inet_config.erl b/lib/kernel/src/inet_config.erl index b5317f72f5..311e6bc9f9 100644 --- a/lib/kernel/src/inet_config.erl +++ b/lib/kernel/src/inet_config.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_config). @@ -130,21 +130,25 @@ init() -> {unix,_} -> %% The Etc variable enables us to run tests with other %% configuration files than the normal ones - Etc = case os:getenv("ERL_INET_ETC_DIR") of - false -> ?DEFAULT_ETC; - _EtcDir -> - _EtcDir - end, + Etc = + case os:getenv("ERL_INET_ETC_DIR") of + false -> + ?DEFAULT_ETC; + _EtcDir -> + _EtcDir + end, case inet_db:res_option(resolv_conf) of undefined -> - inet_db:set_resolv_conf(filename:join(Etc, - ?DEFAULT_RESOLV)); + inet_db:res_option( + resolv_conf_name, + filename:join(Etc, ?DEFAULT_RESOLV)); _ -> ok end, case inet_db:res_option(hosts_file) of undefined -> - inet_db:set_hosts_file(filename:join(Etc, - ?DEFAULT_HOSTS)); + inet_db:res_option( + hosts_file_name, + filename:join(Etc, ?DEFAULT_HOSTS)); _ -> ok end; _ -> ok diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl index 211847014f..a05b380855 100644 --- a/lib/kernel/src/inet_db.erl +++ b/lib/kernel/src/inet_db.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -425,7 +425,9 @@ res_optname(usevc) -> res_usevc; res_optname(edns) -> res_edns; res_optname(udp_payload_size) -> res_udp_payload_size; res_optname(resolv_conf) -> res_resolv_conf; +res_optname(resolv_conf_name) -> res_resolv_conf; res_optname(hosts_file) -> res_hosts_file; +res_optname(hosts_file_name) -> res_hosts_file; res_optname(_) -> undefined. res_check_option(nameserver, NSs) -> %% Legacy @@ -458,9 +460,15 @@ res_check_option(udp_payload_size, S) when is_integer(S), S >= 512 -> true; res_check_option(resolv_conf, "") -> true; res_check_option(resolv_conf, F) -> res_check_option_absfile(F); +res_check_option(resolv_conf_name, "") -> true; +res_check_option(resolv_conf_name, F) -> + res_check_option_absfile(F); res_check_option(hosts_file, "") -> true; res_check_option(hosts_file, F) -> res_check_option_absfile(F); +res_check_option(hosts_file_name, "") -> true; +res_check_option(hosts_file_name, F) -> + res_check_option_absfile(F); res_check_option(_, _) -> false. res_check_option_absfile(F) -> @@ -503,7 +511,7 @@ res_update_hosts() -> res_update(res_hosts_file, res_hosts_file_tm, res_hosts_file_info, set_hosts_file_tm, fun set_hosts_file/1). -res_update(Tag, TagTm, TagInfo, CallTag, SetFun) -> +res_update(Tag, TagTm, TagInfo, TagSetTm, SetFun) -> case db_get(TagTm) of undefined -> ok; TM -> @@ -522,12 +530,12 @@ res_update(Tag, TagTm, TagInfo, CallTag, SetFun) -> atime = undefined}, case db_get(TagInfo) of Finfo -> - call({CallTag, Now}); + call({TagSetTm, Now}); _ -> SetFun(File) end; _ -> - call({CallTag, Now}), + call({TagSetTm, Now}), error end end; @@ -974,37 +982,55 @@ handle_call(Request, From, #state{db=Db}=State) -> {reply, error, State} end; + {res_set, hosts_file_name=Option, Fname} -> + handle_set_file( + Option, Fname, res_hosts_file_tm, res_hosts_file_info, + undefined, From, State); + {res_set, resolv_conf_name=Option, Fname} -> + handle_set_file( + Option, Fname, res_resolv_conf_tm, res_resolv_conf_info, + undefined, From, State); + {res_set, hosts_file=Option, Fname} -> - handle_set_file(Option, Fname, - res_hosts_file_tm, res_hosts_file_info, - fun (Bin) -> - case inet_parse:hosts(Fname, - {chars,Bin}) of - {ok,Opts} -> - [{load_hosts_file,Opts}]; - _ -> error - end - end, - From, State); + handle_set_file( + Option, Fname, res_hosts_file_tm, res_hosts_file_info, + fun (Bin) -> + case inet_parse:hosts( + Fname, {chars,Bin}) of + {ok,Opts} -> + [{load_hosts_file,Opts}]; + _ -> error + end + end, + From, State); %% {res_set, resolv_conf=Option, Fname} -> - handle_set_file(Option, Fname, - res_resolv_conf_tm, res_resolv_conf_info, - fun (Bin) -> - case inet_parse:resolv(Fname, - {chars,Bin}) of - {ok,Opts} -> - [del_ns, - clear_search, - clear_cache - |[Opt || - {T,_}=Opt <- Opts, - (T =:= nameserver orelse - T =:= search)]]; - _ -> error - end - end, - From, State); + handle_set_file( + Option, Fname, res_resolv_conf_tm, res_resolv_conf_info, + fun (Bin) -> + case inet_parse:resolv( + Fname, {chars,Bin}) of + {ok,Opts} -> + Search = + lists:foldl( + fun ({search,L}, _) -> + L; + ({domain,""}, S) -> + S; + ({domain,D}, _) -> + [D]; + (_, S) -> + S + end, [], Opts), + [del_ns, + clear_search, + clear_cache, + {search,Search} + |[Opt || {nameserver,_}=Opt <- Opts]]; + _ -> error + end + end, + From, State); %% {res_set, Opt, Value} -> case res_optname(Opt) of @@ -1156,6 +1182,12 @@ handle_set_file(Option, Fname, TagTm, TagInfo, ParseFun, From, ets:delete(Db, TagInfo), ets:delete(Db, TagTm), handle_set_file(ParseFun, <<>>, From, State); + true when ParseFun =:= undefined -> + File = filename:flatten(Fname), + ets:insert(Db, {res_optname(Option), File}), + ets:insert(Db, {TagInfo, undefined}), + ets:insert(Db, {TagTm, 0}), + {reply,ok,State}; true -> File = filename:flatten(Fname), ets:insert(Db, {res_optname(Option), File}), @@ -1178,7 +1210,8 @@ handle_set_file(Option, Fname, TagTm, TagInfo, ParseFun, From, handle_set_file(ParseFun, Bin, From, State) -> case ParseFun(Bin) of - error -> {reply,error,State}; + error -> + {reply,error,State}; Opts -> handle_rc_list(Opts, From, State) end. diff --git a/lib/kernel/src/inet_gethost_native.erl b/lib/kernel/src/inet_gethost_native.erl index abdbe2b8cf..fabe9bf8b3 100644 --- a/lib/kernel/src/inet_gethost_native.erl +++ b/lib/kernel/src/inet_gethost_native.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_gethost_native). @@ -443,19 +443,23 @@ gethostbyname(Name) -> gethostbyname(Name, inet). gethostbyname(Name, inet) when is_list(Name) -> - getit(?OP_GETHOSTBYNAME, ?PROTO_IPV4, Name); + getit(?OP_GETHOSTBYNAME, ?PROTO_IPV4, Name, Name); gethostbyname(Name, inet6) when is_list(Name) -> - getit(?OP_GETHOSTBYNAME, ?PROTO_IPV6, Name); + getit(?OP_GETHOSTBYNAME, ?PROTO_IPV6, Name, Name); gethostbyname(Name, Type) when is_atom(Name) -> gethostbyname(atom_to_list(Name), Type); gethostbyname(_, _) -> {error, formerr}. -gethostbyaddr({A,B,C,D}) when ?VALID_V4(A), ?VALID_V4(B), ?VALID_V4(C), ?VALID_V4(D) -> - getit(?OP_GETHOSTBYADDR, ?PROTO_IPV4, <<A,B,C,D>>); -gethostbyaddr({A,B,C,D,E,F,G,H}) when ?VALID_V6(A), ?VALID_V6(B), ?VALID_V6(C), ?VALID_V6(D), - ?VALID_V6(E), ?VALID_V6(F), ?VALID_V6(G), ?VALID_V6(H) -> - getit(?OP_GETHOSTBYADDR, ?PROTO_IPV6, <<A:16,B:16,C:16,D:16,E:16,F:16,G:16,H:16>>); +gethostbyaddr({A,B,C,D}=Addr) + when ?VALID_V4(A), ?VALID_V4(B), ?VALID_V4(C), ?VALID_V4(D) -> + getit(?OP_GETHOSTBYADDR, ?PROTO_IPV4, <<A,B,C,D>>, Addr); +gethostbyaddr({A,B,C,D,E,F,G,H}=Addr) + when ?VALID_V6(A), ?VALID_V6(B), ?VALID_V6(C), ?VALID_V6(D), + ?VALID_V6(E), ?VALID_V6(F), ?VALID_V6(G), ?VALID_V6(H) -> + getit + (?OP_GETHOSTBYADDR, ?PROTO_IPV6, + <<A:16,B:16,C:16,D:16,E:16,F:16,G:16,H:16>>, Addr); gethostbyaddr(Addr) when is_list(Addr) -> case inet_parse:address(Addr) of {ok, IP} -> gethostbyaddr(IP); @@ -466,30 +470,30 @@ gethostbyaddr(Addr) when is_atom(Addr) -> gethostbyaddr(_) -> {error, formerr}. control({debug_level, Level}) when is_integer(Level) -> - getit(?OP_CONTROL, ?SETOPT_DEBUG_LEVEL, <<Level:32>>); + getit(?OP_CONTROL, ?SETOPT_DEBUG_LEVEL, <<Level:32>>, undefined); control(soft_restart) -> - getit(restart_port); + getit(restart_port, undefined); control(_) -> {error, formerr}. -getit(Op, Proto, Data) -> - getit({Op, Proto, Data}). +getit(Op, Proto, Data, DefaultName) -> + getit({Op, Proto, Data}, DefaultName). -getit(Req) -> +getit(Req, DefaultName) -> Pid = ensure_started(), Ref = make_ref(), Pid ! {{self(),Ref}, Req}, receive {Ref, {ok,BinHostent}} -> - parse_address(BinHostent); - {Ref, Error} -> - Error + parse_address(BinHostent, DefaultName); + {Ref, Result} -> + Result after 5000 -> Ref2 = erlang:monitor(process,Pid), Res2 = receive {Ref, {ok,BinHostent}} -> - parse_address(BinHostent); - {Ref, Error} -> - Error; + parse_address(BinHostent, DefaultName); + {Ref, Result} -> + Result; {'DOWN', Ref2, process, Pid, Reason} -> {error, Reason} @@ -546,21 +550,23 @@ ensure_started() -> Pid end. -parse_address(BinHostent) -> +parse_address(BinHostent, DefaultName) -> case catch begin case BinHostent of <<?UNIT_ERROR, Errstring/binary>> -> {error, list_to_atom(listify(Errstring))}; <<?UNIT_IPV4, Naddr:32, T0/binary>> -> - {T1,Addresses} = pick_addresses_v4(Naddr, T0), - [Name | Names] = pick_names(T1), + {T1, Addresses} = pick_addresses_v4(Naddr, T0), + {Name, Names} = + expand_default_name(pick_names(T1), DefaultName), {ok, #hostent{h_addr_list = Addresses, h_addrtype = inet, h_aliases = Names, h_length = ?UNIT_IPV4, h_name = Name}}; <<?UNIT_IPV6, Naddr:32, T0/binary>> -> - {T1,Addresses} = pick_addresses_v6(Naddr, T0), - [Name | Names] = pick_names(T1), + {T1, Addresses} = pick_addresses_v6(Naddr, T0), + {Name, Names} = + expand_default_name(pick_names(T1), DefaultName), {ok, #hostent{h_addr_list = Addresses, h_addrtype = inet6, h_aliases = Names, h_length = ?UNIT_IPV6, h_name = Name}}; @@ -573,7 +579,15 @@ parse_address(BinHostent) -> Normal -> Normal end. - + +expand_default_name([], DefaultName) when is_list(DefaultName) -> + {DefaultName, []}; +expand_default_name([], DefaultName) when is_tuple(DefaultName) -> + {inet_parse:ntoa(DefaultName), []}; +expand_default_name([Name|Names], DefaultName) + when is_list(DefaultName); is_tuple(DefaultName) -> + {Name, Names}. + listify(Bin) -> N = byte_size(Bin) - 1, <<Bin2:N/binary, Ch>> = Bin, diff --git a/lib/kernel/src/inet_parse.erl b/lib/kernel/src/inet_parse.erl index 62d44fb723..3bd5fa0958 100644 --- a/lib/kernel/src/inet_parse.erl +++ b/lib/kernel/src/inet_parse.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_parse). @@ -34,6 +34,7 @@ -export([nsswitch_conf/1, nsswitch_conf/2]). -export([ipv4_address/1, ipv6_address/1]). +-export([ipv4strict_address/1, ipv6strict_address/1]). -export([address/1]). -export([visible_string/1, domain/1]). -export([ntoa/1, dots/1]). @@ -456,17 +457,15 @@ is_dom2(_) -> %% -%% Test ipv4 address or ipv6 address +%% Parse ipv4 address or ipv6 address %% Return {ok, Address} | {error, Reason} %% address(Cs) when is_list(Cs) -> case ipv4_address(Cs) of - {ok,IP} -> {ok,IP}; + {ok,IP} -> + {ok,IP}; _ -> - case ipv6_address(Cs) of - {ok, IP} -> {ok, IP}; - Error -> Error - end + ipv6strict_address(Cs) end; address(_) -> {error, einval}. @@ -477,49 +476,145 @@ address(_) -> %% d1.d2.d4 %% d1.d4 %% d4 +%% Any d may be octal, hexadecimal or decimal by C language standards. +%% d4 fills all LSB bytes. This is legacy behaviour from Solaris +%% and FreeBSD. And partly Linux that behave the same except +%% it does not accept hexadecimal. %% %% Return {ok, IP} | {error, einval} %% ipv4_address(Cs) -> - case catch ipv4_addr(Cs) of - {'EXIT',_} -> {error,einval}; - Addr -> {ok,Addr} + try ipv4_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} end. -ipv4_addr(Cs) -> - ipv4_addr(d3(Cs), []). +ipv4_addr(Cs) -> + case ipv4_addr(Cs, []) of + [D] when D < (1 bsl 32) -> + <<D1,D2,D3,D4>> = <<D:32>>, + {D1,D2,D3,D4}; + [D,D1] when D < (1 bsl 24), D1 < 256 -> + <<D2,D3,D4>> = <<D:24>>, + {D1,D2,D3,D4}; + [D,D2,D1] when D < (1 bsl 16), (D2 bor D1) < 256 -> + <<D3,D4>> = <<D:16>>, + {D1,D2,D3,D4}; + [D4,D3,D2,D1] when (D4 bor D3 bor D2 bor D1) < 256 -> + {D1,D2,D3,D4}; + _ -> + erlang:error(badarg) + end. -ipv4_addr({Cs0,[]}, A) when length(A) =< 3 -> - case [tod(Cs0)|A] of - [D4,D3,D2,D1] -> +ipv4_addr([_|_], [_,_,_,_]) -> + %% Early bailout for extra characters + erlang:error(badarg); +ipv4_addr("0x"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [], 16, 8); +ipv4_addr("0X"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [], 16, 8); +ipv4_addr("0"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [$0], 8, 11); +ipv4_addr(Cs, Ds) when is_list(Cs) -> + ipv4_addr(Cs, Ds, [], 10, 10). + +ipv4_addr(Cs0, Ds, Rs, Base, N) -> + case ipv4_field(Cs0, N, Rs, Base) of + {D,""} -> + [D|Ds]; + {D,[$.|[_|_]=Cs]} -> + ipv4_addr(Cs, [D|Ds]); + {_,_} -> + erlang:error(badarg) + end. + +strip0("0"++Cs) -> + strip0(Cs); +strip0(Cs) when is_list(Cs) -> + Cs. + + +%% +%% Parse IPv4 strict dotted decimal address, no leading zeros: +%% d1.d2.d3.d4 +%% +%% Return {ok, IP} | {error, einval} +%% +ipv4strict_address(Cs) -> + try ipv4strict_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} + end. + +ipv4strict_addr(Cs) -> + case ipv4strict_addr(Cs, []) of + [D4,D3,D2,D1] when (D4 bor D3 bor D2 bor D1) < 256 -> {D1,D2,D3,D4}; - [D4,D2,D1] -> - {D1,D2,0,D4}; - [D4,D1] -> - {D1,0,0,D4}; - [D4] -> - {0,0,0,D4} - end; -ipv4_addr({Cs0,"."++Cs1}, A) when length(A) =< 2 -> - ipv4_addr(d3(Cs1), [tod(Cs0)|A]). + _ -> + erlang:error(badarg) + end. + +ipv4strict_addr([_|_], [_,_,_,_]) -> + %% Early bailout for extra characters + erlang:error(badarg); +ipv4strict_addr("0", Ds) -> + [0|Ds]; +ipv4strict_addr("0."++Cs, Ds) -> + ipv4strict_addr(Cs, [0|Ds]); +ipv4strict_addr(Cs0, Ds) when is_list(Cs0) -> + case ipv4_field(Cs0, 3, [], 10) of + {D,""} -> + [D|Ds]; + {D,[$.|[_|_]=Cs]} -> + ipv4strict_addr(Cs, [D|Ds]); + {_,_} -> + erlang:error(badarg) + end. + -d3(Cs) -> d3(Cs, []). -d3([C|Cs], R) when C >= $0, C =< $9, length(R) =< 2 -> - d3(Cs, [C|R]); -d3(Cs, [_|_]=R) -> - {lists:reverse(R),Cs}. +ipv4_field("", _, Rs, Base) -> + {ipv4_field(Rs, Base),""}; +ipv4_field("."++_=Cs, _, Rs, Base) -> + {ipv4_field(Rs, Base),Cs}; +ipv4_field("0"++_, _, [], _) -> + erlang:error(badarg); +ipv4_field([C|Cs], N, Rs, Base) when N > 0 -> + ipv4_field(Cs, N-1, [C|Rs], Base); +ipv4_field(Cs, _, _, _) when is_list(Cs) -> + erlang:error(badarg). + +ipv4_field(Rs, Base) -> + V = erlang:list_to_integer(lists:reverse(Rs), Base), + if V < 0 -> + erlang:error(badarg); + true -> + V + end. -tod(Cs) -> - case erlang:list_to_integer(Cs) of - D when D >= 0, D =< 255 -> - D; + + +%% +%% Forgiving IPv6 address +%% +%% Accepts IPv4 address and returns it as a IPv4 compatible IPv6 address +%% +ipv6_address(Cs) -> + case ipv4_address(Cs) of + {ok,{D1,D2,D3,D4}} -> + {ok,{0,0,0,0,0,16#ffff,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4}}; _ -> - erlang:error(badarg, [Cs]) + ipv6strict_address(Cs) end. %% -%% Parse IPv6 address: +%% Parse IPv6 address according to RFC 4291: %% x1:x2:x3:x4:x5:x6:x7:x8 %% x1:x2::x7:x8 %% ::x7:x8 @@ -530,77 +625,89 @@ tod(Cs) -> %% ::x5:x6:d7a.d7b.d8a.d8b %% x1:x2::d7a.d7b.d8a.d8b %% ::d7a.d7b.d8a.d8b +%% etc %% %% Return {ok, IP} | {error, einval} %% -ipv6_address(Cs) -> - case catch ipv6_addr(Cs) of - {'EXIT',_} -> {error,einval}; - Addr -> {ok,Addr} +ipv6strict_address(Cs) -> + try ipv6_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} end. ipv6_addr("::") -> - ipv6_addr_done([], []); + ipv6_addr_done([], [], 0); ipv6_addr("::"++Cs) -> - ipv6_addr(x4(Cs), [], []); + ipv6_addr(hex(Cs), [], [], 0); ipv6_addr(Cs) -> - ipv6_addr(x4(Cs), []). + ipv6_addr(hex(Cs), [], 0). %% Before "::" -ipv6_addr({Cs0,[]}, A) when length(A) =:= 7 -> - ipv6_addr_done([tox(Cs0)|A]); -ipv6_addr({Cs0,"::"}, A) when length(A) =< 6 -> - ipv6_addr_done([tox(Cs0)|A], []); -ipv6_addr({Cs0,"::"++Cs1}, A) when length(A) =< 5 -> - ipv6_addr(x4(Cs1), [tox(Cs0)|A], []); -ipv6_addr({Cs0,":"++Cs1}, A) when length(A) =< 6 -> - ipv6_addr(x4(Cs1), [tox(Cs0)|A]); -ipv6_addr({Cs0,"."++Cs1}, A) when length(A) =:= 6 -> - ipv6_addr(d3(Cs1), A, [], [tod(Cs0)]). +ipv6_addr({Cs0,[]}, A, N) when N == 7 -> + ipv6_addr_done([hex_to_int(Cs0)|A]); +ipv6_addr({Cs0,"::"}, A, N) when N =< 6 -> + ipv6_addr_done([hex_to_int(Cs0)|A], [], N+1); +ipv6_addr({Cs0,"::"++Cs1}, A, N) when N =< 5 -> + ipv6_addr(hex(Cs1), [hex_to_int(Cs0)|A], [], N+1); +ipv6_addr({Cs0,":"++Cs1}, A, N) when N =< 6 -> + ipv6_addr(hex(Cs1), [hex_to_int(Cs0)|A], N+1); +ipv6_addr({Cs0,"."++_=Cs1}, A, N) when N == 6 -> + ipv6_addr_done(A, [], N, ipv4strict_addr(Cs0++Cs1)); +ipv6_addr(_, _, _) -> + erlang:error(badarg). %% After "::" -ipv6_addr({Cs0,[]}, A, B) when length(A)+length(B) =< 6 -> - ipv6_addr_done(A, [tox(Cs0)|B]); -ipv6_addr({Cs0,":"++Cs1}, A, B) when length(A)+length(B) =< 5 -> - ipv6_addr(x4(Cs1), A, [tox(Cs0)|B]); -ipv6_addr({Cs0,"."++Cs1}, A, B) when length(A)+length(B) =< 5 -> - ipv6_addr(x4(Cs1), A, B, [tod(Cs0)]). +ipv6_addr({Cs0,[]}, A, B, N) when N =< 6 -> + ipv6_addr_done(A, [hex_to_int(Cs0)|B], N+1); +ipv6_addr({Cs0,":"++Cs1}, A, B, N) when N =< 5 -> + ipv6_addr(hex(Cs1), A, [hex_to_int(Cs0)|B], N+1); +ipv6_addr({Cs0,"."++_=Cs1}, A, B, N) when N =< 5 -> + ipv6_addr_done(A, B, N, ipv4strict_addr(Cs0++Cs1)); +ipv6_addr(_, _, _, _) -> + erlang:error(badarg). -%% After "." -ipv6_addr({Cs0,[]}, A, B, C) when length(C) =:= 3 -> - ipv6_addr_done(A, B, [tod(Cs0)|C]); -ipv6_addr({Cs0,"."++Cs1}, A, B, C) when length(C) =< 2 -> - ipv6_addr(d3(Cs1), A, B, [tod(Cs0)|C]). +ipv6_addr_done(Ar, Br, N, {D1,D2,D3,D4}) -> + ipv6_addr_done(Ar, [((D3 bsl 8) bor D4),((D1 bsl 8) bor D2)|Br], N+2). -ipv6_addr_done(Ar, Br, [D4,D3,D2,D1]) -> - ipv6_addr_done(Ar, [((D3 bsl 8) bor D4),((D1 bsl 8) bor D2)|Br]). - -ipv6_addr_done(Ar, Br) -> - ipv6_addr_done(Br++dup(8-length(Ar)-length(Br), 0, Ar)). +ipv6_addr_done(Ar, Br, N) -> + ipv6_addr_done(Br++dup(8-N, 0, Ar)). ipv6_addr_done(Ar) -> list_to_tuple(lists:reverse(Ar)). -x4(Cs) -> x4(Cs, []). - -x4([C|Cs], R) when C >= $0, C =< $9, length(R) =< 3 -> - x4(Cs, [C|R]); -x4([C|Cs], R) when C >= $a, C =< $f, length(R) =< 3 -> - x4(Cs, [C|R]); -x4([C|Cs], R) when C >= $A, C =< $F, length(R) =< 3 -> - x4(Cs, [C|R]); -x4(Cs, [_|_]=R) -> - {lists:reverse(R),Cs}. - -tox(Cs) -> - erlang:list_to_integer(Cs, 16). +%% Collect Hex digits +hex(Cs) -> hex(Cs, []). +%% +hex([C|Cs], R) when C >= $0, C =< $9 -> + hex(Cs, [C|R]); +hex([C|Cs], R) when C >= $a, C =< $f -> + hex(Cs, [C|R]); +hex([C|Cs], R) when C >= $A, C =< $F -> + hex(Cs, [C|R]); +hex(Cs, [_|_]=R) when is_list(Cs) -> + {lists:reverse(R),Cs}; +hex(_, _) -> + erlang:error(badarg). + +%% Hex string to integer +hex_to_int(Cs0) -> + case strip0(Cs0) of + Cs when length(Cs) =< 4 -> + erlang:list_to_integer("0"++Cs, 16); + _ -> + erlang:error(badarg) + end. +%% Dup onto head of existing list dup(0, _, L) -> L; dup(N, E, L) when is_integer(N), N >= 1 -> - dup(N-1, E, [E|L]); -dup(N, E, L) -> - erlang:error(badarg, [N,E,L]). + dup(N-1, E, [E|L]). + + %% Convert IPv4 adress to ascii %% Convert IPv6 / IPV4 adress to ascii (plain format) @@ -674,7 +781,7 @@ separate(_E, [H], R) -> lists:reverse(R, [H]). %% convert to A.B decimal form -dig_to_dec(0) -> [$0,$.,$0]; +dig_to_dec(0) -> "0.0"; dig_to_dec(X) -> integer_to_list((X bsr 8) band 16#ff) ++ "." ++ integer_to_list(X band 16#ff). diff --git a/lib/kernel/src/inet_sctp.erl b/lib/kernel/src/inet_sctp.erl index 30c0e85dd9..795bf83807 100644 --- a/lib/kernel/src/inet_sctp.erl +++ b/lib/kernel/src/inet_sctp.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2007-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% SCTP protocol contribution by Leonid Timochouk and Serge Aleynikov. @@ -64,16 +64,22 @@ close(S) -> listen(S, Flag) -> prim_inet:listen(S, Flag). +%% A non-blocking connect is implemented when the initial call is to +%% gen_sctp:connect_init which passes the value nowait as the Timer connect(S, Addr, Port, Opts, Timer) -> case prim_inet:chgopts(S, Opts) of ok -> case prim_inet:getopt(S, active) of {ok,Active} -> - Timeout = inet:timeout(Timer), + Timeout = if Timer =:= nowait -> + infinity; %% don't start driver timer in inet_drv + true -> + inet:timeout(Timer) + end, case prim_inet:connect(S, Addr, Port, Timeout) of - ok -> + ok when Timer =/= nowait -> connect_get_assoc(S, Addr, Port, Active, Timer); - Err1 -> Err1 + OkOrErr1 -> OkOrErr1 end; Err2 -> Err2 end; @@ -89,10 +95,10 @@ connect(S, Addr, Port, Opts, Timer) -> %% connect_get_assoc/5 below mistakes it for an invalid response %% for a socket in {active,false} or {active,once} modes. %% -%% In {active,true} mode it probably gets right, but it is -%% a blocking connect that is implemented even for {active,true}, -%% and that may be a shortcoming. A non-blocking connect -%% would be nice to have. +%% In {active,true} mode the window of time for the race is smaller, +%% but it is possible and also it is a blocking connect that is +%% implemented even for {active,true}, and that may be a +%% shortcoming. connect_get_assoc(S, Addr, Port, false, Timer) -> case recv(S, inet:timeout(Timer)) of diff --git a/lib/kernel/src/pg2.erl b/lib/kernel/src/pg2.erl index fc9508a194..cb9fec2ffe 100644 --- a/lib/kernel/src/pg2.erl +++ b/lib/kernel/src/pg2.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(pg2). @@ -334,8 +334,11 @@ local_group_members(Name) -> P <- member_in_group(Pid, Name)]. member_in_group(Pid, Name) -> - [{{member, Name, Pid}, N}] = ets:lookup(pg2_table, {member, Name, Pid}), - lists:duplicate(N, Pid). + case ets:lookup(pg2_table, {member, Name, Pid}) of + [] -> []; + [{{member, Name, Pid}, N}] -> + lists:duplicate(N, Pid) + end. member_groups(Pid) -> [Name || [Name] <- ets:match(pg2_table, {{pid, Pid, '$1'}})]. diff --git a/lib/kernel/src/user.erl b/lib/kernel/src/user.erl index edf650ec59..17dc5a56a2 100644 --- a/lib/kernel/src/user.erl +++ b/lib/kernel/src/user.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(user). @@ -698,7 +698,11 @@ get_chars_more(State, M, F, Xa, Port, Q, Fmt) -> prompt(_Port, '') -> ok; prompt(Port, Prompt) -> - put_port(io_lib:format_prompt(Prompt), Port). + put_port(wrap_characters_to_binary(io_lib:format_prompt(Prompt),unicode, + case get(unicode) of + true -> unicode; + _ -> latin1 + end), Port). %% Convert error code to make it look as before err_func(io_lib, get_until, {_,F,_}) -> diff --git a/lib/kernel/test/Makefile b/lib/kernel/test/Makefile index ffad998d96..293c368e2a 100644 --- a/lib/kernel/test/Makefile +++ b/lib/kernel/test/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1997-2010. 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 # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # include $(ERL_TOP)/make/target.mk @@ -116,7 +116,7 @@ EBIN = . make_emakefile: $(ERL_TOP)/make/make_emakefile $(ERL_COMPILE_FLAGS) -o$(EBIN) '*_SUITE_make' \ - >> $(EMAKEFILE) + > $(EMAKEFILE) $(ERL_TOP)/make/make_emakefile $(ERL_COMPILE_FLAGS) -o$(EBIN) $(MODULES) \ >> $(EMAKEFILE) diff --git a/lib/kernel/test/bif_SUITE.erl b/lib/kernel/test/bif_SUITE.erl index c78d82659f..ae2a3a08ff 100644 --- a/lib/kernel/test/bif_SUITE.erl +++ b/lib/kernel/test/bif_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(bif_SUITE). @@ -66,7 +66,7 @@ spawn_opt_tests(suite) -> spawn1(doc) -> ["Test spawn/1"]; spawn1(suite) -> []; -spawn1(Config) when list(Config) -> +spawn1(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -83,7 +83,7 @@ spawn1(Config) when list(Config) -> spawn2(doc) -> ["Test spawn/2"]; spawn2(suite) -> []; -spawn2(Config) when list(Config) -> +spawn2(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn2), ?line Parent = self(), @@ -105,7 +105,7 @@ spawn2(Config) when list(Config) -> spawn3(doc) -> ["Test spawn/3"]; spawn3(suite) -> []; -spawn3(Config) when list(Config) -> +spawn3(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), @@ -127,7 +127,7 @@ spawn3(Config) when list(Config) -> spawn4(doc) -> ["Test spawn/4"]; spawn4(suite) -> []; -spawn4(Config) when list(Config) -> +spawn4(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn4), ?line Parent = self(), @@ -154,7 +154,7 @@ spawn4(Config) when list(Config) -> spawn_link1(doc) -> ["Test spawn_link/1"]; spawn_link1(suite) -> []; -spawn_link1(Config) when list(Config) -> +spawn_link1(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -171,7 +171,7 @@ spawn_link1(Config) when list(Config) -> spawn_link2(doc) -> ["Test spawn_link/2"]; spawn_link2(suite) -> []; -spawn_link2(Config) when list(Config) -> +spawn_link2(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn_link2), ?line Parent = self(), @@ -192,7 +192,7 @@ spawn_link2(Config) when list(Config) -> spawn_link3(doc) -> ["Test spawn_link/3"]; spawn_link3(suite) -> []; -spawn_link3(Config) when list(Config) -> +spawn_link3(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), @@ -214,7 +214,7 @@ spawn_link3(Config) when list(Config) -> spawn_link4(doc) -> ["Test spawn_link/4"]; spawn_link4(suite) -> []; -spawn_link4(Config) when list(Config) -> +spawn_link4(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn_link4), ?line Parent = self(), @@ -240,7 +240,7 @@ spawn_link4(Config) when list(Config) -> spawn_opt2(doc) -> ["Test spawn_opt/2"]; spawn_opt2(suite) -> []; -spawn_opt2(Config) when list(Config) -> +spawn_opt2(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -275,7 +275,7 @@ spawn_opt2(Config) when list(Config) -> spawn_opt3(doc) -> ["Test spawn_opt/3"]; spawn_opt3(suite) -> []; -spawn_opt3(Config) when list(Config) -> +spawn_opt3(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn_opt3), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -312,7 +312,7 @@ spawn_opt3(Config) when list(Config) -> spawn_opt4(doc) -> ["Test spawn_opt/4"]; spawn_opt4(suite) -> []; -spawn_opt4(Config) when list(Config) -> +spawn_opt4(Config) when is_list(Config) -> ?line Node = node(), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -352,7 +352,7 @@ spawn_opt4(Config) when list(Config) -> spawn_opt5(doc) -> ["Test spawn_opt/5"]; spawn_opt5(suite) -> []; -spawn_opt5(Config) when list(Config) -> +spawn_opt5(Config) when is_list(Config) -> ?line {ok, Node} = start_node(spawn_opt5), ?line Parent = self(), ?line {_, _, FA, _} = fetch_proc_vals(self()), @@ -396,7 +396,7 @@ spawn_failures(doc) -> ["Test failure behavior of spawn bifs"]; spawn_failures(suite) -> []; -spawn_failures(Config) when list(Config) -> +spawn_failures(Config) when is_list(Config) -> ?line ThisNode = node(), ?line {ok, Node} = start_node(spawn_remote_failure), @@ -556,7 +556,7 @@ wilderness(doc) -> "wilderness of the heap are interpreted correct by the emulator "]; wilderness(suite) -> []; -wilderness(Config) when list(Config) -> +wilderness(Config) when is_list(Config) -> ?line Dog = ?t:timetrap(?default_timeout), ?line OKParams = {512, 8}, ?line Alloc = erlang:system_info(allocator), @@ -604,11 +604,11 @@ run_wilderness_test({Set_tt, Set_tp}, {Exp_tt, Exp_tp}) -> end, stop_node(Node). -to_string(X) when integer(X) -> +to_string(X) when is_integer(X) -> integer_to_list(X); -to_string(X) when atom(X) -> +to_string(X) when is_atom(X) -> atom_to_list(X); -to_string(X) when list(X) -> +to_string(X) when is_list(X) -> X. get_nodenames(N, T) -> diff --git a/lib/kernel/test/cleanup.erl b/lib/kernel/test/cleanup.erl index 6e1a1edeac..831ceba8f5 100644 --- a/lib/kernel/test/cleanup.erl +++ b/lib/kernel/test/cleanup.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(cleanup). @@ -31,7 +31,7 @@ cleanup(_) -> ?line case nodes() of [] -> ok; - Nodes when list(Nodes) -> + Nodes when is_list(Nodes) -> Kill = fun(Node) -> spawn(Node, erlang, halt, []) end, ?line lists:foreach(Kill, Nodes), ?line test_server:fail({nodes_left, Nodes}) diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl index 9fda66711d..37b9200942 100644 --- a/lib/kernel/test/code_SUITE.erl +++ b/lib/kernel/test/code_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(code_SUITE). @@ -26,28 +26,34 @@ delete/1, purge/1, soft_purge/1, is_loaded/1, all_loaded/1, load_binary/1, dir_req/1, object_code/1, set_path_file/1, sticky_dir/1, pa_pz_option/1, add_del_path/1, - dir_disappeared/1, ext_mod_dep/1, + dir_disappeared/1, ext_mod_dep/1, clash/1, load_cached/1, start_node_with_cache/1, add_and_rehash/1, where_is_file_cached/1, where_is_file_no_cache/1, purge_stacktrace/1, mult_lib_roots/1, bad_erl_libs/1, code_archive/1, code_archive2/1, on_load/1, - on_load_embedded/1]). + on_load_embedded/1, on_load_errors/1]). -export([init_per_testcase/2, fin_per_testcase/2, init_per_suite/1, end_per_suite/1, sticky_compiler/1]). +%% error_logger +-export([init/1, + handle_event/2, handle_call/2, handle_info/2, + terminate/2]). + all(suite) -> [set_path, get_path, add_path, add_paths, del_path, replace_path, load_file, load_abs, ensure_loaded, delete, purge, soft_purge, is_loaded, all_loaded, load_binary, dir_req, object_code, set_path_file, pa_pz_option, add_del_path, - dir_disappeared, ext_mod_dep, + dir_disappeared, ext_mod_dep, clash, load_cached, start_node_with_cache, add_and_rehash, where_is_file_no_cache, where_is_file_cached, purge_stacktrace, mult_lib_roots, bad_erl_libs, - code_archive, code_archive2, on_load, on_load_embedded]. + code_archive, code_archive2, on_load, on_load_embedded, + on_load_errors]. init_per_suite(Config) -> %% The compiler will no longer create a Beam file if @@ -525,7 +531,7 @@ pa_pz_option(Config) when is_list(Config) -> add_del_path(suite) -> []; add_del_path(doc) -> ["add_path, del_path should not cause priv_dir(App) to fail"]; -add_del_path(Config) -> +add_del_path(Config) when is_list(Config) -> DDir = ?config(data_dir,Config), Dir1 = filename:join(DDir,"dummy_app-1.0/ebin"), Dir2 = filename:join(DDir,"dummy_app-2.0/ebin"), @@ -539,9 +545,41 @@ add_del_path(Config) -> ok. +clash(Config) when is_list(Config) -> + DDir = ?config(data_dir,Config)++"clash/", + P = code:get_path(), + + %% test non-clashing entries + + %% remove "." to prevent clash with test-server path + ?line true = code:del_path("."), + ?line true = code:add_path(DDir++"foobar-0.1/ebin"), + ?line true = code:add_path(DDir++"zork-0.8/ebin"), + ?line test_server:capture_start(), + ?line code:clash(), + ?line test_server:capture_stop(), + ?line OKMsg = test_server:capture_get(), + ?line lists:prefix("** Found 0 name clashes in code paths", OKMsg), + ?line true = code:set_path(P), + + %% test clashing entries + + %% remove "." to prevent clash with test-server path + ?line true = code:del_path("."), + ?line true = code:add_path(DDir++"foobar-0.1/ebin"), + ?line true = code:add_path(DDir++"foobar-0.1.ez/foobar-0.1/ebin"), + ?line test_server:capture_start(), + ?line code:clash(), + ?line test_server:capture_stop(), + ?line [ErrMsg1|_] = test_server:capture_get(), + ?line {match, [" hides "]} = re:run(ErrMsg1, "\\*\\* .*( hides ).*", + [{capture,all_but_first,list}]), + ?line true = code:set_path(P), + ok. + ext_mod_dep(suite) -> []; -ext_mod_dep(doce) -> +ext_mod_dep(doc) -> ["Every module that the code_server uses should be preloaded, " "this test case verifies that"]; ext_mod_dep(Config) when is_list(Config) -> @@ -671,6 +709,8 @@ check_funs({'$M_EXPR','$F_EXPR',2}, check_funs({'$M_EXPR','$F_EXPR',1}, [{lists,foreach,2}, {hipe_unified_loader,patch_consts,3} | _]) -> 0; +check_funs({'$M_EXPR',warning_msg,2}, + [{code_server,finish_on_load_report,2} | _]) -> 0; %% This is cheating! /raimo %% %% check_funs(This = {M,_,_}, Path) -> @@ -1229,6 +1269,81 @@ is_source_dir() -> filename:basename(code:lib_dir(kernel)) =:= "kernel" andalso filename:basename(code:lib_dir(stdlib)) =:= "stdlib". +on_load_errors(Config) when is_list(Config) -> + Master = on_load_error_test_case_process, + ?line register(Master, self()), + + ?line Data = filename:join([?config(data_dir, Config),"on_load_errors"]), + ?line ok = file:set_cwd(Data), + ?line up_to_date = make:all([{d,'MASTER',Master}]), + + ?line do_on_load_error(an_atom), + + ?line error_logger:add_report_handler(?MODULE, self()), + + ?line do_on_load_error({something,terrible,is,wrong}), + receive + Any1 -> + ?line {_, "The on_load function"++_, + [on_load_error, + {something,terrible,is,wrong},_]} = Any1 + end, + + ?line do_on_load_error(fail), %Cause exception. + receive + Any2 -> + ?line {_, "The on_load function"++_, + [on_load_error,{failed,[_|_]},_]} = Any2 + end, + + %% There should be no more messages. + receive + Unexpected -> + ?line ?t:fail({unexpected,Unexpected}) + after 10 -> + ok + end, + + ok. + +do_on_load_error(ReturnValue) -> + ?line {_,Ref} = spawn_monitor(fun() -> + exit(on_load_error:main()) + end), + receive {on_load_error,ErrorPid} -> ok end, + ?line ErrorPid ! ReturnValue, + receive + {'DOWN',Ref,process,_,Exit} -> + ?line {undef,[{on_load_error,main,[]}|_]} = Exit + end. + +%%----------------------------------------------------------------- +%% error_logger handler. +%% (Copied from stdlib/test/proc_lib_SUITE.erl.) +%%----------------------------------------------------------------- +init(Tester) -> + {ok, Tester}. + +handle_event({error, _GL, {emulator, _, _}}, Tester) -> + {ok, Tester}; +handle_event({error, _GL, Msg}, Tester) -> + Tester ! Msg, + {ok, Tester}; +handle_event(_Event, State) -> + {ok, State}. + +handle_info(_, State) -> + {ok, State}. + +handle_call(_Query, State) -> {ok, {error, bad_query}, State}. + +terminate(_Reason, State) -> + State. + +%%% +%%% Common utility functions. +%%% + start_node(Name, Param) -> ?t:start_node(Name, slave, [{args, Param}]). diff --git a/lib/kernel/test/code_SUITE_data/clash/foobar-0.1.ez b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1.ez Binary files differnew file mode 100644 index 0000000000..33d8a59b92 --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1.ez diff --git a/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/baz.beam b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/baz.beam new file mode 100644 index 0000000000..da87f32b9f --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/baz.beam @@ -0,0 +1 @@ +baz 298734 diff --git a/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/blarg.beam b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/blarg.beam new file mode 100644 index 0000000000..e4c70c267c --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/foobar-0.1/ebin/blarg.beam @@ -0,0 +1 @@ +baz 86234 diff --git a/lib/kernel/test/code_SUITE_data/clash/zork-0.8.ez b/lib/kernel/test/code_SUITE_data/clash/zork-0.8.ez Binary files differnew file mode 100644 index 0000000000..051fa1efe4 --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/zork-0.8.ez diff --git a/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/bork.beam b/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/bork.beam new file mode 100644 index 0000000000..7b292c0b44 --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/bork.beam @@ -0,0 +1 @@ +baz 23784 diff --git a/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/flarp.beam b/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/flarp.beam new file mode 100644 index 0000000000..7b2f6a850f --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/clash/zork-0.8/ebin/flarp.beam @@ -0,0 +1 @@ +baz 3246238 diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl index 660000df46..f6bcb6570b 100644 --- a/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl +++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl @@ -13,7 +13,7 @@ on_load() -> LibDir = code:lib_dir(kernel), ?MASTER ! {?MODULE,LibDir}, - true. + ok. data() -> [a|on_load_b:data()]. diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl index 5c4d676e2d..947cbd5bcd 100644 --- a/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl +++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl @@ -6,7 +6,7 @@ on_load() -> ?MASTER ! {?MODULE,start}, on_load_c:data(), ?MASTER ! {?MODULE,done}, - true. + ok. data() -> [b|on_load_c:data()]. diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl index 4b2edbfb5a..6ab7f6402f 100644 --- a/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl +++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl @@ -7,7 +7,7 @@ on_load() -> receive go -> ?MASTER ! {?MODULE,done}, - true + ok end. data() -> diff --git a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl index bfc26864d5..a39332f81d 100644 --- a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl +++ b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl @@ -9,7 +9,7 @@ run_me() -> ok end end), - true. + ok. status() -> case whereis(everything_is_fine) of diff --git a/lib/kernel/test/code_SUITE_data/on_load_errors/on_load_error.erl b/lib/kernel/test/code_SUITE_data/on_load_errors/on_load_error.erl new file mode 100644 index 0000000000..0772050aeb --- /dev/null +++ b/lib/kernel/test/code_SUITE_data/on_load_errors/on_load_error.erl @@ -0,0 +1,13 @@ +-module(on_load_error). +-on_load(on_load/0). +-export([main/0]). + +on_load() -> + ?MASTER ! {?MODULE,self()}, + receive + fail -> erlang:error(failed); + Ret -> Ret + end. + +main() -> + ok. diff --git a/lib/kernel/test/erl_distribution_SUITE.erl b/lib/kernel/test/erl_distribution_SUITE.erl index 8f2e2512e0..d15f6aa0d5 100644 --- a/lib/kernel/test/erl_distribution_SUITE.erl +++ b/lib/kernel/test/erl_distribution_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(erl_distribution_SUITE). @@ -62,7 +62,7 @@ all(suite) -> table_waste, net_setuptime, monitor_nodes]. -init_per_testcase(Func, Config) when atom(Func), list(Config) -> +init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) -> Dog=?t:timetrap(?t:minutes(4)), [{watchdog, Dog}|Config]. @@ -72,7 +72,7 @@ fin_per_testcase(_Func, Config) -> tick(suite) -> []; tick(doc) -> []; -tick(Config) when list(Config) -> +tick(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(120)), PaDir = filename:dirname(code:which(erl_distribution_SUITE)), @@ -119,7 +119,7 @@ tick(Config) when list(Config) -> monitor_node(Node, true), receive - {tick_test, T} when integer(T) -> + {tick_test, T} when is_integer(T) -> stop_node(ServNode), stop_node(Node), T; @@ -141,7 +141,7 @@ table_waste(doc) -> ["Checks that pinging nonexistyent nodes does not waste space in distribution table"]; table_waste(suite) -> []; -table_waste(Config) when list(Config) -> +table_waste(Config) when is_list(Config) -> ?line {ok, HName} = inet:gethostname(), F = fun(0,_F) -> []; (N,F) -> @@ -161,7 +161,7 @@ illegal_nodenames(doc) -> ["Test that pinging an illegal nodename does not kill the node"]; illegal_nodenames(suite) -> []; -illegal_nodenames(Config) when list(Config) -> +illegal_nodenames(Config) when is_list(Config) -> ?line Dog=?t:timetrap(?t:minutes(2)), PaDir = filename:dirname(code:which(erl_distribution_SUITE)), ?line {ok, Node}=start_node(illegal_nodenames, "-pa " ++ PaDir), @@ -269,12 +269,12 @@ tick_cli_test1(Node) -> tick_change(doc) -> ["OTP-4255"]; tick_change(suite) -> []; -tick_change(Config) when list(Config) -> +tick_change(Config) when is_list(Config) -> ?line PaDir = filename:dirname(code:which(?MODULE)), ?line [BN, CN] = get_nodenames(2, tick_change), ?line DefaultTT = net_kernel:get_net_ticktime(), ?line case DefaultTT of - I when integer(I) -> ?line ok; + I when is_integer(I) -> ?line ok; _ -> ?line ?t:fail(DefaultTT) end, @@ -445,7 +445,7 @@ hidden_node(doc) -> ["Basic test of hidden node"]; hidden_node(suite) -> []; -hidden_node(Config) when list(Config) -> +hidden_node(Config) when is_list(Config) -> ?line Dog = ?t:timetrap(?t:seconds(40)), PaDir = filename:dirname(code:which(?MODULE)), VArgs = "-pa " ++ PaDir, @@ -548,7 +548,7 @@ monitor_nodes(suite) -> monitor_nodes_nodedown_reason(doc) -> []; monitor_nodes_nodedown_reason(suite) -> []; -monitor_nodes_nodedown_reason(Config) when list(Config) -> +monitor_nodes_nodedown_reason(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line ok = net_kernel:monitor_nodes(true), ?line ok = net_kernel:monitor_nodes(true, [nodedown_reason]), @@ -603,7 +603,7 @@ monitor_nodes_nodedown_reason(Config) when list(Config) -> monitor_nodes_complex_nodedown_reason(doc) -> []; monitor_nodes_complex_nodedown_reason(suite) -> []; -monitor_nodes_complex_nodedown_reason(Config) when list(Config) -> +monitor_nodes_complex_nodedown_reason(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line Me = self(), ?line ok = net_kernel:monitor_nodes(true, [nodedown_reason]), @@ -885,7 +885,7 @@ monitor_nodes_errors(doc) -> []; monitor_nodes_errors(suite) -> []; -monitor_nodes_errors(Config) when list(Config) -> +monitor_nodes_errors(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line error = net_kernel:monitor_nodes(asdf), ?line {error, @@ -922,7 +922,7 @@ monitor_nodes_combinations(doc) -> []; monitor_nodes_combinations(suite) -> []; -monitor_nodes_combinations(Config) when list(Config) -> +monitor_nodes_combinations(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line monitor_nodes_all_comb(true), ?line [VisibleName, HiddenName] = get_nodenames(2, @@ -1044,7 +1044,7 @@ monitor_nodes_cleanup(doc) -> []; monitor_nodes_cleanup(suite) -> []; -monitor_nodes_cleanup(Config) when list(Config) -> +monitor_nodes_cleanup(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line Me = self(), ?line No = monitor_nodes_all_comb(true), @@ -1076,7 +1076,7 @@ monitor_nodes_many(doc) -> []; monitor_nodes_many(suite) -> []; -monitor_nodes_many(Config) when list(Config) -> +monitor_nodes_many(Config) when is_list(Config) -> ?line MonNodeState = monitor_node_state(), ?line [Name] = get_nodenames(1, monitor_nodes_many), %% We want to perform more than 2^16 net_kernel:monitor_nodes @@ -1139,10 +1139,10 @@ start_node(Name, Param, this) -> start_node(Name, Param, "this") -> NewParam = Param ++ " -pa " ++ filename:dirname(code:which(?MODULE)), ?t:start_node(Name, peer, [{args, NewParam}, {erl, [this]}]); -start_node(Name, Param, Rel) when atom(Rel) -> +start_node(Name, Param, Rel) when is_atom(Rel) -> NewParam = Param ++ " -pa " ++ filename:dirname(code:which(?MODULE)), ?t:start_node(Name, peer, [{args, NewParam}, {erl, [{release, atom_to_list(Rel)}]}]); -start_node(Name, Param, Rel) when list(Rel) -> +start_node(Name, Param, Rel) when is_list(Rel) -> NewParam = Param ++ " -pa " ++ filename:dirname(code:which(?MODULE)), ?t:start_node(Name, peer, [{args, NewParam}, {erl, [{release, Rel}]}]). @@ -1216,9 +1216,9 @@ wait_until(Fun) -> end end. -repeat(Fun, 0) when function(Fun) -> +repeat(Fun, 0) when is_function(Fun) -> ok; -repeat(Fun, N) when function(Fun), integer(N), N > 0 -> +repeat(Fun, N) when is_function(Fun), is_integer(N), N > 0 -> Fun(), repeat(Fun, N-1). diff --git a/lib/kernel/test/erl_prim_loader_SUITE.erl b/lib/kernel/test/erl_prim_loader_SUITE.erl index 4d090f4db5..19c84ab34c 100644 --- a/lib/kernel/test/erl_prim_loader_SUITE.erl +++ b/lib/kernel/test/erl_prim_loader_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(erl_prim_loader_SUITE). @@ -27,7 +27,7 @@ inet_existing/1, inet_coming_up/1, inet_disconnects/1, multiple_slaves/1, file_requests/1, local_archive/1, remote_archive/1, - primary_archive/1]). + primary_archive/1, virtual_dir_in_archive/1]). -export([init_per_testcase/2, fin_per_testcase/2]). @@ -41,10 +41,11 @@ all(suite) -> inet_existing, inet_coming_up, inet_disconnects, multiple_slaves, file_requests, local_archive, - remote_archive, primary_archive + remote_archive, primary_archive, + virtual_dir_in_archive ]. -init_per_testcase(Func, Config) when atom(Func), list(Config) -> +init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) -> Dog=?t:timetrap(?t:minutes(3)), [{watchdog, Dog}|Config]. @@ -81,7 +82,7 @@ set_path(Config) when is_list(Config) -> get_file(doc) -> []; get_file(Config) when is_list(Config) -> ?line case erl_prim_loader:get_file("lists" ++ code:objfile_extension()) of - {ok,Bin,File} when binary(Bin), list(File) -> + {ok,Bin,File} when is_binary(Bin), is_list(File) -> ok; _ -> test_server:fail(get_valid_file) @@ -344,8 +345,9 @@ local_archive(Config) when is_list(Config) -> Node = node(), BeamName = "inet.beam", ?line ok = test_archive(Node, Archive, KernelDir, BeamName), - ?line ok = rpc:call(Node, erl_prim_loader, release_archives, []), + %% Cleanup + ?line ok = rpc:call(Node, erl_prim_loader, release_archives, []), ?line ok = file:delete(Archive), ok. @@ -365,6 +367,7 @@ remote_archive(Config) when is_list(Config) -> BeamName = "inet.beam", ?line ok = test_archive(Node, Archive, KernelDir, BeamName), + %% Cleanup ?line stop_node(Node), ?line unlink(BootPid), ?line exit(BootPid, kill), @@ -401,21 +404,22 @@ primary_archive(Config) when is_list(Config) -> ?line Args = " -setcookie " ++ Cookie, ?line {ok,Node} = start_node(primary_archive, Args), ?line wait_really_started(Node, 25), + ?line {_,_,_} = rpc:call(Node, erlang, date, []), %% Set primary archive - ?line {_,_,_} = rpc:call(Node, erlang, date, []), - ?line {ok, Ebins} = rpc:call(Node, erl_prim_loader, set_primary_archive, [Archive, ArchiveBin]), ExpectedEbins = [Archive, DictDir ++ "/ebin", DummyDir ++ "/ebin"], io:format("ExpectedEbins: ~p\n", [ExpectedEbins]), - ?line ExpectedEbins = lists:sort(Ebins), + ?line {ok, FileInfo} = prim_file:read_file_info(Archive), + ?line {ok, Ebins} = rpc:call(Node, erl_prim_loader, set_primary_archive, [Archive, ArchiveBin, FileInfo]), + ?line ExpectedEbins = lists:sort(Ebins), % assert ?line {ok, TopFiles2} = rpc:call(Node, erl_prim_loader, list_dir, [Archive]), ?line [DictDir, DummyDir] = lists:sort(TopFiles2), BeamName = "primary_archive_dict_app.beam", ?line ok = test_archive(Node, Archive, DictDir, BeamName), - ?line {ok, []} = rpc:call(Node, erl_prim_loader, set_primary_archive, [undefined, undefined]), - + %% Cleanup + ?line {ok, []} = rpc:call(Node, erl_prim_loader, set_primary_archive, [undefined, undefined, undefined]), ?line stop_node(Node), ?line ok = file:delete(Archive), ok. @@ -461,6 +465,46 @@ create_archive(Archive, AppDirs) -> io:format("zip:create(~p,\n\t~p,\n\t~p).\n", [Archive, AppDirs, Opts]), zip:create(Archive, AppDirs, Opts). + +virtual_dir_in_archive(suite) -> + []; +virtual_dir_in_archive(doc) -> + ["Read virtual directories from archive."]; +virtual_dir_in_archive(Config) when is_list(Config) -> + PrivDir = ?config(priv_dir, Config), + Data = <<"A little piece of data.">>, + ArchiveBase = "archive_with_virtual_dirs", + Archive = filename:join([PrivDir, ArchiveBase ++ init:archive_extension()]), + FileBase = "a_data_file.beam", + EbinBase = "ebin", + FileInArchive = filename:join([ArchiveBase, EbinBase, FileBase]), + BinFiles = [{FileInArchive, Data}], + Opts = [{compress, []}], + ?line file:delete(Archive), + io:format("zip:create(~p,\n\t~p,\n\t~p).\n", [Archive, BinFiles, Opts]), + ?line {ok, Archive} = zip:create(Archive, BinFiles, Opts), + + %% Verify that there is no directories + ?line {ok, BinFiles} = zip:unzip(Archive, [memory]), + + FullPath = filename:join([Archive, FileInArchive]), + ?line {ok, _} = erl_prim_loader:read_file_info(FullPath), + + %% Read one virtual dir + EbinDir = filename:dirname(FullPath), + ?line {ok, _} = erl_prim_loader:read_file_info(EbinDir), + ?line {ok, [FileBase]} = erl_prim_loader:list_dir(EbinDir), + + %% Read another virtual dir + AppDir = filename:dirname(EbinDir), + ?line {ok, _} = erl_prim_loader:read_file_info(AppDir), + ?line {ok, [EbinBase]} = erl_prim_loader:list_dir(AppDir), + + %% Cleanup + ?line ok = erl_prim_loader:release_archives(), + ?line ok = file:delete(Archive), + ok. + %% Misc. functions ip_str({A, B, C, D}) -> diff --git a/lib/kernel/test/error_logger_SUITE.erl b/lib/kernel/test/error_logger_SUITE.erl index a737949bbb..eda86861d5 100644 --- a/lib/kernel/test/error_logger_SUITE.erl +++ b/lib/kernel/test/error_logger_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(error_logger_SUITE). @@ -45,7 +45,7 @@ all(suite) -> error_report(suite) -> []; error_report(doc) -> []; -error_report(Config) when list(Config) -> +error_report(Config) when is_list(Config) -> ?line error_logger:add_report_handler(?MODULE, self()), Rep1 = [{tag1,"data1"},{tag2,data2},{tag3,3}], Rep2 = [testing,"testing",{tag1,"tag1"}], @@ -85,7 +85,7 @@ error_report(Config) when list(Config) -> info_report(suite) -> []; info_report(doc) -> []; -info_report(Config) when list(Config) -> +info_report(Config) when is_list(Config) -> ?line error_logger:add_report_handler(?MODULE, self()), Rep1 = [{tag1,"data1"},{tag2,data2},{tag3,3}], Rep2 = [testing,"testing",{tag1,"tag1"}], @@ -125,7 +125,7 @@ info_report(Config) when list(Config) -> error(suite) -> []; error(doc) -> []; -error(Config) when list(Config) -> +error(Config) when is_list(Config) -> ?line error_logger:add_report_handler(?MODULE, self()), Msg1 = "This is a plain text string~n", Msg2 = "This is a text with arguments ~p~n", @@ -160,7 +160,7 @@ error(Config) when list(Config) -> info(suite) -> []; info(doc) -> []; -info(Config) when list(Config) -> +info(Config) when is_list(Config) -> ?line error_logger:add_report_handler(?MODULE, self()), Msg1 = "This is a plain text string~n", Msg2 = "This is a text with arguments ~p~n", @@ -188,7 +188,7 @@ info(Config) when list(Config) -> emulator(suite) -> []; emulator(doc) -> []; -emulator(Config) when list(Config) -> +emulator(Config) when is_list(Config) -> ?line error_logger:add_report_handler(?MODULE, self()), spawn(?MODULE, generate_error, []), reported(emulator), @@ -215,7 +215,7 @@ tty(Config) when is_list(Config) -> logfile(suite) -> []; logfile(doc) -> []; -logfile(Config) when list(Config) -> +logfile(Config) when is_list(Config) -> ?line case error_logger:logfile(filename) of {error, no_log_file} -> % Ok, we continues. do_logfile(); @@ -236,7 +236,7 @@ do_logfile() -> add(suite) -> []; add(doc) -> []; -add(Config) when list(Config) -> +add(Config) when is_list(Config) -> ?line {'EXIT',_} = (catch error_logger:add_report_handler("dummy")), ?line {'EXIT',_} = error_logger:add_report_handler(non_existing), ?line my_error = error_logger:add_report_handler(?MODULE, [error]), @@ -246,7 +246,7 @@ add(Config) when list(Config) -> delete(suite) -> []; delete(doc) -> []; -delete(Config) when list(Config) -> +delete(Config) when is_list(Config) -> ?line {'EXIT',_} = (catch error_logger:delete_report_handler("dummy")), ?line {error,_} = error_logger:delete_report_handler(non_existing), ok. @@ -265,7 +265,7 @@ reported(Tag, Type, Report) -> reported(emulator) -> receive - {error, "~s~n", String} when list(String) -> + {error, "~s~n", String} when is_list(String) -> test_server:messages_get(), ok after 1000 -> @@ -277,9 +277,9 @@ reported(emulator) -> %% Sends a notification to the Tester process about the events %% generated by the Tester process. %%----------------------------------------------------------------- -init(Tester) when pid(Tester) -> +init(Tester) when is_pid(Tester) -> {ok, Tester}; -init(Config) when list(Config) -> +init(Config) when is_list(Config) -> my_error. handle_event({Tag, _GL, {_EPid, Type, Report}}, Tester) -> diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl index c645d0f842..d01e1f1fcf 100644 --- a/lib/kernel/test/file_SUITE.erl +++ b/lib/kernel/test/file_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -3371,7 +3371,7 @@ read_line_create_files(TestData) -> [ Function(File) || {Function,File,_,_} <- TestData ]. read_line_remove_files(TestData) -> - [ file:delete(File) || {Function,File,_,_} <- TestData ]. + [ file:delete(File) || {_Function,File,_,_} <- TestData ]. read_line_1(suite) -> []; diff --git a/lib/kernel/test/gen_sctp_SUITE.erl b/lib/kernel/test/gen_sctp_SUITE.erl index dd7d5f111a..fad8c7398b 100644 --- a/lib/kernel/test/gen_sctp_SUITE.erl +++ b/lib/kernel/test/gen_sctp_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2007-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(gen_sctp_SUITE). @@ -24,10 +24,11 @@ %%-compile(export_all). -export([all/1,init_per_testcase/2,fin_per_testcase/2, - basic/1,xfer_min/1,xfer_active/1,api_open_close/1,api_listen/1]). + basic/1,api_open_close/1,api_listen/1,api_connect_init/1, + xfer_min/1,xfer_active/1]). all(suite) -> - [basic,xfer_min,xfer_active,api_open_close,api_listen]. + [basic,api_open_close,api_listen,api_connect_init,xfer_min,xfer_active]. init_per_testcase(_Func, Config) -> Dog = test_server:timetrap(test_server:seconds(15)), @@ -325,7 +326,7 @@ api_listen(Config) when is_list(Config) -> ?line {ok,{Localhost, Pb,[], #sctp_assoc_change{ - state = comm_lost}}} = + state=comm_lost}}} = gen_sctp:recv(Sa, infinity); {error,#sctp_assoc_change{state=cant_assoc}} -> ok end, @@ -336,3 +337,48 @@ api_listen(Config) when is_list(Config) -> ?line ok = gen_sctp:close(Sa), ?line ok = gen_sctp:close(Sb), ok. + +api_connect_init(doc) -> + "Test the API function connect_init/4"; +api_connect_init(suite) -> + []; +api_connect_init(Config) when is_list(Config) -> + ?line Localhost = {127,0,0,1}, + + ?line {ok,S} = gen_sctp:open(), + ?line {ok,Pb} = inet:port(S), + ?line try gen_sctp:connect_init(S, Localhost, not_allowed_for_port, []) + catch error:badarg -> ok + end, + ?line try gen_sctp:connect_init(S, Localhost, 12345, not_allowed_for_opts) + catch error:badarg -> ok + end, + ?line ok = gen_sctp:close(S), + ?line {error,closed} = gen_sctp:connect_init(S, Localhost, 12345, []), + + ?line {ok,Sb} = gen_sctp:open(Pb), + ?line {ok,Sa} = gen_sctp:open(), + ?line case gen_sctp:connect_init(Sa, localhost, Pb, []) of + {error,econnrefused} -> + ?line {ok,{Localhost, + Pb,[], + #sctp_assoc_change{state=comm_lost}}} = + gen_sctp:recv(Sa, infinity); + ok -> + ?line {ok,{Localhost, + Pb,[], + #sctp_assoc_change{state=cant_assoc}}} = + gen_sctp:recv(Sa, infinity) + end, + ?line ok = gen_sctp:listen(Sb, true), + ?line case gen_sctp:connect_init(Sa, localhost, Pb, []) of + ok -> + ?line {ok,{Localhost, + Pb,[], + #sctp_assoc_change{ + state = comm_up}}} = + gen_sctp:recv(Sa, infinity) + end, + ?line ok = gen_sctp:close(Sa), + ?line ok = gen_sctp:close(Sb), + ok. diff --git a/lib/kernel/test/global_group_SUITE.erl b/lib/kernel/test/global_group_SUITE.erl index a8b87390eb..430cc61267 100644 --- a/lib/kernel/test/global_group_SUITE.erl +++ b/lib/kernel/test/global_group_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -42,7 +42,7 @@ all(suite) -> -define(TESTCASE, testcase_name). -define(testcase, ?config(?TESTCASE, Config)). -init_per_testcase(Case, Config) when atom(Case), list(Config) -> +init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) -> Dog=?t:timetrap(?t:minutes(5)), [{?TESTCASE, Case}, {watchdog, Dog}|Config]. @@ -59,7 +59,7 @@ fin_per_testcase(_Func, Config) -> start_gg_proc(suite) -> []; start_gg_proc(doc) -> ["Check that the global_group processes are started automatically. "]; -start_gg_proc(Config) when list(Config) -> +start_gg_proc(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(120)), ?line Dir = ?config(priv_dir, Config), @@ -94,7 +94,7 @@ start_gg_proc(Config) when list(Config) -> no_gg_proc(suite) -> []; no_gg_proc(doc) -> ["Start a system without global groups. Nodes are not " "synced at start (sync_nodes_optional is not defined)"]; -no_gg_proc(Config) when list(Config) -> +no_gg_proc(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(200)), ?line Dir = ?config(priv_dir, Config), @@ -267,7 +267,7 @@ no_gg_proc_sync(suite) -> []; no_gg_proc_sync(doc) -> ["Start a system without global groups, but syncing the nodes by using " "sync_nodes_optional."]; -no_gg_proc_sync(Config) when list(Config) -> +no_gg_proc_sync(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(200)), ?line Dir = ?config(priv_dir, Config), @@ -441,7 +441,7 @@ no_gg_proc_sync(Config) when list(Config) -> compatible(suite) -> []; compatible(doc) -> ["Check that a system without global groups is compatible with the old R4 system."]; -compatible(Config) when list(Config) -> +compatible(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(200)), ?line Dir = ?config(priv_dir, Config), @@ -614,7 +614,7 @@ compatible(Config) when list(Config) -> one_grp(suite) -> []; one_grp(doc) -> ["Test a system with only one global group. "]; -one_grp(Config) when list(Config) -> +one_grp(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(120)), ?line Dir = ?config(priv_dir, Config), @@ -701,7 +701,7 @@ one_grp(Config) when list(Config) -> one_grp_x(suite) -> []; one_grp_x(doc) -> ["Check a system with only one global group. " "Start the nodes with different time intervals. "]; -one_grp_x(Config) when list(Config) -> +one_grp_x(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(120)), ?line Dir = ?config(priv_dir, Config), @@ -763,7 +763,7 @@ one_grp_x(Config) when list(Config) -> two_grp(suite) -> []; two_grp(doc) -> ["Test a two global group system. "]; -two_grp(Config) when list(Config) -> +two_grp(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(200)), ?line Dir = ?config(priv_dir, Config), @@ -1063,7 +1063,7 @@ two_grp(Config) when list(Config) -> hidden_groups(suite) -> []; hidden_groups(doc) -> ["Test hidden global groups."]; -hidden_groups(Config) when list(Config) -> +hidden_groups(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(200)), ?line Dir = ?config(priv_dir, Config), @@ -1138,7 +1138,7 @@ hidden_groups(Config) when list(Config) -> test_exit(suite) -> []; test_exit(doc) -> ["Checks when the search process exits. "]; -test_exit(Config) when list(Config) -> +test_exit(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(120)), ?line NN = node_name(atom_to_list(node())), diff --git a/lib/kernel/test/heart_SUITE.erl b/lib/kernel/test/heart_SUITE.erl index b06244db3c..0d0296238b 100644 --- a/lib/kernel/test/heart_SUITE.erl +++ b/lib/kernel/test/heart_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(heart_SUITE). @@ -80,7 +80,7 @@ start_check(Type, Name) -> end, erlang:monitor_node(Node, true), case rpc:call(Node, erlang, whereis, [heart]) of - Pid when pid(Pid) -> + Pid when is_pid(Pid) -> ok; _ -> test_server:fail(heart_not_started) @@ -355,7 +355,7 @@ erl() -> end. name(Node) when is_list(Node) -> name(Node,[]); -name(Node) when atom(Node) -> name(atom_to_list(Node),[]). +name(Node) when is_atom(Node) -> name(atom_to_list(Node),[]). name([$@|Node], Name) -> case lists:member($., Node) of @@ -368,7 +368,7 @@ name([H|T], Name) -> name(T, [H|Name]). -atom_conv(A) when atom(A) -> +atom_conv(A) when is_atom(A) -> atom_to_list(A); atom_conv(A) when is_list(A) -> A. diff --git a/lib/kernel/test/inet_SUITE.erl b/lib/kernel/test/inet_SUITE.erl index cf33e8b27f..eb8f918491 100644 --- a/lib/kernel/test/inet_SUITE.erl +++ b/lib/kernel/test/inet_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_SUITE). @@ -28,7 +28,7 @@ gethostnative_parallell/1, cname_loop/1, gethostnative_soft_restart/1,gethostnative_debug_level/1,getif/1]). --export([get_hosts/1, get_ipv6_hosts/1, parse_hosts/1, +-export([get_hosts/1, get_ipv6_hosts/1, parse_hosts/1, parse_address/1, kill_gethost/0, parallell_gethost/0]). -export([init_per_testcase/2, end_per_testcase/2]). @@ -249,14 +249,16 @@ t_getaddr_v6(Config) when is_list(Config) -> ?line {ok,IP46} = inet:getaddr(IP46, inet6), ?line {ok,IP46} = inet:getaddr(Name, inet6), ?line {ok,IP46} = inet:getaddr(FullName, inet6), - ?line IP4toIP6 = inet:getaddr(IPStr, inet6), - ?line case IP4toIP6 of - {ok,IP46} -> % only native can do this - ?line true = lists:member(native, - inet_db:res_option(lookup)); - {error,nxdomain} -> - ok - end, + ?line {ok,IP46} = inet:getaddr(IPStr, inet6), +%% ?line IP4toIP6 = inet:getaddr(IPStr, inet6), +%% ?line case IP4toIP6 of +%% {ok,IP46} -> +%% ?line ok; +%% {error,nxdomain} -> +%% ?line false = +%% lists:member(native, +%% inet_db:res_option(lookup)) +%% end, ?line {Name6, FullName6, IPStr6, IP6, _} = ?config(test_host_ipv6_only, Config), ?line {ok,_} = inet:getaddr(list_to_atom(Name6), inet6), @@ -301,7 +303,6 @@ ipv4_to_ipv6(Config) when is_list(Config) -> end, ?line case {IP4to6Res,inet:gethostbyname(IPStr, inet6)} of {true,{ok,HEnt}} -> - ?line true = lists:member(native, inet_db:res_option(lookup)), ?line HEnt_ = HEnt#hostent{h_addrtype = inet6, h_length = 16, h_addr_list = [IP_46]}, @@ -374,9 +375,10 @@ get_hosts([C|Rest], Cur, Ip, Result) -> get_hosts([], _, _, Result) -> Result. -parse(suite) -> [parse_hosts]; +parse(suite) -> [parse_hosts, parse_address]; parse(doc) -> ["Test that parsing of the hosts file or equivalent works,", "and that erroneous lines are skipped"]. + parse_hosts(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir,Config), ?line HostFile = filename:join(DataDir, "hosts"), @@ -388,6 +390,170 @@ parse_hosts(Config) when is_list(Config) -> ?line ResolvErr1 = filename:join(DataDir,"resolv.conf.err1"), ?line inet_parse:resolv(ResolvErr1). +parse_address(Config) when is_list(Config) -> + V4Strict = + [{{0,0,0,0},"0.0.0.0"}, + {{1,2,3,4},"1.2.3.4"}, + {{253,252,251,250},"253.252.251.250"}, + {{1,2,255,254},"1.2.255.254"}], + V6Strict = + [{{0,0,0,0,0,0,0,0},"::"}, + {{15,0,0,0,0,0,0,2},"f::2"}, + {{15,16#f11,0,0,0,0,256,2},"f:f11::0100:2"}, + {{0,0,0,0,0,0,0,16#17},"::17"}, + {{16#700,0,0,0,0,0,0,0},"0700::"}, + {{0,0,0,0,0,0,2,1},"::2:1"}, + {{0,0,0,0,0,3,2,1},"::3:2:1"}, + {{0,0,0,0,4,3,2,1},"::4:3:2:1"}, + {{0,0,0,5,4,3,2,1},"::5:4:3:2:1"}, + {{0,0,6,5,4,3,2,1},"::6:5:4:3:2:1"}, + {{0,7,6,5,4,3,2,1},"::7:6:5:4:3:2:1"}, + {{7,0,0,0,0,0,0,0},"7::"}, + {{7,6,0,0,0,0,0,0},"7:6::"}, + {{7,6,5,0,0,0,0,0},"7:6:5::"}, + {{7,6,5,4,0,0,0,0},"7:6:5:4::"}, + {{7,6,5,4,3,0,0,0},"7:6:5:4:3::"}, + {{7,6,5,4,3,2,0,0},"7:6:5:4:3:2::"}, + {{7,6,5,4,3,2,1,0},"7:6:5:4:3:2:1::"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22:5c33:c440:55c0:c66c:77:0088"}, + {{16#c11,0,16#5c33,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11::5c33:c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22::c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22:5c33::55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,16#c66c,16#77,16#88}, + "c11:0c22:5c33:c440::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,0,16#77,16#88}, + "c11:0c22:5c33:c440:55c0::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,16#c66c,0,16#88}, + "c11:0c22:5c33:c440:55c0:c66c::0088"}, + {{16#c11,0,0,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11::c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,0,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22::55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,16#c66c,16#77,16#88}, + "c11:0c22:5c33::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,0,16#77,16#88}, + "c11:0c22:5c33:c440::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,0,0,16#88}, + "c11:0c22:5c33:c440:55c0::0088"}, + {{16#c11,0,0,0,16#55c0,16#c66c,16#77,16#88}, + "c11::55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,0,0,16#c66c,16#77,16#88}, + "c11:0c22::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,0,16#77,16#88}, + "c11:0c22:5c33::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,0,0,16#88}, + "c11:0c22:5c33:c440::0088"}, + {{16#c11,0,0,0,0,16#c66c,16#77,16#88}, + "c11::c66c:77:0088"}, + {{16#c11,16#c22,0,0,0,0,16#77,16#88}, + "c11:0c22::77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,0,0,16#88}, + "c11:0c22:5c33::0088"}, + {{16#c11,0,0,0,0,0,16#77,16#88}, + "c11::77:0088"}, + {{16#c11,16#c22,0,0,0,0,0,16#88}, + "c11:0c22::0088"}, + {{0,0,0,0,0,65535,258,65534},"::FFFF:1.2.255.254"}, + {{16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff}, + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"} + |[{{D2,0,0,0,0,P,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4}, + erlang:integer_to_list(D2, 16)++"::"++Q++S} + || {{D1,D2,D3,D4},S} <- V4Strict, + {P,Q} <- [{0,""},{16#17,"17:"},{16#ff0,"0ff0:"}]]], + V4Sloppy = + [{{10,1,16#98,16#76},"10.0x019876"}, + {{8#12,1,8#130,8#321},"012.01.054321"}, + {{255,255,255,255},"255.255.255.0377"}, + {{255,255,255,255},"0Xff.000000000377.0x0000ff.255"}, + {{255,255,255,255},"255.255.65535"}, + {{255,255,255,255},"255.0xFF.0177777"}, + {{255,255,255,255},"255.16777215"}, + {{255,255,255,255},"00377.0XFFFFFF"}, + {{255,255,255,255},"4294967295"}, + {{255,255,255,255},"0xffffffff"}, + {{255,255,255,255},"00000000000037777777777"}, + {{16#12,16#34,16#56,16#78},"0x12345678"}, + {{16#12,16#34,16#56,16#78},"0x12.0x345678"}, + {{16#12,16#34,16#56,16#78},"0x12.0X34.0x5678"}, + {{16#12,16#34,16#56,16#78},"0x12.0X34.0x56.0X78"}, + {{0,0,0,0},"0"}, + {{0,0,0,0},"00"}, + {{0,0,0,0},"0.0"}, + {{0,0,0,0},"00.00.00"}, + {{0,0,0,0},"0.00.0.0"}, + {{0,0,0,0},"0.0.000000000000.0"}], + V6Sloppy = + [{{0,0,0,0,0,65535,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4},S} + || {{D1,D2,D3,D4},S} <- V4Strict++V4Sloppy], + V4Err = + ["0.256.0.1", + "1.2.3.4.5", + "256.255.65535", + "4294967296", + "0x100000000", + "040000000000", + "1.2.3.-4", + "1.2.-3.4", + "1.-2.3.4", + "-1.2.3.4", + "10.", + "172.16.", + "198.168.0.", + "127.0.0.1."], + V6Err = + [":::", + "f:::2", + "::-1", + "::g", + "f:f11::10100:2", + "::17000", + "10000::", + "::8:7:6:5:4:3:2:1", + "8:7:6:5:4:3:2:1::", + "8:7:6:5:4::3:2:1", + "::1.2.3.4.5", + "::1.2.3.04", + "::1.256.3.4", + "::-5.4.3.2", + "::5.-4.3.2", + "::5.4.-3.2", + "::5.4.3.-2", + "::FFFF:1.2.3.4.5", + "::10.", + "::FFFF:172.16.", + "fe80::198.168.0.", + "fec0::fFfF:127.0.0.1."], + t_parse_address + (ipv6_address, + V6Strict++V6Sloppy++V6Err++V4Err), + t_parse_address + (ipv6strict_address, + V6Strict++V6Err++V4Err++[S || {_,S} <- V6Sloppy]), + t_parse_address + (ipv4_address, + V4Strict++V4Sloppy++V4Err++V6Err++[S || {_,S} <- V6Strict]), + t_parse_address + (ipv4strict_address, + V4Strict++V4Err++V6Err++[S || {_,S} <- V4Sloppy++V6Strict]). + +t_parse_address(Func, []) -> + io:format("~p done.~n", [Func]), + ok; +t_parse_address(Func, [{Addr,String}|L]) -> + io:format("~p = ~p.~n", [Addr,String]), + {ok,Addr} = inet_parse:Func(String), + t_parse_address(Func, L); +t_parse_address(Func, [String|L]) -> + io:format("~p.~n", [String]), + {error,einval} = inet_parse:Func(String), + t_parse_address(Func, L). + + + t_gethostnative(suite) ->[]; t_gethostnative(doc) ->[]; t_gethostnative(Config) when is_list(Config) -> diff --git a/lib/kernel/test/inet_res_SUITE.erl b/lib/kernel/test/inet_res_SUITE.erl index 659cfc5988..cc32d1f8f9 100644 --- a/lib/kernel/test/inet_res_SUITE.erl +++ b/lib/kernel/test/inet_res_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2009-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_res_SUITE). @@ -239,16 +239,37 @@ resolve(_Opts, []) -> ok; resolve(Opts, [{Class,Type,Name,Answers,Authority}=Q|Qs]) -> io:format("Query: ~p~nOptions: ~p~n", [Q,Opts]), {ok,Msg} = inet_res:resolve(Name, Class, Type, Opts), - if Answers =/= undefined -> - AnList = lists:sort(Answers), - AnList = lists:sort([inet_dns:rr(RR, data) || - RR <- inet_dns:msg(Msg, anlist)]); - true -> ok end, - if Authority =/= undefined -> - NsList = lists:sort(Authority), - NsList = lists:sort([inet_dns:rr(RR, data) || - RR <- inet_dns:msg(Msg, nslist)]); - true -> ok end, + AnList = + if + Answers =/= undefined -> + lists:sort(Answers); + true -> + undefined + end, + NsList = + if + Authority =/= undefined -> + lists:sort(Authority); + true -> + undefined + end, + case {lists:sort + ([inet_dns:rr(RR, data) || RR <- inet_dns:msg(Msg, anlist)]), + lists:sort + ([inet_dns:rr(RR, data) || RR <- inet_dns:msg(Msg, nslist)])} of + {AnList,NsList} -> + ok; + {NsList,AnList} when Type =:= ns -> + %% This whole case statement is kind of inside out just + %% to accept this case when some legacy DNS resolvers + %% return the answer to a NS query in the answer section + %% instead of in the authority section. + ok; + {AnList,_} when NsList =:= undefined -> + ok; + {_,NsList} when AnList =:= undefined -> + ok + end, Buf = inet_dns:encode(Msg), {ok,Msg} = inet_dns:decode(Buf), resolve(Opts, Qs). @@ -292,10 +313,23 @@ edns0(Config) when is_list(Config) -> MXs = lists:sort(inet_res_filter(inet_dns:msg(Msg2, anlist), in, mx)), Buf2 = inet_dns:encode(Msg2), {ok,Msg2} = inet_dns:decode(Buf2), - [OptRR] = [RR || RR <- inet_dns:msg(Msg2, arlist), - inet_dns:rr(RR, type) =:= opt], - io:format("~p~n", [inet_dns:rr(OptRR)]), - ok. + case [RR || RR <- inet_dns:msg(Msg2, arlist), + inet_dns:rr(RR, type) =:= opt] of + [OptRR] -> + io:format("~p~n", [inet_dns:rr(OptRR)]), + ok; + [] -> + case os:type() of + {unix,sunos} -> + case os:version() of + {M,V,_} when M < 5; M == 5, V =< 8 -> + %% In our test park only known platform + %% with an DNS resolver that can not do + %% EDNS0. + {comment,"No EDNS0"} + end + end + end. inet_res_filter(Anlist, Class, Type) -> [inet_dns:rr(RR, data) || RR <- Anlist, @@ -331,11 +365,13 @@ files_monitor(suite) -> files_monitor(doc) -> ["Tests monitoring of /etc/hosts and /etc/resolv.conf, but not them"]; files_monitor(Config) when is_list(Config) -> + Search = inet_db:res_option(search), HostsFile = inet_db:res_option(hosts_file), ResolvConf = inet_db:res_option(resolv_conf), Inet6 = inet_db:res_option(inet6), try do_files_monitor(Config) after + inet_db:res_option(search, Search), inet_db:res_option(resolv_conf, ResolvConf), inet_db:res_option(hosts_file, HostsFile), inet_db:res_option(inet6, Inet6) @@ -344,7 +380,13 @@ files_monitor(Config) when is_list(Config) -> do_files_monitor(Config) -> Dir = ?config(priv_dir, Config), {ok,Hostname} = inet:gethostname(), - FQDN = Hostname++"."++inet_db:res_option(domain), + FQDN = + case inet_db:res_option(domain) of + "" -> + Hostname; + _ -> + Hostname++"."++inet_db:res_option(domain) + end, HostsFile = filename:join(Dir, "files_monitor_hosts"), ResolvConf = filename:join(Dir, "files_monitor_resolv.conf"), ok = inet_db:res_option(resolv_conf, ResolvConf), @@ -362,20 +404,20 @@ do_files_monitor(Config) -> {error,nxdomain} = inet_res:gethostbyname(FQDN), {ok,{127,0,0,10}} = inet:getaddr("mx.otptest", inet), {ok,{0,0,0,0,0,0,32512,28}} = inet:getaddr("resolve.otptest", inet6), - ok = inet_db:res_option(inet6, true), {ok,#hostent{h_name = Hostname, h_addrtype = inet6, h_length = 16, h_addr_list = [{0,0,0,0,0,0,0,1}]}} = - inet:gethostbyname(Hostname), + inet:gethostbyname(Hostname, inet6), {ok,#hostent{h_name = FQDN, h_addrtype = inet6, h_length = 16, h_addr_list = [{0,0,0,0,0,0,0,1}]}} = - inet:gethostbyname(FQDN), + inet:gethostbyname(FQDN, inet6), {error,nxdomain} = inet_res:gethostbyname("resolve"), %% XXX inet does not honour res_option inet6, might be a problem? %% therefore inet_res is called here + ok = inet_db:res_option(inet6, true), {ok,#hostent{h_name = "resolve.otptest", h_addrtype = inet6, h_length = 16, diff --git a/lib/kernel/test/init_SUITE.erl b/lib/kernel/test/init_SUITE.erl index 3d777f93a4..bbd8261197 100644 --- a/lib/kernel/test/init_SUITE.erl +++ b/lib/kernel/test/init_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(init_SUITE). @@ -44,7 +44,7 @@ all(suite) -> restart, get_status, script_id, boot]. -init_per_testcase(Func, Config) when atom(Func), list(Config) -> +init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) -> Dog=?t:timetrap(?t:seconds(?DEFAULT_TIMEOUT_SEC)), [{watchdog, Dog}|Config]. @@ -477,7 +477,7 @@ script_id(Config) when is_list(Config) -> ?line {Name, Vsn} = init:script_id(), ?line if - list(Name), list(Vsn) -> + is_list(Name), is_list(Vsn) -> ok; true -> ?t:fail(not_standard_script) diff --git a/lib/kernel/test/kernel_SUITE.erl b/lib/kernel/test/kernel_SUITE.erl index 225bc38b05..bb1d905de3 100644 --- a/lib/kernel/test/kernel_SUITE.erl +++ b/lib/kernel/test/kernel_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %%%---------------------------------------------------------------- @@ -56,6 +56,6 @@ app_test(doc) -> ["Tests the applications consistency."]; app_test(suite) -> []; -app_test(Config) when list(Config) -> +app_test(Config) when is_list(Config) -> ?line ok=?t:app_test(kernel), ok. diff --git a/lib/kernel/test/kernel_config_SUITE.erl b/lib/kernel/test/kernel_config_SUITE.erl index 6b7d788e60..c72fc3f02d 100644 --- a/lib/kernel/test/kernel_config_SUITE.erl +++ b/lib/kernel/test/kernel_config_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(kernel_config_SUITE). @@ -56,7 +56,7 @@ from(_, []) -> []. %%----------------------------------------------------------------- sync(doc) -> []; sync(suite) -> []; -sync(Conf) when list(Conf) -> +sync(Conf) when is_list(Conf) -> ?line Dog = ?t:timetrap(?t:seconds(120)), % Write a config file Dir = ?config(priv_dir,Conf), diff --git a/lib/kernel/test/loose_node.erl b/lib/kernel/test/loose_node.erl index ac1ddb8d9a..87a4ef01c0 100644 --- a/lib/kernel/test/loose_node.erl +++ b/lib/kernel/test/loose_node.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -55,7 +55,7 @@ %% Exported functions. %% -stop(Node) when atom(Node) -> +stop(Node) when is_atom(Node) -> rpc:cast(Node, erlang, halt, []), io:format("Stopped loose node ~p~n", [Node]), ok. @@ -63,9 +63,10 @@ stop(Node) when atom(Node) -> start(Name, Args) -> start(Name, Args, -1). -start(Name, Args, TimeOut) when atom(Name) -> +start(Name, Args, TimeOut) when is_atom(Name) -> start(atom_to_list(Name), Args, TimeOut); -start(Name, Args, TimeOut) when list(Name), list(Args), integer(TimeOut) -> +start(Name, Args, TimeOut) + when is_list(Name), is_list(Args), is_integer(TimeOut) -> Parent = self(), Ref = make_ref(), Starter @@ -119,7 +120,7 @@ start(Name, Args, TimeOut) when list(Name), list(Args), integer(TimeOut) -> io:format("Trying to start loose node...~n" " --> ~p~n", [Cmd]), Res = case open_port({spawn, Cmd}, []) of - P when port(P) -> + P when is_port(P) -> receive {loose_node_started, Node, @@ -150,14 +151,14 @@ start(Name, Args, TimeOut) when list(Name), list(Args), integer(TimeOut) -> %% Exported functions for internal use. %% -loose_node_started([Name, Node, TimeOutSecs]) when list(Name), - list(Node), - list(TimeOutSecs) -> +loose_node_started([Name, Node, TimeOutSecs]) when is_list(Name), + is_list(Node), + is_list(TimeOutSecs) -> spawn_opt(fun () -> process_flag(trap_exit, true), Proc = {list_to_atom(Name), list_to_atom(Node)}, Timeout = case catch list_to_integer(TimeOutSecs) of - I when integer(I), I >= 0 -> I*1000; + I when is_integer(I), I >= 0 -> I*1000; _ -> infinity end, wait_until(fun () -> is_alive() end), diff --git a/lib/kernel/test/os_SUITE.erl b/lib/kernel/test/os_SUITE.erl index 667f267079..1673b33010 100644 --- a/lib/kernel/test/os_SUITE.erl +++ b/lib/kernel/test/os_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(os_SUITE). @@ -32,7 +32,7 @@ space_in_cwd(doc) -> "Test that executing a command in a current working directory " "with space in its name works."; space_in_cwd(suite) -> []; -space_in_cwd(Config) when list(Config) -> +space_in_cwd(Config) when is_list(Config) -> ?line PrivDir = ?config(priv_dir, Config), ?line Dirname = filename:join(PrivDir, "cwd with space"), ?line ok = file:make_dir(Dirname), @@ -60,7 +60,7 @@ space_in_cwd(Config) when list(Config) -> quoting(doc) -> "Test that various ways of quoting arguments work."; quoting(suite) -> []; -quoting(Config) when list(Config) -> +quoting(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir, Config), ?line Echo = filename:join(DataDir, "my_echo"), @@ -78,7 +78,7 @@ quoting(Config) when list(Config) -> space_in_name(doc) -> "Test that program with a space in its name can be executed."; space_in_name(suite) -> []; -space_in_name(Config) when list(Config) -> +space_in_name(Config) when is_list(Config) -> ?line PrivDir = ?config(priv_dir, Config), ?line DataDir = ?config(data_dir, Config), ?line Spacedir = filename:join(PrivDir, "program files"), @@ -108,7 +108,7 @@ space_in_name(Config) when list(Config) -> bad_command(doc) -> "Check that a bad command doesn't crasch the server or the emulator (it used to)."; bad_command(suite) -> []; -bad_command(Config) when list(Config) -> +bad_command(Config) when is_list(Config) -> ?line catch os:cmd([a|b]), ?line catch os:cmd({bad, thing}), @@ -120,7 +120,7 @@ bad_command(Config) when list(Config) -> find_executable(suite) -> []; find_executable(doc) -> []; -find_executable(Config) when list(Config) -> +find_executable(Config) when is_list(Config) -> case os:type() of {win32, _} -> ?line DataDir = filename:join(?config(data_dir, Config), "win32"), @@ -159,7 +159,7 @@ find_exe(Where, Name, Ext, Path) -> case os:find_executable(Name, Path) of Expected -> ok; - Name when list(Name) -> + Name when is_list(Name) -> case filename:absname(Name) of Expected -> ok; @@ -176,7 +176,7 @@ find_exe(Where, Name, Ext, Path) -> unix_comment_in_command(doc) -> "OTP-1805: Test that os:cmd(\"ls #\") works correctly (used to hang)."; unix_comment_in_command(suite) -> []; -unix_comment_in_command(Config) when list(Config) -> +unix_comment_in_command(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(20)), ?line Priv = ?config(priv_dir, Config), ?line ok = file:set_cwd(Priv), diff --git a/lib/kernel/test/pdict_SUITE.erl b/lib/kernel/test/pdict_SUITE.erl index 6aa434b614..87ee951a0c 100644 --- a/lib/kernel/test/pdict_SUITE.erl +++ b/lib/kernel/test/pdict_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1999-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(pdict_SUITE). @@ -49,7 +49,7 @@ simple(doc) -> ["Tests simple functionality in process dictionary."]; simple(suite) -> []; -simple(Config) when list(Config) -> +simple(Config) when is_list(Config) -> XX = get(), erase(), L = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p, @@ -146,7 +146,7 @@ info(doc) -> ["Tests process_info(Pid, dictionary)"]; info(suite) -> []; -info(Config) when list(Config) -> +info(Config) when is_list(Config) -> L = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p, q,r,s,t,u,v,x,y,z,'A','B','C','D'], process_flag(trap_exit,true), diff --git a/lib/kernel/test/rpc_SUITE.erl b/lib/kernel/test/rpc_SUITE.erl index 2b39e31a80..2b7de40797 100644 --- a/lib/kernel/test/rpc_SUITE.erl +++ b/lib/kernel/test/rpc_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2000-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(rpc_SUITE). @@ -333,7 +333,7 @@ suicide(exit, Reason) -> suicide(erlang, exit, [Name, Reason]) when is_atom(Name) -> case whereis(Name) of - Pid when pid(Pid) -> suicide(erlang, exit, [Pid, Reason]) + Pid when is_pid(Pid) -> suicide(erlang, exit, [Pid, Reason]) end; suicide(Mod, Func, Args) -> spawn_link( @@ -448,7 +448,7 @@ call_benchmark(Config) when is_list(Config) -> ?t:timetrap_cancel(Timetrap), ok. -do_call_benchmark(Node, M) when integer(M), M > 0 -> +do_call_benchmark(Node, M) when is_integer(M), M > 0 -> do_call_benchmark(Node, erlang:now(), 0, M). do_call_benchmark(Node, {A,B,C}, M, M) -> diff --git a/lib/kernel/test/seq_trace_SUITE.erl b/lib/kernel/test/seq_trace_SUITE.erl index f582b94c97..b557c7fb1e 100644 --- a/lib/kernel/test/seq_trace_SUITE.erl +++ b/lib/kernel/test/seq_trace_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(seq_trace_SUITE). @@ -381,7 +381,7 @@ port(Config) when is_list(Config) -> get_port_message(Port) -> receive - {Port,{data,Bin}} when binary(Bin) -> + {Port,{data,Bin}} when is_binary(Bin) -> binary_to_term(Bin); Other -> ?t:fail({unexpected,Other}) @@ -678,7 +678,7 @@ transparent_tracer() -> receive {started, Ref} -> ok end, fun(pid) -> Pid; - ({stop, N}) when integer(N), N >= 0 -> + ({stop, N}) when is_integer(N), N >= 0 -> Mref = erlang:monitor(process, Pid), receive {'DOWN', Mref, _, _, _} -> @@ -717,7 +717,7 @@ simple_tracer(Data, DN) -> From ! {tracerlog,lists:reverse(Data)} end. -stop_tracer(N) when integer(N) -> +stop_tracer(N) when is_integer(N) -> case catch (seq_trace_SUITE_tracer ! {stop,N,self()}) of {'EXIT', _} -> {error, not_started}; diff --git a/lib/kernel/test/wrap_log_reader_SUITE.erl b/lib/kernel/test/wrap_log_reader_SUITE.erl index 1d1570fbd9..ceac593e44 100644 --- a/lib/kernel/test/wrap_log_reader_SUITE.erl +++ b/lib/kernel/test/wrap_log_reader_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -48,7 +48,7 @@ all(suite) -> [no_file, one, two, four, wrap, wrapping, external, error]. -init_per_testcase(Func, Config) when atom(Func), list(Config) -> +init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) -> Dog=?t:timetrap(?t:seconds(60)), [{watchdog, Dog} | Config]. @@ -58,7 +58,7 @@ fin_per_testcase(_Func, _Config) -> no_file(suite) -> []; no_file(doc) -> ["No log file exists"]; -no_file(Conf) when list(Conf) -> +no_file(Conf) when is_list(Conf) -> ?line code:add_path(?config(data_dir,Conf)), Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), @@ -81,7 +81,7 @@ one(doc) -> ["One index file"]. one_empty(suite) -> []; one_empty(doc) -> ["One empty index file"]; -one_empty(Conf) when list(Conf) -> +one_empty(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -107,7 +107,7 @@ one_empty(Conf) when list(Conf) -> one_filled(suite) -> []; one_filled(doc) -> ["One filled index file"]; -one_filled(Conf) when list(Conf) -> +one_filled(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -144,7 +144,7 @@ two(doc) -> ["Two index files"]. two_filled(suite) -> []; two_filled(doc) -> ["Two filled index files"]; -two_filled(Conf) when list(Conf) -> +two_filled(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = list_to_atom(join(Dir, "sune.LOG")), delete_files(File), @@ -186,7 +186,7 @@ four(doc) -> ["Four index files"]. four_filled(suite) -> []; four_filled(doc) -> ["Four filled index files"]; -four_filled(Conf) when list(Conf) -> +four_filled(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -231,7 +231,7 @@ wrap(doc) -> ["Wrap index file, first wrapping"]. wrap_filled(suite) -> []; wrap_filled(doc) -> ["First wrap, open, filled index file"]; -wrap_filled(Conf) when list(Conf) -> +wrap_filled(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -274,7 +274,7 @@ test_wrap(File) -> wrapping(suite) -> []; wrapping(doc) -> ["Wrapping at the same time as reading"]; -wrapping(Conf) when list(Conf) -> +wrapping(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -329,7 +329,7 @@ wrapping(Conf) when list(Conf) -> external(suite) -> []; external(doc) -> ["External format"]; -external(Conf) when list(Conf) -> +external(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), @@ -349,7 +349,7 @@ external(Conf) when list(Conf) -> error(suite) -> []; error(doc) -> ["Error situations"]; -error(Conf) when list(Conf) -> +error(Conf) when is_list(Conf) -> Dir = ?privdir(Conf), File = join(Dir, "sune.LOG"), delete_files(File), |