4 \chapter{Bacula Regression Testing}
6 \index{Testing!Bacula Regression}
7 \index{Bacula Regression Testing}
8 \addcontentsline{toc}{section}{Bacula Regression Testing}
12 \addcontentsline{toc}{section}{General}
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}.
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.
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.
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
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):
43 git clone git://bacula.git.sourceforge.net/gitroot/bacula bacula
47 This will create the directory {\bf bacula} and populate it with
48 three directories: {\bf bacula}, {\bf gui}, and {\bf regress}.
49 {\bf bacula} contains the Bacula source code; {\bf gui} contains
50 certain gui programs that you will not need, and {\bf regress} contains
51 all the regression scripts. The above should be needed only
52 once. Thereafter to update to the latest code, you do:
61 If you want to test with SQLite and it is not installed on your system,
62 you will need to download the latest depkgs release from Source Forge and
63 unpack it into {\bf depkgs}, then simply:
73 There are two different aspects of regression testing that this document will
74 discuss: 1. Running the Regression Script, 2. Writing a Regression test.
76 \section{Running the Regression Script}
77 \index{Running the Regression Script}
78 \index{Script!Running the Regression}
79 \addcontentsline{toc}{section}{Running the Regression Script}
81 There are a number of different tests that may be run, such as: the standard
82 set that uses disk Volumes and runs under any userid; a small set of tests
83 that write to tape; another set of tests where you must be root to run them.
84 Normally, I run all my tests as non-root and very rarely run the root
85 tests. The tests vary in length, and running the full tests including disk
86 based testing, tape based testing, autochanger based testing, and multiple
87 drive autochanger based testing can take 3 or 4 hours.
89 \subsection{Setting the Configuration Parameters}
90 \index{Setting the Configuration Parameters}
91 \index{Parameters!Setting the Configuration}
92 \addcontentsline{toc}{subsection}{Setting the Configuration Parameters}
94 There is nothing you need to change in the source directory.
106 very first time you are going to run the regression scripts, you will
107 need to create a custom config file for your system.
108 We suggest that you start by:
112 cp prototype.conf config
116 Then you can edit the {\bf config} file directly.
121 # Where to get the source to be tested
122 BACULA_SOURCE="${HOME}/bacula/bacula"
124 # Where to send email !!!!! Change me !!!!!!!
125 EMAIL=your-name@your-domain.com
126 SMTP_HOST="localhost"
128 # Full "default" path where to find sqlite (no quotes!)
129 SQLITE3_DIR=${HOME}/depkgs/sqlite3
130 SQLITE_DIR=${HOME}/depkgs/sqlite
132 TAPE_DRIVE="/dev/nst0"
133 # if you don't have an autochanger set AUTOCHANGER to /dev/null
134 AUTOCHANGER="/dev/sg0"
135 # For two drive tests -- set to /dev/null if you do not have it
136 TAPE_DRIVE1="/dev/null"
138 # This must be the path to the autochanger including its name
139 AUTOCHANGER_PATH="/usr/sbin/mtx"
141 # Set your database here
142 #WHICHDB="--with-sqlite=${SQLITE_DIR}"
143 #WHICHDB="--with-sqlite3=${SQLITE3_DIR}"
144 #WHICHDB="--with-mysql"
145 WHICHDB="--with-postgresql"
147 # Set this to "--with-tcp-wrappers" or "--without-tcp-wrappers"
148 TCPWRAPPERS="--with-tcp-wrappers"
150 # Set this to "" to disable OpenSSL support, "--with-openssl=yes"
151 # to enable it, or provide the path to the OpenSSL installation,
152 # eg "--with-openssl=/usr/local"
153 OPENSSL="--with-openssl"
155 # You may put your real host name here, but localhost is valid also
156 # and it has the advantage that it works on a non-newtworked machine
163 \item {\bf BACULA\_SOURCE} should be the full path to the Bacula source code
164 that you wish to test. It will be loaded configured, compiled, and
165 installed with the "make setup" command, which needs to be done only
166 once each time you change the source code.
168 \item {\bf EMAIL} should be your email addres. Please remember to change this
169 or I will get a flood of unwanted messages. You may or may not want to see
170 these emails. In my case, I don't need them so I direct it to the bit bucket.
172 \item {\bf SMTP\_HOST} defines where your SMTP server is.
174 \item {\bf SQLITE\_DIR} should be the full path to the sqlite package, must
175 be build before running a Bacula regression, if you are using SQLite. This
176 variable is ignored if you are using MySQL or PostgreSQL. To use PostgreSQL,
177 edit the Makefile and change (or add) WHICHDB?=``\verb{--{with-postgresql''. For
178 MySQL use ``WHICHDB=''\verb{--{with-mysql``.
180 The advantage of using SQLite is that it is totally independent of any
181 installation you may have running on your system, and there is no
182 special configuration or authorization that must be done to run it.
183 With both MySQL and PostgreSQL, you must pre-install the packages,
184 initialize them and ensure that you have authorization to access the
185 database and create and delete tables.
187 \item {\bf TAPE\_DRIVE} is the full path to your tape drive. The base set of
188 regression tests do not use a tape, so this is only important if you want to
189 run the full tests. Set this to /dev/null if you do not have a tape drive.
191 \item {\bf TAPE\_DRIVE1} is the full path to your second tape drive, if
192 have one. The base set of
193 regression tests do not use a tape, so this is only important if you want to
194 run the full two drive tests. Set this to /dev/null if you do not have a
197 \item {\bf AUTOCHANGER} is the name of your autochanger control device. Set this to
198 /dev/null if you do not have an autochanger.
200 \item {\bf AUTOCHANGER\_PATH} is the full path including the program name for
201 your autochanger program (normally {\bf mtx}. Leave the default value if you
204 \item {\bf TCPWRAPPERS} defines whether or not you want the ./configure
205 to be performed with tcpwrappers enabled.
207 \item {\bf OPENSSL} used to enable/disable SSL support for Bacula
208 communications and data encryption.
210 \item {\bf HOST} is the hostname that it will use when building the
211 scripts. The Bacula daemons will be named <HOST>-dir, <HOST>-fd,
212 ... It is also the name of the HOST machine that to connect to the
213 daemons by the network. Hence the name should either be your real
214 hostname (with an appropriate DNS or /etc/hosts entry) or {\bf
215 localhost} as it is in the default file.
217 \item {\bf bin} is the binary location.
219 \item {\bf scripts} is the bacula scripts location (where we could find
220 database creation script, autochanger handler, etc.)
224 \subsection{Building the Test Bacula}
225 \index{Building the Test Bacula}
226 \index{Bacula!Building the Test}
227 \addcontentsline{toc}{subsection}{Building the Test Bacula}
229 Once the above variables are set, you can build the Makefile by entering:
237 Where xxx.conf is the name of the conf file containing your system parameters.
238 This will build a Makefile from Makefile.in, and you should not need to
239 do this again unless you want to change the database or other regression
240 configuration parameter.
243 \subsection{Setting up your SQL engine}
244 \index{Setting up your SQL engine}
245 \addcontentsline{toc}{subsection}{Setting up your SQL engine}
246 If you are using SQLite or SQLite3, there is nothing more to do; you can
247 simply run the tests as described in the next section.
249 If you are using MySQL or PostgreSQL, you will need to establish an
250 account with your database engine for the user name {\bf regress} and
251 you will need to manually create a database named {\bf regress} that can be
252 used by user name regress, which means you will have to give the user
253 regress sufficient permissions to use the database named regress.
254 There is no password on the regress account.
256 You have probably already done this procedure for the user name and
257 database named bacula. If not, the manual describes roughly how to
258 do it, and the scripts in bacula/regress/build/src/cats named
259 create\_mysql\_database, create\_postgresql\_database, grant\_mysql\_privileges,
260 and grant\_postgresql\_privileges may be of a help to you.
262 Generally, to do the above, you will need to run under root to
263 be able to create databases and modify permissions within MySQL and
267 \subsection{Running the Disk Only Regression}
268 \index{Regression!Running the Disk Only}
269 \index{Running the Disk Only Regression}
270 \addcontentsline{toc}{subsection}{Running the Disk Only Regression}
272 The simplest way to copy the source code, configure it, compile it, link
273 it, and run the tests is to use a helper script:
284 This will run the base set of tests using disk Volumes.
285 If you are testing on a
286 non-Linux machine several of the of the tests may not be run. In any case,
287 as we add new tests, the number will vary. It will take about 1 hour
288 and you don't need to be root
289 to run these tests (I run under my regular userid). The result should be
290 something similar to:
295 ===== auto-label-test OK 12:31:33 =====
296 ===== backup-bacula-test OK 12:32:32 =====
297 ===== bextract-test OK 12:33:27 =====
298 ===== bscan-test OK 12:34:47 =====
299 ===== bsr-opt-test OK 12:35:46 =====
300 ===== compressed-test OK 12:36:52 =====
301 ===== compressed-encrypt-test OK 12:38:18 =====
302 ===== concurrent-jobs-test OK 12:39:49 =====
303 ===== data-encrypt-test OK 12:41:11 =====
304 ===== encrypt-bug-test OK 12:42:00 =====
305 ===== fifo-test OK 12:43:46 =====
306 ===== backup-bacula-fifo OK 12:44:54 =====
307 ===== differential-test OK 12:45:36 =====
308 ===== four-concurrent-jobs-test OK 12:47:39 =====
309 ===== four-jobs-test OK 12:49:22 =====
310 ===== incremental-test OK 12:50:38 =====
311 ===== query-test OK 12:51:37 =====
312 ===== recycle-test OK 12:53:52 =====
313 ===== restore2-by-file-test OK 12:54:53 =====
314 ===== restore-by-file-test OK 12:55:40 =====
315 ===== restore-disk-seek-test OK 12:56:29 =====
316 ===== six-vol-test OK 12:57:44 =====
317 ===== span-vol-test OK 12:58:52 =====
318 ===== sparse-compressed-test OK 13:00:00 =====
319 ===== sparse-test OK 13:01:04 =====
320 ===== two-jobs-test OK 13:02:39 =====
321 ===== two-vol-test OK 13:03:49 =====
322 ===== verify-vol-test OK 13:04:56 =====
323 ===== weird-files2-test OK 13:05:47 =====
324 ===== weird-files-test OK 13:06:33 =====
325 ===== migration-job-test OK 13:08:15 =====
326 ===== migration-jobspan-test OK 13:09:33 =====
327 ===== migration-volume-test OK 13:10:48 =====
328 ===== migration-time-test OK 13:12:59 =====
329 ===== hardlink-test OK 13:13:50 =====
330 ===== two-pool-test OK 13:18:17 =====
331 ===== fast-two-pool-test OK 13:24:02 =====
332 ===== two-volume-test OK 13:25:06 =====
333 ===== incremental-2disk OK 13:25:57 =====
334 ===== 2drive-incremental-2disk OK 13:26:53 =====
335 ===== scratch-pool-test OK 13:28:01 =====
336 Total time = 0:57:55 or 3475 secs
341 and the working tape tests are run with
354 ===== Bacula tape test OK =====
355 ===== Small File Size test OK =====
356 ===== restore-by-file-tape test OK =====
357 ===== incremental-tape test OK =====
358 ===== four-concurrent-jobs-tape OK =====
359 ===== four-jobs-tape OK =====
363 Each separate test is self contained in that it initializes to run Bacula from
364 scratch (i.e. newly created database). It will also kill any Bacula session
365 that is currently running. In addition, it uses ports 8101, 8102, and 8103 so
366 that it does not intefere with a production system.
368 Alternatively, you can do the ./do\_disk work by hand with:
376 The above will then copy the source code within
377 the regression tree (in directory regress/build), configure it, and build it.
378 There should be no errors. If there are, please correct them before
379 continuing. From this point on, as long as you don't change the Bacula
380 source code, you should not need to repeat any of the above steps. If
381 you pull down a new version of the source code, simply run {\bf make setup}
385 Once Bacula is built, you can run the basic disk only non-root regression test
395 \subsection{Other Tests}
398 \addcontentsline{toc}{subsection}{Other Tests}
400 There are a number of other tests that can be run as well. All the tests are a
401 simply shell script keep in the regress directory. For example the ''make
402 test`` simply executes {\bf ./all-non-root-tests}. The other tests, which
403 are invoked by directly running the script are:
407 \item [all\_non-root-tests]
408 \index{all\_non-root-tests}
409 All non-tape tests not requiring root. This is the standard set of tests,
410 that in general, backup some data, then restore it, and finally compares the
411 restored data with the original data.
413 \item [all-root-tests]
414 \index{all-root-tests}
415 All non-tape tests requiring root permission. These are a relatively small
416 number of tests that require running as root. The amount of data backed up
417 can be quite large. For example, one test backs up /usr, another backs up
418 /etc. One or more of these tests reports an error -- I'll fix it one day.
420 \item [all-non-root-tape-tests]
421 \index{all-non-root-tape-tests}
422 All tape test not requiring root. There are currently three tests, all run
423 without being root, and backup to a tape. The first two tests use one volume,
424 and the third test requires an autochanger, and uses two volumes. If you
425 don't have an autochanger, then this script will probably produce an error.
427 \item [all-tape-and-file-tests]
428 \index{all-tape-and-file-tests}
429 All tape and file tests not requiring root. This includes just about
430 everything, and I don't run it very often.
433 \subsection{If a Test Fails}
434 \index{Fails!If a Test}
435 \index{If a Test Fails}
436 \addcontentsline{toc}{subsection}{If a Test Fails}
438 If you one or more tests fail, the line output will be similar to:
442 !!!!! concurrent-jobs-test failed!!! !!!!!
446 If you want to determine why the test failed, you will need to rerun the
447 script with the debug output turned on. You do so by defining the
448 environment variable {\bf REGRESS\_DEBUG} with commands such as:
455 Then from the "regress" directory (all regression scripts assume that
456 you have "regress" as the current directory), enter:
462 where test-name should be the name of a test script -- for example:
463 {\bf tests/backup-bacula-test}.
465 \section{Testing a Binary Installation}
466 \index{Test!Testing a Binary Installation}
468 If you have installed your Bacula from a binary release such as (rpms or debs),
469 you can still run regression tests on it.
470 First, make sure that your regression {\bf config} file uses the same catalog backend as
471 your installed binaries. Then define the variables \texttt{bin} and \texttt{scripts} variables
477 scripts=/opt/bacula/scripts
480 The \texttt{./scripts/prepare-other-loc} will tweak the regress scripts to use
481 your binary location. You will need to run it manually once before you run any
485 $ ./scripts/prepare-other-loc
486 $ ./tests/backup-bacula-test
490 All regression scripts must be run by hand or by calling the test scripts.
491 These are principally scripts that begin with {\bf all\_...} such as {\bf all\_disk\_tests},
492 {\bf ./all\_test} ...
494 {\bf ./do\_disk}, {\bf ./do\_all}, {\bf ./nightly...} scripts will work.
496 If you want to switch back to running the regression scripts from source, first
497 remove the {\bf bin} and {\bf scripts} variables from your {\bf config} file and
498 rerun the {\bf make setup} step.
500 \section{Running a Single Test}
501 \index{Running a Single Test}
502 \addcontentsline{toc}{section}{Running a Single Test}
504 If you wish to run a single test, you can simply:
511 or, if the source code has been updated, you would do:
522 \section{Writing a Regression Test}
523 \index{Test!Writing a Regression}
524 \index{Writing a Regression Test}
525 \addcontentsline{toc}{section}{Writing a Regression Test}
527 Any developer, who implements a major new feature, should write a regression
528 test that exercises and validates the new feature. Each regression test is a
529 complete test by itself. It terminates any running Bacula, initializes the
530 database, starts Bacula, then runs the test by using the console program.
532 \subsection{Running the Tests by Hand}
533 \index{Hand!Running the Tests by}
534 \index{Running the Tests by Hand}
535 \addcontentsline{toc}{subsection}{Running the Tests by Hand}
537 You can run any individual test by hand by cd'ing to the {\bf regress}
538 directory and entering:
546 \subsection{Directory Structure}
547 \index{Structure!Directory}
548 \index{Directory Structure}
549 \addcontentsline{toc}{subsection}{Directory Structure}
551 The directory structure of the regression tests is:
555 regress - Makefile, scripts to start tests
556 |------ scripts - Scripts and conf files
557 |-------tests - All test scripts are here
559 |------------------ -- All directories below this point are used
560 | for testing, but are created from the
561 | above directories and are removed with
564 |------ bin - This is the install directory for
565 | Bacula to be used testing
566 |------ build - Where the Bacula source build tree is
567 |------ tmp - Most temp files go here
568 |------ working - Bacula working directory
569 |------ weird-files - Weird files used in two of the tests.
573 \subsection{Adding a New Test}
574 \index{Adding a New Test}
575 \index{Test!Adding a New}
576 \addcontentsline{toc}{subsection}{Adding a New Test}
578 If you want to write a new regression test, it is best to start with one of
579 the existing test scripts, and modify it to do the new test.
581 When adding a new test, be extremely careful about adding anything to any of
582 the daemons' configuration files. The reason is that it may change the prompts
583 that are sent to the console. For example, adding a Pool means that the
584 current scripts, which assume that Bacula automatically selects a Pool, will
585 now be presented with a new prompt, so the test will fail. If you need to
586 enhance the configuration files, consider making your own versions.
588 \subsection{Running a Test Under The Debugger}
590 \addcontentsline{toc}{subsection}{Running a Test Under The Debugger}
591 You can run a test under the debugger (actually run a Bacula daemon
592 under the debugger) by first setting the environment variable
593 {\bf REGRESS\_WAIT} with commands such as:
600 Then executing the script. When the script prints the following line:
603 Start Bacula under debugger and enter anything when ready ...
606 You start the Bacula component you want to run under the debugger in a
607 different shell window. For example:
612 (possibly set breakpoints, ...)
616 Then enter any character in the window with the above message.
617 An error message will appear saying that the daemon you are debugging
618 is already running, which is the case. You can simply ignore the