File: ct.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (675 lines) | stat: -rw-r--r-- 12,381 bytes parent folder | download
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
.TH ct 3 "common_test  1.3.2" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
ct \- Main user interface for the Common Test framework\&.
.SH DESCRIPTION
.LP
Main user interface for the Common Test framework\&.
.LP
This module implements the command line interface for running tests and some basic functions for common test case issues such as configuration and logging\&. 
.LP
\fITest Suite Support Macros\fR
.LP
The \fIconfig\fR macro is defined in \fIct\&.hrl\fR\&. This macro should be used to retrieve information from the \fIConfig\fR variable sent to all test cases\&. It is used with two arguments, where the first is the name of the configuration variable you wish to retrieve, and the second is the \fIConfig\fR variable supplied to the test case\&.
.LP
Possible configuration variables include:
.RS 2
.TP 2
*
\fIdata_dir\fR - Data file directory\&.
.TP 2
*
\fIpriv_dir\fR - Scratch file directory\&.
.TP 2
*
Whatever added by \fIinit_per_suite/1\fR or \fIinit_per_testcase/2\fR in the test suite\&.
.RE

.SH DATA TYPES
.RS 2
.TP 4
.B
\fIhandle() = handle() (see module ct_gen_conn) | term()\fR:

.RS 4
.LP
The identity of a specific connection\&.
.LP

.RE
.TP 4
.B
\fItarget_name() = var_name()\fR:

.RS 4
.LP
The name of a target\&. 
.LP

.RE
.TP 4
.B
\fIvar_name() = atom()\fR:

.RS 4
.LP
A variable name which is specified when \fIct:require/2\fR is called, e\&.g\&. \fIct:require(mynodename, {node, [telnet]})\fR 
.LP

.RE
.RE
.SH EXPORTS
.LP
.B
comment(Comment) -> void()
.br
.RS
.TP
Types
Comment = term()
.br
.RE
.RS
.LP
Print the given \fIComment\fR in the comment field of the table on the test suite result page\&.
.LP
If called several times, only the last comment is printed\&. \fIcomment/1\fR is also overwritten by the return value \fI{comment, Comment}\fR or by the function \fIfail/1\fR (which prints \fIReason\fR as a comment)\&.
.RE
.LP
.B
fail(Reason) -> void()
.br
.RS
.TP
Types
Reason = term()
.br
.RE
.RS
.LP
Terminate a test case with the given error \fIReason\fR\&.
.RE
.LP
.B
get_config(Required) -> Value
.br
.RS
.LP
Equivalent to get_config(Required, undefined)\&.
.RE
.LP
.B
get_config(Required, Default) -> Value
.br
.RS
.TP
Types
Required = KeyOrName | {KeyOrName, SubKey}
.br
KeyOrName = atom()
.br
SubKey = atom()
.br
Default = term()
.br
Value = term() | Default
.br
.RE
.RS
.LP
Get the value of config data\&.
.LP
This function returns the value of the requested config element\&.
.LP
Example, given the following config file:

.nf
   {unix,[{telnet,IpAddr},
          {username,Username},
          {password,Password}]}\&.
.fi
.LP
\fIget_config(unix, Default) -> [{telnet, IpAddr}, {username, Username}, {password, Password}]\fR
.br
 \fIget_config({unix, telnet}, Default) -> IpAddr\fR
.br
 \fIget_config({unix, ftp}, Default) -> Default\fR
.br
 \fIget_config(unknownkey, Default) -> Default\fR
.LP
If you want to access a config variable which has been given a name by \fIrequire/2\fR, the name must be used instead of the key when reading the value:
.LP
\fIrequire(myhost, unix) -> ok\fR
.br
 \fIget_config(myhost, Default) -> [{telnet, IpAddr}, {username, Username}, {password, Password}]\fR
.LP
\fISee also:\fR get_config/1, require/1, require/2\&.
.RE
.LP
.B
get_status() -> TestStatus | {error, Reason}
.br
.RS
.TP
Types
TestDir = term()
.br
Reason = term()
.br
.RE
.RS
.LP
Returns status of ongoing tests\&.
.RE
.LP
.B
get_target_name(Handle) -> {ok, TargetName} | {error, Reason}
.br
.RS
.TP
Types
Handle = handle()
.br
TargetName = target_name()
.br
.RE
.RS
.LP
Return the name of the target that the given connection belongs to\&.
.RE
.LP
.B
install(Opts) -> ok | {error, Reason}
.br
.RS
.TP
Types
Opts = [Opt]
.br
Opt = {config, ConfigFiles} | {event_handler, Modules}
.br
ConfigFiles = [ConfigFile]
.br
ConfigFile = string()
.br
Modules = [atom()]
.br
.RE
.RS
.LP
Install config files and event handlers\&.
.LP
Run this function once before first test\&.
.LP
Example:
.br
 \fIinstall([{config, ["config_node\&.ctc", "config_user\&.ctc"]}])\fR\&.
.LP
Note that this function is automatically run by the \fIrun_test\fR script\&.
.RE
.LP
.B
listenv(Telnet) -> [Env]
.br
.RS
.TP
Types
Telnet = term()
.br
Env = {Key, Value}
.br
Key = string()
.br
Value = string()
.br
.RE
.RS
.LP
Performs the listenv command on the given telnet connection and returns the result as a list of Key-Value pairs\&.
.RE
.LP
.B
log(Format) -> ok
.br
.RS
.LP
Equivalent to log(default, Format, [])\&.
.RE
.LP
.B
log(X1, X2) -> ok
.br
.RS
.TP
Types
X1 = Category | Format
.br
X2 = Format | Args
.br
.RE
.RS
.LP
Equivalent to log(Category, Format, Args)\&.
.RE
.LP
.B
log(Category, Format, Args) -> ok
.br
.RS
.TP
Types
Category = atom()
.br
Format = string()
.br
Args = list()
.br
.RE
.RS
.LP
Printout from a testcase to the log\&.
.LP
This function is meant for printing stuff directly from a testcase (i\&.e\&. not from within the CT framework) in the test log\&.
.LP
Default \fICategory\fR is \fIdefault\fR and default \fIArgs\fR is \fI[]\fR\&.
.RE
.LP
.B
pal(Format) -> ok
.br
.RS
.LP
Equivalent to pal(default, Format, [])\&.
.RE
.LP
.B
pal() -> term()
.br
.RS
.LP
Equivalent to pal(Category, Format, Args)\&.
.RE
.LP
.B
pal(Category, Format, Args) -> ok
.br
.RS
.TP
Types
Category = atom()
.br
Format = string()
.br
Args = list()
.br
.RE
.RS
.LP
Print and log from a testcase\&.
.LP
This function is meant for printing stuff from a testcase both in the log and on the console\&.
.LP
Default \fICategory\fR is \fIdefault\fR and default \fIArgs\fR is \fI[]\fR\&.
.RE
.LP
.B
parse_table(Data) -> {Heading, Table}
.br
.RS
.TP
Types
Data = [string()]
.br
Heading = tuple()
.br
Table = [tuple()]
.br
.RE
.RS
.LP
Parse the printout from an SQL table and return a list of tuples\&.
.LP
The printout to parse would typically be the result of a \fIselect\fR command in SQL\&. The returned \fITable\fR is a list of tuples, where each tuple is a row in the table\&.
.LP
\fIHeading\fR is a tuple of strings representing the headings of each column in the table\&.
.RE
.LP
.B
print(Format) -> ok
.br
.RS
.LP
Equivalent to print(default, Format, [])\&.
.RE
.LP
.B
print() -> term()
.br
.RS
.LP
Equivalent to print(Category, Format, Args)\&.
.RE
.LP
.B
print(Category, Format, Args) -> ok
.br
.RS
.TP
Types
Category = atom()
.br
Format = string()
.br
Args = list()
.br
.RE
.RS
.LP
Printout from a testcase to the console\&.
.LP
This function is meant for printing stuff from a testcase on the console\&.
.LP
Default \fICategory\fR is \fIdefault\fR and default \fIArgs\fR is \fI[]\fR\&.
.RE
.LP
.B
require(Required) -> ok | {error, Reason}
.br
.RS
.TP
Types
Required = Key | {Key, SubKeys}
.br
Key = atom()
.br
SubKeys = SubKey | [SubKey]
.br
SubKey = atom()
.br
.RE
.RS
.LP
Check if the required configuration is available\&.
.LP
Example: require the variable \fImyvar\fR:
.br
 \fIok = ct:require(myvar)\fR
.LP
In this case the config file must at least contain:

.nf
   {myvar,Value}\&.
.fi
.LP
Example: require the variable \fImyvar\fR with subvariable \fIsub1\fR:
.br
 \fIok = ct:require({myvar, sub1})\fR
.LP
In this case the config file must at least contain:

.nf
   {myvar,[{sub1,Value}]}\&.
.fi
.LP
\fISee also:\fR get_config/1, get_config/2, require/2\&.
.RE
.LP
.B
require(Name, Required) -> ok | {error, Reason}
.br
.RS
.TP
Types
Name = atom()
.br
Required = Key | {Key, SubKeys}
.br
Key = atom()
.br
SubKeys = SubKey | [SubKey]
.br
SubKey = atom()
.br
.RE
.RS
.LP
Check if the required configuration is available, and give it a name\&.
.LP
If the requested data is available, the main entry will be marked as allocated\&. An allocated element can only be used if the correct name is given\&. This means that to read the value of the element with \fIget_config/1, 2\fR, you need to provide the \fIName\fR instead of the \fIKey\fR\&.
.LP
Example: Require one node with a telnet connection and an ftp connection\&. Name the node \fIa\fR:
.br
 \fIok = ct:require(a, {node, [telnet, ftp]})\&.\fR
.br
 All references to this node must then use the node name\&. E\&.g\&. you can fetch a file over ftp like this:
.br
 \fIok = ct:ftp_get(a, RemoteFile, LocalFile)\&.\fR
.LP
For this to work, the config file must at least contain:

.nf
   {node,[{telnet,IpAddr},
          {ftp,IpAddr}]}\&.
.fi
.LP
\fISee also:\fR get_config/1, get_config/2, require/1\&.
.RE
.LP
.B
run(TestDirs) -> Result
.br
.RS
.TP
Types
TestDirs = TestDir | [TestDir]
.br
.RE
.RS
.LP
Run all testcases in all suites in the given directories\&.
.LP
\fISee also:\fR run/3\&.
.RE
.LP
.B
run(TestDir, Suite) -> Result
.br
.RS
.LP
Run all testcases in the given suite\&.
.LP
\fISee also:\fR run/3\&.
.RE
.LP
.B
run(TestDir, Suite, Cases) -> Result
.br
.RS
.TP
Types
TestDir = string()
.br
Suite = atom()
.br
Cases = atom() | [atom()]
.br
Result = [TestResult] | {error, Reason}
.br
.RE
.RS
.LP
Run the given testcase(s)\&.
.LP
Requires that \fIct:install/1\fR has been run first\&.
.LP
Suites (*_SUITE\&.erl) files must be stored in \fITestDir\fR or \fITestDir/test\fR\&. All suites will be compiled when test is run\&.
.RE
.LP
.B
run_test(Opts) -> Result
.br
.RS
.TP
Types
Opts = [OptTuples]
.br
OptTuples = {config, CfgFiles} | {dir, TestDirs} | {suite, Suites} | {testcase, Cases} | {spec, TestSpecs} | {allow_user_terms, Bool} | {logdir, LogDir} | {silent_connections, Conns} | {cover, CoverSpecFile} | {event_handler, EventHandlers} | {repeat, N} | {duration, DurTime} | {until, StopTime} | {force_stop, Bool}
.br
CfgFiles = [string()] | string()
.br
TestDirs = [string()] | string()
.br
Suites = [string()] | string()
.br
Cases = [atom()] | atom()
.br
TestSpecs = [string()] | string()
.br
LogDir = string()
.br
EventHandlers = EH | [EH]
.br
EH = atom() | {atom(), InitArgs} | {[atom()], InitArgs}
.br
InitArgs = [term()]
.br
Conns = all | [atom()]
.br
CoverSpecFile = string()
.br
N = integer()
.br
DurTime = string(HHMMSS)
.br
StopTime = string(YYMoMoDDHHMMSS) | string(HHMMSS)
.br
Result = [TestResult] | {error, Reason}
.br
.RE
.RS
.LP
Run tests as specified by the combination of options in \fIOpts\fR\&. The options are the same as those used with the \fIrun_test\fR script\&. Note that here a \fITestDir\fR can be used to point out the path to a \fISuite\fR\&. Note also that the option \fItestcase\fR corresponds to the \fI-case\fR option in the \fIrun_test\fR script\&. Configuration files specified in \fIOpts\fR will be installed automatically at startup\&.
.RE
.LP
.B
run_testspec(TestSpec) -> Result
.br
.RS
.TP
Types
TestSpec = [term()]
.br
.RE
.RS
.LP
Run test specified by \fITestSpec\fR\&. The terms are the same as those used in test specification files\&.
.RE
.LP
.B
start_interactive() -> ok
.br
.RS
.LP
Start CT in interactive mode\&.
.LP
From this mode all test case support functions can be executed directly from the erlang shell\&. The interactive mode can also be started from the unix command line with \fIrun_test -shell [-config File\&.\&.\&.]\fR\&.
.LP
If any functions using "required config data" (e\&.g\&. telnet or ftp functions) are to be called from the erlang shell, config data must first be required with \fIct:require/2\fR\&.
.LP
Example:
.br
 \fI> ct:require(a, {unix, [telnet]})\&.\fR
.br
\fIok\fR
.br
 \fI> ct:cmd(a, "ls")\&.\fR
.br
 \fI{ok, ["ls", "file1 \&.\&.\&.", \&.\&.\&.]}\fR
.RE
.LP
.B
step(TestDir, Suite, Case) -> Result
.br
.RS
.TP
Types
Case = atom()
.br
.RE
.RS
.LP
Step through a test case with the debugger\&.
.LP
\fISee also:\fR run/3\&.
.RE
.LP
.B
stop_interactive() -> ok
.br
.RS
.LP
Exit the interactive mode\&.
.LP
\fISee also:\fR start_interactive/0\&.
.RE
.LP
.B
testcases(TestDir, Suite) -> Testcases | {error, Reason}
.br
.RS
.TP
Types
TestDir = string()
.br
Suite = atom()
.br
Testcases = list()
.br
Reason = term()
.br
.RE
.RS
.LP
Returns all testcases in the specified suite\&.
.RE
.LP
.B
userdata(TestDir, Suite) -> SuiteUserData | {error, Reason}
.br
.RS
.TP
Types
TestDir = string()
.br
Suite = atom()
.br
SuiteUserData = [term()]
.br
Reason = term()
.br
.RE
.RS
.LP
Returns any data specified with the tag \fIuserdata\fR in the list of tuples returned from \fISuite:suite/0\fR\&.
.RE
.LP
.B
userdata(TestDir, Suite, Case) -> TCUserData | {error, Reason}
.br
.RS
.TP
Types
TestDir = string()
.br
Suite = atom()
.br
Case = atom()
.br
TCUserData = [term()]
.br
Reason = term()
.br
.RE
.RS
.LP
Returns any data specified with the tag \fIuserdata\fR in the list of tuples returned from \fISuite:Case/0\fR\&.
.RE