-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebuggingUnitTests.html
241 lines (198 loc) · 10.6 KB
/
DebuggingUnitTests.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Debugging Unit Tests</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/bootstrap-sphinx.css?v=fadd4351" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=77160d70" />
<script src="_static/documentation_options.js?v=a8da1a53"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Unit Test Good Practice" href="UnitTestGoodPractice.html" />
<link rel="prev" title="Running the Unit Tests" href="RunningTheUnitTests.html" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59110517-1', 'auto');
ga('send', 'pageview');
</script>
</head><body>
<div id="navbar" class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.mantidproject.org">
</a>
<span class="navbar-text navbar-version pull-left"><b>main</b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="index.html">Home</a></li>
<li><a href="https://download.mantidproject.org">Download</a></li>
<li><a href="https://docs.mantidproject.org">User Documentation</a></li>
<li><a href="http://www.mantidproject.org/contact">Contact Us</a></li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="index.html">Documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Debugging Unit Tests</a></li>
</ul>
</div> </p>
</div>
<div class="container">
<div class="row">
<div class="body col-md-12 content" role="main">
<section id="debugging-unit-tests">
<h1>Debugging Unit Tests<a class="headerlink" href="#debugging-unit-tests" title="Link to this heading">¶</a></h1>
<nav class="contents local" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#using-gdb" id="id2">Using gdb</a></p></li>
<li><p><a class="reference internal" href="#within-eclipse" id="id3">Within Eclipse</a></p></li>
<li><p><a class="reference internal" href="#within-visual-studio-debugging-run-method" id="id4">Within Visual Studio (debugging run method)</a></p></li>
<li><p><a class="reference internal" href="#within-visual-studio-attach-to-process-version" id="id5">Within Visual Studio (attach to process version)</a></p></li>
</ul>
</nav>
<section id="using-gdb">
<h2><a class="toc-backref" href="#id2" role="doc-backlink">Using gdb</a><a class="headerlink" href="#using-gdb" title="Link to this heading">¶</a></h2>
<p>Debugging typically requires the test executable to be run directly,
rather than via ctest (which typically spawns off a separate process to
run the actual tests). So an example of debugging test function
<code class="docutils literal notranslate"><span class="pre">testworkspace1D_dist</span></code> of Suite <code class="docutils literal notranslate"><span class="pre">RebinTest</span></code> from the command line
using gdb would be:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ gdb bin/AlgorithmsTest
(gdb) r RebinTest testworkspace1D_dist
</pre></div>
</div>
<p>If you do need to run ctest in order to debug - if, for example, a test
is failing when run in ctest, but not if run directly - then you can
start the test off and then attach to the actual test executable from
another terminal (or your IDE). You may need to pause or slow down the
test using, e.g., the method described for Visual Studio debugging
below.</p>
<p>If the issue is with a python unit test, the call is slightly more
complicated:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ env PYTHONPATH=$PWD/bin gdb --args python /full/path/to/mantid/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py
(gdb) run
</pre></div>
</div>
</section>
<section id="within-eclipse">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">Within Eclipse</a><a class="headerlink" href="#within-eclipse" title="Link to this heading">¶</a></h2>
<ol class="arabic simple">
<li><p>Go to Run->Debug Configurations</p></li>
<li><p>Create a new Debug Configuration. I called mine “DataHandling Test
Debug”.</p></li>
<li><p>For me, it worked best using the “Standard Create Process Launcher”
(bottom option on the “Main” tab)</p></li>
<li><p>Set the C/C++ application to the path to the test executable, e.g.
bin/DataHandlingTest</p></li>
<li><p>Under the “Arguments” tab, add the name of the test class you want to
debug under “Program arguments”, e.g. LoadTest</p>
<ol class="arabic simple">
<li><p>To only run one test in a class, you can add the particular test
to run, e.g. “LoadTest test_exec”</p></li>
</ol>
</li>
<li><p>Under “Common” you can put the debug config in your “favorites” menu.</p></li>
</ol>
<p>You can then run the debugger on this configuration from the Run menu or
the toolbar.</p>
</section>
<section id="within-visual-studio-debugging-run-method">
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Within Visual Studio (debugging run method)</a><a class="headerlink" href="#within-visual-studio-debugging-run-method" title="Link to this heading">¶</a></h2>
<p>I’ve found that this method works with Visual Studio Express (which does
not allow “attach to process”).</p>
<ul class="simple">
<li><p>Right-click the test project, e.g. DataObjectsTest.</p></li>
<li><p>Select Properties.</p>
<ul>
<li><p>Under Debugging -> Command Arguments, type in the test suite and,
optionally, single test name. e.g. “EventListTest
test_MinusOperator_inPlace_3cases” in the screenshot below.</p></li>
</ul>
</li>
</ul>
<figure class="align-default" id="id1">
<img alt="VisualStudioTestDebugProperties.png" src="_images/VisualStudioTestDebugProperties.png" />
<figcaption>
<p><span class="caption-text">VisualStudioTestDebugProperties.png</span><a class="headerlink" href="#id1" title="Link to this image">¶</a></p>
</figcaption>
</figure>
<ul class="simple">
<li><p>Put a break point somewhere in the test code that will be run.</p></li>
<li><p>Select the project and click Debug -> Start Debugging.</p></li>
<li><p>Fun test debugging times!</p></li>
</ul>
</section>
<section id="within-visual-studio-attach-to-process-version">
<h2><a class="toc-backref" href="#id5" role="doc-backlink">Within Visual Studio (attach to process version)</a><a class="headerlink" href="#within-visual-studio-attach-to-process-version" title="Link to this heading">¶</a></h2>
<p>The process here is not as straight forward as it is in eclipse. It
involves a few steps, but it does work!</p>
<p>1. Edit the test to add a pause at the start of the test you are
interested in. This will make the test wait for keyboard input, all you
need to do is hit enter, but you can use this delay to attach to the
debugger to running process.</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">s</span><span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">getline</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cin</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">);</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">2. Run ctest with the appropriate arguments to run the test you are
investigating.</div>
<div class="line">3. When the test pauses for input within visual studio select
DebugAttach to Process… <img alt="AttachToProcess.png" src="_images/AttachToProcess.png" /></div>
<div class="line">4. Select the test executable (e.g. DataHandlingTest.exe) from the
list and click attach. Visual studio will change to debug mode.</div>
<div class="line">5. Set any breakpoints you want, go back to the runner.exe window and
hit enter to stop the pause. This should then ctach on any breakpoints
you have set.</div>
<div class="line">6. VERY IMPORTANT - Clean up when you have done, and do not check in
with any paused tests!</div>
</div>
</section>
</section>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<ul class="nav navbar-nav" style=" float: right;">
<li>
<a href="RunningTheUnitTests.html" title="Previous Chapter: Running the Unit Tests"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">« Running the U...</span>
</a>
</li>
<li>
<a href="UnitTestGoodPractice.html" title="Next Chapter: Unit Test Good Practice"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">Unit Test Goo... »</span>
</a>
</li>
<li><a href="#">Back to top</a></li>
</ul>
<p>
</p>
</div>
</footer>
</body>
</html>