Debugging with Debug Helper
From Erlang Community
| Revision as of 18:00, 1 June 2007 (edit) RPK (Talk | contribs) m (→Debugging - minor wording improvement.) ← Previous diff |
Current revision (16:37, 2 July 2007) (edit) (undo) Karl (Talk | contribs) m (Tagged as Article) |
||
| Line 1: | Line 1: | ||
| [[Category:Debugging]] | [[Category:Debugging]] | ||
| [[Category:Testing]] | [[Category:Testing]] | ||
| + | [[Category:Articles]] | ||
| ==Authors== | ==Authors== | ||
Current revision
Contents |
[edit] Authors
[edit] Debugging
Sometimes one needs to debug a particular section of code and see functions being called and their parameters and return values. In Erlang you use [ tracing]
Using our test case from Testing with Test Helper, we modify it with a configuration case that enables basic function tracing:
tracing_start(doc) -> ["Starts tracing on test_case"]; tracing_start(suite) -> []; tracing_start(Config) -> debughelper:start(), debughelper:trace(?MODULE,test_case), Config. |
and adds it to our all(...) test case:
all(suite) ->
[{conf,
tracing_start,[test_case_2],
tracing_stop}].
|
The intention here is to see what test_case_3 does.
Here is the output of test case 3:
====================Start of Test test_case_3======================
(<0.220.0>) call simple_test_SUITE:test_case_3(suite)
(<0.220.0>) returned from simple_test_SUITE:test_case_3/1 -> []
This is test 3!
(<0.220.0>) call simple_test_SUITE:test_case_3([{data_dir,"/Users/rvg/svn/modules/common/test/simple_test_SUITE_data/"},
{priv_dir,"/Users/rvg/svn/modules/common/test/simple_test_SUITE_priv/"}])
Function 1!
Function 2!
====================End of Test test_case_3========================
(<0.220.0>) returned from simple_test_SUITE:test_case_3/1 -> ok
|
How do we read this?
(<0.220.0>) call simple_test_SUITE:test_case_3(suite) (<0.220.0>) returned from simple_test_SUITE:test_case_3/1 -> []
This is the call into test_case_3 that testhelper makes to determine of the test has sub tests. We can see that there are none, based on the empty list return.
Here testhelper runs our test:
(<0.220.0>) call simple_test_SUITE:test_case_3([{data_dir,"/Users/rvg/svn/modules/common/test/simple_test_SUITE_data/"},
{priv_dir,"/Users/rvg/svn/modules/common/test/simple_test_SUITE_priv/"}])
(<0.220.0>) returned from simple_test_SUITE:test_case_3/1 -> ok
You can see that erlang should us the call into test_case_3 and that it returned the Atom ok.
[edit] debughelper.erl
Here is the code for debughelper.erl. As you can see, it is simply a wrapper around dbg, but it makes it easy and programmers don't have to remember anything about Match Specifications.
%%% Author : Rudolph van Graan <>
%%% Description :
%%% Created : 25 Jul 2006 by Rudolph van Graan <>
-module(debughelper).
-export([start/0,
trace/1,
trace/2]).
start() ->
dbg:tracer(),
dbg:p(all,[c,sos,sol]).
trace(ModuleName) ->
dbg:tpl(ModuleName,[{'_',[],[{message,{return_trace}}]}]).
trace(ModuleName,Function) ->
dbg:tpl(ModuleName,Function,[{'_',[],[{message,{return_trace}}]}]).
|

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

