~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/test_server/doc/src/test_server.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>2007</year>
 
8
      <year>2008</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>test_server</title>
 
27
    <prepared>Siri Hansen</prepared>
 
28
    <responsible></responsible>
 
29
    <docno></docno>
 
30
    <approved></approved>
 
31
    <checked></checked>
 
32
    <date></date>
 
33
    <rev></rev>
 
34
    <file>test_server_ref.sgml</file>
 
35
  </header>
 
36
  <module>test_server</module>
 
37
  <modulesummary>This module provides support for test suite authors.</modulesummary>
 
38
  <description>
 
39
    <p>The <c>test_server</c> module aids the test suite author by providing
 
40
      various support functions. The supported functionality includes:
 
41
      </p>
 
42
    <list type="bulleted">
 
43
      <item>Logging and timestamping
 
44
      </item>
 
45
      <item>Capturing output to stdout
 
46
      </item>
 
47
      <item>Retrieving and flushing the message queue of a process
 
48
      </item>
 
49
      <item>Watchdog timers, process sleep, time measurement and unit
 
50
       conversion
 
51
      </item>
 
52
      <item>Private scratch directory for all test suites
 
53
      </item>
 
54
      <item>Start and stop of slave- or peer nodes</item>
 
55
    </list>
 
56
    <p>For more information on how to write test cases and for
 
57
      examples, please see the Test Server User's Guide. 
 
58
      </p>
 
59
  </description>
 
60
 
 
61
  <section>
 
62
    <title>TEST SUITE SUPPORT FUNCTIONS</title>
 
63
    <p>The following functions are supposed to be used inside a test
 
64
      suite.
 
65
      </p>
 
66
  </section>
 
67
  <funcs>
 
68
    <func>
 
69
      <name>os_type() -> OSType</name>
 
70
      <fsummary>Returns the OS type of the target node</fsummary>
 
71
      <type>
 
72
        <v>OSType = term()</v>
 
73
        <d>This is the same as returned from <c>os:type/0</c></d>
 
74
      </type>
 
75
      <desc>
 
76
        <p>This function can be called on controller or target node, and
 
77
          it will always return the OS type of the target node.</p>
 
78
      </desc>
 
79
    </func>
 
80
    <func>
 
81
      <name>fail()</name>
 
82
      <name>fail(Reason)</name>
 
83
      <fsummary>Makes the test case fail.</fsummary>
 
84
      <type>
 
85
        <v>Reason = term()</v>
 
86
        <d>The reason why the test case failed.</d>
 
87
      </type>
 
88
      <desc>
 
89
        <p>This will make the test suite fail with a given reason, or
 
90
          with <c>suite_failed</c> if no reason was given. Use this
 
91
          function if you want to terminate a test case, as this will
 
92
          make it easier to read the log- and HTML files. <c>Reason</c>
 
93
          will appear in the comment field in the HTML log.</p>
 
94
      </desc>
 
95
    </func>
 
96
    <func>
 
97
      <name>timetrap(Timout) -> Handle</name>
 
98
      <fsummary></fsummary>
 
99
      <type>
 
100
        <v>Timeout = integer() | {hours,H} | {minutes,M} | {seconds,S}</v>
 
101
        <v>H = M = S = integer()</v>
 
102
        <v>Pid = pid()</v>
 
103
        <d>The process that is to be timetrapped (<c>self()</c>by default)</d>
 
104
      </type>
 
105
      <desc>
 
106
        <p>Sets up a time trap for the current process. An expired
 
107
          timetrap kills the process with reason
 
108
          <c>timetrap_timeout</c>. The returned handle is to be given
 
109
          as argument to <c>timetrap_cancel</c> before the timetrap
 
110
          expires.  If <c>Timeout</c> is an integer, it is expected to
 
111
          be milliseconds.</p>
 
112
        <note>
 
113
          <p>If the current process is trapping exits, it will not be killed
 
114
            by the exit signal with reason <c>timetrap_timeout</c>.
 
115
            If this happens, the process will be sent an exit signal
 
116
            with reason <c>kill</c> 10 seconds later which will kill the
 
117
            process. Information about the timetrap timeout will in
 
118
            this case not be found in the test logs. However, the
 
119
            error_logger will be sent a warning.</p>
 
120
        </note>
 
121
      </desc>
 
122
    </func>
 
123
    <func>
 
124
      <name>timetrap_cancel(Handle) -> ok</name>
 
125
      <fsummary>Cancels a timetrap.</fsummary>
 
126
      <type>
 
127
        <v>Handle = term()</v>
 
128
        <d>Handle returned from <c>timetrap</c></d>
 
129
      </type>
 
130
      <desc>
 
131
        <p>This function cancels a timetrap. This must be done before
 
132
          the timetrap expires.</p>
 
133
      </desc>
 
134
    </func>
 
135
    <func>
 
136
      <name>timetrap_scale_factor() -> ScaleFactor</name>
 
137
      <fsummary>Returns the scale factor for timeouts.</fsummary>
 
138
      <type>
 
139
        <v>ScaleFactor = integer()</v>
 
140
      </type>
 
141
      <desc>
 
142
        <p>This function returns the scale factor by which all timetraps
 
143
        are scaled. It is normally 1, but can be greater than 1 if
 
144
        the test_server is running <c>cover</c>, using a larger amount of
 
145
        scheduler threads than the amount of logical processors on the
 
146
        system, running under purify, valgrind or in a debug-compiled
 
147
        emulator. The scale factor can be used if you need to scale you
 
148
        own timeouts in test cases with same factor as the test_server
 
149
        uses.</p>
 
150
      </desc>
 
151
    </func>
 
152
    <func>
 
153
      <name>sleep(MSecs) -> ok</name>
 
154
      <fsummary>Suspens the calling task for a specified time.</fsummary>
 
155
      <type>
 
156
        <v>MSecs = integer() | float() | infinity</v>
 
157
        <d>The number of milliseconds to sleep</d>
 
158
      </type>
 
159
      <desc>
 
160
        <p>This function suspends the calling process for at least the
 
161
          supplied number of milliseconds. There are two major reasons
 
162
          why you should use this function instead of
 
163
          <c>timer:sleep</c>, the first being that the module
 
164
          <c>timer</c> may be unavaliable at the time the test suite is
 
165
          run, and the second that it also accepts floating point
 
166
          numbers.</p>
 
167
      </desc>
 
168
    </func>
 
169
    <func>
 
170
      <name>hours(N) -> MSecs</name>
 
171
      <name>minutes(N) -> MSecs</name>
 
172
      <name>seconds(N) -> MSecs</name>
 
173
      <fsummary></fsummary>
 
174
      <type>
 
175
        <v>N = integer()</v>
 
176
        <d>Value to convert to milliseconds.</d>
 
177
      </type>
 
178
      <desc>
 
179
        <p>Theese functions convert <c>N</c> number of hours, minutes
 
180
          or seconds into milliseconds.
 
181
          </p>
 
182
        <p>Use this function when you want to
 
183
          <c>test_server:sleep/1</c> for a number of seconds, minutes or
 
184
          hours(!).</p>
 
185
      </desc>
 
186
    </func>
 
187
    <func>
 
188
      <name>format(Format) -> ok</name>
 
189
      <name>format(Format, Args)</name>
 
190
      <name>format(Pri,Format)</name>
 
191
      <name>format(Pri, Format, Args)</name>
 
192
      <fsummary></fsummary>
 
193
      <type>
 
194
        <v>Format = string()</v>
 
195
        <d>Format as described for <c>io_:format</c>.</d>
 
196
        <v>Args = list()</v>
 
197
        <d>List of arguments to format.</d>
 
198
      </type>
 
199
      <desc>
 
200
        <p>Formats output just like <c>io:format</c> but sends the
 
201
          formatted string to a logfile. If the urgency value,
 
202
          <c>Pri</c>, is lower than some threshold value, it will also
 
203
          be written to the test person's console. Default urgency is
 
204
          50, default threshold for display on the console is 1.
 
205
          </p>
 
206
        <p>Typically, the test person don't want to see everything a
 
207
          test suite outputs, but is merely interested in if the test
 
208
          cases succeeded or not, wich the test server tells him. If he
 
209
          would like to see more, he could manually change the threshold
 
210
          values by using the <c>test_server_ctrl:set_levels/3</c>
 
211
          function.</p>
 
212
      </desc>
 
213
    </func>
 
214
    <func>
 
215
      <name>capture_start() -> ok</name>
 
216
      <name>capture_stop() -> ok</name>
 
217
      <name>capture_get() -> list()</name>
 
218
      <fsummary>Captures all output to stdout for a process.</fsummary>
 
219
      <desc>
 
220
        <p>These functions makes it possible to capture all output to
 
221
          stdout from a process started by the test suite. The list of
 
222
          characters captured can be purged by using <c>capture_get</c>.</p>
 
223
      </desc>
 
224
    </func>
 
225
    <func>
 
226
      <name>messages_get() -> list()</name>
 
227
      <fsummary>Empty the message queue.</fsummary>
 
228
      <desc>
 
229
        <p>This function will empty and return all the messages
 
230
          currently in the calling process' message queue.</p>
 
231
      </desc>
 
232
    </func>
 
233
    <func>
 
234
      <name>timecall(M, F, A) -> {Time, Value}</name>
 
235
      <fsummary>Measures the time needed to call a function.</fsummary>
 
236
      <type>
 
237
        <v>M = atom()</v>
 
238
        <d>The name of the module where the function resides.</d>
 
239
        <v>F = atom()</v>
 
240
        <d>The name of the function to call in the module.</d>
 
241
        <v>A = list()</v>
 
242
        <d>The arguments to supplu the called function.</d>
 
243
        <v>Time = integer()</v>
 
244
        <d>The number of seconds it took to call the function.</d>
 
245
        <v>Value = term()</v>
 
246
        <d>Value returned from the called function.</d>
 
247
      </type>
 
248
      <desc>
 
249
        <p>This function measures the time (in seconds) it takes to
 
250
          call a certain function. The function call is <em>not</em>
 
251
          caught within a catch.</p>
 
252
      </desc>
 
253
    </func>
 
254
    <func>
 
255
      <name>do_times(N, M, F, A) -> ok</name>
 
256
      <name>do_times(N, Fun)</name>
 
257
      <fsummary>Calls MFA or Fun N times.</fsummary>
 
258
      <type>
 
259
        <v>N = integer()</v>
 
260
        <d>Number of times to call MFA.</d>
 
261
        <v>M = atom()</v>
 
262
        <d>Module name where the function resides.</d>
 
263
        <v>F = atom()</v>
 
264
        <d>Function name to call.</d>
 
265
        <v>A = list()</v>
 
266
        <d>Arguments to M:F.</d>
 
267
      </type>
 
268
      <desc>
 
269
        <p>Calls MFA or Fun N times. Useful for extensive testing of a
 
270
          sensitive function.</p>
 
271
      </desc>
 
272
    </func>
 
273
    <func>
 
274
      <name>m_out_of_n(M, N, Fun) -> ok | exit({m_out_of_n_failed, {R,left_to_do}}</name>
 
275
      <fsummary>Fault tolerant <c>do_times</c>.</fsummary>
 
276
      <type>
 
277
        <v>N = integer()</v>
 
278
        <d>Number of times to call the Fun.</d>
 
279
        <v>M = integer()</v>
 
280
        <d>Number of times to require a successful return.</d>
 
281
      </type>
 
282
      <desc>
 
283
        <p>Repeatedly evaluates the given function until it succeeds
 
284
          (doesn't crash) M times. If, after N times, M successful
 
285
          attempts have not been accomplished, the process crashes with
 
286
          reason {m_out_of_n_failed, {R,left_to_do}}, where R indicates
 
287
          how many cases that was still to be successfully completed.
 
288
          </p>
 
289
        <p>For example:
 
290
          </p>
 
291
        <p><c>m_out_of_n(1,4,fun() -> tricky_test_case() end)</c>          <br></br>
 
292
Tries to run tricky_test_case() up to 4 times, and is
 
293
          happy if it succeeds once.
 
294
          </p>
 
295
        <p><c>m_out_of_n(7,8,fun() -> clock_sanity_check() end)</c>          <br></br>
 
296
Tries running clock_sanity_check() up to 8 times,and
 
297
          allows the function to fail once.  This might be useful if
 
298
          clock_sanity_check/0 is known to fail if the clock crosses an
 
299
          hour boundary during the test (and the up to 8 test runs could
 
300
          never cross 2 boundaries)</p>
 
301
      </desc>
 
302
    </func>
 
303
    <func>
 
304
      <name>call_crash(M, F, A) -> Result</name>
 
305
      <name>call_crash(Time, M, F, A) -> Result</name>
 
306
      <name>call_crash(Time, Crash, M, F, A) -> Result</name>
 
307
      <fsummary>Calls MFA and succeeds if it crashes.</fsummary>
 
308
      <type>
 
309
        <v>Result = ok | exit(call_crash_timeout) | exit({wrong_crash_reason, Reason})</v>
 
310
        <v>Crash = term()</v>
 
311
        <d>Crash return from the function.</d>
 
312
        <v>Time = integer()</v>
 
313
        <d>Timeout in milliseconds.</d>
 
314
        <v>M = atom()</v>
 
315
        <d>Module name where the function resides.</d>
 
316
        <v>F = atom()</v>
 
317
        <d>Function name to call.</d>
 
318
        <v>A = list()</v>
 
319
        <d>Arguments to M:F.</d>
 
320
      </type>
 
321
      <desc>
 
322
        <p>Spawns a new process that calls MFA. The call is considered
 
323
          successful if the call crashes with the gives reason
 
324
          (<c>Crash</c>) or any reason if not specified. The call must
 
325
          terminate within the given time (default <c>infinity</c>), or
 
326
          it is considered a failure.</p>
 
327
      </desc>
 
328
    </func>
 
329
    <func>
 
330
      <name>temp_name(Stem) -> Name</name>
 
331
      <fsummary>Returns a unique filename.</fsummary>
 
332
      <type>
 
333
        <v>Stem = string()</v>
 
334
      </type>
 
335
      <desc>
 
336
        <p>Returns a unique filename starting with <c>Stem</c> with
 
337
          enough extra characters appended to make up a unique
 
338
          filename. The filename returned is guaranteed not to exist in
 
339
          the filesystem at the time of the call.</p>
 
340
      </desc>
 
341
    </func>
 
342
    <func>
 
343
      <name>break(Comment) -> ok</name>
 
344
      <fsummary>Cancel all timetraps and wait for call to continue/0.</fsummary>
 
345
      <type>
 
346
        <v>Comment = string()</v>
 
347
      </type>
 
348
      <desc>
 
349
        <p><c>Comment</c> is a string which will be written in
 
350
          the shell, e.g. explaining what to do.</p>
 
351
        <p>This function will cancel all timetraps and pause the
 
352
          execution of the test case until the user executes the
 
353
          <c>continue/0</c> function. It gives the user the opportunity
 
354
          to interact with the erlang node running the tests, e.g. for
 
355
          debugging purposes or for manually executing a part of the
 
356
          test case.</p>
 
357
        <p>When the <c>break/1</c> function is called, the shell will
 
358
          look something like this:</p>
 
359
        <code type="none"><![CDATA[
 
360
   --- SEMIAUTOMATIC TESTING ---
 
361
   The test case executes on process <0.51.0>
 
362
 
 
363
 
 
364
   "Here is a comment, it could e.g. instruct to pull out a card"
 
365
 
 
366
 
 
367
   -----------------------------
 
368
 
 
369
   Continue with --> test_server:continue().        ]]></code>
 
370
        <p>The user can now interact with the erlang node, and when
 
371
          ready call <c>test_server:continue().</c></p>
 
372
        <p>Note that this function can not be used if the test is
 
373
          executed with <c>ts:run/0/1/2/3/4</c> in <c>batch</c> mode.</p>
 
374
      </desc>
 
375
    </func>
 
376
    <func>
 
377
      <name>continue() -> ok</name>
 
378
      <fsummary>Continue after break/1.</fsummary>
 
379
      <desc>
 
380
        <p>This function must be called in order to continue after a
 
381
          test case has called <c>break/1</c>.</p>
 
382
      </desc>
 
383
    </func>
 
384
    <func>
 
385
      <name>run_on_shielded_node(Fun, CArgs) -> term()</name>
 
386
      <fsummary>Execute a function a shielded node.</fsummary>
 
387
      <type>
 
388
        <v>Fun = function() (arity 0)</v>
 
389
        <d>Function to execute on the shielded node.</d>
 
390
        <v>CArg = string()</v>
 
391
        <d>Extra command line arguments to use when starting the shielded node.</d>
 
392
      </type>
 
393
      <desc>
 
394
        <p><c>Fun</c> is executed in a process on a temporarily created
 
395
          hidden node with a proxy for communication with the test server
 
396
          node. The node is called a shielded node (should have been called
 
397
          a shield node). If <c>Fun</c> is successfully executed, the result
 
398
          is returned. A peer node (see <c>start_node/3</c>) started from
 
399
          the shielded node will be shielded from test server node, i.e.
 
400
          they will not be aware of eachother. This is useful when you want
 
401
          to start nodes from earlier OTP releases than the OTP release of
 
402
          the test server node.</p>
 
403
        <p>Nodes from an earlier OTP release can normally not be started
 
404
          if the test server hasn't been started in compatibility mode
 
405
          (see the <c>+R</c> flag in the <c>erl(1)</c> documentation) of
 
406
          an earlier release. If a shielded node is started in compatibility
 
407
          mode of an earlier OTP release than the OTP release of the test
 
408
          server node, the shielded node can start nodes of an earlier OTP
 
409
          release.</p>
 
410
        <note>
 
411
          <p>You <em>must</em> make sure that nodes started by the shielded
 
412
            node never communicate directly with the test server node.</p>
 
413
        </note>
 
414
        <note>
 
415
          <p>Slave nodes always communicate with the test server node;
 
416
            therefore, <em>never</em> start <em>slave nodes</em> from the
 
417
            shielded node, <em>always</em> start <em>peer nodes</em>.</p>
 
418
        </note>
 
419
      </desc>
 
420
    </func>
 
421
    <func>
 
422
      <name>start_node(Name, Type, Options) -> {ok, Node} | {error, Reason}</name>
 
423
      <fsummary>Start a node.</fsummary>
 
424
      <type>
 
425
        <v>Name = atom() | string()</v>
 
426
        <d>Name of the slavenode to start (as given to -sname or -name)</d>
 
427
        <v>Type = slave | peer</v>
 
428
        <d>The type of node to start.</d>
 
429
        <v>Options = [{atom(), term()]</v>
 
430
        <d>Tuplelist of options</d>
 
431
      </type>
 
432
      <desc>
 
433
        <p>This functions starts a node, possibly on a remote machine,
 
434
          and guarantees cross architecture transparency. Type is set to
 
435
          either <c>slave</c> or <c>peer</c>.
 
436
          </p>
 
437
        <p><c>slave</c> means that the new node will have a master,
 
438
          i.e. the slave node will terminate if the master terminates,
 
439
          TTY output produced on the slave will be sent back to the
 
440
          master node and file I/O is done via the master. The master is
 
441
          normally the target node unless the target is itself a slave.
 
442
          </p>
 
443
        <p><c>peer</c> means that the new node is an independent node
 
444
          with no master.
 
445
          </p>
 
446
        <p><c>Options</c> is a tuplelist wich can contain one or more
 
447
          of
 
448
          </p>
 
449
        <taglist>
 
450
          <tag><c>{remote, true}</c></tag>
 
451
          <item>Start the node on a remote host. If not specified, the
 
452
           node will be started on the local host (with some
 
453
           exceptions, as for the case of VxWorks, where
 
454
           all nodes are started on a remote host).  Test cases that
 
455
           require a remote host will fail with a reasonable comment if
 
456
           no remote hosts are availiable at the time they are run.
 
457
          </item>
 
458
          <tag><c>{args, Arguments}</c></tag>
 
459
          <item>Arguments passed directly to the node. This is
 
460
           typically a string appended to the command line.
 
461
          </item>
 
462
          <tag><c>{wait, false}</c></tag>
 
463
          <item>Don't wait until the node is up. By default, this
 
464
           function does not return until the node is up and running,
 
465
           but this option makes it return as soon as the node start
 
466
           command is given..
 
467
                    <br></br>
 
468
Only valid for peer nodes
 
469
          </item>
 
470
          <tag><c>{fail_on_error, false}</c></tag>
 
471
          <item>Returns <c>{error, Reason}</c> rather than failing the
 
472
           test case.
 
473
                    <br></br>
 
474
Only valid for peer nodes. Note that slave nodes always
 
475
           act as if they had <c>fail_on_error=false</c></item>
 
476
          <tag><c>{erl, ReleaseList}</c></tag>
 
477
          <item>Use an Erlang emulator determined by ReleaseList when
 
478
           starting nodes, instead of the same emulator as the test
 
479
           server is running. ReleaseList is a list of specifiers,
 
480
           where a specifier is either {release, Rel}, {prog, Prog}, or
 
481
           'this'. Rel is either the name of a release, e.g., "r12b_patched"
 
482
           or 'latest'. 'this' means using the same emulator as the test
 
483
           server. Prog is the name of an emulator executable.  If the
 
484
           list has more than one element, one of them is picked
 
485
           randomly.  (Only works on Solaris, and the test server gives
 
486
           warnings when it notices that nodes are not of the same
 
487
           version as itself.)
 
488
                    <br></br>
 
489
          <br></br>
 
490
 
 
491
           When specififying this option to run a previous release, use
 
492
          <c>is_release_available/1</c> function to test if the given
 
493
           release is available and skip the test case if not.
 
494
                    <br></br>
 
495
          <br></br>
 
496
 
 
497
           In order to avoid compatibility problems (may not appear right
 
498
           away), use a shielded node (see <c>run_on_shielded_node/2</c>)
 
499
           when starting nodes from different OTP releases than the test
 
500
           server.
 
501
          </item>
 
502
          <tag><c>{cleanup, false}</c></tag>
 
503
          <item>Tells the test server not to kill this node if it is
 
504
           still alive after the test case is completed. This is useful
 
505
           if the same node is to be used by a group of test cases.
 
506
          </item>
 
507
          <tag><c>{env, Env}</c></tag>
 
508
          <item><c>Env</c> should be a list of tuples <c>{Name, Val}</c>,
 
509
           where <c>Name</c> is the name of an environment variable, and
 
510
          <c>Val</c> is the value it is to have in the started node.
 
511
           Both <c>Name</c> and <c>Val</c> must be strings. The one
 
512
           exception is <c>Val</c> being the atom <c>false</c> (in
 
513
           analogy  with  <c>os:getenv/1</c>),  which  removes  the
 
514
           environment variable. Only valid for peer nodes. Not
 
515
           available on VxWorks.</item>
 
516
        </taglist>
 
517
      </desc>
 
518
    </func>
 
519
    <func>
 
520
      <name>stop_node(NodeName) -> bool()</name>
 
521
      <fsummary>Stops a node</fsummary>
 
522
      <type>
 
523
        <v>NodeName = term()</v>
 
524
        <d>Name of the node to stop</d>
 
525
      </type>
 
526
      <desc>
 
527
        <p>This functions stops a node previously started with
 
528
          <c>start_node/3</c>. Use this function to stop any node you
 
529
          start, or the test server will produce a warning message in
 
530
          the test logs, and kill the nodes automatically unless it was
 
531
          started with the <c>{cleanup, false}</c> option.</p>
 
532
      </desc>
 
533
    </func>
 
534
    <func>
 
535
      <name>is_commercial() -> bool()</name>
 
536
      <fsummary>Tests whether the emulator is commercially supported</fsummary>
 
537
      <desc>
 
538
        <p>This function test whether the emulator is commercially supported
 
539
        emulator. The tests for a commercially supported emulator could be more
 
540
        stringent (for instance, a commercial release should always contain
 
541
        documentation for all applications).</p>
 
542
      </desc>
 
543
    </func>
 
544
 
 
545
    <func>
 
546
      <name>is_release_available(Release) -> bool()</name>
 
547
      <fsummary>Tests whether a release is available</fsummary>
 
548
      <type>
 
549
        <v>Release = string() | atom()</v>
 
550
        <d>Release to test for</d>
 
551
      </type>
 
552
      <desc>
 
553
        <p>This function test whether the release given by
 
554
          <c>Release</c> (for instance, "r12b_patched") is available
 
555
          on the computer that the test_server controller is running on.
 
556
          Typically, you should skip the test case if not.</p>
 
557
        <p>Caution: This function may not be called from the <c>suite</c>
 
558
          clause of a test case, as the test_server will deadlock.</p>
 
559
      </desc>
 
560
    </func>
 
561
    <func>
 
562
      <name>is_native(Mod) -> bool()</name>
 
563
      <fsummary>Checks wether the module is natively compiled or not</fsummary>
 
564
      <type>
 
565
        <v>Mod = atom()</v>
 
566
        <d>A module name</d>
 
567
      </type>
 
568
      <desc>
 
569
        <p>Checks wether the module is natively compiled or not</p>
 
570
      </desc>
 
571
    </func>
 
572
    <func>
 
573
      <name>app_test(App) -> ok | test_server:fail()</name>
 
574
      <name>app_test(App,Mode)</name>
 
575
      <fsummary>Checks an applications .app file for obvious errors</fsummary>
 
576
      <type>
 
577
        <v>App = term()</v>
 
578
        <d>The name of the application to test</d>
 
579
        <v>Mode = pedantic | tolerant</v>
 
580
        <d>Default is pedantic</d>
 
581
      </type>
 
582
      <desc>
 
583
        <p>Checks an applications .app file for obvious errors.
 
584
          The following is checked:
 
585
          </p>
 
586
        <list type="bulleted">
 
587
          <item>required fields
 
588
          </item>
 
589
          <item>that all modules specified actually exists
 
590
          </item>
 
591
          <item>that all requires applications exists
 
592
          </item>
 
593
          <item>that no module included in the application has export_all
 
594
          </item>
 
595
          <item>that all modules in the ebin/ dir is included (If
 
596
          <c>Mode==tolerant</c> this only produces a warning, as all
 
597
           modules does not have to be included)</item>
 
598
        </list>
 
599
      </desc>
 
600
    </func>
 
601
    <func>
 
602
      <name>comment(Comment) -> ok</name>
 
603
      <fsummary>Print a comment on the HTML result page</fsummary>
 
604
      <type>
 
605
        <v>Comment = string()</v>
 
606
      </type>
 
607
      <desc>
 
608
        <p>The given String will occur in the comment field of the
 
609
          table on the HTML result page. If called several times, only
 
610
          the last comment is printed.  comment/1 is also overwritten by
 
611
          the return value {comment,Comment} from a test case or by
 
612
          fail/1 (which prints Reason as a comment).</p>
 
613
      </desc>
 
614
    </func>
 
615
  </funcs>
 
616
 
 
617
  <section>
 
618
    <title>TEST SUITE EXPORTS</title>
 
619
    <p>The following functions must be exported from a test suite
 
620
      module.
 
621
      </p>
 
622
  </section>
 
623
  <funcs>
 
624
    <func>
 
625
      <name>all(suite) -> TestSpec | {skip, Comment}</name>
 
626
      <fsummary>Returns the module's test specification</fsummary>
 
627
      <type>
 
628
        <v>TestSpec = list()</v>
 
629
        <v>Comment = string()</v>
 
630
        <d>This comment will be printed on the HTML result page</d>
 
631
      </type>
 
632
      <desc>
 
633
        <p>This function must return the test specification for the
 
634
          test suite module. The syntax of a test specification is
 
635
          described in the Test Server User's Guide.</p>
 
636
      </desc>
 
637
    </func>
 
638
    <func>
 
639
      <name>init_per_suite(Config0) -> Config1 | {skip, Comment}</name>
 
640
      <fsummary>Test suite initiation</fsummary>
 
641
      <type>
 
642
        <v>Config0 = Config1 = [tuple()]</v>
 
643
        <v>Comment = string()</v>
 
644
        <d>Describes why the suite is skipped</d>
 
645
      </type>
 
646
      <desc>
 
647
        <p>This function is called before all other test cases in the
 
648
          suite. <c>Config</c> is the configuration which can be modified
 
649
          here. Whatever is returned from this function is given as
 
650
          <c>Config</c> to the test cases.
 
651
          </p>
 
652
        <p>If this function fails, all test cases in the suite will be
 
653
          skipped.</p>
 
654
      </desc>
 
655
    </func>
 
656
    <func>
 
657
      <name>end_per_suite(Config) -> void()</name>
 
658
      <fsummary>Test suite finalization</fsummary>
 
659
      <type>
 
660
        <v>Config = [tuple()]</v>
 
661
      </type>
 
662
      <desc>
 
663
        <p>This function is called after the last test case in the
 
664
          suite, and can be used to clean up whatever the test cases
 
665
          have done. The return value is ignored.</p>
 
666
      </desc>
 
667
    </func>
 
668
    <func>
 
669
      <name>init_per_testcase(Case, Config0) -> Config1 | {skip, Comment}</name>
 
670
      <fsummary>Test case initiation</fsummary>
 
671
      <type>
 
672
        <v>Case = atom()</v>
 
673
        <v>Config0 = Config1 = [tuple()]</v>
 
674
        <v>Comment = string()</v>
 
675
        <d>Describes why the test case is skipped</d>
 
676
      </type>
 
677
      <desc>
 
678
        <p>This function is called before each test case. The
 
679
          <c>Case</c> argument is the name of the test case, and
 
680
          <c>Config</c> is the configuration which can be modified
 
681
          here. Whatever is returned from this function is given as
 
682
          <c>Config</c> to the test case.</p>
 
683
      </desc>
 
684
    </func>
 
685
    <func>
 
686
      <name>end_per_testcase(Case, Config) -> void()</name>
 
687
      <fsummary>Test case finalization</fsummary>
 
688
      <type>
 
689
        <v>Case = atom()</v>
 
690
        <v>Config = [tuple()]</v>
 
691
      </type>
 
692
      <desc>
 
693
        <p>This function is called after each test case, and can be
 
694
          used to clean up whatever the test case has done. The return
 
695
          value is ignored.</p>
 
696
      </desc>
 
697
    </func>
 
698
    <func>
 
699
      <name>Case(doc) -> [Decription]</name>
 
700
      <name>Case(suite) -> [] | TestSpec | {skip, Comment}</name>
 
701
      <name>Case(Config) -> {skip, Comment} | {comment, Comment} | Ok</name>
 
702
      <fsummary>A test case</fsummary>
 
703
      <type>
 
704
        <v>Description = string()</v>
 
705
        <d>Short description of the test case</d>
 
706
        <v>TestSpec = list()</v>
 
707
        <v>Comment = string()</v>
 
708
        <d>This comment will be printed on the HTML result page</d>
 
709
        <v>Ok = term()</v>
 
710
        <v>Config = [tuple()]</v>
 
711
        <d>Elements from the Config parameter can be read with the ?config macro, see section about test suite support macros</d>
 
712
      </type>
 
713
      <desc>
 
714
        <p>The <em>documentation clause</em> (argument <c>doc</c>) can
 
715
          be used for automatic generation of test documentation or test
 
716
          descriptions.
 
717
          </p>
 
718
        <p>The <em>specification clause</em> (argument <c>spec</c>)
 
719
          shall return an empty list, the test specification for the
 
720
          test case or <c>{skip,Comment}</c>. The syntax of a test
 
721
          specification is described in the Test Server User's Guide.
 
722
          </p>
 
723
        <p><em>Note that the specification clause always is executed on the controller host.</em></p>
 
724
        <p>The <em>execution clause</em> (argument <c>Config</c>) is
 
725
          only called if the specification clause returns an empty list.
 
726
          The execution clause is the real test case. Here you must call
 
727
          the functions you want to test, and do whatever you need to
 
728
          check the result. If someting fails, make sure the process
 
729
          crashes or call <c>test_server:fail/0/1</c> (which also will
 
730
          cause the process to crash).
 
731
          </p>
 
732
        <p>You can return <c>{skip,Comment}</c> if you decide not to
 
733
          run the test case after all, e.g. if it is not applicable on
 
734
          this platform.
 
735
          </p>
 
736
        <p>You can return <c>{comment,Comment}</c> if you wish to
 
737
          print some information in the 'Comment' field on the HTML
 
738
          result page.
 
739
          </p>
 
740
        <p>If the execution clause returns anything else, it is
 
741
          considered a success, unless it is <c>{'EXIT',Reason}</c> or
 
742
          <c>{'EXIT',Pid,Reason}</c> which can't be distinguished from a
 
743
          crash, and thus will be considered a failure.
 
744
          </p>
 
745
        <p>A <em>conf test case</em> is a group of test cases with an
 
746
          init and a cleanup function. The init and cleanup functions
 
747
          are also test cases, but they have spcial rules:</p>
 
748
          <list type="bulleted">
 
749
          <item>They do not need a specification clause.</item>
 
750
          <item>They must always have the execution clause.</item>
 
751
          <item>They must return the <c>Config</c> parameter, a modified
 
752
          version of it or <c>{skip,Comment}</c> from the execution clause.</item>
 
753
          <item><c>init_per_testcase</c> and <c>end_per_testcase</c> are
 
754
          not called before and after these functions.</item>
 
755
          </list>
 
756
      </desc>
 
757
    </func>
 
758
  </funcs>
 
759
 
 
760
  <section>
 
761
    <title>TEST SUITE LINE NUMBERS</title>
 
762
    <p>If a test case fails, the test server can report the exact line
 
763
      number at which it failed. There are two ways of doing this,
 
764
      either by using the <c>line</c> macro or by using the
 
765
      <c>test_server_line</c> parse transform.
 
766
      </p>
 
767
    <p>The <c>line</c> macro is described under TEST SUITE SUPPORT
 
768
      MACROS below. The <c>line</c> macro will only report the last line
 
769
      executed when a test case failed.
 
770
      </p>
 
771
    <p>The <c>test_server_line</c> parse transform is activated by
 
772
      including the headerfile <c>test_server_line.hrl</c> in the test
 
773
      suite. When doing this, it is important that the
 
774
      <c>test_server_line</c> module is in the code path of the erlang
 
775
      node compiling the test suite. The parse transform will report a
 
776
      history of a maximum of 10 lines when a test case
 
777
      fails. Consecutive lines in the same function are not shown.
 
778
      </p>
 
779
    <p>The attribute <c>-no_lines(FuncList).</c> can be used in the
 
780
      test suite to exclude specific functions from the parse
 
781
      transform. This is necessary e.g. for functions that are executed
 
782
      on old (i.e. &lt;R10B) OTP releases. <c>FuncList = [{Func,Arity}]</c>.
 
783
      </p>
 
784
    <p>If both the <c>line</c> macro and the parse tranform is used in
 
785
      the same module, the parse transform will overrule the macro.
 
786
      </p>
 
787
  </section>
 
788
 
 
789
  <section>
 
790
    <title>TEST SUITE SUPPORT MACROS</title>
 
791
    <p>There are some macros defined in the <c>test_server.hrl</c>
 
792
      that are quite useful for test suite programmers:
 
793
      </p>
 
794
    <p>The <em>line</em> macro, is quite
 
795
      essential when writing test cases. It tells the test server
 
796
      exactly what line of code that is being executed, so that it can
 
797
      report this line back if the test case fails. Use this macro at
 
798
      the beginning of every test case line of code.
 
799
      </p>
 
800
    <p>The <em>config</em> macro, is used to
 
801
      retrieve information from the <c>Config</c> variable sent to all
 
802
      test cases. It is used with two arguments, where the first is the
 
803
      name of the configuration variable you wish to retrieve, and the
 
804
      second is the <c>Config</c> variable supplied to the test case
 
805
      from the test server.
 
806
      </p>
 
807
    <p>Possible configuration variables include:</p>
 
808
    <list type="bulleted">
 
809
      <item><c>data_dir</c>  - Data file directory.</item>
 
810
      <item><c>priv_dir</c>  - Scratch file directory.</item>
 
811
      <item><c>nodes</c>     - Nodes specified in the spec file</item>
 
812
      <item><c>nodenames</c> - Generated nodenames.</item>
 
813
      <item>Whatever added by conf test cases or
 
814
      <c>init_per_testcase/2</c></item>
 
815
    </list>
 
816
    <p>Examples of the <c>line</c> and <c>config</c> macros can be
 
817
      seen in the Examples chapter in the user's guide.
 
818
      </p>
 
819
    <p>If the <c>line_trace</c> macro is defined, you will get a
 
820
      timestamp (<c>erlang:now()</c>) in your minor log for each
 
821
      <c>line</c> macro in your suite. This way you can at any time see
 
822
      which line is currently being executed, and when the line was
 
823
      called.
 
824
      </p>
 
825
    <p>The <c>line_trace</c> macro can also be used together with the
 
826
      <c>test_server_line</c> parse tranform described above. A
 
827
      timestamp will then be written for each line in the suite, except
 
828
      for functions stated in the <c>-no_lines</c> attribute.
 
829
      </p>
 
830
    <p>The <c>line_trace</c> macro can e.g. be defined as a compile
 
831
      option, like this:
 
832
            <br></br>
 
833
<c>erlc -W -Dline_trace my_SUITE.erl</c></p>
 
834
  </section>
 
835
</erlref>
 
836