]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/developers/regression.tex
Add instructions for providing ~/.my.cnf and ~/.pgpass files to provide database...
[bacula/docs] / docs / manuals / en / developers / regression.tex
1 %%
2 %%
3
4 \chapter{Bacula Regression Testing}
5 \label{_ChapterStart8}
6 \index{Testing!Bacula Regression}
7 \index{Bacula Regression Testing}
8 \addcontentsline{toc}{section}{Bacula Regression Testing}
9
10 \section{Setting up Regession Testing}
11 \index{Setting up Regession Testing}
12 \addcontentsline{toc}{section}{Setting up Regression Testing}
13
14 This document is intended mostly for developers who wish to ensure that their
15 changes to Bacula don't introduce bugs in the base code.  However, you
16 don't need to be a developer to run the regression scripts, and we 
17 recommend them before putting your system into production, and before each
18 upgrade, especially if you build from source code.  They are
19 simply shell scripts that drive Bacula through bconsole and then typically
20 compare the input and output with {\bf diff}.
21
22 You can find the existing regression scripts in the Bacula developer's
23 {\bf git} repository on SourceForge.  We strongly recommend that you {\bf
24 clone} the repository because afterwards, you can easily get pull the
25 updates that have been made.
26
27 To get started, we recommend that you create a directory named {\bf
28 bacula}, under which you will put the current source code and the current
29 set of regression scripts.  Below, we will describe how to set this up.
30
31 The top level directory that we call {\bf bacula} can be named anything you
32 want.  Note, all the standard regression scripts run as non-root and can be
33 run on the same machine as a production Bacula system (the developers run
34 it this way).
35
36 To create the directory structure for the current trunk and to
37 clone the repository, do the following (note, we assume you
38 are working in your home directory in a non-root account):
39
40 \footnotesize
41 \begin{verbatim}
42 git clone git://bacula.git.sourceforge.net/gitroot/bacula/bacula bacula
43 \end{verbatim}
44 \normalsize
45
46 This will create the directory {\bf bacula} and populate it with
47 three directories: {\bf bacula}, {\bf gui}, and {\bf regress}.
48 {\bf bacula} contains the Bacula source code; {\bf gui} contains
49 certain gui programs that you will not need, and {\bf regress} contains
50 all the regression scripts.  The above should be needed only
51 once. Thereafter to update to the latest code, you do:
52
53 \footnotesize
54 \begin{verbatim}
55 cd bacula
56 git pull
57 \end{verbatim}
58 \normalsize
59
60 If you want to test with SQLite and it is not installed on your system,
61 you will need to download the latest depkgs release from Source Forge and       
62 unpack it into {\bf depkgs}, then simply: 
63
64 \footnotesize
65 \begin{verbatim}
66 cd depkgs
67 make
68 \end{verbatim}
69 \normalsize
70
71
72 There are two different aspects of regression testing that this document will
73 discuss: 1. Running the Regression Script, 2. Writing a Regression test. 
74
75 \section{Running the Regression Script}
76 \index{Running the Regression Script}
77 \index{Script!Running the Regression}
78 \addcontentsline{toc}{section}{Running the Regression Script}
79
80 There are a number of different tests that may be run, such as: the standard
81 set that uses disk Volumes and runs under any userid; a small set of tests
82 that write to tape; another set of tests where you must be root to run them.
83 Normally, I run all my tests as non-root and very rarely run the root
84 tests.  The tests vary in length, and running the full tests including disk
85 based testing, tape based testing, autochanger based testing, and multiple
86 drive autochanger based testing can take 3 or 4 hours.
87
88 \subsection{Setting the Configuration Parameters}
89 \index{Setting the Configuration Parameters}
90 \index{Parameters!Setting the Configuration}
91 \addcontentsline{toc}{subsection}{Setting the Configuration Parameters}
92
93 There is nothing you need to change in the source directory.  
94  
95 To begin:
96
97 \footnotesize
98 \begin{verbatim}
99 cd bacula/regress
100 \end{verbatim}
101 \normalsize
102
103
104 The        
105 very first time you are going to run the regression scripts, you will
106 need to create a custom config file for your system. 
107 We suggest that you start by:
108
109 \footnotesize
110 \begin{verbatim}
111 cp prototype.conf config
112 \end{verbatim}
113 \normalsize
114
115 Then you can edit the {\bf config} file directly.
116
117 \footnotesize
118 \begin{verbatim}
119                                                                                         
120 # Where to get the source to be tested
121 BACULA_SOURCE="${HOME}/bacula/bacula"
122
123 # Where to send email   !!!!! Change me !!!!!!!
124 EMAIL=your-name@your-domain.com
125 SMTP_HOST="localhost"
126
127 # Full "default" path where to find sqlite (no quotes!)
128 SQLITE3_DIR=${HOME}/depkgs/sqlite3
129 SQLITE_DIR=${HOME}/depkgs/sqlite
130
131 TAPE_DRIVE="/dev/nst0"
132 # if you don't have an autochanger set AUTOCHANGER to /dev/null
133 AUTOCHANGER="/dev/sg0"
134 # For two drive tests -- set to /dev/null if you do not have it 
135 TAPE_DRIVE1="/dev/null"
136
137 # This must be the path to the autochanger including its name
138 AUTOCHANGER_PATH="/usr/sbin/mtx"
139
140 # Set your database here
141 #WHICHDB="--with-sqlite=${SQLITE_DIR}"
142 #WHICHDB="--with-sqlite3=${SQLITE3_DIR}"
143 #WHICHDB="--with-mysql"
144 WHICHDB="--with-postgresql"
145
146 # Set this to "--with-tcp-wrappers" or "--without-tcp-wrappers"
147 TCPWRAPPERS="--with-tcp-wrappers"
148
149 # Set this to "" to disable OpenSSL support, "--with-openssl=yes"
150 # to enable it, or provide the path to the OpenSSL installation,
151 # eg "--with-openssl=/usr/local"
152 OPENSSL="--with-openssl"
153
154 # You may put your real host name here, but localhost is valid also
155 #  and it has the advantage that it works on a non-newtworked machine
156 HOST="localhost"
157                                                                                         
158 \end{verbatim}
159 \normalsize
160
161 \begin{itemize}
162 \item {\bf BACULA\_SOURCE} should be the full path to the Bacula source code 
163    that you wish to test. It will be loaded configured, compiled, and
164    installed with the "make setup" command, which needs to be done only
165    once each time you change the source code.
166
167 \item {\bf EMAIL} should be your email addres. Please remember  to change this
168    or I will get a flood of unwanted  messages. You may or may not want to see
169    these emails. In  my case, I don't need them so I direct it to the bit bucket.
170
171 \item {\bf SMTP\_HOST} defines where your SMTP server is.
172
173 \item {\bf SQLITE\_DIR} should be the full path to the sqlite package,  must
174    be build before running a Bacula regression, if you are  using SQLite. This
175    variable is ignored if you are using  MySQL or PostgreSQL. To use PostgreSQL,
176    edit the Makefile  and change (or add) WHICHDB?=``\verb{--{with-postgresql''.  For
177    MySQL use ``WHICHDB=''\verb{--{with-mysql``. 
178    
179    The advantage of using SQLite is that it is totally independent of any
180    installation you may have running on your system, and there is no
181    special configuration or authorization that must be done to run it.
182    With both MySQL and PostgreSQL, you must pre-install the packages,
183    initialize them and ensure that you have authorization to access the 
184    database and create and delete tables.
185
186 \item {\bf TAPE\_DRIVE} is the full path to your tape drive.  The base set of
187    regression tests do not use a tape, so this is only important if you want to
188    run the full tests. Set this to  /dev/null if you do not have a tape drive.
189
190 \item {\bf TAPE\_DRIVE1} is the full path to your second tape drive, if
191    have one. The base set of
192    regression tests do not use a tape, so  this is only important if you want to
193    run the full two drive tests.  Set this to  /dev/null if you do not have a
194    second tape drive.
195
196 \item {\bf AUTOCHANGER} is the name of your autochanger control device.  Set this to
197    /dev/null if you do not have an autochanger. 
198
199 \item {\bf AUTOCHANGER\_PATH} is the full path including the  program name for
200    your autochanger program (normally  {\bf mtx}. Leave the default value if you
201    do not have one. 
202
203 \item {\bf TCPWRAPPERS} defines whether or not you want the ./configure
204    to be performed with tcpwrappers enabled.
205
206 \item {\bf OPENSSL} used to enable/disable SSL support for Bacula
207    communications and data encryption.
208
209 \item {\bf HOST} is the hostname that it will use when building the
210    scripts. The Bacula daemons will be named <HOST>-dir, <HOST>-fd,
211    ... It is also the name of the HOST machine that to connect to the
212    daemons by the network.  Hence the name should either be your real
213    hostname (with an appropriate DNS or /etc/hosts entry) or {\bf
214    localhost} as it is in the default file.
215
216 \item {\bf bin} is the binary location.
217
218 \item {\bf scripts} is the bacula scripts location (where we could find
219   database creation script, autochanger handler, etc.)
220
221 \end{itemize}
222
223 \subsection{Building the Test Bacula}
224 \index{Building the Test Bacula}
225 \index{Bacula!Building the Test}
226 \addcontentsline{toc}{subsection}{Building the Test Bacula}
227
228 Once the above variables are set, you can build the setup by entering:
229
230 \footnotesize
231 \begin{verbatim}
232 make setup
233 \end{verbatim}
234 \normalsize
235
236 This will setup the regression testing and you should not need to
237 do this again unless you want to change the database or other regression
238 configuration parameters.
239
240
241 \subsection{Setting up your SQL engine}
242 \index{Setting up your SQL engine}
243 \addcontentsline{toc}{subsection}{Setting up your SQL engine}
244 If you are using SQLite or SQLite3, there is nothing more to do; you can   
245 simply run the tests as described in the next section.
246
247 If you are using MySQL or PostgreSQL, you will need to establish an
248 account with your database engine for the user name {\bf regress} and
249 you will need to manually create a database named {\bf regress} that can be
250 used by user name regress, which means you will have to give the user
251 regress sufficient permissions to use the database named regress.
252 There is no password on the regress account.
253
254 You have probably already done this procedure for the user name and
255 database named bacula.  If not, the manual describes roughly how to
256 do it, and the scripts in bacula/regress/build/src/cats named
257 create\_mysql\_database, create\_postgresql\_database, grant\_mysql\_privileges,
258 and grant\_postgresql\_privileges may be of a help to you.
259
260 Generally, to do the above, you will need to run under root to 
261 be able to create databases and modify permissions within MySQL and
262 PostgreSQL.
263
264 It is possible to configure MySQL access for database accounts that
265 require a password to be supplied. This can be done by creating a ~/.my.cnf
266 file which supplies the credentials by default to the MySQL commandline
267 utilities.
268
269 \begin{verbatim}
270 [client]
271 host     = localhost
272 user     = regress
273 password = asecret
274 \end{verbatim}
275
276 A similar technique can be used PostgreSQL regression testing where the
277 database is configured to require a password. The ~/.pgpass file should
278 contain a line with the database connection properties.
279
280 \begin{verbatim}
281 hostname:port:database:username:password
282 \end{verbatim}
283
284 \subsection{Running the Disk Only Regression}
285 \index{Regression!Running the Disk Only}
286 \index{Running the Disk Only Regression}
287 \addcontentsline{toc}{subsection}{Running the Disk Only Regression}
288
289 The simplest way to copy the source code, configure it, compile it, link
290 it, and run the tests is to use a helper script:
291
292 \footnotesize
293 \begin{verbatim}
294 ./do_disk
295 \end{verbatim}
296 \normalsize
297
298
299
300
301 This will run the base set of tests using disk Volumes.
302 If you are testing on a
303 non-Linux machine several of the of the tests may not be run.  In any case,
304 as we add new tests, the number will vary.  It will take about 1 hour
305 and you don't need to be root
306 to run these tests (I run under my regular userid).  The result should be
307 something similar to:
308
309 \footnotesize
310 \begin{verbatim}
311 Test results
312   ===== auto-label-test OK 12:31:33 =====
313   ===== backup-bacula-test OK 12:32:32 =====
314   ===== bextract-test OK 12:33:27 =====
315   ===== bscan-test OK 12:34:47 =====
316   ===== bsr-opt-test OK 12:35:46 =====
317   ===== compressed-test OK 12:36:52 =====
318   ===== compressed-encrypt-test OK 12:38:18 =====
319   ===== concurrent-jobs-test OK 12:39:49 =====
320   ===== data-encrypt-test OK 12:41:11 =====
321   ===== encrypt-bug-test OK 12:42:00 =====
322   ===== fifo-test OK 12:43:46 =====
323   ===== backup-bacula-fifo OK 12:44:54 =====
324   ===== differential-test OK 12:45:36 =====
325   ===== four-concurrent-jobs-test OK 12:47:39 =====
326   ===== four-jobs-test OK 12:49:22 =====
327   ===== incremental-test OK 12:50:38 =====
328   ===== query-test OK 12:51:37 =====
329   ===== recycle-test OK 12:53:52 =====
330   ===== restore2-by-file-test OK 12:54:53 =====
331   ===== restore-by-file-test OK 12:55:40 =====
332   ===== restore-disk-seek-test OK 12:56:29 =====
333   ===== six-vol-test OK 12:57:44 =====
334   ===== span-vol-test OK 12:58:52 =====
335   ===== sparse-compressed-test OK 13:00:00 =====
336   ===== sparse-test OK 13:01:04 =====
337   ===== two-jobs-test OK 13:02:39 =====
338   ===== two-vol-test OK 13:03:49 =====
339   ===== verify-vol-test OK 13:04:56 =====
340   ===== weird-files2-test OK 13:05:47 =====
341   ===== weird-files-test OK 13:06:33 =====
342   ===== migration-job-test OK 13:08:15 =====
343   ===== migration-jobspan-test OK 13:09:33 =====
344   ===== migration-volume-test OK 13:10:48 =====
345   ===== migration-time-test OK 13:12:59 =====
346   ===== hardlink-test OK 13:13:50 =====
347   ===== two-pool-test OK 13:18:17 =====
348   ===== fast-two-pool-test OK 13:24:02 =====
349   ===== two-volume-test OK 13:25:06 =====
350   ===== incremental-2disk OK 13:25:57 =====
351   ===== 2drive-incremental-2disk OK 13:26:53 =====
352   ===== scratch-pool-test OK 13:28:01 =====
353 Total time = 0:57:55 or 3475 secs
354
355 \end{verbatim}
356 \normalsize
357
358 and the working tape tests are run with
359
360 \footnotesize
361 \begin{verbatim}
362 make full_test
363 \end{verbatim}
364 \normalsize
365
366
367 \footnotesize
368 \begin{verbatim}
369 Test results
370   
371   ===== Bacula tape test OK =====
372   ===== Small File Size test OK =====
373   ===== restore-by-file-tape test OK =====
374   ===== incremental-tape test OK =====
375   ===== four-concurrent-jobs-tape OK =====
376   ===== four-jobs-tape OK =====
377 \end{verbatim}
378 \normalsize
379
380 Each separate test is self contained in that it initializes to run Bacula from
381 scratch (i.e. newly created database). It will also kill any Bacula session
382 that is currently running. In addition, it uses ports 8101, 8102, and 8103 so
383 that it does not intefere with a production system. 
384
385 Alternatively, you can do the ./do\_disk work by hand with:
386
387 \footnotesize
388 \begin{verbatim}
389 make setup
390 \end{verbatim}
391 \normalsize
392
393 The above will then copy the source code within
394 the regression tree (in directory regress/build), configure it, and build it.
395 There should be no errors. If there are, please correct them before
396 continuing. From this point on, as long as you don't change the Bacula
397 source code, you should not need to repeat any of the above steps.  If
398 you pull down a new version of the source code, simply run {\bf make setup}
399 again.
400
401
402 Once Bacula is built, you can run the basic disk only non-root regression test
403 by entering: 
404
405 \footnotesize
406 \begin{verbatim}
407 make test
408 \end{verbatim}
409 \normalsize
410
411
412 \subsection{Other Tests}
413 \index{Other Tests}
414 \index{Tests!Other}
415 \addcontentsline{toc}{subsection}{Other Tests}
416
417 There are a number of other tests that can be run as well. All the tests are a
418 simply shell script keep in the regress directory. For example the ''make
419 test`` simply executes {\bf ./all-non-root-tests}. The other tests, which
420 are invoked by directly running the script are:
421
422 \begin{description}
423
424 \item [all\_non-root-tests]
425    \index{all\_non-root-tests}
426    All non-tape tests not requiring root.  This is the standard set of tests,
427 that in general, backup some  data, then restore it, and finally compares the
428 restored data  with the original data.  
429
430 \item [all-root-tests]
431    \index{all-root-tests}
432    All non-tape tests requiring root permission.  These are a relatively small
433 number of tests that require running  as root. The amount of data backed up
434 can be quite large. For  example, one test backs up /usr, another backs up
435 /etc. One  or more of these tests reports an error -- I'll fix it one  day. 
436
437 \item [all-non-root-tape-tests]
438    \index{all-non-root-tape-tests}
439    All tape test not requiring root.  There are currently three tests, all run
440 without being root,  and backup to a tape. The first two tests use one volume,
441 and the third test requires an autochanger, and uses two  volumes. If you
442 don't have an autochanger, then this script  will probably produce an error. 
443
444 \item [all-tape-and-file-tests]
445    \index{all-tape-and-file-tests}
446    All tape and file tests not requiring  root. This includes just about
447 everything, and I don't run it  very often. 
448 \end{description}
449
450 \subsection{If a Test Fails}
451 \index{Fails!If a Test}
452 \index{If a Test Fails}
453 \addcontentsline{toc}{subsection}{If a Test Fails}
454
455 If you one or more tests fail, the line output will be similar to: 
456
457 \footnotesize
458 \begin{verbatim}
459   !!!!! concurrent-jobs-test failed!!! !!!!!
460 \end{verbatim}
461 \normalsize
462
463 If you want to determine why the test failed, you will need to rerun the
464 script with the debug output turned on.  You do so by defining the
465 environment variable {\bf REGRESS\_DEBUG} with commands such as:
466
467 \begin{verbatim}
468 REGRESS_DEBUG=1
469 export REGRESS_DEBUG
470 \end{verbatim}
471
472 Then from the "regress" directory (all regression scripts assume that
473 you have "regress" as the current directory), enter:
474
475 \begin{verbatim}
476 tests/test-name
477 \end{verbatim}
478
479 where test-name should be the name of a test script -- for example:
480 {\bf tests/backup-bacula-test}.
481
482 \section{Testing a Binary Installation}
483 \index{Test!Testing a Binary Installation}
484
485 If you have installed your Bacula from a binary release such as (rpms or debs),
486 you can still run regression tests on it.
487 First, make sure that your regression {\bf config} file uses the same catalog backend as
488 your installed binaries. Then define the variables \texttt{bin} and \texttt{scripts} variables
489 in your config file.
490
491 Example:
492 \begin{verbatim}
493 bin=/opt/bacula/bin
494 scripts=/opt/bacula/scripts
495 \end{verbatim}
496
497 The \texttt{./scripts/prepare-other-loc} will tweak the regress scripts to use
498 your binary location. You will need to run it manually once before you run any
499 regression tests.
500
501 \begin{verbatim}
502 $ ./scripts/prepare-other-loc
503 $ ./tests/backup-bacula-test
504 ...
505 \end{verbatim}
506
507 All regression scripts must be run by hand or by calling the test scripts.  
508 These are principally scripts that begin with {\bf all\_...} such as {\bf all\_disk\_tests},
509 {\bf ./all\_test} ...
510 None of the 
511 {\bf ./do\_disk}, {\bf ./do\_all}, {\bf ./nightly...}  scripts will work.
512
513 If you want to switch back to running the regression scripts from source, first
514 remove the {\bf bin} and {\bf scripts} variables from your {\bf config} file and
515 rerun the {\bf make setup} step.
516
517 \section{Running a Single Test}
518 \index{Running a Single Test}
519 \addcontentsline{toc}{section}{Running a Single Test}
520
521 If you wish to run a single test, you can simply:
522
523 \begin{verbatim}
524 cd regress
525 tests/<name-of-test>
526 \end{verbatim}
527
528 or, if the source code has been updated, you would do:
529
530 \begin{verbatim}
531 cd bacula
532 git pull
533 cd regress
534 make setup
535 tests/backup-to-null
536 \end{verbatim}
537
538
539 \section{Writing a Regression Test}
540 \index{Test!Writing a Regression}
541 \index{Writing a Regression Test}
542 \addcontentsline{toc}{section}{Writing a Regression Test}
543
544 Any developer, who implements a major new feature, should write a regression
545 test that exercises and validates the new feature. Each regression test is a
546 complete test by itself. It terminates any running Bacula, initializes the
547 database, starts Bacula, then runs the test by using the console program. 
548
549 \subsection{Running the Tests by Hand}
550 \index{Hand!Running the Tests by}
551 \index{Running the Tests by Hand}
552 \addcontentsline{toc}{subsection}{Running the Tests by Hand}
553
554 You can run any individual test by hand by cd'ing to the {\bf regress}
555 directory and entering: 
556
557 \footnotesize
558 \begin{verbatim}
559 tests/<test-name>
560 \end{verbatim}
561 \normalsize
562
563 \subsection{Directory Structure}
564 \index{Structure!Directory}
565 \index{Directory Structure}
566 \addcontentsline{toc}{subsection}{Directory Structure}
567
568 The directory structure of the regression tests is: 
569
570 \footnotesize
571 \begin{verbatim}
572   regress                - Makefile, scripts to start tests
573     |------ scripts      - Scripts and conf files
574     |-------tests        - All test scripts are here
575     |
576     |------------------ -- All directories below this point are used
577     |                       for testing, but are created from the
578     |                       above directories and are removed with
579     |                       "make distclean"
580     |
581     |------ bin          - This is the install directory for
582     |                        Bacula to be used testing
583     |------ build        - Where the Bacula source build tree is
584     |------ tmp          - Most temp files go here
585     |------ working      - Bacula working directory
586     |------ weird-files  - Weird files used in two of the tests.
587 \end{verbatim}
588 \normalsize
589
590 \subsection{Adding a New Test}
591 \index{Adding a New Test}
592 \index{Test!Adding a New}
593 \addcontentsline{toc}{subsection}{Adding a New Test}
594
595 If you want to write a new regression test, it is best to start with one of
596 the existing test scripts, and modify it to do the new test. 
597
598 When adding a new test, be extremely careful about adding anything to any of
599 the daemons' configuration files. The reason is that it may change the prompts
600 that are sent to the console. For example, adding a Pool means that the
601 current scripts, which assume that Bacula automatically selects a Pool, will
602 now be presented with a new prompt, so the test will fail. If you need to
603 enhance the configuration files, consider making your own versions. 
604
605 \subsection{Running a Test Under The Debugger}
606 \index{Debugger}
607 \addcontentsline{toc}{subsection}{Running a Test Under The Debugger}
608 You can run a test under the debugger (actually run a Bacula daemon
609 under the debugger) by first setting the environment variable
610 {\bf REGRESS\_WAIT} with commands such as:
611
612 \begin{verbatim}
613 REGRESS_WAIT=1
614 export REGRESS_WAIT
615 \end{verbatim}
616
617 Then executing the script.  When the script prints the following line:
618
619 \begin{verbatim}
620 Start Bacula under debugger and enter anything when ready ...
621 \end{verbatim}
622
623 You start the Bacula component you want to run under the debugger in a
624 different shell window.  For example:
625
626 \begin{verbatim}
627 cd .../regress/bin
628 gdb bacula-sd 
629 (possibly set breakpoints, ...)
630 run -s -f
631 \end{verbatim}
632
633 Then enter any character in the window with the above message. 
634 An error message will appear saying that the daemon you are debugging
635 is already running, which is the case. You can simply ignore the
636 error message.