From a41174d5ef937a22455f8cc52428fee313ae156e Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 21 Nov 2011 17:56:37 +0100 Subject: Various minor dialyzer related cleanup. --- lib/inets/src/http_client/httpc_manager.erl | 2 +- lib/inets/src/http_server/httpd_acceptor.erl | 4 ++++ .../src/http_server/httpd_request_handler.erl | 25 ++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/inets/src/http_client/httpc_manager.erl b/lib/inets/src/http_client/httpc_manager.erl index ab575d867e..121562195f 100644 --- a/lib/inets/src/http_client/httpc_manager.erl +++ b/lib/inets/src/http_client/httpc_manager.erl @@ -37,7 +37,7 @@ delete_session/2, set_options/2, store_cookies/3, - which_cookies/1, which_cookies/2, + which_cookies/1, which_cookies/2, which_cookies/3, reset_cookies/1, session_type/1, info/1 diff --git a/lib/inets/src/http_server/httpd_acceptor.erl b/lib/inets/src/http_server/httpd_acceptor.erl index bcebb6a9e3..1c954106c1 100644 --- a/lib/inets/src/http_server/httpd_acceptor.erl +++ b/lib/inets/src/http_server/httpd_acceptor.erl @@ -152,6 +152,9 @@ handle_connection(Manager, ConfigDb, AcceptTimeout, SocketType, Socket) -> http_transport:controlling_process(SocketType, Socket, Pid), httpd_request_handler:socket_ownership_transfered(Pid, SocketType, Socket). + +-spec handle_error(Error::timeout|emfile|closed|econnreset|econnaborted|esslaccept|{enfile, _}|{'EXIT', Reason::any()}|any(), ConfigDB::any()) -> ok | no_return(). + handle_error(timeout, _) -> ok; @@ -197,6 +200,7 @@ handle_error(Reason, ConfigDb) -> String = lists:flatten(io_lib:format("Accept error: ~p", [Reason])), accept_failed(ConfigDb, String). + -spec accept_failed(_, string()) -> no_return(). accept_failed(ConfigDb, String) -> diff --git a/lib/inets/src/http_server/httpd_request_handler.erl b/lib/inets/src/http_server/httpd_request_handler.erl index d2f22fce93..b62c10bbc7 100644 --- a/lib/inets/src/http_server/httpd_request_handler.erl +++ b/lib/inets/src/http_server/httpd_request_handler.erl @@ -162,7 +162,14 @@ continue_init(Manager, ConfigDB, SocketType, Socket, TimeOut) -> %% {stop, Reason, State} %% Description: Handling call messages %%-------------------------------------------------------------------- -handle_call(Request, From, State) -> +handle_call(Request, From, #state{mod = ModData} = State) -> + Error = + lists:flatten( + io_lib:format("Unexpected request: " + "~n~p" + "~nto request handler (~p) from ~p" + "~n", [Request, self(), From])), + error_log(Error, ModData), {stop, {call_api_violation, Request, From}, State}. %%-------------------------------------------------------------------- @@ -171,8 +178,15 @@ handle_call(Request, From, State) -> %% {stop, Reason, State} %% Description: Handling cast messages %%-------------------------------------------------------------------- -handle_cast(Msg, State) -> - {reply, {cast_api_violation, Msg}, State}. +handle_cast(Msg, #state{mod = ModData} = State) -> + Error = + lists:flatten( + io_lib:format("Unexpected message: " + "~n~p" + "~nto request handler (~p)" + "~n", [Msg, self()])), + error_log(Error, ModData), + {noreply, State}. %%-------------------------------------------------------------------- %% handle_info(Info, State) -> {noreply, State} | @@ -253,7 +267,10 @@ handle_info(timeout, #state{mod = ModData} = State) -> %% Default case handle_info(Info, #state{mod = ModData} = State) -> Error = lists:flatten( - io_lib:format("Unexpected message received: ~n~p~n", [Info])), + io_lib:format("Unexpected info: " + "~n~p" + "~nto request handler (~p)" + "~n", [Info, self()])), error_log(Error, ModData), {noreply, State}. -- cgit v1.2.3 From 206c869501fe5e441bcb5db63827f50e5f00d8e6 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 22 Nov 2011 12:07:48 +0100 Subject: [httpd] Sometimes entries in the transfer log was written with the message size as list of numbers. This list was actually the size as a string, e.g. "123", written with the control sequence ~w. This has now been corrected so that any string is converted to an integer (if possible). OTP-9733 --- lib/inets/src/http_server/httpd_log.erl | 126 +++++++++++++++++++++----------- 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/lib/inets/src/http_server/httpd_log.erl b/lib/inets/src/http_server/httpd_log.erl index db1e2c627a..60ab326a20 100644 --- a/lib/inets/src/http_server/httpd_log.erl +++ b/lib/inets/src/http_server/httpd_log.erl @@ -24,68 +24,110 @@ -export([access_entry/8, error_entry/5, error_report_entry/5, security_entry/5]). + %%%========================================================================= %%% Internal Application API %%%========================================================================= -access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, Bytes) -> - ConfigDB = Info#mod.config_db, - case httpd_util:lookup(ConfigDB, Log) of - undefined -> - NoLog; - LogRef -> - {_, RemoteHost} - = (Info#mod.init_data)#init_data.peername, - RequestLine = Info#mod.request_line, - Headers = Info#mod.parsed_header, - Entry = do_access_entry(ConfigDB, Headers, RequestLine, - RemoteHost, RFC931, AuthUser, - Date, StatusCode, Bytes), - {LogRef, Entry} - end. -error_entry(Log, NoLog, Info, Date, Reason) -> - ConfigDB = Info#mod.config_db, - case httpd_util:lookup(ConfigDB, Log) of - undefined -> - NoLog; - LogRef -> - {_, RemoteHost} = - (Info#mod.init_data)#init_data.peername, - URI = Info#mod.request_uri, - Entry = do_error_entry(ConfigDB, RemoteHost, URI, Date, Reason), - {LogRef, Entry} - end. +-spec access_entry(Log :: term(), % Id of the log + NoLog :: term(), % What to return when no log is found + Info :: #mod{}, + RFC931 :: string(), + AuthUser :: string(), + Date :: string(), + StatusCode :: pos_integer(), + Size :: pos_integer() | string()) -> + {Log :: atom() | pid(), Entry :: string()}. + +access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, SizeStr) + when is_list(SizeStr) -> + Size = + case (catch list_to_integer(SizeStr)) of + I when is_integer(I) -> + I; + _ -> + SizeStr % This is better then nothing + end, + access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, Size); +access_entry(Log, NoLog, + #mod{config_db = ConfigDB, + init_data = #init_data{peername = {_, RemoteHost}}, + request_line = RequestLine, + parsed_header = Headers}, + RFC931, AuthUser, Date, StatusCode, Size) -> + MakeEntry = + fun() -> + do_access_entry(ConfigDB, Headers, RequestLine, + RemoteHost, RFC931, AuthUser, + Date, StatusCode, Size) + end, + log_entry(Log, NoLog, ConfigDB, MakeEntry). + + +-spec error_entry(Log :: term(), % Id of the log + NoLog :: term(), % What to return when no log is found + Info :: #mod{}, + Date :: string(), + Reason :: term()) -> + {Log :: atom() | pid(), Entry :: string()}. + +error_entry(Log, NoLog, + #mod{config_db = ConfigDB, + init_data = #init_data{peername = {_, RemoteHost}}, + request_uri = URI}, Date, Reason) -> + MakeEntry = + fun() -> + do_error_entry(ConfigDB, RemoteHost, URI, Date, Reason) + end, + log_entry(Log, NoLog, ConfigDB, MakeEntry). + + +-spec error_report_entry(Log :: term(), + NoLog :: term(), + ConfigDB :: term(), + Date :: string(), + ErrroStr :: string()) -> + {Log :: atom() | pid(), Entry :: string()}. error_report_entry(Log, NoLog, ConfigDb, Date, ErrorStr) -> - case httpd_util:lookup(ConfigDb, Log) of - undefined -> - NoLog; - LogRef -> - Entry = io_lib:format("[~s], ~s~n", [Date, ErrorStr]), - {LogRef, Entry} - end. + MakeEntry = fun() -> io_lib:format("[~s], ~s~n", [Date, ErrorStr]) end, + log_entry(Log, NoLog, ConfigDb, MakeEntry). + -security_entry(Log, NoLog, #mod{config_db = ConfigDb}, Date, Reason) -> +-spec security_entry(Log :: term(), + NoLog :: term(), + ConfigDB :: term(), + Date :: string(), + Reason :: term()) -> + {Log :: atom() | pid(), Entry :: string()}. + +security_entry(Log, NoLog, #mod{config_db = ConfigDB}, Date, Reason) -> + MakeEntry = fun() -> io_lib:format("[~s] ~s~n", [Date, Reason]) end, + log_entry(Log, NoLog, ConfigDB, MakeEntry). + + +log_entry(Log, NoLog, ConfigDb, MakeEntry) when is_function(MakeEntry) -> case httpd_util:lookup(ConfigDb, Log) of undefined -> NoLog; LogRef -> - Entry = io_lib:format("[~s] ~s~n", [Date, Reason]), - {LogRef, Entry} + {LogRef, MakeEntry()} end. - + + %%%======================================================================== %%% Internal functions %%%======================================================================== + do_access_entry(ConfigDB, Headers, RequestLine, - RemoteHost, RFC931, AuthUser, Date, StatusCode, - Bytes) -> + RemoteHost, RFC931, AuthUser, Date, StatusCode, + Size) -> case httpd_util:lookup(ConfigDB, log_format, common) of common -> lists:flatten(io_lib:format("~s ~s ~s [~s] \"~s\" ~w ~w~n", [RemoteHost, RFC931, AuthUser, Date, RequestLine, - StatusCode, Bytes])); + StatusCode, Size])); combined -> Referer = proplists:get_value("referer", Headers, "-"), @@ -94,7 +136,7 @@ do_access_entry(ConfigDB, Headers, RequestLine, Headers, "-"), io_lib:format("~s ~s ~s [~s] \"~s\" ~w ~w ~s ~s~n", [RemoteHost, RFC931, AuthUser, Date, - RequestLine, StatusCode, Bytes, + RequestLine, StatusCode, Size, Referer, UserAgent]) end. -- cgit v1.2.3 From 3a94ee84c863798aed81869c71d4ab6b4b902ee5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 22 Nov 2011 12:16:36 +0100 Subject: Used wrong interface module (http instead of httpc: copy-and-paste). --- lib/inets/test/httpc_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index d86e52f3d5..2b580cd95d 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -370,7 +370,7 @@ init_per_testcase(Case, Timeout, Config) -> %% This will fail for the ipv6_ - cases (but that is ok) ProxyExceptions = ["localhost", ?IPV6_LOCAL_HOST], - http:set_options([{proxy, {{?PROXY, ?PROXY_PORT}, ProxyExceptions}}]), + httpc:set_options([{proxy, {{?PROXY, ?PROXY_PORT}, ProxyExceptions}}]), inets:enable_trace(max, io, httpc), %% inets:enable_trace(max, io, all), %% snmp:set_trace([gen_tcp]), -- cgit v1.2.3 From 87abb60af318a471df1c3614bfa860a7fd55ccf7 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 22 Nov 2011 12:38:13 +0100 Subject: Added release notes for OTP-9736. --- lib/inets/doc/src/notes.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/inets/doc/src/notes.xml b/lib/inets/doc/src/notes.xml index 7f0f61148c..346c881df0 100644 --- a/lib/inets/doc/src/notes.xml +++ b/lib/inets/doc/src/notes.xml @@ -66,6 +66,11 @@

Own Id: OTP-9715

+ +

Fixed various problems detected by Dialyzer.

+

Own Id: OTP-9736

+
+ -- cgit v1.2.3 From ed6b55aeb44bbbc32563f1fe7c066712b04e8fe9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 22 Nov 2011 12:42:03 +0100 Subject: Added release notes for OTP-9733. --- lib/inets/doc/src/notes.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/inets/doc/src/notes.xml b/lib/inets/doc/src/notes.xml index 346c881df0..c9944964e4 100644 --- a/lib/inets/doc/src/notes.xml +++ b/lib/inets/doc/src/notes.xml @@ -66,6 +66,15 @@

Own Id: OTP-9715

+ +

[httpd] Sometimes entries in the transfer log was written + with the message size as list of numbers. This list was actually + the size as a string, e.g. "123", written with the control + sequence ~w. This has now been corrected so that any string is + converted to an integer (if possible).

+

Own Id: OTP-9733

+
+

Fixed various problems detected by Dialyzer.

Own Id: OTP-9736

-- cgit v1.2.3 From 9e7449804168f701109a5fd6b2ebe6b43ecece44 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 14:32:18 +0100 Subject: Added dialyzer targets for building inets plt and running dialyzer on inets. --- lib/inets/Makefile | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/inets/Makefile b/lib/inets/Makefile index 4765a2ca3c..1ad6ccf39f 100644 --- a/lib/inets/Makefile +++ b/lib/inets/Makefile @@ -31,12 +31,17 @@ VSN = $(INETS_VSN) SPECIAL_TARGETS = +INETS_DIA_PLT = ./priv/inets.plt +INETS_DIA_PLT_LOG = $(basename $(INETS_DIA_PLT)).dialyzer_plt_log +INETS_DIA_LOG = $(basename $(INETS_DIA_PLT)).dialyzer_log + + # ---------------------------------------------------- # Default Subdir Targets # ---------------------------------------------------- include $(ERL_TOP)/make/otp_subdir.mk -.PHONY: info gclean +.PHONY: info gclean dialyzer dialyzer_plt dclean info: @echo "OS: $(OS)" @@ -45,6 +50,30 @@ info: @echo "INETS_VSN: $(INETS_VSN)" @echo "APP_VSN: $(APP_VSN)" @echo "" + @echo "INETS_DIA_PLT: $(INETS_DIA_PLT)" + @echo "INETS_DIA_LOG: $(INETS_DIA_LOG)" + @echo "" gclean: git clean -fXd + +dclean: + rm -f $(INETS_DIA_PLT) + rm -f $(INETS_DIA_PLT_LOG) + rm -f $(INETS_DIA_LOG) + +dialyzer_plt: $(INETS_DIA_PLT) + +$(INETS_DIA_PLT): + @echo "Building inets plt file" + @dialyzer --build_plt \ + --output_plt $@ \ + -r ../inets/ebin \ + -o $(INETS_DIA_PLT_LOG) \ + --verbose + +dialyzer: $(INETS_DIA_PLT) + @echo "Running dialyzer on inets" + @dialyzer --plt $< \ + ../inets/ebin \ + --verbose -- cgit v1.2.3 From 473c6308bbfed958ab04f45f53305e5d82d733fa Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 16:22:50 +0100 Subject: Fixed acceptor exit warnings (detected by dialyzer). Also fixed cookie_header/3 and updated documented accordingly. Also added documentation for undocumented URI parse option. --- lib/inets/doc/src/httpc.xml | 33 +++++++++++++++++++++------- lib/inets/src/http_client/httpc.erl | 21 +++++++++++++----- lib/inets/src/http_client/httpc_manager.erl | 4 +++- lib/inets/src/http_server/httpd_acceptor.erl | 20 ++++++----------- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/lib/inets/doc/src/httpc.xml b/lib/inets/doc/src/httpc.xml index b1f964ae69..730efb729f 100644 --- a/lib/inets/doc/src/httpc.xml +++ b/lib/inets/doc/src/httpc.xml @@ -178,13 +178,14 @@ filename() = string() timeout() = integer() >= 0 | infinity Options = options() options() = [option()] - option() = {sync, boolean()} | - {stream, stream_to()} | - {body_format, body_format()} | - {full_result, boolean()} | - {headers_as_is, boolean() | - {socket_opts, socket_opts()} | - {receiver, receiver()}} + option() = {sync, boolean()} | + {stream, stream_to()} | + {body_format, body_format()} | + {full_result, boolean()} | + {headers_as_is, boolean() | + {socket_opts, socket_opts()} | + {receiver, receiver()}, + {ipv6_host_with_brackets, boolean()}} stream_to() = none | self | {self, once} | filename() socket_opts() = [socket_opt()] receiver() = pid() | function()/1 | {Module, Function, Args} @@ -408,6 +409,15 @@ apply(Module, Function, [ReplyInfo | Args])

Defaults to the pid() of the process calling the request function (self()).

+ + + +

When parsing the Host-Port part of an URI with a IPv6 address + with brackets, shall we retain those brackets (true) or + strip them (false).

+

Defaults to false.

+
+ @@ -572,17 +582,24 @@ apply(Module, Function, [ReplyInfo | Args]) cookie_header(Url) -> - cookie_header(Url, Profile) -> header() | {error, Reason} + cookie_header(Url, Profile | Opts) -> header() | {error, Reason} + cookie_header(Url, Opts, Profile) -> header() | {error, Reason} Returns the cookie header that would be sent when making a request to Url using the profile Profile. Url = url() + Opts = [cookie_header_opt()] Profile = profile() | pid() (when started stand_alone) + cookie_header_opt() = {ipv6_host_with_brackets, boolean()}

Returns the cookie header that would be sent when making a request to Url using the profile Profile. If no profile is specified the default profile will be used.

+

The option ipv6_host_with_bracket deals with how to + parse IPv6 addresses. + See the Options argument of the + request/4,5 for more info.

diff --git a/lib/inets/src/http_client/httpc.erl b/lib/inets/src/http_client/httpc.erl index d72c34fa6b..ae87ceed93 100644 --- a/lib/inets/src/http_client/httpc.erl +++ b/lib/inets/src/http_client/httpc.erl @@ -34,7 +34,7 @@ set_option/2, set_option/3, set_options/1, set_options/2, store_cookies/2, store_cookies/3, - cookie_header/1, cookie_header/2, + cookie_header/1, cookie_header/2, cookie_header/3, which_cookies/0, which_cookies/1, reset_cookies/0, reset_cookies/1, stream_next/1, @@ -290,25 +290,36 @@ store_cookies(SetCookieHeaders, Url, Profile) %%-------------------------------------------------------------------------- -%% cookie_header(Url [, Profile]) -> Header | {error, Reason} -%% +%% cookie_header(Url) -> Header | {error, Reason} +%% cookie_header(Url, Profile) -> Header | {error, Reason} +%% cookie_header(Url, Opts, Profile) -> Header | {error, Reason} +%% %% Description: Returns the cookie header that would be sent when making %% a request to . %%------------------------------------------------------------------------- cookie_header(Url) -> cookie_header(Url, default_profile()). -cookie_header(Url, Profile) -> +cookie_header(Url, Profile) when is_atom(Profile) orelse is_pid(Profile) -> + cookie_header(Url, [], Profile); +cookie_header(Url, Opts) when is_list(Opts) -> + cookie_header(Url, Opts, default_profile()). + +cookie_header(Url, Opts, Profile) + when (is_list(Opts) andalso (is_atom(Profile) orelse is_pid(Profile))) -> ?hcrt("cookie header", [{url, Url}, + {opts, Opts}, {profile, Profile}]), try begin - httpc_manager:which_cookies(Url, profile_name(Profile)) + httpc_manager:which_cookies(Url, Opts, profile_name(Profile)) end catch exit:{noproc, _} -> {error, {not_started, Profile}} end. + + %%-------------------------------------------------------------------------- diff --git a/lib/inets/src/http_client/httpc_manager.erl b/lib/inets/src/http_client/httpc_manager.erl index 121562195f..a97cbb83f1 100644 --- a/lib/inets/src/http_client/httpc_manager.erl +++ b/lib/inets/src/http_client/httpc_manager.erl @@ -271,9 +271,11 @@ reset_cookies(ProfileName) -> which_cookies(ProfileName) when is_atom(ProfileName) -> call(ProfileName, which_cookies). + which_cookies(Url, ProfileName) when is_list(Url) andalso is_atom(ProfileName) -> - call(ProfileName, {which_cookies, Url, []}). + which_cookies(Url, [], ProfileName). + which_cookies(Url, Options, ProfileName) when is_list(Url) andalso is_list(Options) andalso is_atom(ProfileName) -> call(ProfileName, {which_cookies, Url, Options}). diff --git a/lib/inets/src/http_server/httpd_acceptor.erl b/lib/inets/src/http_server/httpd_acceptor.erl index 1c954106c1..046e491bbf 100644 --- a/lib/inets/src/http_server/httpd_acceptor.erl +++ b/lib/inets/src/http_server/httpd_acceptor.erl @@ -139,11 +139,11 @@ acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout) -> handle_error(Reason, ConfigDb), ?MODULE:acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout); - {'EXIT', _Reason} = EXIT -> - ?hdri("accept exited", [{reason, _Reason}]), - handle_error(EXIT, ConfigDb), - ?MODULE:acceptor_loop(Manager, SocketType, ListenSocket, - ConfigDb, AcceptTimeout) + {'EXIT', Reason} -> + ?hdri("accept exited", [{reason, Reason}]), + ReasonString = + lists:flatten(io_lib:format("Accept exit: ~p", [Reason])), + accept_failed(ConfigDb, ReasonString) end. @@ -152,9 +152,6 @@ handle_connection(Manager, ConfigDb, AcceptTimeout, SocketType, Socket) -> http_transport:controlling_process(SocketType, Socket, Pid), httpd_request_handler:socket_ownership_transfered(Pid, SocketType, Socket). - --spec handle_error(Error::timeout|emfile|closed|econnreset|econnaborted|esslaccept|{enfile, _}|{'EXIT', Reason::any()}|any(), ConfigDB::any()) -> ok | no_return(). - handle_error(timeout, _) -> ok; @@ -192,16 +189,13 @@ handle_error(esslaccept, _) -> %% not write an error message. ok; -handle_error({'EXIT', Reason}, ConfigDb) -> - String = lists:flatten(io_lib:format("Accept exit: ~p", [Reason])), - accept_failed(ConfigDb, String); - handle_error(Reason, ConfigDb) -> String = lists:flatten(io_lib:format("Accept error: ~p", [Reason])), accept_failed(ConfigDb, String). --spec accept_failed(_, string()) -> no_return(). +-spec accept_failed(ConfigDB :: term(), + ReasonString :: string()) -> no_return(). accept_failed(ConfigDb, String) -> error_logger:error_report(String), -- cgit v1.2.3 From 20733e3fd8b7ca6ec37585e17a88a8c9cf0d4410 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 16:54:23 +0100 Subject: Added priv subdir (inets/priv/plt) as plt destination. --- lib/inets/Makefile | 14 ++++++-------- lib/inets/priv/plt/.gitignore | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 lib/inets/priv/plt/.gitignore diff --git a/lib/inets/Makefile b/lib/inets/Makefile index 1ad6ccf39f..1414a89621 100644 --- a/lib/inets/Makefile +++ b/lib/inets/Makefile @@ -31,9 +31,8 @@ VSN = $(INETS_VSN) SPECIAL_TARGETS = -INETS_DIA_PLT = ./priv/inets.plt -INETS_DIA_PLT_LOG = $(basename $(INETS_DIA_PLT)).dialyzer_plt_log -INETS_DIA_LOG = $(basename $(INETS_DIA_PLT)).dialyzer_log +INETS_DIA_PLT = ./priv/plt/inets.plt +INETS_DIA_ANALYSIS = $(basename $(INETS_DIA_PLT)).dialyzer_analysis # ---------------------------------------------------- @@ -50,8 +49,8 @@ info: @echo "INETS_VSN: $(INETS_VSN)" @echo "APP_VSN: $(APP_VSN)" @echo "" - @echo "INETS_DIA_PLT: $(INETS_DIA_PLT)" - @echo "INETS_DIA_LOG: $(INETS_DIA_LOG)" + @echo "INETS_DIA_PLT: $(INETS_DIA_PLT)" + @echo "INETS_DIA_ANALYSIS: $(INETS_DIA_ANALYSIS)" @echo "" gclean: @@ -59,8 +58,7 @@ gclean: dclean: rm -f $(INETS_DIA_PLT) - rm -f $(INETS_DIA_PLT_LOG) - rm -f $(INETS_DIA_LOG) + rm -f $(INETS_DIA_ANALYSIS) dialyzer_plt: $(INETS_DIA_PLT) @@ -69,7 +67,7 @@ $(INETS_DIA_PLT): @dialyzer --build_plt \ --output_plt $@ \ -r ../inets/ebin \ - -o $(INETS_DIA_PLT_LOG) \ + --output $(INETS_DIA_ANALYSIS) \ --verbose dialyzer: $(INETS_DIA_PLT) diff --git a/lib/inets/priv/plt/.gitignore b/lib/inets/priv/plt/.gitignore new file mode 100644 index 0000000000..2051b52d48 --- /dev/null +++ b/lib/inets/priv/plt/.gitignore @@ -0,0 +1,2 @@ +/*.plt +/*.dialyzer_analysis -- cgit v1.2.3 From a42bf8a5f11dcc5e35685951964a293a0e9ee6a4 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 17:16:47 +0100 Subject: Make dialyzer targets more general... --- lib/inets/Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/inets/Makefile b/lib/inets/Makefile index 1414a89621..fd22c65ddb 100644 --- a/lib/inets/Makefile +++ b/lib/inets/Makefile @@ -31,8 +31,8 @@ VSN = $(INETS_VSN) SPECIAL_TARGETS = -INETS_DIA_PLT = ./priv/plt/inets.plt -INETS_DIA_ANALYSIS = $(basename $(INETS_DIA_PLT)).dialyzer_analysis +DIA_PLT = ./priv/plt/$(APPLICATION).plt +DIA_ANALYSIS = $(basename $(DIA_PLT)).dialyzer_analysis # ---------------------------------------------------- @@ -49,29 +49,29 @@ info: @echo "INETS_VSN: $(INETS_VSN)" @echo "APP_VSN: $(APP_VSN)" @echo "" - @echo "INETS_DIA_PLT: $(INETS_DIA_PLT)" - @echo "INETS_DIA_ANALYSIS: $(INETS_DIA_ANALYSIS)" + @echo "DIA_PLT: $(DIA_PLT)" + @echo "DIA_ANALYSIS: $(DIA_ANALYSIS)" @echo "" gclean: git clean -fXd dclean: - rm -f $(INETS_DIA_PLT) - rm -f $(INETS_DIA_ANALYSIS) + rm -f $(DIA_PLT) + rm -f $(DIA_ANALYSIS) -dialyzer_plt: $(INETS_DIA_PLT) +dialyzer_plt: $(DIA_PLT) $(INETS_DIA_PLT): - @echo "Building inets plt file" + @echo "Building $(APPLICATION) plt file" @dialyzer --build_plt \ --output_plt $@ \ - -r ../inets/ebin \ - --output $(INETS_DIA_ANALYSIS) \ + -r ../$(APPLICATION)/ebin \ + --output $(DIA_ANALYSIS) \ --verbose -dialyzer: $(INETS_DIA_PLT) - @echo "Running dialyzer on inets" +dialyzer: $(DIA_PLT) + @echo "Running dialyzer on $(APPLICATION)" @dialyzer --plt $< \ - ../inets/ebin \ + ../$(APPLICATION)/ebin \ --verbose -- cgit v1.2.3 From 3a540a0069ee419664954978f0ccd56dd4235b66 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 23 Nov 2011 17:23:22 +0100 Subject: Forgot to rename plt target... --- lib/inets/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inets/Makefile b/lib/inets/Makefile index fd22c65ddb..d837a3396a 100644 --- a/lib/inets/Makefile +++ b/lib/inets/Makefile @@ -62,7 +62,7 @@ dclean: dialyzer_plt: $(DIA_PLT) -$(INETS_DIA_PLT): +$(DIA_PLT): @echo "Building $(APPLICATION) plt file" @dialyzer --build_plt \ --output_plt $@ \ -- cgit v1.2.3 From ee353c6eddf4396fa0fa054f7e8f80c72ae0b4f2 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 28 Nov 2011 12:42:25 +0100 Subject: Handle more possible results from parsing the response. --- lib/inets/test/httpd_time_test.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index c54674be36..39ea44fec7 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -377,7 +377,15 @@ validate(ExpStatusCode, SocketType, Socket, Response) -> "Expected status code: ~p (~s)", [StatusCode, status_to_message(StatusCode), ExpStatusCode, status_to_message(ExpStatusCode)]), - exit({unexpected_response_code, StatusCode, ExpStatusCode}) + exit({unexpected_response_code, StatusCode, ExpStatusCode}); + {ok, Unexpected} -> + error_msg("Unexpected response split: ~p (~s)", + [Unexpected, Response]), + exit({unexpected_response, Unexpected, Response}); + {error, Reason} -> + error_msg("Failed processing response: ~p (~s)", + [Reason, Response]), + exit({failed_response_processing, Reason, Response}) end. -- cgit v1.2.3 From b1b51d10ab3fe405f773d597c29a42040d53bb17 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 28 Nov 2011 15:15:55 +0100 Subject: Be more forgiving when waiting for the response... --- lib/inets/test/httpd_time_test.erl | 55 ++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index 39ea44fec7..f86e2837f4 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -333,46 +333,61 @@ poll(Error, _SocketType, _URI, _ExpRes) -> exit({failed_creating_socket, Error}). await_poll_response(ok, SocketType, Socket, ExpStatusCode) -> + await_poll_response2(SocketType, Socket, ExpStatusCode, []); +await_poll_response(Error, _SocketType, _Socket, _ExpStatusCode) -> + exit(Error). + +%% The reply *can* be split into two messages (this is a +%% result of OTP-9757 for ssl), so we read them all until +%% the sockets closes, then we analyze the response. +await_poll_response2(SocketType, Socket, ExpStatusCode, Data) -> receive %% SSL receives - {ssl, Socket, Data} -> - validate(ExpStatusCode, SocketType, Socket, Data); - {ssl_closed, Socket} -> - exit(connection_closed); + {ssl, Socket, NewData} -> + await_poll_response2(SocketType, Socket, ExpStatusCode, + [NewData | Data]); + {ssl_closed, Socket} -> + %% We are done or we failed + validate(ExpStatusCode, SocketType, Socket, + lists:flatten(lists:reverse(Data))); {ssl_error, Socket, Error} -> exit({connection_error, Error}); %% TCP receives - {tcp, Socket, Response} -> - validate(ExpStatusCode, SocketType, Socket, Response); + {tcp, Socket, NewData} -> + await_poll_response2(SocketType, Socket, ExpStatusCode, + [NewData | Data]); {tcp_closed, Socket} -> - exit(connection_closed); + %% We are done or we failed + validate(ExpStatusCode, SocketType, Socket, + lists:flatten(lists:reverse(Data))); {tcp_error, Socket, Error} -> exit({connection_error, Error}) after 10000 -> - exit(response_timed_out) - end; -await_poll_response(Error, _SocketType, _Socket, _ExpStatusCode) -> - exit(Error). - + d("we timed out while waiting for response, " + "validate whatever we got so far"), + validate(ExpStatusCode, SocketType, Socket, + lists:flatten(lists:reverse(Data))) + %% exit(response_timed_out) + end. -validate(ExpStatusCode, SocketType, Socket, Response) -> - Sz = sz(Response), - trash_the_rest(Socket, Sz), - inets_test_lib:close(SocketType, Socket), +validate(ExpStatusCode, _SocketType, _Socket, Response) -> + %% Sz = sz(Response), + %% trash_the_rest(Socket, Sz), + %% inets_test_lib:close(SocketType, Socket), case inets_regexp:split(Response," ") of - {ok,["HTTP/1.0", ExpStatusCode|_]} -> + {ok, ["HTTP/1.0", ExpStatusCode|_]} -> ok; - {ok,["HTTP/1.0", StatusCode|_]} -> + {ok, ["HTTP/1.0", StatusCode|_]} -> error_msg("Unexpected status code: ~p (~s). " "Expected status code: ~p (~s)", [StatusCode, status_to_message(StatusCode), ExpStatusCode, status_to_message(ExpStatusCode)]), exit({unexpected_response_code, StatusCode, ExpStatusCode}); - {ok,["HTTP/1.1", ExpStatusCode|_]} -> + {ok, ["HTTP/1.1", ExpStatusCode|_]} -> ok; - {ok,["HTTP/1.1", StatusCode|_]} -> + {ok, ["HTTP/1.1", StatusCode|_]} -> error_msg("Unexpected status code: ~p (~s). " "Expected status code: ~p (~s)", [StatusCode, status_to_message(StatusCode), -- cgit v1.2.3 From ef692b0461b263a2025d289c31d8f491b53311e5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 28 Nov 2011 19:45:26 +0100 Subject: Add ssl (and crypto and public_key) ensure tests. That is, for test cases that depend of a running ssl app, added tests that ssl is actually running (actually the key app here is crypto, since the simplest way to test if ssl works is by testing if crypto does...). --- lib/inets/test/httpc_SUITE.erl | 36 ++++++----------------------------- lib/inets/test/httpd_SUITE.erl | 39 +++++++------------------------------- lib/inets/test/httpd_time_test.erl | 8 ++++++++ lib/inets/test/inets_app_test.erl | 16 ++++------------ lib/inets/test/inets_test_lib.erl | 32 +++++++++++++++++++++++++++++++ lib/inets/test/inets_test_lib.hrl | 9 +++++---- 6 files changed, 62 insertions(+), 78 deletions(-) diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 2b580cd95d..6e69c9a469 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -145,14 +145,6 @@ groups() -> ]. - -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(_GroupName, Config) -> - Config. - - %%-------------------------------------------------------------------- %% Function: init_per_suite(Config) -> Config %% Config - [tuple()] @@ -226,9 +218,7 @@ init_per_testcase(initial_server_connect = Case, Config) -> %% this test case does not work unless it does try begin - ensure_started(crypto), - ensure_started(public_key), - ensure_started(ssl), + ?ENSURE_STARTED([crypto, public_key, ssl]), inets:start(), Config end @@ -267,10 +257,12 @@ init_per_testcase(Case, Timeout, Config) -> NewConfig = case atom_to_list(Case) of [$s, $s, $l | _] -> + ?ENSURE_STARTED([crypto, public_key, ssl]), init_per_testcase_ssl(ssl, PrivDir, SslConfFile, [{watchdog, Dog} | TmpConfig]); [$e, $s, $s, $l | _] -> + ?ENSURE_STARTED([crypto, public_key, ssl]), init_per_testcase_ssl(essl, PrivDir, SslConfFile, [{watchdog, Dog} | TmpConfig]); @@ -282,7 +274,7 @@ init_per_testcase(Case, Timeout, Config) -> inets:start(), tsp("init_per_testcase -> " "[proxy case] start crypto, public_key and ssl"), - try ensure_started([crypto, public_key, ssl]) of + try ?ENSURE_STARTED([crypto, public_key, ssl]) of ok -> [{watchdog, Dog} | TmpConfig] catch @@ -335,8 +327,8 @@ init_per_testcase(Case, Timeout, Config) -> end; "ipv6_" ++ _Rest -> - %% Ensure needed apps (crypto, public_key and ssl) started - try ensure_started([crypto, public_key, ssl]) of + %% Ensure needed apps (crypto, public_key and ssl) are started + try ?ENSURE_STARTED([crypto, public_key, ssl]) of ok -> Profile = ipv6, %% A stand-alone profile is represented by a pid() @@ -3553,21 +3545,5 @@ dummy_ssl_server_hang_loop(_) -> end. -ensure_started([]) -> - ok; -ensure_started([App|Apps]) -> - ensure_started(App), - ensure_started(Apps); -ensure_started(App) when is_atom(App) -> - case (catch application:start(App)) of - ok -> - ok; - {error, {already_started, _}} -> - ok; - Error -> - throw({error, {failed_starting, App, Error}}) - end. - - skip(Reason) -> {skip, Reason}. diff --git a/lib/inets/test/httpd_SUITE.erl b/lib/inets/test/httpd_SUITE.erl index ba31788ccc..5b571a9649 100644 --- a/lib/inets/test/httpd_SUITE.erl +++ b/lib/inets/test/httpd_SUITE.erl @@ -497,6 +497,7 @@ init_per_testcase2(Case, Config) -> _ -> NewConfig end; + _ -> NewConfig end, @@ -528,7 +529,7 @@ init_per_testcase3(Case, Config) -> application:stop(ssl), cleanup_mnesia(), - %% Set trace + %% Set trace level case lists:reverse(atom_to_list(Case)) of "tset_emit" ++ _Rest -> % test-cases ending with time_test io:format(user, "~w:init_per_testcase3(~w) -> disabling trace", @@ -581,9 +582,10 @@ init_per_testcase3(Case, Config) -> Rest; [X, $s, $s, $l, $_, $m, $o, $d, $_, $h, $t, $a, $c, $c, $e, $s, $s] -> + ?ENSURE_STARTED([crypto, public_key, ssl]), SslTag = case X of - $p -> ssl; % plain + $p -> ssl; % Plain $e -> essl % Erlang based ssl end, case inets_test_lib:start_http_server_ssl( @@ -597,6 +599,7 @@ init_per_testcase3(Case, Config) -> {skip, "SSL does not seem to be supported"} end; [X, $s, $s, $l, $_ | Rest] -> + ?ENSURE_STARTED([crypto, public_key, ssl]), SslTag = case X of $p -> ssl; @@ -679,36 +682,6 @@ end_per_testcase2(Case, Config) -> %%------------------------------------------------------------------------- %%------------------------------------------------------------------------- - - - - - - -%%------------------------------------------------------------------------- -http_1_1_ip(doc) -> - ["HTTP/1.1"]; -http_1_1_ip(suite) -> - [ - ip_host, - ip_chunked, - ip_expect, - ip_range, - ip_if_test, - ip_http_trace, - ip_http1_1_head, - ip_mod_cgi_chunked_encoding_test - ]. - -%%------------------------------------------------------------------------- - -%%------------------------------------------------------------------------- - -%%------------------------------------------------------------------------- - -%%------------------------------------------------------------------------- - -%%------------------------------------------------------------------------- ip_mod_alias(doc) -> ["Module test: mod_alias"]; ip_mod_alias(suite) -> @@ -717,6 +690,7 @@ ip_mod_alias(Config) when is_list(Config) -> httpd_mod:alias(ip_comm, ?IP_PORT, ?config(host, Config), ?config(node, Config)), ok. + %%------------------------------------------------------------------------- ip_mod_actions(doc) -> ["Module test: mod_actions"]; @@ -726,6 +700,7 @@ ip_mod_actions(Config) when is_list(Config) -> httpd_mod:actions(ip_comm, ?IP_PORT, ?config(host, Config), ?config(node, Config)), ok. + %%------------------------------------------------------------------------- ip_mod_security(doc) -> ["Module test: mod_security"]; diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index f86e2837f4..4e5f332122 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -344,10 +344,14 @@ await_poll_response2(SocketType, Socket, ExpStatusCode, Data) -> receive %% SSL receives {ssl, Socket, NewData} -> + d("await_poll_response2 -> " + "received part (~w bytes) of the response", [sz(NewData)]), await_poll_response2(SocketType, Socket, ExpStatusCode, [NewData | Data]); {ssl_closed, Socket} -> %% We are done or we failed + d("await_poll_response2 -> " + "we are done after receiving ~w bytes data", [sz(Data)]), validate(ExpStatusCode, SocketType, Socket, lists:flatten(lists:reverse(Data))); {ssl_error, Socket, Error} -> @@ -355,10 +359,14 @@ await_poll_response2(SocketType, Socket, ExpStatusCode, Data) -> %% TCP receives {tcp, Socket, NewData} -> + d("await_poll_response2 -> " + "received part (~w bytes) of the response", [sz(NewData)]), await_poll_response2(SocketType, Socket, ExpStatusCode, [NewData | Data]); {tcp_closed, Socket} -> %% We are done or we failed + d("await_poll_response2 -> " + "we are done after receiving ~w bytes data", [sz(Data)]), validate(ExpStatusCode, SocketType, Socket, lists:flatten(lists:reverse(Data))); {tcp_error, Socket, Error} -> diff --git a/lib/inets/test/inets_app_test.erl b/lib/inets/test/inets_app_test.erl index 9d7202e087..db2218f3b6 100644 --- a/lib/inets/test/inets_app_test.erl +++ b/lib/inets/test/inets_app_test.erl @@ -45,8 +45,7 @@ end_per_testcase(_Case, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% all() -> - [fields, modules, exportall, app_depend, - undef_funcs]. + [fields, modules, exportall, app_depend, undef_funcs]. groups() -> []. @@ -243,18 +242,11 @@ undef_funcs(doc) -> undef_funcs(Config) when is_list(Config) -> %% We need to check if there is a point to run this test. %% On some platforms, crypto will not build, which in turn - %% causes ssl to not to not build (at this time, this will + %% causes ssl to not build (at this time, this will %% change in the future). %% So, we first check if we can start crypto, and if not, %% we skip this test case! - case (catch crypto:start()) of - ok -> - ok; - {error, {already_started, crypto}} -> - ok; - _ -> - ?SKIP(crypto_start_check_failed) - end, + ?ENSURE_STARTED(crypto), App = inets, AppFile = key1search(app_file, Config), Mods = key1search(modules, AppFile), @@ -266,7 +258,7 @@ undef_funcs(Config) when is_list(Config) -> ok = xref:set_default(XRef, [{verbose,false},{warnings,false}]), XRefName = undef_funcs_make_name(App, xref_name), - {ok, XRefName} = xref:add_release(XRef, Root, {name,XRefName}), + {ok, XRefName} = xref:add_release(XRef, Root, {name, XRefName}), {ok, App} = xref:replace_application(XRef, App, EbinDir), {ok, Undefs} = xref:analyze(XRef, undefined_function_calls), xref:stop(XRef), diff --git a/lib/inets/test/inets_test_lib.erl b/lib/inets/test/inets_test_lib.erl index ddb1a49394..bbed35e1f8 100644 --- a/lib/inets/test/inets_test_lib.erl +++ b/lib/inets/test/inets_test_lib.erl @@ -35,6 +35,7 @@ -export([check_body/1]). -export([millis/0, millis_diff/2, hours/1, minutes/1, seconds/1, sleep/1]). -export([oscmd/1, has_ipv6_support/1]). +-export([ensure_started/1]). -export([non_pc_tc_maybe_skip/4, os_based_skip/1, skip/3, fail/3]). -export([flush/0]). -export([start_node/1, stop_node/1]). @@ -125,6 +126,37 @@ await_stopped(Node, N) -> end. +%% ---------------------------------------------------------------- +%% Ensure apps are started +%% This to ensure we dont attempt to run teatcases on platforms +%% where there is no working ssl app. + +ensure_started([]) -> + ok; +ensure_started([App|Apps]) -> + ensure_started(App), + ensure_started(Apps); +ensure_started(crypto = App) -> + %% We have to treat crypto in this special way because + %% only this function ensures that the NIF lib is actually + %% loaded. And only by loading that lib can we know if it + %% is even possible to run crypto. + do_ensure_started(App, fun() -> crypto:start() end); +ensure_started(App) when is_atom(App) -> + do_ensure_started(App, fun() -> application:start(App) end). + +do_ensure_started(App, Start) when is_function(Start) -> + case (catch Start()) of + ok -> + ok; + {error, {already_started, _}} -> + ok; + Error -> + throw({error, {failed_starting, App, Error}}) + end. + + + %% ---------------------------------------------------------------- %% HTTPD starter functions %% diff --git a/lib/inets/test/inets_test_lib.hrl b/lib/inets/test/inets_test_lib.hrl index 4dd81093a2..c578398c55 100644 --- a/lib/inets/test/inets_test_lib.hrl +++ b/lib/inets/test/inets_test_lib.hrl @@ -64,10 +64,11 @@ %% - Misc macros - --define(UPDATE(K,V,C), inets_test_lib:update_config(K,V,C)). --define(CONFIG(K,C), inets_test_lib:get_config(K,C)). --define(HOSTNAME(), inets_test_lib:hostname()). --define(SZ(X), inets_test_lib:sz(X)). +-define(ENSURE_STARTED(A), inets_test_lib:ensure_started(A)). +-define(UPDATE(K,V,C), inets_test_lib:update_config(K,V,C)). +-define(CONFIG(K,C), inets_test_lib:get_config(K,C)). +-define(HOSTNAME(), inets_test_lib:hostname()). +-define(SZ(X), inets_test_lib:sz(X)). %% - Test case macros - -- cgit v1.2.3