|
23 | 23 | -module(snmp_test_lib). |
24 | 24 |
|
25 | 25 | -include_lib("kernel/include/file.hrl"). |
| 26 | +-include_lib("common_test/include/ct.hrl"). |
26 | 27 |
|
27 | 28 |
|
28 | 29 | -export([tc_try/2, tc_try/3, |
|
42 | 43 | -export([fail/3, skip/3]). |
43 | 44 | -export([hours/1, minutes/1, seconds/1, sleep/1]). |
44 | 45 | -export([pi/2, flush_mqueue/0, mqueue/0, mqueue/1, trap_exit/0, trap_exit/1]). |
45 | | --export([ping/1, local_nodes/0, nodes_on/1]). |
| 46 | +-export([start_node/2, ping/1, local_nodes/0, nodes_on/1]). |
46 | 47 | -export([is_app_running/1, |
47 | 48 | is_crypto_running/0, is_mnesia_running/0, is_snmp_running/0, |
48 | 49 | ensure_not_running/3]). |
@@ -1042,7 +1043,10 @@ fail(Reason, Mod, Line) -> |
1042 | 1043 | skip(Reason, Module, Line) -> |
1043 | 1044 | String = lists:flatten(io_lib:format("Skipping ~p(~p): ~p~n", |
1044 | 1045 | [Module, Line, Reason])), |
1045 | | - exit({skip, String}). |
| 1046 | + skip(String). |
| 1047 | + |
| 1048 | +skip(Reason) -> |
| 1049 | + exit({skip, Reason}). |
1046 | 1050 |
|
1047 | 1051 |
|
1048 | 1052 | %% This function prints various host info, which might be useful |
@@ -3163,6 +3167,42 @@ trap_exit(Flag) -> |
3163 | 3167 | %% Node utility functions |
3164 | 3168 | %% |
3165 | 3169 |
|
| 3170 | +%% This hinges on an updated peer verbose start |
| 3171 | +%% -define(VERBOSE_PEER_START, true). |
| 3172 | + |
| 3173 | +-ifdef(VERBOSE_PEER_START). |
| 3174 | +-define(MAYBE_VERBOSE_START(SO), (SO)#{verbose => true}). |
| 3175 | +-define(START_OPTIONS(SO), (SO)#{connection => standard_io}). |
| 3176 | +-else. |
| 3177 | +-define(MAYBE_VERBOSE_START(SO), SO). |
| 3178 | +-define(START_OPTIONS(SO), SO). |
| 3179 | +-endif. |
| 3180 | + |
| 3181 | +start_node(Name, Unlink) -> |
| 3182 | + Args = ["-s", "snmp_test_sys_monitor", "start", "-s", "global", "sync"], |
| 3183 | + %% Note that the 'verbose' option may not exist... |
| 3184 | + %% If it does not exist, this (verbose => true) "should" do nothing... |
| 3185 | + BaseStartOptions = #{name => Name, |
| 3186 | + args => Args}, |
| 3187 | + StartOptions0 = ?MAYBE_VERBOSE_START(BaseStartOptions), |
| 3188 | + StartOptions = ?START_OPTIONS(StartOptions0), |
| 3189 | + case ?CT_PEER(StartOptions) of |
| 3190 | + {ok, Peer, Node} -> |
| 3191 | + %% Must unlink, otherwise peer will exit before test case |
| 3192 | + maybe_unlink(Unlink, Peer), |
| 3193 | + global:sync(), |
| 3194 | + {Peer, Node}; |
| 3195 | + {error, Reason} -> |
| 3196 | + %%% throw({skip, {failed_starting_node, Name, Reason}}) |
| 3197 | + skip({failed_starting_node, Name, Reason}) |
| 3198 | + end. |
| 3199 | + |
| 3200 | +maybe_unlink(true, Pid) -> |
| 3201 | + unlink(Pid); |
| 3202 | +maybe_unlink(false, _) -> |
| 3203 | + ok. |
| 3204 | + |
| 3205 | + |
3166 | 3206 | ping(N) -> |
3167 | 3207 | case net_adm:ping(N) of |
3168 | 3208 | pang -> |
|
0 commit comments