aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2011-12-22 12:00:55 +0100
committerMicael Karlberg <[email protected]>2012-02-06 12:31:58 +0100
commit0d580acdc51bd88a0d364b76ac35fcf2506c2d9e (patch)
treeeca18e4c62f62ecd5032538ea81293921e3e7601 /lib
parent67b0023a0756c69f58a40702ed9a808e1e5a66a7 (diff)
downloadotp-0d580acdc51bd88a0d364b76ac35fcf2506c2d9e.tar.gz
otp-0d580acdc51bd88a0d364b76ac35fcf2506c2d9e.tar.bz2
otp-0d580acdc51bd88a0d364b76ac35fcf2506c2d9e.zip
[inets] Improved test util error handling when copy dirs
Copy dirs failed for some cases, so added more info when that happens. Also added more info during httpd test case init.
Diffstat (limited to 'lib')
-rw-r--r--lib/inets/test/httpc_SUITE.erl88
-rw-r--r--lib/inets/test/httpd_SUITE.erl122
-rw-r--r--lib/inets/test/httpd_mod.erl14
-rw-r--r--lib/inets/test/inets_test_lib.erl57
4 files changed, 175 insertions, 106 deletions
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index 8cce152697..734964698e 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -362,9 +362,15 @@ init_per_testcase(Case, Timeout, Config) ->
_ ->
%% Try inet6fb4 on windows...
+ tsp("init_per_testcase -> allways try IPv6 on windows"),
?RUN_ON_WINDOWS(
fun() ->
- httpc:set_options([{ipfamily, inet6fb4}])
+ tsp("init_per_testcase:set_options_fun -> "
+ "set-option ipfamily to inet6fb4"),
+ Res = httpc:set_options([{ipfamily, inet6fb4}]),
+ tsp("init_per_testcase:set_options_fun -> "
+ "~n Res: ~p", [Res]),
+ Res
end),
TmpConfig2 = lists:keydelete(local_server, 1, TmpConfig),
@@ -471,22 +477,32 @@ http_head(doc) ->
http_head(suite) ->
[];
http_head(Config) when is_list(Config) ->
- case ?config(local_server, Config) of
- ok ->
- Port = ?config(local_port, Config),
- URL = ?URL_START ++ integer_to_list(Port) ++ "/dummy.html",
- case httpc:request(head, {URL, []}, [], []) of
- {ok, {{_,200,_}, [_ | _], []}} ->
- ok;
- {ok, WrongReply} ->
- tsf({wrong_reply, WrongReply});
- Error ->
- tsf({failed, Error})
- end;
- _ ->
- {skip, "Failed to start local http-server"}
- end.
+ tsp("http_head -> entry with"
+ "~n Config: ~p", [Config]),
+ Method = head,
+ Port = ?config(local_port, Config),
+ URL = ?URL_START ++ integer_to_list(Port) ++ "/dummy.html",
+ Request = {URL, []},
+ HttpOpts = [],
+ Opts = [],
+ VerifyResult =
+ fun({ok, {{_,200,_}, [_ | _], []}}) ->
+ ok;
+ ({ok, UnexpectedReply}) ->
+ tsp("http_head:verify_fun -> Unexpected Reply: "
+ "~n ~p", [UnexpectedReply]),
+ tsf({unexpected_reply, UnexpectedReply});
+ ({error, Reason} = Error) ->
+ tsp("http_head:verify_fun -> Error reply: "
+ "~n Reason: ~p", [Reason]),
+ tsf({bad_reply, Error})
+ end,
+ simple_request_and_verify(Config,
+ Method, Request, HttpOpts, Opts, VerifyResult).
+
+
%%-------------------------------------------------------------------------
+
http_get(doc) ->
["Test http get request against local server"];
http_get(suite) ->
@@ -503,7 +519,8 @@ http_get(Config) when is_list(Config) ->
Request = {URL, []},
Timeout = timer:seconds(1),
ConnTimeout = Timeout + timer:seconds(1),
- HttpOptions1 = [{timeout, Timeout}, {connect_timeout, ConnTimeout}],
+ HttpOptions1 = [{timeout, Timeout},
+ {connect_timeout, ConnTimeout}],
Options1 = [],
Body =
case httpc:request(Method, Request, HttpOptions1, Options1) of
@@ -535,10 +552,11 @@ http_get(Config) when is_list(Config) ->
end.
%%-------------------------------------------------------------------------
+
http_post(doc) ->
- ["Test http post request against local server. We do in this case"
- " only care about the client side of the the post. The server"
- " script will not actually use the post data."];
+ ["Test http post request against local server. We do in this case "
+ "only care about the client side of the the post. The server "
+ "script will not actually use the post data."];
http_post(suite) ->
[];
http_post(Config) when is_list(Config) ->
@@ -3839,6 +3857,34 @@ pick_header(Headers, Name) ->
Val
end.
+
+%% -------------------------------------------------------------------------
+
+simple_request_and_verify(Config,
+ Method, Request, HttpOpts, Opts, VerifyResult)
+ when (is_list(Config) andalso
+ is_atom(Method) andalso
+ is_list(HttpOpts) andalso
+ is_list(Opts) andalso
+ is_function(VerifyResult, 1)) ->
+ tsp("request_and_verify -> entry with"
+ "~n Method: ~p"
+ "~n Request: ~p"
+ "~n HttpOpts: ~p"
+ "~n Opts: ~p", [Method, Request, HttpOpts, Opts]),
+ case ?config(local_server, Config) of
+ ok ->
+ tsp("request_and_verify -> local-server running"),
+ Result = (catch httpc:request(Method, Request, HttpOpts, Opts)),
+ VerifyResult(Result);
+ _ ->
+ tsp("request_and_verify -> local-server *not* running - skip"),
+ hard_skip("Local http-server not running")
+ end.
+
+
+
+
not_implemented_yet() ->
exit(not_implemented_yet).
@@ -3890,6 +3936,8 @@ dummy_ssl_server_hang_loop(_) ->
ok
end.
+hard_skip(Reason) ->
+ throw(skip(Reason)).
skip(Reason) ->
{skip, Reason}.
diff --git a/lib/inets/test/httpd_SUITE.erl b/lib/inets/test/httpd_SUITE.erl
index 2c4c0f84a8..907d58fd8c 100644
--- a/lib/inets/test/httpd_SUITE.erl
+++ b/lib/inets/test/httpd_SUITE.erl
@@ -327,10 +327,11 @@ init_per_suite(Config) ->
throw({error, {failed_creating_suite_top_dir, Error}})
end,
- [{suite_top_dir, SuiteTopDir},
- {node, node()},
- {host, inets_test_lib:hostname()},
- {address, getaddr()} | Config].
+ [{has_ipv6_support, inets_test_lib:has_ipv6_support()},
+ {suite_top_dir, SuiteTopDir},
+ {node, node()},
+ {host, inets_test_lib:hostname()},
+ {address, getaddr()} | Config].
%%--------------------------------------------------------------------
@@ -365,10 +366,9 @@ init_per_testcase(Case, Config) ->
init_per_testcase2(Case, Config) ->
- io:format(user, "~w:init_per_testcase2(~w) -> entry with"
- "~n Config: ~p"
- "~n", [?MODULE, Case, Config]),
-
+ tsp("init_per_testcase2(~w) -> entry with"
+ "~n Config: ~p", [Case, Config]),
+
IpNormal = integer_to_list(?IP_PORT) ++ ".conf",
IpHtaccess = integer_to_list(?IP_PORT) ++ "htaccess.conf",
SslNormal = integer_to_list(?SSL_PORT) ++ ".conf",
@@ -377,39 +377,33 @@ init_per_testcase2(Case, Config) ->
DataDir = ?config(data_dir, Config),
SuiteTopDir = ?config(suite_top_dir, Config),
- io:format(user, "~w:init_per_testcase2(~w) -> "
- "~n SuiteDir: ~p"
- "~n DataDir: ~p"
- "~n", [?MODULE, Case, SuiteTopDir, DataDir]),
+ tsp("init_per_testcase2(~w) -> "
+ "~n SuiteDir: ~p"
+ "~n DataDir: ~p", [Case, SuiteTopDir, DataDir]),
TcTopDir = filename:join(SuiteTopDir, Case),
?line ok = file:make_dir(TcTopDir),
- io:format(user, "~w:init_per_testcase2(~w) -> "
- "~n TcTopDir: ~p"
- "~n", [?MODULE, Case, TcTopDir]),
+ tsp("init_per_testcase2(~w) -> "
+ "~n TcTopDir: ~p", [Case, TcTopDir]),
DataSrc = filename:join([DataDir, "server_root"]),
ServerRoot = filename:join([TcTopDir, "server_root"]),
- io:format(user, "~w:init_per_testcase2(~w) -> "
- "~n DataSrc: ~p"
- "~n ServerRoot: ~p"
- "~n", [?MODULE, Case, DataSrc, ServerRoot]),
+ tsp("init_per_testcase2(~w) -> "
+ "~n DataSrc: ~p"
+ "~n ServerRoot: ~p", [Case, DataSrc, ServerRoot]),
ok = file:make_dir(ServerRoot),
ok = file:make_dir(filename:join([TcTopDir, "logs"])),
NewConfig = [{tc_top_dir, TcTopDir}, {server_root, ServerRoot} | Config],
- io:format(user, "~w:init_per_testcase2(~w) -> "
- "copy DataSrc to ServerRoot~n",
- [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> copy DataSrc to ServerRoot", [Case]),
inets_test_lib:copy_dirs(DataSrc, ServerRoot),
- io:format(user, "~w:init_per_testcase2(~w) -> fix cgi~n",
- [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> fix cgi", [Case]),
EnvCGI = filename:join([ServerRoot, "cgi-bin", "printenv.sh"]),
{ok, FileInfo} = file:read_file_info(EnvCGI),
ok = file:write_file_info(EnvCGI,
@@ -429,16 +423,14 @@ init_per_testcase2(Case, Config) ->
FileInfo1#file_info{mode = 8#00755}),
%% To be used by IP test cases
- io:format(user, "~w:init_per_testcase2(~w) -> ip testcase setups~n",
- [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> ip testcase setups", [Case]),
create_config([{port, ?IP_PORT}, {sock_type, ip_comm} | NewConfig],
normal_access, IpNormal),
create_config([{port, ?IP_PORT}, {sock_type, ip_comm} | NewConfig],
mod_htaccess, IpHtaccess),
%% To be used by SSL test cases
- io:format(user, "~w:init_per_testcase2(~w) -> ssl testcase setups~n",
- [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> ssl testcase setups", [Case]),
SocketType =
case atom_to_list(Case) of
[X, $s, $s, $l | _] ->
@@ -462,8 +454,7 @@ init_per_testcase2(Case, Config) ->
%% when you run the whole test suite due to shortcomings
%% of the test server.
- io:format(user, "~w:init_per_testcase2(~w) -> "
- "maybe generate IPv6 config file(s)", [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> maybe generate IPv6 config file(s)", [Case]),
NewConfig2 =
case atom_to_list(Case) of
"ipv6_" ++ _ ->
@@ -504,15 +495,15 @@ init_per_testcase2(Case, Config) ->
NewConfig
end,
- io:format(user, "~w:init_per_testcase2(~w) -> done~n",
- [?MODULE, Case]),
+ tsp("init_per_testcase2(~w) -> done when"
+ "~n NewConfig2: ~p", [Case, NewConfig2]),
NewConfig2.
init_per_testcase3(Case, Config) ->
- io:format(user, "~w:init_per_testcase3(~w) -> entry with"
- "~n Config: ~p", [?MODULE, Case, Config]),
+ tsp("init_per_testcase3(~w) -> entry with"
+ "~n Config: ~p", [Case, Config]),
%% %% Create a new fresh node to be used by the server in this test-case
@@ -534,12 +525,10 @@ init_per_testcase3(Case, Config) ->
%% 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",
- [?MODULE, Case]),
+ tsp("init_per_testcase3(~w) -> disabling trace", [Case]),
inets:disable_trace();
_ ->
- io:format(user, "~w:init_per_testcase3(~w) -> enabling trace",
- [?MODULE, Case]),
+ tsp("init_per_testcase3(~w) -> enabling trace", [Case]),
%% TraceLevel = 70,
TraceLevel = max,
TraceDest = io,
@@ -547,8 +536,7 @@ init_per_testcase3(Case, Config) ->
end,
%% Start initialization
- io:format(user, "~w:init_per_testcase3(~w) -> start init",
- [?MODULE, Case]),
+ tsp("init_per_testcase3(~w) -> start init", [Case]),
Dog = test_server:timetrap(inets_test_lib:minutes(10)),
@@ -629,26 +617,32 @@ init_per_testcase3(Case, Config) ->
end
end,
- case CaseRest of
- {skip, _} = Skip ->
- Skip;
- "mod_auth_" ++ _ ->
- start_mnesia(?config(node, Config)),
- [{watchdog, Dog} | NewConfig];
- "mod_htaccess" ->
- ServerRoot = ?config(server_root, Config),
- Path = filename:join([ServerRoot, "htdocs"]),
- catch remove_htaccess(Path),
- create_htaccess_data(Path, ?config(address, Config)),
- [{watchdog, Dog} | NewConfig];
- "range" ->
- ServerRoot = ?config(server_root, Config),
- Path = filename:join([ServerRoot, "htdocs"]),
- create_range_data(Path),
- [{watchdog, Dog} | NewConfig];
- _ ->
- [{watchdog, Dog} | NewConfig]
- end.
+ InitRes =
+ case CaseRest of
+ {skip, _} = Skip ->
+ Skip;
+ "mod_auth_" ++ _ ->
+ start_mnesia(?config(node, Config)),
+ [{watchdog, Dog} | NewConfig];
+ "mod_htaccess" ->
+ ServerRoot = ?config(server_root, Config),
+ Path = filename:join([ServerRoot, "htdocs"]),
+ catch remove_htaccess(Path),
+ create_htaccess_data(Path, ?config(address, Config)),
+ [{watchdog, Dog} | NewConfig];
+ "range" ->
+ ServerRoot = ?config(server_root, Config),
+ Path = filename:join([ServerRoot, "htdocs"]),
+ create_range_data(Path),
+ [{watchdog, Dog} | NewConfig];
+ _ ->
+ [{watchdog, Dog} | NewConfig]
+ end,
+
+ tsp("init_per_testcase3(~w) -> done when"
+ "~n InitRes: ~p", [Case, InitRes]),
+
+ InitRes.
%%--------------------------------------------------------------------
@@ -666,16 +660,14 @@ end_per_testcase(Case, Config) ->
ok.
end_per_testcase2(Case, Config) ->
- io:format(user, "~w:end_per_testcase2(~w) -> entry with"
- "~n Config: ~p~n",
- [?MODULE, Case, Config]),
+ tsp("end_per_testcase2(~w) -> entry with"
+ "~n Config: ~p", [Case, Config]),
application:unset_env(inets, services),
application:stop(inets),
application:stop(ssl),
application:stop(crypto), % used by the new ssl (essl test cases)
cleanup_mnesia(),
- io:format(user, "~w:end_per_testcase2(~w) -> done~n",
- [?MODULE, Case]),
+ tsp("end_per_testcase2(~w) -> done", [Case]),
ok.
diff --git a/lib/inets/test/httpd_mod.erl b/lib/inets/test/httpd_mod.erl
index 6ba0624210..25a03ab9c8 100644
--- a/lib/inets/test/httpd_mod.erl
+++ b/lib/inets/test/httpd_mod.erl
@@ -47,16 +47,15 @@ alias(Type, Port, Host, Node) ->
%% "~n", [?MODULE, Type, Port, Host, Node]),
%% This is very crude, but...
- io:format(user,
- "alias -> Has IPv6 support: ~p",
- [inets_test_lib:has_ipv6_support()]),
+ tsp("alias -> Has IPv6 support: ~p", [inets_test_lib:has_ipv6_support()]),
Opts = case os:type() of
{win32, _} ->
[inet6fb4];
_ ->
[]
end,
-
+ tsp("alias -> Opts: ~p", [Opts]),
+
ok = httpd_test_lib:verify_request(Type, Host, Port, Opts, Node,
"GET /pics/icon.sheet.gif "
"HTTP/1.0\r\n\r\n",
@@ -1043,9 +1042,10 @@ check_lists_members1(L1,L2) ->
%% tsp(F) ->
-%% tsp(F, []).
-%% tsp(F, A) ->
-%% test_server:format("~p ~p:" ++ F ++ "~n", [self(), ?MODULE | A]).
+%% inets_test_lib:tsp(F).
+tsp(F, A) ->
+ inets_test_lib:tsp(F, A).
+
tsf(Reason) ->
test_server:fail(Reason).
diff --git a/lib/inets/test/inets_test_lib.erl b/lib/inets/test/inets_test_lib.erl
index 434fa17307..b03127691d 100644
--- a/lib/inets/test/inets_test_lib.erl
+++ b/lib/inets/test/inets_test_lib.erl
@@ -306,20 +306,49 @@ copy_files(FromDir, ToDir) ->
copy_dirs(FromDirRoot, ToDirRoot) ->
- {ok, Files} = file:list_dir(FromDirRoot),
- lists:foreach(
- fun(FileOrDir) ->
- %% Check if it's a directory or a file
- case filelib:is_dir(filename:join(FromDirRoot, FileOrDir)) of
- true ->
- FromDir = filename:join([FromDirRoot, FileOrDir]),
- ToDir = filename:join([ToDirRoot, FileOrDir]),
- ok = file:make_dir(ToDir),
- copy_dirs(FromDir, ToDir);
- false ->
- copy_file(FileOrDir, FromDirRoot, ToDirRoot)
- end
- end, Files).
+ case file:list_dir(FromDirRoot) of
+ {ok, Files} ->
+ lists:foreach(
+ fun(FileOrDir) ->
+ %% Check if it's a directory or a file
+ case filelib:is_dir(filename:join(FromDirRoot,
+ FileOrDir)) of
+ true ->
+ FromDir = filename:join([FromDirRoot, FileOrDir]),
+ ToDir = filename:join([ToDirRoot, FileOrDir]),
+ case file:make_dir(ToDir) of
+ ok ->
+ copy_dirs(FromDir, ToDir);
+ {error, Reason} ->
+ tsp("<ERROR> Failed creating directory: "
+ "~n ToDir: ~p"
+ "~n Reason: ~p"
+ "~nwhen"
+ "~n ToDirRoot: ~p"
+ "~n ToDirRoot file info: ~p",
+ [ToDir,
+ Reason,
+ ToDirRoot,
+ file:read_file_info(ToDirRoot)]),
+ tsf({failed_copy_dir, ToDir, Reason})
+ end;
+ false ->
+ copy_file(FileOrDir, FromDirRoot, ToDirRoot)
+ end
+ end, Files);
+ {error, Reason} ->
+ tsp("<ERROR> Failed get directory file list: "
+ "~n FromDirRoot: ~p"
+ "~n Reason: ~p"
+ "~nwhen"
+ "~n FromDirRoot file info: ~p",
+ [FromDirRoot,
+ Reason,
+ file:read_file_info(FromDirRoot)]),
+ tsf({failed_list_dir, FromDirRoot, Reason})
+ end.
+
+
del_dirs(Dir) ->
case file:list_dir(Dir) of