1BEAKERLIB(1) User Contributed Perl Documentation BEAKERLIB(1)
2
3
4
6 BeakerLib - a shell-level integration testing library
7
9 BeakerLib is a shell-level integration testing library, providing
10 convenience functions which simplify writing, running and analysis of
11 integration and blackbox tests.
12
13 The essential features include:
14
15 · Journal - uniform logging mechanism (logs & results saved in
16 flexible XML format, easy to compare results & generate reports)
17
18 · Phases - logical grouping of test actions, clear separation of
19 setup / test / cleanup (preventing false fails)
20
21 · Asserts - common checks affecting the overall results of the
22 individual phases (checking for exit codes, file existence &
23 content...)
24
25 · Helpers - convenience functions for common operations such as
26 managing services, backup & restore
27
28 The main script sets the "BEAKERLIB" variable and sources other scripts
29 where the actual functions are defined. You should source it at the
30 beginning of your test with:
31
32 . /usr/lib/beakerlib/beakerlib.sh
33
34 See the EXAMPLES section for quick start inspiration.
35
37 Journalling
38 rlJournalStart
39
40 Initialize the journal file.
41
42 rlJournalStart
43
44 Run on the very beginning of your script to initialize journalling
45 functionality.
46
47 rlJournalEnd
48
49 Summarize the test run and upload the journal file.
50
51 rlJournalEnd
52
53 Run on the very end of your script to print summary of the whole test
54 run, generate OUTPUTFILE and include journal in Beaker logs.
55
56 rlJournalPrint
57
58 Print the content of the journal in pretty xml format.
59
60 rlJournalPrint [type]
61
62 type
63 Can be either 'raw' or 'pretty', with the latter as a default.
64 Raw: xml is in raw form, no indentation etc Pretty: xml is pretty
65 printed, indented, with one record per line
66
67 Example:
68
69 <?xml version="1.0"?>
70 <BEAKER_TEST>
71 <test_id>debugging</test_id>
72 <package>setup</package>
73 <pkgdetails>setup-2.8.9-1.fc12.noarch</pkgdetails>
74 <starttime>2010-02-08 15:17:47</starttime>
75 <endtime>2010-02-08 15:17:47</endtime>
76 <testname>/examples/beakerlib/Sanity/simple</testname>
77 <release>Fedora release 12 (Constantine)</release>
78 <hostname>localhost</hostname>
79 <arch>i686</arch>
80 <purpose>PURPOSE of /examples/beakerlib/Sanity/simple
81 Description: Minimal BeakerLib sanity test
82 Author: Petr Splichal <psplicha@redhat.com>
83
84 This is a minimal sanity test for BeakerLib. It contains a single
85 phase with a couple of asserts. We Just check that the "setup"
86 package is installed and that there is a sane /etc/passwd file.
87 </purpose>
88 <log>
89 <phase endtime="2010-02-08 15:17:47" name="Test" result="PASS"
90 score="0" starttime="2010-02-08 15:17:47" type="FAIL">
91 <test message="Checking for the presence of setup rpm">PASS</test>
92 <test message="File /etc/passwd should exist">PASS</test>
93 <test message="File '/etc/passwd' should contain 'root'">PASS</test>
94 </phase>
95 </log>
96 </BEAKER_TEST>
97
98 rlJournalPrintText
99
100 Print the content of the journal in pretty text format.
101
102 rlJournalPrintText
103
104 Example:
105
106 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
107 :: [ LOG ] :: TEST PROTOCOL
108 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
109
110 :: [ LOG ] :: Test run ID : debugging
111 :: [ LOG ] :: Package : debugging
112 :: [ LOG ] :: Test started : 2010-02-08 14:45:57
113 :: [ LOG ] :: Test finished : 2010-02-08 14:45:58
114 :: [ LOG ] :: Test name :
115 :: [ LOG ] :: Distro: : Fedora release 12 (Constantine)
116 :: [ LOG ] :: Hostname : localhost
117 :: [ LOG ] :: Architecture : i686
118
119 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
120 :: [ LOG ] :: Test description
121 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
122
123 PURPOSE of /examples/beakerlib/Sanity/simple
124 Description: Minimal BeakerLib sanity test
125 Author: Petr Splichal <psplicha@redhat.com>
126
127 This is a minimal sanity test for BeakerLib. It contains a single
128 phase with a couple of asserts. We Just check that the "setup"
129 package is installed and that there is a sane /etc/passwd file.
130
131
132 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
133 :: [ LOG ] :: Test
134 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
135
136 :: [ PASS ] :: Checking for the presence of setup rpm
137 :: [ PASS ] :: File /etc/passwd should exist
138 :: [ PASS ] :: File '/etc/passwd' should contain 'root'
139 :: [ LOG ] :: Duration: 1s
140 :: [ LOG ] :: Assertions: 3 good, 0 bad
141 :: [ PASS ] :: RESULT: Test
142
143 Logging
144 rlLog
145
146 rlLogDebug
147
148 rlLogInfo
149
150 rlLogWarning
151
152 rlLogError
153
154 rlLogFatal
155
156 Create a time-labelled message in the log. There is a bunch of aliases
157 which can create messages formated as DEBUG/INFO/WARNING/ERROR or FATAL
158 (but you would probably want to use rlDie instead of the last one).
159
160 rlLog message [logfile] [priority]
161
162 message
163 Message you want to show (use quotes when invoking).
164
165 logfile
166 Log file. If not supplied, OUTPUTFILE is assumed.
167
168 priority
169 Priority of the log.
170
171 rlDie
172
173 Create a time-labelled message in the log, report test result, upload
174 logs, close unfinished phase and terminate the test.
175
176 rlDie message [file...]
177
178 message
179 Message you want to show (use quotes when invoking) - this option
180 is mandatory.
181
182 file
183 Files (logs) you want to upload as well. "rlBundleLogs" will be
184 used for it. Files which are not readable will be excluded before
185 calling "rlBundleLogs", so it is safe to call even with possibly
186 not existent logs and it will succeed.
187
188 rlBundleLogs
189
190 Create a tarball of files (e.g. logs) and attach them to the test
191 result.
192
193 rlBundleLogs package file [file...]
194
195 package
196 Name of the package. Will be used as a part of the tar-ball name.
197
198 file
199 File(s) to be packed and submitted.
200
201 Returns result of submiting the tarball.
202
203 rlFileSubmit
204
205 Resolves absolute path to the file, replaces / for - and uploads this
206 renamed file using rhts-submit-log. It also allows you to specify your
207 custom name for the uploaded file.
208
209 rlFileSubmit [-s sep] path_to_file [required_name]
210
211 -s sep
212 Sets separator (i.e. the replacement of the /) to sep.
213
214 path_to_file
215 Either absolute or relative path to file. Relative path is
216 converted to absolute.
217
218 required_name
219 Default behavior renames file to full_path_to_file with / replaced
220 for -, if this does not suit your needs, you can specify the name
221 using this option.
222
223 Examples:
224
225 rlFileSubmit logfile.txt -> logfile.txt cd /etc; rlFileSubmit
226 ./passwd -> etc-passwd rlFileSubmit /etc/passwd -> etc-passwd
227 rlFileSubmit /etc/passwd my-top-secret_file -> my-top-secret-file
228 rlFileSubmit -s '_' /etc/passwd -> etc_passwd
229
230 Info
231 rlShowPackageVersion
232
233 Shows a message about version of packages.
234
235 rlShowPackageVersion package [package...]
236
237 package
238 Name of a package(s) you want to log.
239
240 rlGetArch
241
242 Return base arch for the current system (good when you need base arch
243 on a multilib system).
244
245 rlGetArch
246
247 On an i686 system you will get i386, on a ppc64 you will get ppc.
248
249 rlGetDistroRelease
250
251 rlGetDistroVariant
252
253 Return release or variant of the distribution on the system.
254
255 rlGetDistroRelease
256 rlGetDistroVariant
257
258 For example on the RHEL-4-AS you will get release 4 and variant AS, on
259 the RHEL-5-Client you will get release 5 and variant Client.
260
261 rlShowRunningKernel
262
263 Log a message with version of the currently running kernel.
264
265 rlShowRunningKernel
266
267 Phases
268 rlPhaseStart
269
270 Starts a phase of a specific type. The final phase result is based on
271 all asserts included in the phase. Do not forget to end phase with
272 "rlPhaseEnd" when you are done.
273
274 rlPhaseStart type [name]
275
276 type
277 Type of the phase, one of the following:
278
279 ABORT
280 When assert fails in this phase, test will be aborted.
281
282 FAIL
283 When assert fails here, phase will report a FAIL.
284
285 WARN
286 When assert fails here, phase will report a WARN.
287
288 name
289 Optional name of the phase (if not provided, one will be
290 generated).
291
292 If all asserts included in the phase pass, phase reports PASS.
293
294 rlPhaseEnd
295
296 End current phase, summarize asserts included and report phase result.
297
298 rlPhaseEnd
299
300 Final phase result is based on included asserts and phase type.
301
302 rlPhaseStartSetup
303
304 rlPhaseStartTest
305
306 rlPhaseStartCleanup
307
308 Start a phase of the specified type: Setup -> ABORT, Test -> FAIL,
309 Cleanup -> WARN.
310
311 rlPhaseStartSetup [name]
312 rlPhaseStartTest [name]
313 rlPhaseStartCleanup [name]
314
315 name
316 Optional name of the phase. If not specified, default
317 Setup/Test/Cleanup are used.
318
319 If you do not want these shortcuts, use plain "rlPhaseStart" function.
320
321 Metric
322 rlLogMetricLow
323
324 Log a metric, which should be as low as possible to the journal.
325 (Example: memory consumption, run time)
326
327 rlLogMetricLow name value [tolerance]
328
329 name
330 Name of the metric. It has to be unique in a phase.
331
332 value
333 Value of the metric.
334
335 tolerance
336 It is used when comparing via rcw. It means how larger can the
337 second value be to not trigger a FAIL. Default is 0.2
338
339 When comparing FIRST, SECOND, then:
340
341 FIRST >= SECOND means PASS
342 FIRST+FIRST*tolerance >= SECOND means WARN
343 FIRST+FIRST*tolerance < SECOND means FAIL
344
345 Example: Simple benchmark is compared via this metric type in rcw. It
346 has a tolerance of 0.2. First run had 1 second. So:
347
348 For PASS, second run has to be better or equal to first.
349 So any value of second or less is a PASS.
350 For WARN, second run can be a little worse than first.
351 Tolerance is 0.2, so anything lower than 1.2 means WARN.
352 For FAIL, anything worse than 1.2 means FAIL.
353
354 rlLogMetricHigh
355
356 Log a metric, which should be as high as possible to the journal.
357 (Example: number of executions per second)
358
359 rlLogMetricHigh name value [tolerance]
360
361 name
362 Name of the metric. It has to be unique in a phase.
363
364 value
365 Value of the metric.
366
367 tolerance
368 It is used when comparing via rcw. It means how lower can the
369 second value be to not trigger a FAIL. Default is 0.2
370
371 When comparing FIRST, SECOND, then:
372
373 FIRST <= SECOND means PASS
374 FIRST+FIRST*tolerance <= SECOND means WARN
375 FIRST+FIRST*tolerance > SECOND means FAIL
376
377 Manual Asserts
378 rlPass
379
380 Manual assertion, asserts and logs PASS.
381
382 rlPass comment
383
384 comment
385 Short test summary.
386
387 Returns 0 and asserts PASS.
388
389 rlFail
390
391 Manual assertion, asserts and logs FAIL.
392
393 rlFail comment
394
395 comment
396 Short test summary.
397
398 Returns 1 and asserts FAIL.
399
400 Arithmetic Asserts
401 rlAssert0
402
403 Assertion checking for the equality of parameter to zero.
404
405 rlAssert0 comment value
406
407 comment
408 Short test summary, e.g. "Test if compilation ended successfully".
409
410 value
411 Integer value (usually return code of a command).
412
413 Returns 0 and asserts PASS when "value == 0".
414
415 rlAssertEquals
416
417 Assertion checking for the equality of two parameters.
418
419 rlAssertEquals comment value1 value2
420
421 comment
422 Short test summary, e.g. "Test if all 3 packages have been
423 downloaded".
424
425 value1
426 First parameter to compare, can be a number or a string
427
428 value2
429 Second parameter to compare, can be a number or a string
430
431 Returns 0 and asserts PASS when "value1 == value2".
432
433 rlAssertNotEquals
434
435 Assertion checking for the non-equality of two parameters.
436
437 rlAssertNotEquals comment value1 value2
438
439 comment
440 Short test summary, e.g. "Test if return code is not 139".
441
442 value1
443 First parameter to compare, can be a number or a string
444
445 value2
446 Second parameter to compare, can be a number or a string
447
448 Returns 0 and asserts PASS when "value1 != value2".
449
450 rlAssertGreater
451
452 Assertion checking whether first parameter is greater than the second
453 one.
454
455 rlAssertGreater comment value1 value2
456
457 comment
458 Short test summary, e.g. "Test whether there are running more
459 instances of program."
460
461 value1
462 Integer value.
463
464 value2
465 Integer value.
466
467 Returns 0 and asserts PASS when "value1 > value2".
468
469 rlAssertGreaterOrEqual
470
471 Assertion checking whether first parameter is greater or equal to the
472 second one.
473
474 rlAssertGreaterOrEqual comment value1 value2
475
476 comment
477 Short test summary (e.g. "There should present at least one...")
478
479 value1
480 Integer value.
481
482 value2
483 Integer value.
484
485 Returns 0 and asserts PASS when "value1 >= value2".
486
487 File Asserts
488 rlAssertExists
489
490 Assertion checking for the existence of a file.
491
492 rlAssertExists file
493
494 file
495 Path to the file.
496
497 Returns 0 and asserts PASS when "file" exists.
498
499 rlAssertNotExists
500
501 Assertion checking for the non-existence of a file.
502
503 rlAssertNotExists file
504
505 file
506 Path to the file.
507
508 Returns 0 and asserts PASS when "file" does not exist.
509
510 rlAssertGrep
511
512 Assertion checking if the file contains a pattern.
513
514 rlAssertGrep pattern file [options]
515
516 pattern
517 Regular expression to be searched for.
518
519 file
520 Path to the file.
521
522 options
523 Optional parameters to be passed to grep, default is "-q". Can be
524 used to perform case insensitive matches (-i), or using extended
525 (-E) or perl (-P) regular expressions.
526
527 Returns 0 and asserts PASS when "file" exists and contains given
528 "pattern".
529
530 rlAssertNotGrep
531
532 Assertion checking that the file does not contain a pattern.
533
534 rlAssertNotGrep pattern file [options]
535
536 pattern
537 Regular expression to be searched for.
538
539 file
540 Path to the file.
541
542 options
543 Optional parameters to be passed to grep, default is "-q". Can be
544 used to perform case insensitive matches (-i), or using extended
545 (-E) or perl (-P) regular expressions.
546
547 Returns 0 and asserts PASS when "file" exists and does not contain
548 given "pattern".
549
550 rlAssertDiffer
551
552 Assertion checking that two files differ (are not identical).
553
554 rlAssertDiffer file1 file2
555
556 file1
557 Path to first file1
558
559 file2
560 Path to second file
561
562 Returns 0 and asserts PASS when "file1" and "file2" differs.
563
564 rlAssertNotDiffer
565
566 Assertion checking that two files do not differ (are identical).
567
568 rlAssertNotDiffer file1 file2
569
570 file1
571 Path to first file1
572
573 file2
574 Path to second file
575
576 Returns 0 and asserts PASS when "file1" and "file2" do not differ.
577
578 Run, Watch, Report
579 rlRun
580
581 Run command with optional comment and make sure its exit code matches
582 expectations.
583
584 rlRun [-t] [-l] [-s] command [status[,status...]] [comment]
585
586 -t If specified, stdout and stderr of the command output will be
587 tagged with strigs 'STDOUT: ' and 'STDERR: '.
588
589 -l If specified, output of the command (tagged, if -t was specified)
590 is logged using rlLog function.
591
592 -s Store stdout and stderr to a file (mixed together, as the user
593 would see it on a terminal) and set $rlRun_LOG variable to name of
594 the file. Caller is responsible for removing the file. When -t
595 option is used, the content of the file becomes tagged too.
596
597 If the -s option is not used, $rlRun_LOG is not modified and keeps
598 its content from the last "rlRun -s".
599
600 command
601 Command to run.
602
603 status
604 Expected exit code(s). Optional, default 0. If you expect more exit
605 codes, separate them with comma (e.g. "0,1" when both 0 and 1 are
606 OK and expected), or use from-to notation (i.e. "2-5" for
607 "2,3,4,5"), or combine them (e.g. "2-4,26" for "2,3,4,26").
608
609 comment
610 Short summary describing the action (optional, but recommended -
611 explain what are you doing here).
612
613 Returns the exit code of the command run. Asserts PASS when command's
614 exit status is in the list of expected exit codes.
615
616 Note: The output of rlRun is buffered when using "-t", "-l" or "-s"
617 option (they use unix pipes, which are buffered by nature). If you need
618 an unbuffered output just make sure that "expect" package is installed
619 on your system (its "unbuffer" tool will automatically be used to
620 produce unbuffered output).
621
622 rlWatchdog
623
624 Run "command". If it does not finish in specified time, then kill it
625 using "signal".
626
627 rlWatchdog command timeout [signal]
628
629 command
630 Command to run.
631
632 timeout
633 Timeout to wait, in seconds.
634
635 signal
636 Signal to use (optional, default KILL).
637
638 Returns 0 if the command ends normally, without need to be killed.
639
640 rlReport
641
642 Report test result to the test harness. The command to be used for
643 reporting is set by the respective plugin. You can also use the
644 $BEAKERLIB_COMMAND_REPORT_RESULT variable to use your custom command.
645
646 rlReport name result [score] [log]
647
648 name
649 Name of the test result.
650
651 result
652 Result (one of PASS, WARN, FAIL). If called with something else,
653 will use WARN.
654
655 score
656 Test score (optional).
657
658 log Optional log file to be submitted instead of default "OUTPUTFILE".
659
660 Rpm Handling
661 rlCheckRpm
662
663 Check whether a package is installed.
664
665 rlCheckRpm name [version] [release] [arch]
666
667 name
668 Package name like "kernel"
669
670 version
671 Package version like 2.6.25.6
672
673 release
674 Package release like "55.fc9"
675
676 arch
677 Package architucture like "i386"
678
679 Returns 0 if the specified package is installed.
680
681 rlAssertRpm
682
683 Assertion making sure that a package is installed.
684
685 rlAssertRpm name [version] [release] [arch]>
686
687 name
688 Package name like "kernel"
689
690 version
691 Package version like 2.6.25.6
692
693 release
694 Package release like "55.fc9"
695
696 arch
697 Package architucture like "i386"
698
699 Returns 0 and asserts PASS if the specified package is installed.
700
701 rlAssertNotRpm
702
703 Assertion making sure that a package is not installed. This is just
704 inverse of "rlAssertRpm".
705
706 rlAssertNotRpm name [version] [release] [arch]>
707
708 name
709 Package name like "kernel"
710
711 version
712 Package version like 2.6.25.6
713
714 release
715 Package release like "55.fc9"
716
717 arch
718 Package architucture like "i386"
719
720 Returns 0 and asserts PASS if the specified package is not installed.
721
722 Example
723
724 Function "rlAssertRpm" is useful especially in prepare phase where it
725 causes abort if a package is missing, while "rlCheckRpm" is handy when
726 doing something like:
727
728 if ! rlCheckRpm package; then
729 yum install package
730 rlAssertRpm package
731 fi
732
733 Mounting
734 rlMount
735
736 Create mount point (if neccessary) and mount a NFS share.
737
738 rlMount server share mountpoint
739
740 server
741 NFS server hostname.
742
743 share
744 Shared directory name.
745
746 mountpoint
747 Local mount point.
748
749 Returns 0 if mounting the share was successful.
750
751 rlCheckMount
752
753 Check whether a share is mounted.
754
755 rlCheckMount server share mountpoint
756
757 server
758 NFS server hostname.
759
760 share
761 Shared directory name.
762
763 mountpoint
764 Local mount point.
765
766 Returns 0 when specified mount point exists and NFS share is mounted.
767
768 rlAssertMount
769
770 Assertion making sure that given NFS share is mounted.
771
772 rlAssertMount server share mountpoint
773
774 server
775 NFS server hostname.
776
777 share
778 Shared directory name.
779
780 mountpoint
781 Local mount point.
782
783 Returns 0 and asserts PASS when specified mount point exists and NFS
784 share is mounted.
785
786 Backup and Restore
787 rlFileBackup
788
789 Create a backup of files or directories (recursive). Can be used
790 multiple times to add more files to backup. Backing up an already
791 backed up file overwrites the original backup.
792
793 rlFileBackup [--clean] file [file...]
794
795 --clean
796 If this option is provided (have to be first option of the
797 command), then file/dir backuped using this command (provided in
798 next options) will be (resursively) removed before we will restore
799 it.
800
801 file
802 Files and/or directories to be backed up.
803
804 Returns 0 if the backup was successful.
805
806 Example with --clean:
807
808 touch cleandir/aaa
809 rlFileBackup --clean cleandir/
810 touch cleandir/bbb
811 ls cleandir/
812 aaa bbb
813 rlFileRestore
814 ls cleandir/
815 aaa
816
817 rlFileRestore
818
819 Restore backed up files to their original location. "rlFileRestore"
820 does not remove new files appearing after backup has been made. If you
821 don't want to leave anything behind just remove the whole original tree
822 before running "rlFileRestore", or see "--clean" option of
823 "rlFileBackup".
824
825 rlFileRestore
826
827 Returns 0 if backup dir is found and files are restored successfully.
828
829 Services
830 Following routines implement comfortable way how to start/stop system
831 services with the possibility to restore them to their original state
832 after testing.
833
834 rlServiceStart
835
836 Make sure the given "service" is running with fresh configuration.
837 (Start it if it's stopped and restart if it is already running.) In
838 addition, when called for the first time, the current state is saved so
839 that the "service" can be restored to its original state when testing
840 is finished, see "rlServiceRestore".
841
842 rlServiceStart service [service...]
843
844 service
845 Name of the service(s) to start.
846
847 Returns number of services which failed to start/restart; thus zero is
848 returned when everything is OK.
849
850 rlServiceStop
851
852 Make sure the given "service" is stopped. Stop it if it is running and
853 do nothing when it is already stopped. In addition, when called for the
854 first time, the current state is saved so that the "service" can be
855 restored to its original state when testing is finished, see
856 "rlServiceRestore".
857
858 rlServiceStop service [service...]
859
860 service
861 Name of the service(s) to stop.
862
863 Returns number of services which failed to become stopped; thus zero is
864 returned when everything is OK.
865
866 rlServiceRestore
867
868 Restore given "service" into its original state (before the first
869 "rlServiceStart" or "rlServiceStop" was called).
870
871 rlServiceRestore service [service...]
872
873 service
874 Name of the service(s) to restore to original state.
875
876 Returns number of services which failed to get back to their original
877 state; thus zero is returned when everything is OK.
878
879 Time Performance
880 rlPerfTime_RunsInTime
881
882 Measures, how many runs of some commands can be done in specified time.
883 This approach is suitable for short-time running tasks (up to few
884 seconds), where averaging few runs is not precise. This is done several
885 times, and the final result is the average of all runs. It prints the
886 number on stdout, so it has to be captured.
887
888 rlPerfTime_RunsInTime command [time] [runs]
889
890 command
891 Command to run.
892
893 time
894 Time in seconds (optional, default=30).
895
896 runs
897 Number of averaged runs (optional, default=3).
898
899 rlPerfTime_AvgFromRuns
900
901 Measures the average time of running some task. This approach is
902 suitable for long-time running tasks (tens of seconds and more), where
903 it is precise enough. Measured runs can be preceded by dry run, which
904 is not measured and it's purpose is to warm up various caches. It
905 prints the number on stdout, so it has to be captured. Or, result is
906 then stored in special rl_retval variable.
907
908 rlPerfTime_AvgFromRuns command [count] [warmup]
909
910 command
911 Command to run.
912
913 count
914 Times to run (optional, default=3).
915
916 warmup
917 Warm-up run, run if this option is not "warmup" (optional,
918 default="warmup")
919
920 Analyze
921 rlDejaSum
922
923 TODO description
924
925 rlDejaSum par1 par2
926
927 par1
928 TODO description
929
930 par2
931 TODO description
932
933 Return 0 if... TODO
934
935 Virtual X Server
936 Functions providing simple way how to start and stop virtual X server.
937
938 rlVirtualXStart
939
940 Start a virtual X server on a first free display. Tries only first N
941 displays, so you can run out of them.
942
943 rlVirtualXStart name
944
945 name
946 String identifying the X server.
947
948 Returns 0 when the server is started successfully.
949
950 rlVirtualXGetDisplay
951
952 Get the DISPLAY variable for specified virtual X server.
953
954 rlVirtualXGetDisplay name
955
956 name
957 String identifying the X server.
958
959 Displays the number of display where specified virtual X server is
960 running to standard output. Returns 0 on success.
961
962 rlVirtualXStop
963
964 Kill the specified X server.
965
966 rlVirtualXStop name
967
968 name
969 String identifying the X server.
970
971 Returns 0 when the server is stopped successfully.
972
973 Example
974
975 Below is a simple example of usage. Note that a lot of usefull
976 debugging information is reported on the DEBUG level, so you can run
977 your test with "DEBUG=1 make run" to get them.
978
979 rlVirtualXStart $TEST
980 rlAssert0 "Virtual X server started" $?
981 export DISPLAY="$( rlVirtualXGetDisplay $TEST )"
982 # ...your test which needs X...
983 rlVirtualXStop $TEST
984 rlAssert0 "Virtual X server killed" $?
985
986 These are "Requires" lines for your scripts - note different package
987 names for different RHEL versions:
988
989 @echo "Requires: xorg-x11-server-Xvfb" >> $(METADATA) # RHEL-5
990 @echo "Requires: xorg-x11-Xvfb" >> $(METADATA) # RHEL-4
991 @echo "Requires: XFree86-Xvfb" >> $(METADATA) # RHEL-3
992
994 Simple
995 A minimal BeakerLib test can look like this:
996
997 . /usr/lib/beakerlib/beakerlib.sh
998
999 rlJournalStart
1000 rlPhaseStartTest
1001 rlAssertRpm "setup"
1002 rlAssertExists "/etc/passwd"
1003 rlAssertGrep "root" "/etc/passwd"
1004 rlPhaseEnd
1005 rlJournalEnd
1006
1007 Phases
1008 Here comes a bit more interesting example of a test which sets all the
1009 recommended variables and makes use of the phases:
1010
1011 # Include the BeakerLib environment
1012 . /usr/lib/beakerlib/beakerlib.sh
1013
1014 # Set the full test name
1015 TEST="/examples/beakerlib/Sanity/phases"
1016
1017 # Package being tested
1018 PACKAGE="coreutils"
1019
1020 rlJournalStart
1021 # Setup phase: Prepare test directory
1022 rlPhaseStartSetup
1023 rlAssertRpm $PACKAGE
1024 rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
1025 rlRun "pushd $TmpDir"
1026 rlPhaseEnd
1027
1028 # Test phase: Testing touch, ls and rm commands
1029 rlPhaseStartTest
1030 rlRun "touch foo" 0 "Creating the foo test file"
1031 rlAssertExists "foo"
1032 rlRun "ls -l foo" 0 "Listing the foo test file"
1033 rlRun "rm foo" 0 "Removing the foo test file"
1034 rlAssertNotExists "foo"
1035 rlRun "ls -l foo" 2 "Listing foo should now report an error"
1036 rlPhaseEnd
1037
1038 # Cleanup phase: Remove test directory
1039 rlPhaseStartCleanup
1040 rlRun "popd"
1041 rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
1042 rlPhaseEnd
1043 rlJournalEnd
1044
1045 # Print the test report
1046 rlJournalPrintText
1047
1048 The ouput of the rlJournalPrintText command would produce an output
1049 similar to the following:
1050
1051 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1052 :: [ LOG ] :: TEST PROTOCOL
1053 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1054
1055 :: [ LOG ] :: Test run ID : debugging
1056 :: [ LOG ] :: Package : coreutils
1057 :: [ LOG ] :: Installed: : coreutils-7.6-9.fc12.i686
1058 :: [ LOG ] :: Test started : 2010-02-08 14:55:44
1059 :: [ LOG ] :: Test finished : 2010-02-08 14:55:50
1060 :: [ LOG ] :: Test name : /examples/beakerlib/Sanity/phases
1061 :: [ LOG ] :: Distro: : Fedora release 12 (Constantine)
1062 :: [ LOG ] :: Hostname : localhost
1063 :: [ LOG ] :: Architecture : i686
1064
1065 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1066 :: [ LOG ] :: Test description
1067 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1068
1069 PURPOSE of /examples/beakerlib/Sanity/phases
1070 Description: Testing BeakerLib phases
1071 Author: Petr Splichal <psplicha@redhat.com>
1072
1073 This example shows how the phases work in the BeakerLib on a
1074 trivial smoke test for the "touch", "ls" and "rm" commands from
1075 the coreutils package.
1076
1077
1078 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1079 :: [ LOG ] :: Setup
1080 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1081
1082 :: [ PASS ] :: Checking for the presence of coreutils rpm
1083 :: [ PASS ] :: Creating tmp directory
1084 :: [ PASS ] :: Running 'pushd /tmp/tmp.IcluQu5GVS'
1085 :: [ LOG ] :: Duration: 0s
1086 :: [ LOG ] :: Assertions: 3 good, 0 bad
1087 :: [ PASS ] :: RESULT: Setup
1088
1089 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1090 :: [ LOG ] :: Test
1091 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1092
1093 :: [ PASS ] :: Creating the foo test file
1094 :: [ PASS ] :: File foo should exist
1095 :: [ PASS ] :: Listing the foo test file
1096 :: [ PASS ] :: Removing the foo test file
1097 :: [ PASS ] :: File foo should not exist
1098 :: [ PASS ] :: Listing foo should now report an error
1099 :: [ LOG ] :: Duration: 1s
1100 :: [ LOG ] :: Assertions: 6 good, 0 bad
1101 :: [ PASS ] :: RESULT: Test
1102
1103 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1104 :: [ LOG ] :: Cleanup
1105 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1106
1107 :: [ PASS ] :: Running 'popd'
1108 :: [ PASS ] :: Removing tmp directory
1109 :: [ LOG ] :: Duration: 1s
1110 :: [ LOG ] :: Assertions: 2 good, 0 bad
1111 :: [ PASS ] :: RESULT: Cleanup
1112
1113 Note that the detailed test description is read from a separate file
1114 PURPOSE placed in the same directory as the test itself.
1115
1117 Project Page
1118 https://fedorahosted.org/beakerlib/
1119
1120 Manual
1121 https://fedorahosted.org/beakerlib/wiki/Manual
1122
1123 Reporting bugs
1124 TODO
1125
1127 · Petr Muller <pmuller@redhat.com>
1128
1129 · Ondrej Hudlicky <ohudlick@redhat.com>
1130
1131 · Jan Hutar <jhutar@redhat.com>
1132
1133 · Petr Splichal <psplicha@redhat.com>
1134
1135 · Ales Zelinka <azelinka@redhat.com>
1136
1137
1138
1139perl v5.10.1 2010-05-27 BEAKERLIB(1)