diff options
author | Péter Dimitrov <[email protected]> | 2018-03-27 11:01:22 +0200 |
---|---|---|
committer | Péter Dimitrov <[email protected]> | 2018-03-28 10:19:38 +0200 |
commit | 8a805f67cff9bf04188d38dca3f0031455c73e90 (patch) | |
tree | af2de3add9698c52a90d385e7e1e40c4fab452f3 | |
parent | 6af39a440826d5d1653dad9e1eb47a397921471a (diff) | |
download | otp-8a805f67cff9bf04188d38dca3f0031455c73e90.tar.gz otp-8a805f67cff9bf04188d38dca3f0031455c73e90.tar.bz2 otp-8a805f67cff9bf04188d38dca3f0031455c73e90.zip |
tftp: Add tests (app, appup, start_tftpd)
Change-Id: I585ba5097632d460705257f03cb44adf8038f0be
-rw-r--r-- | lib/tftp/src/tftp_app.erl | 11 | ||||
-rw-r--r-- | lib/tftp/test/tftp_SUITE.erl | 58 |
2 files changed, 65 insertions, 4 deletions
diff --git a/lib/tftp/src/tftp_app.erl b/lib/tftp/src/tftp_app.erl index bbcd107e30..80d54c6cbe 100644 --- a/lib/tftp/src/tftp_app.erl +++ b/lib/tftp/src/tftp_app.erl @@ -36,7 +36,8 @@ %%==================================================================== start(_StartType, _StartArgs) -> - tftp_sup:start_link([]). + Config = get_configuration(), + tftp_sup:start_link(Config). %%-------------------------------------------------------------------- stop(_State) -> @@ -45,3 +46,11 @@ stop(_State) -> %%==================================================================== %% Internal functions %%==================================================================== + +get_configuration() -> + case (catch application:get_env(tftp, services)) of + {ok, Services} -> + Services; + _ -> + [] + end. diff --git a/lib/tftp/test/tftp_SUITE.erl b/lib/tftp/test/tftp_SUITE.erl index a43fd51153..fd1d209c25 100644 --- a/lib/tftp/test/tftp_SUITE.erl +++ b/lib/tftp/test/tftp_SUITE.erl @@ -26,6 +26,7 @@ %% Includes and defines %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-include_lib("common_test/include/ct.hrl"). -include("tftp_test_lib.hrl"). -define(START_DAEMON(Port, Options), @@ -74,9 +75,18 @@ end_per_testcase(Case, Config) when is_list(Config) -> suite() -> [{ct_hooks,[ts_install_cth]}]. -all() -> - [simple, extra, reuse_connection, resend_client, - resend_server, large_file]. +all() -> + [ + simple, + extra, + reuse_connection, + resend_client, + resend_server, + large_file, + app, + appup, + start_tftpd + ]. groups() -> []. @@ -94,6 +104,48 @@ end_per_group(_GroupName, Config) -> Config. +app() -> + [{doc, "Test that the tftp app file is ok"}]. +app(Config) when is_list(Config) -> + ok = ?t:app_test(tftp). + +%%-------------------------------------------------------------------- +appup() -> + [{doc, "Test that the tftp appup file is ok"}]. +appup(Config) when is_list(Config) -> + ok = ?t:appup_test(tftp). + +start_tftpd() -> + [{doc, "Start/stop of tfpd service"}]. +start_tftpd(Config) when is_list(Config) -> + process_flag(trap_exit, true), + ok = tftp:start(), + {ok, Pid0} = tftp:start_service([{host, "localhost"}, {port, 0}]), + Pids0 = [ServicePid || {_, ServicePid} <- tftp:services()], + true = lists:member(Pid0, Pids0), + {ok, [_|_]} = tftp:service_info(Pid0), + tftp:stop_service(Pid0), + ct:sleep(100), + Pids1 = [ServicePid || {_, ServicePid} <- tftp:services()], + false = lists:member(Pid0, Pids1), + + {ok, Pid1} = + tftp:start_standalone([{host, "localhost"}, {port, 0}]), + Pids2 = [ServicePid || {_, ServicePid} <- tftp:services()], + false = lists:member(Pid1, Pids2), + %% Standalone service is not supervised + {error,not_found} = tftp:stop_service(Pid1), + ok = tftp:stop(), + + application:load(tftp), + application:set_env(tftp, services, [{tftpd, [{host, "localhost"}, + {port, 0}]}]), + ok = tftp:start(), + 1 = length(tftp:services()), + application:unset_env(tftp, services), + ok = tftp:stop(). + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Simple %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |