xfs/{422,517}: kill background jobs on test termination
[xfstests-dev.git] / README
1 _______________________
2 BUILDING THE FSQA SUITE
3 _______________________
4
5 Ubuntu or Debian
6 ----------------
7
8 1. Make sure that package list is up-to-date and install all necessary packages:
9
10    $ sudo apt-get update
11    $ sudo apt-get install acl attr automake bc dbench dump e2fsprogs fio gawk \
12         gcc git indent libacl1-dev libaio-dev libcap-dev libgdbm-dev libtool \
13         libtool-bin liburing-dev libuuid1 lvm2 make psmisc python3 quota sed \
14         uuid-dev uuid-runtime xfsprogs linux-headers-$(uname -r) sqlite3
15
16 2. Install packages for the filesystem(s) being tested:
17
18    $ sudo apt-get install exfatprogs f2fs-tools ocfs2-tools udftools xfsdump \
19         xfslibs-dev
20
21    For OverlayFS install:
22     - see https://github.com/hisilicon/overlayfs-progs
23
24 Fedora
25 ------
26
27 1. Install all necessary packages from standard repository:
28
29    $ sudo yum install acl attr automake bc dbench dump e2fsprogs fio gawk gcc \
30         gdbm-devel git indent kernel-devel libacl-devel libaio-devel \
31         libcap-devel libtool liburing-devel libuuid-devel lvm2 make psmisc \
32         python3 quota sed sqlite udftools  xfsprogs
33
34 2. Install packages for the filesystem(s) being tested:
35
36     $ sudo yum install btrfs-progs exfatprogs f2fs-tools ocfs2-tools xfsdump \
37         xfsprogs-devel
38
39    For OverlayFS build and install:
40     - see https://github.com/hisilicon/overlayfs-progs
41
42 RHEL or CentOS
43 --------------
44
45 1. Enable EPEL repository:
46     - see https://docs.fedoraproject.org/en-US/epel/#How_can_I_use_these_extra_packages.3F
47
48 2. Install all necessary packages which are available from standard repository
49    and EPEL:
50
51    $ sudo yum install acl attr automake bc dbench dump e2fsprogs fio gawk gcc \
52         gdbm-devel git indent kernel-devel libacl-devel libaio-devel \
53         libcap-devel libtool libuuid-devel lvm2 make psmisc python3 quota sed \
54         sqlite udftools xfsprogs
55
56    Or, EPEL packages could be compiled from sources, see:
57     - https://dbench.samba.org/web/download.html
58     - https://www.gnu.org/software/indent/
59
60 3. Build and install 'liburing':
61     - see https://github.com/axboe/liburing.
62
63 4. Install packages for the filesystem(s) being tested:
64
65     For XFS install:
66      $ sudo yum install xfsdump xfsprogs-devel
67
68     For exfat install:
69      $ sudo yum install exfatprogs
70
71     For f2fs build and install:
72      - see https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/about/
73
74     For ocfs2 build and install:
75      - see https://github.com/markfasheh/ocfs2-tools
76
77     For OverlayFS build and install:
78      - see https://github.com/hisilicon/overlayfs-progs
79
80 Build and install test, libs and utils
81 --------------------------------------
82
83 $ git clone git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git
84 $ cd xfstests-dev
85 $ make
86 $ sudo make install
87
88 Setup Environment
89 -----------------
90
91 1. Compile XFS/EXT4/BTRFS/etc. into your kernel or load as module. For example,
92    for XFS, enable XFS_FS in your kernel configuration, or compile it as a
93    module and load it with 'sudo modprobe xfs'. Most of the distributions will
94    have these filesystems already in the kernel/as module.
95
96 2. Create TEST device:
97     - format as the filesystem type you wish to test.
98     - should be at least 10GB in size.
99     - optionally populate with destroyable data.
100     - device contents may be destroyed.
101
102 3. (optional) Create SCRATCH device.
103     - many tests depend on the SCRATCH device existing.
104     - not need to be formatted.
105     - should be at least 10GB in size.
106     - must be different to TEST device.
107     - device contents will be destroyed.
108
109 4. (optional) Create SCRATCH device pool.
110     - needed for BTRFS testing
111     - specifies 3 or more independent SCRATCH devices via the SCRATCH_DEV_POOL
112       variable e.g SCRATCH_DEV_POOL="/dev/sda /dev/sdb /dev/sdc"
113     - device contents will be destroyed.
114     - SCRATCH device should be left unset, it will be overridden
115       by the SCRATCH_DEV_POOL implementation.
116
117 5. Copy local.config.example to local.config and edit as needed. The TEST_DEV
118    and TEST_DIR are required.
119
120 6. (optional) Create fsgqa test users and groups:
121
122    $ sudo useradd -m fsgqa
123    $ sudo useradd 123456-fsgqa
124    $ sudo useradd fsgqa2
125    $ sudo groupadd fsgqa
126
127    The "123456-fsgqa" user creation step can be safely skipped if your system
128    doesn't support names starting with digits, only a handful of tests require
129    it.
130
131 7. (optional) If you wish to run the udf components of the suite install
132    mkudffs. Also download and build the Philips UDF Verification Software from
133    https://www.lscdweb.com/registered/udf_verifier.html, then copy the udf_test
134    binary to xfstests/src/.
135
136
137 For example, to run the tests with loopback partitions:
138
139     # xfs_io -f -c "falloc 0 10g" test.img
140     # xfs_io -f -c "falloc 0 10g" scratch.img
141     # mkfs.xfs test.img
142     # losetup /dev/loop0 ./test.img
143     # losetup /dev/loop1 ./scratch.img
144     # mkdir -p /mnt/test && mount /dev/loop0 /mnt/test
145     # mkdir -p /mnt/scratch
146
147 The config for the setup above is:
148
149     $ cat local.config
150     export TEST_DEV=/dev/loop0
151     export TEST_DIR=/mnt/test
152     export SCRATCH_DEV=/dev/loop1
153     export SCRATCH_MNT=/mnt/scratch
154
155 From this point you can run some basic tests, see 'USING THE FSQA SUITE' below.
156
157 Additional Setup
158 ----------------
159
160 Some tests require additional configuration in your local.config. Add these
161 variables to a local.config and keep that file in your workarea. Or add a case
162 to the switch in common/config assigning these variables based on the hostname
163 of your test machine. Or use 'setenv' to set them.
164
165 Extra TEST device specifications:
166  - Set TEST_LOGDEV to "device for test-fs external log"
167  - Set TEST_RTDEV to "device for test-fs realtime data"
168  - If TEST_LOGDEV and/or TEST_RTDEV, these will always be used.
169  - Set FSTYP to "the filesystem you want to test", the filesystem type is
170    devised from the TEST_DEV device, but you may want to override it; if
171    unset, the default is 'xfs'
172
173 Extra SCRATCH device specifications:
174  - Set SCRATCH_LOGDEV to "device for scratch-fs external log"
175  - Set SCRATCH_RTDEV to "device for scratch-fs realtime data"
176  - If SCRATCH_LOGDEV and/or SCRATCH_RTDEV, the USE_EXTERNAL environment
177
178 Tape device specification for xfsdump testing:
179  - Set TAPE_DEV to "tape device for testing xfsdump".
180  - Set RMT_TAPE_DEV to "remote tape device for testing xfsdump"
181    variable set to "yes" will enable their use.
182  - Note that if testing xfsdump, make sure the tape devices have a tape which
183    can be overwritten.
184
185 Extra XFS specification:
186  - Set TEST_XFS_REPAIR_REBUILD=1 to have _check_xfs_filesystem run
187    xfs_repair -n to check the filesystem; xfs_repair to rebuild metadata
188    indexes; and xfs_repair -n (a third time) to check the results of the
189    rebuilding.
190  - Set FORCE_XFS_CHECK_PROG=yes to have _check_xfs_filesystem run xfs_check
191    to check the filesystem. As of August 2021, xfs_repair finds all
192    filesystem corruptions found by xfs_check, and more, which means that
193    xfs_check is no longer run by default.
194  - xfs_scrub, if present, will always check the test and scratch
195    filesystems if they are still online at the end of the test. It is no
196    longer necessary to set TEST_XFS_SCRUB.
197
198 Tools specification:
199  - dump:
200     - Set DUMP_CORRUPT_FS=1 to record metadata dumps of XFS, ext* or
201       btrfs filesystems if a filesystem check fails.
202     - Set DUMP_COMPRESSOR to a compression program to compress metadumps of
203       filesystems. This program must accept '-f' and the name of a file to
204       compress; and it must accept '-d -f -k' and the name of a file to
205       decompress. In other words, it must emulate gzip.
206  - dmesg:
207     - Set KEEP_DMESG=yes to keep dmesg log after test
208  - kmemleak:
209     - Set USE_KMEMLEAK=yes to scan for memory leaks in the kernel after every
210       test, if the kernel supports kmemleak.
211  - fsstress:
212     - Set FSSTRESS_AVOID and/or FSX_AVOID, which contain options added to
213       the end of fsstresss and fsx invocations, respectively, in case you wish
214       to exclude certain operational modes from these tests.
215
216 Kernel/Modules related configuration:
217  - Set TEST_FS_MODULE_RELOAD=1 to unload the module and reload it between
218    test invocations. This assumes that the name of the module is the same
219    as FSTYP.
220  - Set MODPROBE_PATIENT_RM_TIMEOUT_SECONDS to specify the amount of time we
221    should try a patient module remove. The default is 50 seconds. Set this
222    to "forever" and we'll wait forever until the module is gone.
223  - Set KCONFIG_PATH to specify your preferred location of kernel config
224    file. The config is used by tests to check if kernel feature is enabled.
225
226 Misc:
227  - If you wish to disable UDF verification test set the environment variable
228    DISABLE_UDF_TEST to 1.
229  - Set LOGWRITES_DEV to a block device to use for power fail testing.
230  - Set PERF_CONFIGNAME to a arbitrary string to be used for identifying
231    the test setup for running perf tests. This should be different for
232    each type of performance test you wish to run so that relevant results
233    are compared. For example 'spinningrust' for configurations that use
234    spinning disks and 'nvme' for tests using nvme drives.
235  - Set MIN_FSSIZE to specify the minimal size (bytes) of a filesystem we
236    can create. Setting this parameter will skip the tests creating a
237    filesystem less than MIN_FSSIZE.
238  - Set DIFF_LENGTH to "number of diff lines to print from a failed test",
239    by default 10, set to 0 to print the full diff
240  - set IDMAPPED_MOUNTS=true to run all tests on top of idmapped mounts. While
241    this option is supported for all filesystems currently only -overlay is
242    expected to run without issues. For other filesystems additional patches
243    and fixes to the test suite might be needed.
244
245 ______________________
246 USING THE FSQA SUITE
247 ______________________
248
249 Running tests:
250
251     - cd xfstests
252     - By default the tests suite will run all the tests in the auto group. These
253       are the tests that are expected to function correctly as regression tests,
254       and it excludes tests that exercise conditions known to cause machine
255       failures (i.e. the "dangerous" tests).
256     - ./check '*/001' '*/002' '*/003'
257     - ./check '*/06?'
258     - Groups of tests maybe ran by: ./check -g [group(s)]
259       See the tests/*/group.list files after building xfstests to learn about
260       each test's group memberships.
261     - If you want to run all tests regardless of what group they are in
262       (including dangerous tests), use the "all" group: ./check -g all
263     - To randomize test order: ./check -r [test(s)]
264     - You can explicitly specify NFS/CIFS/OVERLAY, otherwise
265       the filesystem type will be autodetected from $TEST_DEV:
266         - for running nfs tests: ./check -nfs [test(s)]
267         - for running cifs/smb3 tests: ./check -cifs [test(s)]
268         - for overlay tests: ./check -overlay [test(s)]
269           The TEST and SCRATCH partitions should be pre-formatted
270           with another base fs, where the overlay dirs will be created
271
272
273     The check script tests the return value of each script, and
274     compares the output against the expected output. If the output
275     is not as expected, a diff will be output and an .out.bad file
276     will be produced for the failing test.
277
278     Unexpected console messages, crashes and hangs may be considered
279     to be failures but are not necessarily detected by the QA system.
280
281 __________________________
282 ADDING TO THE FSQA SUITE
283 __________________________
284
285
286 Creating new tests scripts:
287
288     Use the "new" script.
289
290 Test script environment:
291
292     When developing a new test script keep the following things in
293     mind.  All of the environment variables and shell procedures are
294     available to the script once the "common/preamble" file has been
295     sourced and the "_begin_fstest" function has been called.
296
297      1. The tests are run from an arbitrary directory.  If you want to
298         do operations on an XFS filesystem (good idea, eh?), then do
299         one of the following:
300
301         (a) Create directories and files at will in the directory
302             $TEST_DIR ... this is within an XFS filesystem and world
303             writeable.  You should cleanup when your test is done,
304             e.g. use a _cleanup shell procedure in the trap ... see
305             001 for an example.  If you need to know, the $TEST_DIR
306             directory is within the filesystem on the block device
307             $TEST_DEV.
308
309         (b) mkfs a new XFS filesystem on $SCRATCH_DEV, and mount this
310             on $SCRATCH_MNT. Call the the _require_scratch function
311             on startup if you require use of the scratch partition.
312             _require_scratch does some checks on $SCRATCH_DEV &
313             $SCRATCH_MNT and makes sure they're unmounted. You should
314             cleanup when your test is done, and in particular unmount
315             $SCRATCH_MNT.
316             Tests can make use of $SCRATCH_LOGDEV and $SCRATCH_RTDEV
317             for testing external log and realtime volumes - however,
318             these tests need to simply "pass" (e.g. cat $seq.out; exit
319             - or default to an internal log) in the common case where
320             these variables are not set.
321
322      2. You can safely create temporary files that are not part of the
323         filesystem tests (e.g. to catch output, prepare lists of things
324         to do, etc.) in files named $tmp.<anything>.  The standard test
325         script framework created by "new" will initialize $tmp and
326         cleanup on exit.
327
328      3. By default, tests are run as the same uid as the person
329         executing the control script "check" that runs the test scripts.
330
331      4. Some other useful shell procedures:
332
333         _get_fqdn               - echo the host's fully qualified
334                                   domain name
335
336         _get_pids_by_name       - one argument is a process name, and
337                                   return all of the matching pids on
338                                   standard output
339
340         _within_tolerance       - fancy numerical "close enough is good
341                                   enough" filter for deterministic
342                                   output ... see comments in
343                                   common/filter for an explanation
344
345         _filter_date            - turn ctime(3) format dates into the
346                                   string DATE for deterministic
347                                   output
348
349         _cat_passwd,            - dump the content of the password
350         _cat_group                or group file (both the local file
351                                   and the content of the NIS database
352                                   if it is likely to be present)
353
354      5. General recommendations, usage conventions, etc.:
355         - When the content of the password or group file is
356           required, get it using the _cat_passwd and _cat_group
357           functions, to ensure NIS information is included if NIS
358           is active.
359         - When calling getfacl in a test, pass the "-n" argument so
360           that numeric rather than symbolic identifiers are used in
361           the output.
362         - When creating a new test, it is possible to enter a custom name
363           for the file. Filenames are in form NNN-custom-name, where NNN
364           is automatically added by the ./new script as an unique ID,
365           and "custom-name" is the optional string entered into a prompt
366           in the ./new script. It can contain only alphanumeric characters
367           and dash. Note the "NNN-" part is added automatically.
368
369      6. Test group membership: Each test can be associated with any number
370         of groups for convenient selection of subsets of tests.  Group names
371         must  be human readable using only characters in the set [:alnum:_-].
372
373         Test authors associate a test with groups by passing the names of those
374         groups as arguments to the _begin_fstest function. While _begin_fstests
375         is a shell function that must be called at the start of a test to
376         initialise the test environment correctly, the the build infrastructure
377         also scans the test files for _begin_fstests invocations. It does this
378         to compile the group lists that are used to determine which tests to run
379         when `check` is executed. In other words, test files files must call
380         _begin_fstest with their intended groups or they will not be run.
381
382         However, because the build infrastructure also uses _begin_fstests as
383         a defined keyword, addition restrictions are placed on how it must be
384         formatted:
385
386         (a) It must be a single line with no multi-line continuations.
387
388         (b) group names should be separated by spaces and not other whitespace
389
390         (c) A '#' placed anywhere in the list, even in the middle of a group
391             name, will cause everything from the # to the end of the line to be
392             ignored.
393
394         For example, the code:
395
396         _begin_fstest auto quick subvol snapshot # metadata
397
398         associates the current test with the "auto", "quick", "subvol", and
399         "snapshot" groups. Because "metadata" is after the "#" comment
400         delimiter, it is ignored by the build infrastructure and so it will not
401         be associated with that group.
402
403         It is not necessary to specify the "all" group in the list because that
404         group is always computed at run time from the group lists.
405
406
407 Verified output:
408
409     Each test script has a name, e.g. 007, and an associated
410     verified output, e.g. 007.out.
411
412     It is important that the verified output is deterministic, and
413     part of the job of the test script is to filter the output to
414     make this so.  Examples of the sort of things that need filtering:
415
416     - dates
417     - pids
418     - hostnames
419     - filesystem names
420     - timezones
421     - variable directory contents
422     - imprecise numbers, especially sizes and times
423
424 Pass/failure:
425
426     The script "check" may be used to run one or more tests.
427
428     Test number $seq is deemed to "pass" when:
429     (a) no "core" file is created,
430     (b) the file $seq.notrun is not created,
431     (c) the exit status is 0, and
432     (d) the output matches the verified output.
433
434     In the "not run" case (b), the $seq.notrun file should contain a
435     short one-line summary of why the test was not run.  The standard
436     output is not checked, so this can be used for a more verbose
437     explanation and to provide feedback when the QA test is run
438     interactively.
439
440
441     To force a non-zero exit status use:
442         status=1
443         exit
444
445     Note that:
446         exit 1
447     won't have the desired effect because of the way the exit trap
448     works.
449
450     The recent pass/fail history is maintained in the file "check.log".
451     The elapsed time for the most recent pass for each test is kept
452     in "check.time".
453
454     The compare-failures script in tools/ may be used to compare failures
455     across multiple runs, given files containing stdout from those runs.
456
457 __________________
458 SUBMITTING PATCHES
459 __________________
460
461 Send patches to the fstests mailing list at fstests@vger.kernel.org.