xref: /freebsd/sys/contrib/openzfs/tests/test-runner/bin/zts-report.py.in (revision dd32d6b29d49838c99d38ba30846ade210b2e6f7)
1#!/usr/bin/env @PYTHON_SHEBANG@
2# SPDX-License-Identifier: CDDL-1.0
3
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14
15#
16# Copyright (c) 2017 by Delphix. All rights reserved.
17# Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
18# Copyright (c) 2025, Klara, Inc.
19#
20# This script must remain compatible with Python 3.6+.
21#
22
23import os
24import re
25import sys
26import argparse
27
28#
29# This script parses the stdout of zfstest, which has this format:
30#
31# Test: /path/to/testa (run as root) [00:00] [PASS]
32# Test: /path/to/testb (run as jkennedy) [00:00] [PASS]
33# Test: /path/to/testc (run as root) [00:00] [FAIL]
34# [...many more results...]
35#
36# Results Summary
37# FAIL      22
38# SKIP      32
39# PASS    1156
40#
41# Running Time:   02:50:31
42# Percent passed: 95.5%
43# Log directory:  /var/tmp/test_results/20180615T205926
44#
45
46#
47# Common generic reasons for a test or test group to be skipped.
48#
49# Some test cases are known to fail in ways which are not harmful or dangerous.
50# In these cases simply mark the test as a known failure until it can be
51# updated and the issue resolved.  Note that it's preferable to open a unique
52# issue on the GitHub issue tracker for each test case failure.
53#
54known_reason = 'Known issue'
55
56#
57# Some tests require that a test user be able to execute the zfs utilities.
58# This may not be possible when testing in-tree due to the default permissions
59# on the user's home directory.  When testing this can be resolved by granting
60# group read access.
61#
62# chmod 0750 $HOME
63#
64exec_reason = 'Test user execute permissions required for utilities'
65
66#
67# Some tests require that the kernel supports renameat2 syscall.
68#
69renameat2_reason = 'Kernel renameat2 support required'
70
71#
72# Some tests require the statx(2) system call on Linux which was first
73# introduced in the 4.11 kernel.
74#
75statx_reason = 'Kernel statx(2) system call required on Linux'
76
77#
78# Some tests require that the lsattr utility support the project id feature.
79#
80project_id_reason = 'lsattr with set/show project ID required'
81
82#
83# Some tests require that the kernel support user namespaces.
84#
85user_ns_reason = 'Kernel user namespace support required'
86
87#
88# Some rewind tests can fail since nothing guarantees that old MOS blocks
89# are not overwritten.  Snapshots protect datasets and data files but not
90# the MOS.  Reasonable efforts are made in the test case to increase the
91# odds that some txgs will have their MOS data left untouched, but it is
92# never a sure thing.
93#
94rewind_reason = 'Arbitrary pool rewind is not guaranteed'
95
96#
97# Some tests require a minimum version of the fio benchmark utility.
98# Older distributions such as CentOS 6.x only provide fio-2.0.13.
99#
100fio_reason = 'Fio v2.3 or newer required'
101
102#
103# Some tests require that the DISKS provided support the discard operation.
104# Normally this is not an issue because loop back devices are used for DISKS
105# and they support discard (TRIM/UNMAP).
106#
107trim_reason = 'DISKS must support discard (TRIM/UNMAP)'
108
109#
110# Some tests on FreeBSD require the fspacectl(2) system call and the
111# truncate(1) utility supporting the -d option.  The system call was first
112# introduced in FreeBSD version 1400032.
113#
114fspacectl_reason = 'fspacectl(2) and truncate -d support required'
115
116#
117# Some tests are not applicable to a platform or need to be updated to operate
118# in the manor required by the platform.  Any tests which are skipped for this
119# reason will be suppressed in the final analysis output.
120#
121na_reason = "Not applicable"
122
123#
124# Idmapped mount is only supported in kernel version >= 5.12
125#
126idmap_reason = 'Idmapped mount needs kernel 5.12+'
127
128#
129# copy_file_range() is not supported by all kernels
130#
131cfr_reason = 'Kernel copy_file_range support required'
132
133#
134# Some statx fields are not supported by all kernels
135#
136statx_reason = 'Needed statx(2) field not supported on this kernel'
137
138if sys.platform.startswith('freebsd'):
139    cfr_cross_reason = 'copy_file_range(2) cross-filesystem needs FreeBSD 14+'
140else:
141    cfr_cross_reason = 'copy_file_range(2) cross-filesystem needs kernel 5.3+'
142
143#
144# These tests are known to fail, thus we use this list to prevent these
145# failures from failing the job as a whole; only unexpected failures
146# bubble up to cause this script to exit with a non-zero exit status.
147#
148# Format: { 'test-name': ['expected result', 'issue-number | reason'] }
149#
150# For each known failure it is recommended to link to a GitHub issue by
151# setting the reason to the issue number.  Alternately, one of the generic
152# reasons listed above can be used.
153#
154known = {
155    'casenorm/mixed_none_lookup_ci': ['FAIL', 7633],
156    'casenorm/mixed_formd_lookup_ci': ['FAIL', 7633],
157    'cli_root/zpool_import/import_rewind_device_replaced':
158        ['FAIL', rewind_reason],
159    'cli_user/misc/zfs_share_001_neg': ['SKIP', na_reason],
160    'cli_user/misc/zfs_unshare_001_neg': ['SKIP', na_reason],
161    'pool_checkpoint/checkpoint_discard_busy': ['SKIP', 12053],
162    'privilege/setup': ['SKIP', na_reason],
163    'refreserv/refreserv_004_pos': ['FAIL', known_reason],
164    'rootpool/setup': ['SKIP', na_reason],
165    'rsend/rsend_008_pos': ['SKIP', 6066],
166    'vdev_zaps/vdev_zaps_007_pos': ['FAIL', known_reason],
167}
168
169if sys.platform.startswith('freebsd'):
170    known.update({
171        'cli_root/zfs_receive/receive-o-x_props_override':
172            ['FAIL', known_reason],
173        'cli_root/zpool_resilver/zpool_resilver_concurrent':
174            ['SKIP', na_reason],
175        'cli_root/zpool_wait/zpool_wait_trim_basic': ['SKIP', trim_reason],
176        'cli_root/zpool_wait/zpool_wait_trim_cancel': ['SKIP', trim_reason],
177        'cli_root/zpool_wait/zpool_wait_trim_flag': ['SKIP', trim_reason],
178        'cli_root/zfs_unshare/zfs_unshare_008_pos': ['SKIP', na_reason],
179        'cp_files/cp_files_002_pos': ['SKIP', na_reason],
180        'link_count/link_count_001': ['SKIP', na_reason],
181        'mmap/mmap_sync_001_pos': ['SKIP', na_reason],
182        'rsend/send_raw_ashift': ['SKIP', 14961],
183    })
184elif sys.platform.startswith('linux'):
185    known.update({
186        'casenorm/mixed_formd_lookup': ['FAIL', 7633],
187        'casenorm/mixed_formd_delete': ['FAIL', 7633],
188        'casenorm/sensitive_formd_lookup': ['FAIL', 7633],
189        'casenorm/sensitive_formd_delete': ['FAIL', 7633],
190        'removal/removal_with_zdb': ['SKIP', known_reason],
191        'cli_root/zfs_unshare/zfs_unshare_002_pos': ['SKIP', na_reason],
192    })
193
194
195#
196# These tests may occasionally fail or be skipped.  We want there failures
197# to be reported but only unexpected failures should bubble up to cause
198# this script to exit with a non-zero exit status.
199#
200# Format: { 'test-name': ['expected result', 'issue-number | reason'] }
201#
202# For each known failure it is recommended to link to a GitHub issue by
203# setting the reason to the issue number.  Alternately, one of the generic
204# reasons listed above can be used.
205#
206maybe = {
207    'append/threadsappend_001_pos': ['FAIL', 6136],
208    'chattr/setup': ['SKIP', exec_reason],
209    'crtime/crtime_001_pos': ['SKIP', statx_reason],
210    'cli_root/zdb/zdb_006_pos': ['FAIL', known_reason],
211    'cli_root/zfs_copies/zfs_copies_006_pos': ['FAIL', known_reason],
212    'cli_root/zfs_destroy/zfs_destroy_dev_removal_condense':
213        ['FAIL', known_reason],
214    'cli_root/zfs_get/zfs_get_004_pos': ['FAIL', known_reason],
215    'cli_root/zfs_get/zfs_get_009_pos': ['SKIP', 5479],
216    'cli_root/zfs_rollback/zfs_rollback_001_pos': ['FAIL', known_reason],
217    'cli_root/zfs_rollback/zfs_rollback_002_pos': ['FAIL', known_reason],
218    'cli_root/zfs_share/zfs_share_concurrent_shares': ['FAIL', known_reason],
219    'cli_root/zfs_snapshot/zfs_snapshot_002_neg': ['FAIL', known_reason],
220    'cli_root/zfs_unshare/zfs_unshare_006_pos': ['SKIP', na_reason],
221    'cli_root/zpool_add/zpool_add_004_pos': ['FAIL', known_reason],
222    'cli_root/zpool_destroy/zpool_destroy_001_pos': ['SKIP', 6145],
223    'cli_root/zpool_import/import_devices_missing': ['FAIL', 16669],
224    'cli_root/zpool_import/zpool_import_missing_003_pos': ['SKIP', 6839],
225    'cli_root/zpool_initialize/zpool_initialize_import_export':
226        ['FAIL', 11948],
227    'cli_root/zpool_initialize/zpool_initialize_suspend_resume':
228        ['FAIL', known_reason],
229    'cli_root/zpool_labelclear/zpool_labelclear_removed':
230        ['FAIL', known_reason],
231    'cli_root/zpool_trim/setup': ['SKIP', trim_reason],
232    'cli_root/zpool_trim/zpool_trim_fault_export_import_online':
233        ['FAIL', known_reason],
234    'cli_root/zpool_upgrade/zpool_upgrade_004_pos': ['FAIL', 6141],
235    'cli_user/misc/zarcsummary_001_pos': ['FAIL', known_reason],
236    'delegate/setup': ['SKIP', exec_reason],
237    'events/zed_cksum_config': ['FAIL', known_reason],
238    'fault/auto_replace_002_pos': ['FAIL', known_reason],
239    'fallocate/fallocate_punch-hole': ['SKIP', fspacectl_reason],
240    'history/history_004_pos': ['FAIL', 7026],
241    'history/history_005_neg': ['FAIL', 6680],
242    'history/history_006_neg': ['FAIL', 5657],
243    'history/history_008_pos': ['FAIL', known_reason],
244    'history/history_010_pos': ['SKIP', exec_reason],
245    'io/mmap': ['SKIP', fio_reason],
246    'l2arc/l2arc_l2miss_pos': ['FAIL', known_reason],
247    'l2arc/persist_l2arc_005_pos': ['FAIL', known_reason],
248    'largest_pool/largest_pool_001_pos': ['FAIL', known_reason],
249    'mmap/mmap_sync_001_pos': ['FAIL', known_reason],
250    'mmp/mmp_on_uberblocks': ['FAIL', known_reason],
251    'pam/setup': ['SKIP', "pamtester might be not available"],
252    'pool_checkpoint/checkpoint_discard_busy': ['FAIL', 11946],
253    'projectquota/setup': ['SKIP', exec_reason],
254    'raidz/raidz_002_pos': ['FAIL', known_reason],
255    'raidz/raidz_expand_001_pos': ['FAIL', 16421],
256    'redundancy/redundancy_draid_spare1': ['FAIL', known_reason],
257    'redundancy/redundancy_draid_spare3': ['FAIL', known_reason],
258    'removal/removal_condense_export': ['FAIL', known_reason],
259    'renameat2/setup': ['SKIP', renameat2_reason],
260    'reservation/reservation_008_pos': ['FAIL', 7741],
261    'reservation/reservation_018_pos': ['FAIL', 5642],
262    'snapshot/clone_001_pos': ['FAIL', known_reason],
263    'snapshot/snapshot_006_pos': ['FAIL', known_reason],
264    'snapshot/snapshot_009_pos': ['FAIL', 7961],
265    'snapshot/snapshot_010_pos': ['FAIL', 7961],
266    'snapused/snapused_004_pos': ['FAIL', 5513],
267    'trim/setup': ['SKIP', trim_reason],
268    'upgrade/upgrade_projectquota_001_pos': ['SKIP', project_id_reason],
269    'upgrade/upgrade_projectquota_002_pos': ['SKIP', project_id_reason],
270    'user_namespace/setup': ['SKIP', user_ns_reason],
271    'userquota/setup': ['SKIP', exec_reason],
272    'vdev_zaps/vdev_zaps_004_pos': ['FAIL', known_reason],
273    'zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos': ['FAIL', 5848],
274}
275
276if sys.platform.startswith('freebsd'):
277    maybe.update({
278        'cli_root/zfs_copies/zfs_copies_002_pos': ['FAIL', known_reason],
279        'cli_root/zfs_inherit/zfs_inherit_001_neg': ['FAIL', known_reason],
280        'cli_root/zpool_import/zpool_import_012_pos': ['FAIL', known_reason],
281        'delegate/zfs_allow_003_pos': ['FAIL', known_reason],
282        'inheritance/inherit_001_pos': ['FAIL', 11829],
283        'pool_checkpoint/checkpoint_big_rewind': ['FAIL', 12622],
284        'pool_checkpoint/checkpoint_indirect': ['FAIL', 12623],
285        'resilver/resilver_restart_001': ['FAIL', known_reason],
286        'snapshot/snapshot_002_pos': ['FAIL', 14831],
287        'zvol/zvol_misc/zvol_misc_volmode': ['FAIL', 16668],
288        'bclone/bclone_crossfs_corner_cases': ['SKIP', cfr_cross_reason],
289        'bclone/bclone_crossfs_corner_cases_limited':
290            ['SKIP', cfr_cross_reason],
291        'bclone/bclone_crossfs_data': ['SKIP', cfr_cross_reason],
292        'bclone/bclone_crossfs_embedded': ['SKIP', cfr_cross_reason],
293        'bclone/bclone_crossfs_hole': ['SKIP', cfr_cross_reason],
294        'bclone/bclone_diffprops_all': ['SKIP', cfr_cross_reason],
295        'bclone/bclone_diffprops_checksum': ['SKIP', cfr_cross_reason],
296        'bclone/bclone_diffprops_compress': ['SKIP', cfr_cross_reason],
297        'bclone/bclone_diffprops_copies': ['SKIP', cfr_cross_reason],
298        'bclone/bclone_diffprops_recordsize': ['SKIP', cfr_cross_reason],
299        'bclone/bclone_prop_sync': ['SKIP', cfr_cross_reason],
300        'block_cloning/block_cloning_cross_enc_dataset':
301            ['SKIP', cfr_cross_reason],
302        'block_cloning/block_cloning_copyfilerange_cross_dataset':
303            ['SKIP', cfr_cross_reason],
304        'stat/statx_dioalign': ['SKIP', 'na_reason'],
305    })
306elif sys.platform.startswith('linux'):
307    maybe.update({
308        'bclone/bclone_crossfs_corner_cases': ['SKIP', cfr_cross_reason],
309        'bclone/bclone_crossfs_corner_cases_limited':
310            ['SKIP', cfr_cross_reason],
311        'bclone/bclone_crossfs_data': ['SKIP', cfr_cross_reason],
312        'bclone/bclone_crossfs_embedded': ['SKIP', cfr_cross_reason],
313        'bclone/bclone_crossfs_hole': ['SKIP', cfr_cross_reason],
314        'bclone/bclone_diffprops_all': ['SKIP', cfr_cross_reason],
315        'bclone/bclone_diffprops_checksum': ['SKIP', cfr_cross_reason],
316        'bclone/bclone_diffprops_compress': ['SKIP', cfr_cross_reason],
317        'bclone/bclone_diffprops_copies': ['SKIP', cfr_cross_reason],
318        'bclone/bclone_diffprops_recordsize': ['SKIP', cfr_cross_reason],
319        'bclone/bclone_prop_sync': ['SKIP', cfr_cross_reason],
320        'bclone/bclone_samefs_corner_cases': ['SKIP', cfr_reason],
321        'bclone/bclone_samefs_corner_cases_limited': ['SKIP', cfr_reason],
322        'bclone/bclone_samefs_data': ['SKIP', cfr_reason],
323        'bclone/bclone_samefs_embedded': ['SKIP', cfr_reason],
324        'bclone/bclone_samefs_hole': ['SKIP', cfr_reason],
325        'block_cloning/block_cloning_clone_mmap_cached': ['SKIP', cfr_reason],
326        'block_cloning/block_cloning_clone_mmap_write':
327            ['SKIP', cfr_reason],
328        'block_cloning/block_cloning_copyfilerange':
329            ['SKIP', cfr_reason],
330        'block_cloning/block_cloning_copyfilerange_cross_dataset':
331            ['SKIP', cfr_cross_reason],
332        'block_cloning/block_cloning_copyfilerange_fallback':
333            ['SKIP', cfr_reason],
334        'block_cloning/block_cloning_copyfilerange_fallback_same_txg':
335            ['SKIP', cfr_cross_reason],
336        'block_cloning/block_cloning_copyfilerange_partial':
337            ['SKIP', cfr_reason],
338        'block_cloning/block_cloning_cross_enc_dataset':
339            ['SKIP', cfr_cross_reason],
340        'block_cloning/block_cloning_disabled_copyfilerange':
341            ['SKIP', cfr_reason],
342        'block_cloning/block_cloning_lwb_buffer_overflow':
343            ['SKIP', cfr_reason],
344        'block_cloning/block_cloning_replay':
345            ['SKIP', cfr_reason],
346        'block_cloning/block_cloning_replay_encrypted':
347            ['SKIP', cfr_reason],
348        'block_cloning/block_cloning_rlimit_fsize':
349            ['SKIP', cfr_reason],
350        'block_cloning/block_cloning_large_offset':
351            ['SKIP', cfr_reason],
352        'cli_root/zfs_rename/zfs_rename_002_pos': ['FAIL', known_reason],
353        'cli_root/zpool_reopen/zpool_reopen_003_pos': ['FAIL', known_reason],
354        'cp_files/cp_files_002_pos': ['SKIP', cfr_reason],
355        'fault/auto_online_002_pos': ['FAIL', 11889],
356        'fault/auto_replace_001_pos': ['FAIL', 14851],
357        'fault/auto_spare_002_pos': ['FAIL', 11889],
358        'fault/auto_spare_multiple': ['FAIL', 11889],
359        'fault/auto_spare_shared': ['FAIL', 11889],
360        'fault/decompress_fault': ['FAIL', 11889],
361        'idmap_mount/idmap_mount_001': ['SKIP', idmap_reason],
362        'idmap_mount/idmap_mount_002': ['SKIP', idmap_reason],
363        'idmap_mount/idmap_mount_003': ['SKIP', idmap_reason],
364        'idmap_mount/idmap_mount_004': ['SKIP', idmap_reason],
365        'idmap_mount/idmap_mount_005': ['SKIP', idmap_reason],
366        'io/io_uring': ['SKIP', 'io_uring support required'],
367        'limits/filesystem_limit': ['SKIP', known_reason],
368        'limits/snapshot_limit': ['SKIP', known_reason],
369        'mmp/mmp_active_import': ['FAIL', known_reason],
370        'mmp/mmp_exported_import': ['FAIL', known_reason],
371        'mmp/mmp_inactive_import': ['FAIL', known_reason],
372        'stat/statx_dioalign': ['SKIP', 'statx_reason'],
373    })
374
375
376def process_results(pathname):
377    try:
378        f = open(pathname, errors='replace')
379    except IOError as e:
380        print('Error opening file:', e)
381        sys.exit(1)
382
383    prefix = '/zfs-tests/tests/(?:functional|perf/regression)/'
384    pattern = \
385        r'^(?:\[[0-9\-T:\.]+\]\s+)?' + \
386        r'Test(?:\s+\(\S+\))?:' + \
387        rf'\s*\S*{prefix}(\S+)' + \
388        r'\s*\(run as (\S+)\)\s*\[(\S+)\]\s*\[(\S+)\]'
389    pattern_log = r'^\s*Log directory:\s*(\S*)'
390
391    d = {}
392    logdir = 'Could not determine log directory.'
393    for line in f.readlines():
394        m = re.match(pattern, line)
395        if m and len(m.groups()) == 4:
396            d[m.group(1)] = m.group(4)
397            continue
398
399        m = re.match(pattern_log, line)
400        if m:
401            logdir = m.group(1)
402
403    return d, logdir
404
405
406class ListMaybesAction(argparse.Action):
407    def __init__(self,
408                 option_strings,
409                 dest="SUPPRESS",
410                 default="SUPPRESS",
411                 help="list flaky tests and exit"):
412        super(ListMaybesAction, self).__init__(
413            option_strings=option_strings,
414            dest=dest,
415            default=default,
416            nargs=0,
417            help=help)
418
419    def __call__(self, parser, namespace, values, option_string=None):
420        for test in maybe:
421            print(test)
422        sys.exit(0)
423
424
425if __name__ == "__main__":
426    parser = argparse.ArgumentParser(description='Analyze ZTS logs')
427    parser.add_argument('logfile')
428    parser.add_argument('--list-maybes', action=ListMaybesAction)
429    parser.add_argument('--no-maybes', action='store_false', dest='maybes')
430    args = parser.parse_args()
431
432    results, logdir = process_results(args.logfile)
433
434    if not results:
435        print("\n\nNo test results were found.")
436        print("Log directory:", logdir)
437        sys.exit(0)
438
439    expected = []
440    unexpected = []
441    all_maybes = True
442
443    for test in list(results.keys()):
444        if results[test] == "PASS":
445            continue
446
447        setup = test.replace(os.path.basename(test), "setup")
448        if results[test] == "SKIP" and test != setup:
449            if setup in known and known[setup][0] == "SKIP":
450                continue
451            if setup in maybe and maybe[setup][0] == "SKIP":
452                continue
453
454        if (test in known and results[test] in known[test][0]):
455            expected.append(test)
456        elif test in maybe and results[test] in maybe[test][0]:
457            if results[test] == 'SKIP' or args.maybes:
458                expected.append(test)
459            elif not args.maybes:
460                unexpected.append(test)
461        else:
462            unexpected.append(test)
463            all_maybes = False
464
465    print("\nTests with results other than PASS that are expected:")
466    for test in sorted(expected):
467        issue_url = 'https://github.com/openzfs/zfs/issues/'
468
469        # Include the reason why the result is expected, given the following:
470        # 1. Suppress test results which set the "Not applicable" reason.
471        # 2. Numerical reasons are assumed to be GitHub issue numbers.
472        # 3. When an entire test group is skipped only report the setup reason.
473        if test in known:
474            if known[test][1] == na_reason:
475                continue
476            elif isinstance(known[test][1], int):
477                expect = f"{issue_url}{known[test][1]}"
478            else:
479                expect = known[test][1]
480        elif test in maybe:
481            if isinstance(maybe[test][1], int):
482                expect = f"{issue_url}{maybe[test][1]}"
483            else:
484                expect = maybe[test][1]
485        elif setup in known and known[setup][0] == "SKIP" and setup != test:
486            continue
487        elif setup in maybe and maybe[setup][0] == "SKIP" and setup != test:
488            continue
489        else:
490            expect = "UNKNOWN REASON"
491        print(f"    {results[test]} {test} ({expect})")
492
493    print("\nTests with result of PASS that are unexpected:")
494    for test in sorted(known.keys()):
495        # We probably should not be silently ignoring the case
496        # where "test" is not in "results".
497        if test not in results or results[test] != "PASS":
498            continue
499        print(f"    {results[test]} {test} (expected {known[test][0]})")
500
501    print("\nTests with results other than PASS that are unexpected:")
502    for test in sorted(unexpected):
503        expect = "PASS" if test not in known else known[test][0]
504        print(f"    {results[test]} {test} (expected {expect})")
505
506    if len(unexpected) == 0:
507        sys.exit(0)
508    elif not args.maybes and all_maybes:
509        sys.exit(2)
510    else:
511        sys.exit(1)
512