1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 1996-2018. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22-define(log(Format,Args),mnesia_test_lib:log(Format,Args,?FILE,?LINE)). 23-define(warning(Format,Args),?log("<>WARNING<>~n " ++ Format,Args)). 24-define(error(Format,Args), 25 mnesia_test_lib:error(Format,Args,?FILE,?LINE)). 26-define(verbose(Format,Args),mnesia_test_lib:verbose(Format,Args,?FILE,?LINE)). 27 28-define(fatal(Format,Args), 29 ?error(Format, Args), 30 exit({test_case_fatal, Format, Args, ?FILE, ?LINE})). 31 32-define(skip(Format,Args), 33 ?warning(Format, Args), 34 exit({skipped, ?flat_format(Format, Args)})). 35 36-define(flat_format(Format,Args), 37 lists:flatten(io_lib:format(Format, Args))). 38 39-define(sort(What), mnesia_test_lib:sort(What)). 40 41-define(ignore(Expr), 42 fun() -> 43 AcTuAlReS = (catch (Expr)), 44 ?verbose("ok, ~n Result as expected:~p~n",[AcTuAlReS]), 45 AcTuAlReS 46 end()). 47 48-define(match(ExpectedRes,Expr), 49 fun() -> 50 try Expr of 51 _AR_0 = ExpectedRes -> 52 ?verbose("ok, ~n Result as expected:~p~n",[_AR_0]), 53 {success,_AR_0}; 54 _AR_0 -> 55 ?error("Not Matching Actual result was:~n ~p~n",[_AR_0]), 56 {fail,_AR_0} 57 catch 58 exit:{aborted, _ER_1}:Stacktrace when 59 element(1, _ER_1) =:= node_not_running; 60 element(1, _ER_1) =:= bad_commit; 61 element(1, _ER_1) =:= cyclic -> 62 %% Need to re-raise these to restart transaction 63 erlang:raise(exit, {aborted, _ER_1}, Stacktrace); 64 exit:_AR_1:Stacktrace -> 65 case fun(_AR_EXIT_) -> {'EXIT', _AR_EXIT_} end(_AR_1) of 66 _AR_2 = ExpectedRes -> 67 ?verbose("ok, ~n Result as expected:~p~n",[_AR_2]), 68 {success,_AR_2}; 69 _AR_2 -> 70 ?error("Not Matching Actual result was:~n ~p~n ~p~n", 71 [_AR_2, Stacktrace]), 72 {fail,_AR_2} 73 end; 74 _T1_:_AR_1:Stacktrace -> 75 ?error("Not Matching Actual result was:~n ~p~n ~p~n", 76 [{_T1_,_AR_1}, Stacktrace]), 77 {fail,{_T1_,_AR_1}} 78 end 79 end()). 80 81-define(match_inverse(NotExpectedRes,Expr), 82 fun() -> 83 AcTuAlReS = (catch (Expr)), 84 case AcTuAlReS of 85 NotExpectedRes -> 86 ?error("Not matching Actual result was:~n ~p~n", 87 [AcTuAlReS]), 88 {fail,AcTuAlReS}; 89 _ -> 90 ?verbose("ok, ~n Result as expected: ~p~n",[AcTuAlReS]), 91 {success,AcTuAlReS} 92 end 93 end()). 94 95-define(match_receive(ExpectedMsg), 96 ?match(ExpectedMsg,mnesia_test_lib:pick_msg())). 97 98%% ExpectedMsgs must be completely bound 99-define(match_multi_receive(ExpectedMsgs), 100 fun() -> 101 TmPeXpCtEdMsGs = lists:sort(ExpectedMsgs), 102 ?match(TmPeXpCtEdMsGs, 103 lists:sort(lists:map(fun(_) -> 104 mnesia_test_lib:pick_msg() 105 end, 106 TmPeXpCtEdMsGs))) 107 end()). 108 109-define(start_activities(Nodes), 110 mnesia_test_lib:start_activities(Nodes)). 111 112-define(start_transactions(Pids), 113 mnesia_test_lib:start_transactions(Pids)). 114 115-define(acquire_nodes(N, Config), 116 mnesia_test_lib:prepare_test_case([{init_test_case, [mnesia]}, 117 delete_schema, 118 create_schema, 119 {start_appls, [mnesia]}], 120 N, Config, ?FILE, ?LINE)). 121 122-define(activate_debug_fun(I, F, C), 123 mnesia_lib:activate_debug_fun(I, F, C, ?FILE, ?LINE)). 124 125-define(remote_activate_debug_fun(N, I, F, C), 126 ?match(ok, mnesia_test_lib:remote_activate_debug_fun(N, I, F, C, 127 ?FILE, ?LINE))). 128 129-define(deactivate_debug_fun(I), 130 mnesia_lib:deactivate_debug_fun(I, ?FILE, ?LINE)). 131 132-define(remote_deactivate_debug_fun(N, I), 133 rpc:call(N, mnesia_lib, deactivate_debug_fun, [I, ?FILE, ?LINE])). 134 135-define(is_debug_compiled, 136 case mnesia_lib:is_debug_compiled() of 137 false -> 138 ?skip("Mnesia is not debug compiled, test case ignored.~n", []); 139 _OhTeR -> 140 ok 141 end). 142 143-define(needs_disc(Config), 144 case mnesia_test_lib:diskless(Config) of 145 false -> 146 ok; 147 true -> 148 ?skip("Must have disc, test case ignored.~n", []) 149 end). 150 151-define(verify_mnesia(Ups, Downs), 152 mnesia_test_lib:verify_mnesia(Ups, Downs, ?FILE, ?LINE)). 153 154-define(BACKEND, [{backend_types, [{ext_ets, ext_test},{ext_dets, ext_test}]}]). 155