4 \chapter{Bacula Regression Testing}
6 \index{Testing!Bacula Regression}
7 \index{Bacula Regression Testing}
8 \addcontentsline{toc}{section}{Bacula Regression Testing}
10 \section{Setting up Regession Testing}
11 \index{Setting up Regession Testing}
12 \addcontentsline{toc}{section}{Setting up Regression Testing}
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):
42 git clone git://bacula.git.sourceforge.net/gitroot/bacula/bacula bacula
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:
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:
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.
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}
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.
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}
93 There is nothing you need to change in the source directory.
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:
111 cp prototype.conf config
115 Then you can edit the {\bf config} file directly.
120 # Where to get the source to be tested
121 BACULA_SOURCE="${HOME}/bacula/bacula"
123 # Where to send email !!!!! Change me !!!!!!!
124 EMAIL=your-name@your-domain.com
125 SMTP_HOST="localhost"
127 # Full "default" path where to find sqlite (no quotes!)
128 SQLITE3_DIR=${HOME}/depkgs/sqlite3
129 SQLITE_DIR=${HOME}/depkgs/sqlite
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"
137 # This must be the path to the autochanger including its name
138 AUTOCHANGER_PATH="/usr/sbin/mtx"
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"
146 # Set this to "--with-tcp-wrappers" or "--without-tcp-wrappers"
147 TCPWRAPPERS="--with-tcp-wrappers"
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"
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
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.
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.
171 \item {\bf SMTP\_HOST} defines where your SMTP server is.
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``.
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.
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.
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
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.
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
203 \item {\bf TCPWRAPPERS} defines whether or not you want the ./configure
204 to be performed with tcpwrappers enabled.
206 \item {\bf OPENSSL} used to enable/disable SSL support for Bacula
207 communications and data encryption.
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.
216 \item {\bf bin} is the binary location.
218 \item {\bf scripts} is the bacula scripts location (where we could find
219 database creation script, autochanger handler, etc.)
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}
228 Once the above variables are set, you can build the Makefile by entering:
236 Where xxx.conf is the name of the conf file containing your system parameters.
237 This will build a Makefile from Makefile.in, and you should not need to
238 do this again unless you want to change the database or other regression
239 configuration parameter.
242 \subsection{Setting up your SQL engine}
243 \index{Setting up your SQL engine}
244 \addcontentsline{toc}{subsection}{Setting up your SQL engine}
245 If you are using SQLite or SQLite3, there is nothing more to do; you can
246 simply run the tests as described in the next section.
248 If you are using MySQL or PostgreSQL, you will need to establish an
249 account with your database engine for the user name {\bf regress} and
250 you will need to manually create a database named {\bf regress} that can be
251 used by user name regress, which means you will have to give the user
252 regress sufficient permissions to use the database named regress.
253 There is no password on the regress account.
255 You have probably already done this procedure for the user name and
256 database named bacula. If not, the manual describes roughly how to
257 do it, and the scripts in bacula/regress/build/src/cats named
258 create\_mysql\_database, create\_postgresql\_database, grant\_mysql\_privileges,
259 and grant\_postgresql\_privileges may be of a help to you.
261 Generally, to do the above, you will need to run under root to
262 be able to create databases and modify permissions within MySQL and
266 \subsection{Running the Disk Only Regression}
267 \index{Regression!Running the Disk Only}
268 \index{Running the Disk Only Regression}
269 \addcontentsline{toc}{subsection}{Running the Disk Only Regression}
271 The simplest way to copy the source code, configure it, compile it, link
272 it, and run the tests is to use a helper script:
283 This will run the base set of tests using disk Volumes.
284 If you are testing on a
285 non-Linux machine several of the of the tests may not be run. In any case,
286 as we add new tests, the number will vary. It will take about 1 hour
287 and you don't need to be root
288 to run these tests (I run under my regular userid). The result should be
289 something similar to:
294 ===== auto-label-test OK 12:31:33 =====
295 ===== backup-bacula-test OK 12:32:32 =====
296 ===== bextract-test OK 12:33:27 =====
297 ===== bscan-test OK 12:34:47 =====
298 ===== bsr-opt-test OK 12:35:46 =====
299 ===== compressed-test OK 12:36:52 =====
300 ===== compressed-encrypt-test OK 12:38:18 =====
301 ===== concurrent-jobs-test OK 12:39:49 =====
302 ===== data-encrypt-test OK 12:41:11 =====
303 ===== encrypt-bug-test OK 12:42:00 =====
304 ===== fifo-test OK 12:43:46 =====
305 ===== backup-bacula-fifo OK 12:44:54 =====
306 ===== differential-test OK 12:45:36 =====
307 ===== four-concurrent-jobs-test OK 12:47:39 =====
308 ===== four-jobs-test OK 12:49:22 =====
309 ===== incremental-test OK 12:50:38 =====
310 ===== query-test OK 12:51:37 =====
311 ===== recycle-test OK 12:53:52 =====
312 ===== restore2-by-file-test OK 12:54:53 =====
313 ===== restore-by-file-test OK 12:55:40 =====
314 ===== restore-disk-seek-test OK 12:56:29 =====
315 ===== six-vol-test OK 12:57:44 =====
316 ===== span-vol-test OK 12:58:52 =====
317 ===== sparse-compressed-test OK 13:00:00 =====
318 ===== sparse-test OK 13:01:04 =====
319 ===== two-jobs-test OK 13:02:39 =====
320 ===== two-vol-test OK 13:03:49 =====
321 ===== verify-vol-test OK 13:04:56 =====
322 ===== weird-files2-test OK 13:05:47 =====
323 ===== weird-files-test OK 13:06:33 =====
324 ===== migration-job-test OK 13:08:15 =====
325 ===== migration-jobspan-test OK 13:09:33 =====
326 ===== migration-volume-test OK 13:10:48 =====
327 ===== migration-time-test OK 13:12:59 =====
328 ===== hardlink-test OK 13:13:50 =====
329 ===== two-pool-test OK 13:18:17 =====
330 ===== fast-two-pool-test OK 13:24:02 =====
331 ===== two-volume-test OK 13:25:06 =====
332 ===== incremental-2disk OK 13:25:57 =====
333 ===== 2drive-incremental-2disk OK 13:26:53 =====
334 ===== scratch-pool-test OK 13:28:01 =====
335 Total time = 0:57:55 or 3475 secs
340 and the working tape tests are run with
353 ===== Bacula tape test OK =====
354 ===== Small File Size test OK =====
355 ===== restore-by-file-tape test OK =====
356 ===== incremental-tape test OK =====
357 ===== four-concurrent-jobs-tape OK =====
358 ===== four-jobs-tape OK =====
362 Each separate test is self contained in that it initializes to run Bacula from
363 scratch (i.e. newly created database). It will also kill any Bacula session
364 that is currently running. In addition, it uses ports 8101, 8102, and 8103 so
365 that it does not intefere with a production system.
367 Alternatively, you can do the ./do\_disk work by hand with:
375 The above will then copy the source code within
376 the regression tree (in directory regress/build), configure it, and build it.
377 There should be no errors. If there are, please correct them before
378 continuing. From this point on, as long as you don't change the Bacula
379 source code, you should not need to repeat any of the above steps. If
380 you pull down a new version of the source code, simply run {\bf make setup}
384 Once Bacula is built, you can run the basic disk only non-root regression test
394 \subsection{Other Tests}
397 \addcontentsline{toc}{subsection}{Other Tests}
399 There are a number of other tests that can be run as well. All the tests are a
400 simply shell script keep in the regress directory. For example the ''make
401 test`` simply executes {\bf ./all-non-root-tests}. The other tests, which
402 are invoked by directly running the script are:
406 \item [all\_non-root-tests]
407 \index{all\_non-root-tests}
408 All non-tape tests not requiring root. This is the standard set of tests,
409 that in general, backup some data, then restore it, and finally compares the
410 restored data with the original data.
412 \item [all-root-tests]
413 \index{all-root-tests}
414 All non-tape tests requiring root permission. These are a relatively small
415 number of tests that require running as root. The amount of data backed up
416 can be quite large. For example, one test backs up /usr, another backs up
417 /etc. One or more of these tests reports an error -- I'll fix it one day.
419 \item [all-non-root-tape-tests]
420 \index{all-non-root-tape-tests}
421 All tape test not requiring root. There are currently three tests, all run
422 without being root, and backup to a tape. The first two tests use one volume,
423 and the third test requires an autochanger, and uses two volumes. If you
424 don't have an autochanger, then this script will probably produce an error.
426 \item [all-tape-and-file-tests]
427 \index{all-tape-and-file-tests}
428 All tape and file tests not requiring root. This includes just about
429 everything, and I don't run it very often.
432 \subsection{If a Test Fails}
433 \index{Fails!If a Test}
434 \index{If a Test Fails}
435 \addcontentsline{toc}{subsection}{If a Test Fails}
437 If you one or more tests fail, the line output will be similar to:
441 !!!!! concurrent-jobs-test failed!!! !!!!!
445 If you want to determine why the test failed, you will need to rerun the
446 script with the debug output turned on. You do so by defining the
447 environment variable {\bf REGRESS\_DEBUG} with commands such as:
454 Then from the "regress" directory (all regression scripts assume that
455 you have "regress" as the current directory), enter:
461 where test-name should be the name of a test script -- for example:
462 {\bf tests/backup-bacula-test}.
464 \section{Testing a Binary Installation}
465 \index{Test!Testing a Binary Installation}
467 If you have installed your Bacula from a binary release such as (rpms or debs),
468 you can still run regression tests on it.
469 First, make sure that your regression {\bf config} file uses the same catalog backend as
470 your installed binaries. Then define the variables \texttt{bin} and \texttt{scripts} variables
476 scripts=/opt/bacula/scripts
479 The \texttt{./scripts/prepare-other-loc} will tweak the regress scripts to use
480 your binary location. You will need to run it manually once before you run any
484 $ ./scripts/prepare-other-loc
485 $ ./tests/backup-bacula-test
489 All regression scripts must be run by hand or by calling the test scripts.
490 These are principally scripts that begin with {\bf all\_...} such as {\bf all\_disk\_tests},
491 {\bf ./all\_test} ...
493 {\bf ./do\_disk}, {\bf ./do\_all}, {\bf ./nightly...} scripts will work.
495 If you want to switch back to running the regression scripts from source, first
496 remove the {\bf bin} and {\bf scripts} variables from your {\bf config} file and
497 rerun the {\bf make setup} step.
499 \section{Running a Single Test}
500 \index{Running a Single Test}
501 \addcontentsline{toc}{section}{Running a Single Test}
503 If you wish to run a single test, you can simply:
510 or, if the source code has been updated, you would do:
521 \section{Writing a Regression Test}
522 \index{Test!Writing a Regression}
523 \index{Writing a Regression Test}
524 \addcontentsline{toc}{section}{Writing a Regression Test}
526 Any developer, who implements a major new feature, should write a regression
527 test that exercises and validates the new feature. Each regression test is a
528 complete test by itself. It terminates any running Bacula, initializes the
529 database, starts Bacula, then runs the test by using the console program.
531 \subsection{Running the Tests by Hand}
532 \index{Hand!Running the Tests by}
533 \index{Running the Tests by Hand}
534 \addcontentsline{toc}{subsection}{Running the Tests by Hand}
536 You can run any individual test by hand by cd'ing to the {\bf regress}
537 directory and entering:
545 \subsection{Directory Structure}
546 \index{Structure!Directory}
547 \index{Directory Structure}
548 \addcontentsline{toc}{subsection}{Directory Structure}
550 The directory structure of the regression tests is:
554 regress - Makefile, scripts to start tests
555 |------ scripts - Scripts and conf files
556 |-------tests - All test scripts are here
558 |------------------ -- All directories below this point are used
559 | for testing, but are created from the
560 | above directories and are removed with
563 |------ bin - This is the install directory for
564 | Bacula to be used testing
565 |------ build - Where the Bacula source build tree is
566 |------ tmp - Most temp files go here
567 |------ working - Bacula working directory
568 |------ weird-files - Weird files used in two of the tests.
572 \subsection{Adding a New Test}
573 \index{Adding a New Test}
574 \index{Test!Adding a New}
575 \addcontentsline{toc}{subsection}{Adding a New Test}
577 If you want to write a new regression test, it is best to start with one of
578 the existing test scripts, and modify it to do the new test.
580 When adding a new test, be extremely careful about adding anything to any of
581 the daemons' configuration files. The reason is that it may change the prompts
582 that are sent to the console. For example, adding a Pool means that the
583 current scripts, which assume that Bacula automatically selects a Pool, will
584 now be presented with a new prompt, so the test will fail. If you need to
585 enhance the configuration files, consider making your own versions.
587 \subsection{Running a Test Under The Debugger}
589 \addcontentsline{toc}{subsection}{Running a Test Under The Debugger}
590 You can run a test under the debugger (actually run a Bacula daemon
591 under the debugger) by first setting the environment variable
592 {\bf REGRESS\_WAIT} with commands such as:
599 Then executing the script. When the script prints the following line:
602 Start Bacula under debugger and enter anything when ready ...
605 You start the Bacula component you want to run under the debugger in a
606 different shell window. For example:
611 (possibly set breakpoints, ...)
615 Then enter any character in the window with the above message.
616 An error message will appear saying that the daemon you are debugging
617 is already running, which is the case. You can simply ignore the