4
%% Copyright Ericsson AB 1999-2010. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
-module(etrap_test_lib).
23
%%--------------- INCLUDES ---------------------------------------------
24
-include("etrap_test_lib.hrl").
25
-include_lib("cosTransactions/src/ETraP_Common.hrl").
27
%%--------------- EXPORTS ----------------------------------------------
28
-export([scratch_debug_fun/0,
31
deactivate_debug_fun/3,
33
set_debug_context/4]).
35
%%--------------- CONSTANTS/DEFINITIONS --------------------------------
36
-define(DEBUG_TAB, etrap_debug).
37
-record(debug_info, {id, function, type, file, line}).
39
%%--------------- DEBUG FUNCTIONS --------------------------------------
40
%% Managing conditional debug functions
42
%% The main idea with the debug_fun's is to allow test programs
43
%% to control the internal behaviour of CosTransactions.
45
%% First should calls to ?eval_debug_fun be inserted at well
46
%% defined places in CosTransaction's code. E.g. in critical situations
47
%% of startup, transaction commit, backups etc.
49
%% Then compile CosTransactions with the compiler option 'debug'.
51
%% In test programs ?activate_debug_fun should be called
52
%% in order to bind a fun to the debug identifier stated
53
%% in the call to ?eval_debug_fun.
55
scratch_debug_fun() ->
56
catch ets:delete(?DEBUG_TAB),
58
[set, public, named_table, {keypos, 2}]).
60
activate_debug_fun(FunId, Fun, Type, File, Line) ->
61
io:format("Activiating ~p RETRIES: ~p WAIT: ~p~n",
62
[FunId, ?tr_max_retries, ?tr_comm_failure_wait]),
63
Info = #debug_info{id = FunId,
68
update_debug_info(Info).
70
update_debug_info(Info) ->
71
case catch ets:insert(?DEBUG_TAB, Info) of
74
ets:insert(?DEBUG_TAB, Info);
80
deactivate_debug_fun(FunId, _File, _Line) ->
81
catch ets:delete(?DEBUG_TAB, FunId),
84
eval_debug_fun(FunId, Env, File, Line) ->
85
case catch ets:lookup(?DEBUG_TAB, FunId) of
89
Fun = Info#debug_info.function,
90
case Info#debug_info.type of
92
deactivate_debug_fun(FunId, File, Line);
96
io:format("Running debug fun ~p:~p (LINE: ~p)~n", [File, FunId, Line]),
103
set_debug_context([], [], _, _)-> ok;
104
set_debug_context([], _, _, _)->
105
ets:delete(?DEBUG_TAB),
106
exit("failed transactions_SUITE. Bad configuration.");
107
set_debug_context(_, [], _, _)->
108
ets:delete(?DEBUG_TAB),
109
exit("failed transactions_SUITE Bad configuration.");
110
set_debug_context([RHead|RTail], [CHead|CTail], File, Line)->
111
write_context(RHead, CHead, File, Line),
112
set_debug_context(RTail, CTail, File, Line).
114
write_context(_Resource, [], _, _)-> ok;
115
write_context(Resource, [{Func, Fun, Type}|PTail], File, Line)->
116
etrap_test_lib:activate_debug_fun({Resource, Func},
119
write_context(Resource, PTail, File, Line);
120
write_context(_,_, _, _) ->
121
ets:delete(?DEBUG_TAB),
122
exit("failed transactions_SUITE. Bad configuration.").
125
%%--------------- END OF MODULE ----------------------------------------