xref: /openbmc/qemu/tests/qemu-iotests/check (revision f203080bbd9f9e5b31041b1f2afcd6040c5aaec5)
1*f203080bSVladimir Sementsov-Ogievskiy#!/usr/bin/env python3
26bf19c94SChristoph Hellwig#
3*f203080bSVladimir Sementsov-Ogievskiy# Configure environment and run group of tests in it.
4*f203080bSVladimir Sementsov-Ogievskiy#
5*f203080bSVladimir Sementsov-Ogievskiy# Copyright (c) 2020-2021 Virtuozzo International GmbH
66bf19c94SChristoph Hellwig#
76bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or
86bf19c94SChristoph Hellwig# modify it under the terms of the GNU General Public License as
96bf19c94SChristoph Hellwig# published by the Free Software Foundation.
106bf19c94SChristoph Hellwig#
116bf19c94SChristoph Hellwig# This program is distributed in the hope that it would be useful,
126bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of
136bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
146bf19c94SChristoph Hellwig# GNU General Public License for more details.
156bf19c94SChristoph Hellwig#
166bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License
17e8c212d6SChristoph Hellwig# along with this program.  If not, see <http://www.gnu.org/licenses/>.
186bf19c94SChristoph Hellwig
19*f203080bSVladimir Sementsov-Ogievskiyimport os
20*f203080bSVladimir Sementsov-Ogievskiyimport sys
21*f203080bSVladimir Sementsov-Ogievskiyimport argparse
22*f203080bSVladimir Sementsov-Ogievskiyfrom findtests import TestFinder
23*f203080bSVladimir Sementsov-Ogievskiyfrom testenv import TestEnv
24*f203080bSVladimir Sementsov-Ogievskiyfrom testrunner import TestRunner
256bf19c94SChristoph Hellwig
26e8f8624dSMax Reitz
27*f203080bSVladimir Sementsov-Ogievskiydef make_argparser() -> argparse.ArgumentParser:
28*f203080bSVladimir Sementsov-Ogievskiy    p = argparse.ArgumentParser(description="Test run options")
29e8f8624dSMax Reitz
30*f203080bSVladimir Sementsov-Ogievskiy    p.add_argument('-n', '--dry-run', action='store_true',
31*f203080bSVladimir Sementsov-Ogievskiy                   help='show me, do not run tests')
32*f203080bSVladimir Sementsov-Ogievskiy    p.add_argument('-makecheck', action='store_true',
33*f203080bSVladimir Sementsov-Ogievskiy                   help='pretty print output for make check')
34e8f8624dSMax Reitz
35*f203080bSVladimir Sementsov-Ogievskiy    p.add_argument('-d', dest='debug', action='store_true', help='debug')
36*f203080bSVladimir Sementsov-Ogievskiy    p.add_argument('-misalign', action='store_true',
37*f203080bSVladimir Sementsov-Ogievskiy                   help='misalign memory allocations')
38*f203080bSVladimir Sementsov-Ogievskiy    p.add_argument('--color', choices=['on', 'off', 'auto'],
39*f203080bSVladimir Sementsov-Ogievskiy                   default='auto', help="use terminal colors. The default "
40*f203080bSVladimir Sementsov-Ogievskiy                   "'auto' value means use colors if terminal stdout detected")
417fed1a49SMax Reitz
42*f203080bSVladimir Sementsov-Ogievskiy    g_env = p.add_argument_group('test environment options')
43*f203080bSVladimir Sementsov-Ogievskiy    mg = g_env.add_mutually_exclusive_group()
44*f203080bSVladimir Sementsov-Ogievskiy    # We don't set default for cachemode, as we need to distinguish default
45*f203080bSVladimir Sementsov-Ogievskiy    # from user input later.
46*f203080bSVladimir Sementsov-Ogievskiy    mg.add_argument('-nocache', dest='cachemode', action='store_const',
47*f203080bSVladimir Sementsov-Ogievskiy                    const='none', help='set cache mode "none" (O_DIRECT), '
48*f203080bSVladimir Sementsov-Ogievskiy                    'sets CACHEMODE environment variable')
49*f203080bSVladimir Sementsov-Ogievskiy    mg.add_argument('-c', dest='cachemode',
50*f203080bSVladimir Sementsov-Ogievskiy                    help='sets CACHEMODE environment variable')
516bf19c94SChristoph Hellwig
52*f203080bSVladimir Sementsov-Ogievskiy    g_env.add_argument('-i', dest='aiomode', default='threads',
53*f203080bSVladimir Sementsov-Ogievskiy                       help='sets AIOMODE environment variable')
5409d653e6SPaolo Bonzini
55*f203080bSVladimir Sementsov-Ogievskiy    p.set_defaults(imgfmt='raw', imgproto='file')
5609d653e6SPaolo Bonzini
57*f203080bSVladimir Sementsov-Ogievskiy    format_list = ['raw', 'bochs', 'cloop', 'parallels', 'qcow', 'qcow2',
58*f203080bSVladimir Sementsov-Ogievskiy                   'qed', 'vdi', 'vpc', 'vhdx', 'vmdk', 'luks', 'dmg']
59*f203080bSVladimir Sementsov-Ogievskiy    g_fmt = p.add_argument_group(
60*f203080bSVladimir Sementsov-Ogievskiy        '  image format options',
61*f203080bSVladimir Sementsov-Ogievskiy        'The following options set the IMGFMT environment variable. '
62*f203080bSVladimir Sementsov-Ogievskiy        'At most one choice is allowed, default is "raw"')
63*f203080bSVladimir Sementsov-Ogievskiy    mg = g_fmt.add_mutually_exclusive_group()
64*f203080bSVladimir Sementsov-Ogievskiy    for fmt in format_list:
65*f203080bSVladimir Sementsov-Ogievskiy        mg.add_argument('-' + fmt, dest='imgfmt', action='store_const',
66*f203080bSVladimir Sementsov-Ogievskiy                        const=fmt, help=f'test {fmt}')
6770ff5b07SAlex Bennée
68*f203080bSVladimir Sementsov-Ogievskiy    protocol_list = ['file', 'rbd', 'sheepdog', 'nbd', 'ssh', 'nfs',
69*f203080bSVladimir Sementsov-Ogievskiy                     'fuse']
70*f203080bSVladimir Sementsov-Ogievskiy    g_prt = p.add_argument_group(
71*f203080bSVladimir Sementsov-Ogievskiy        '  image protocol options',
72*f203080bSVladimir Sementsov-Ogievskiy        'The following options set the IMGPROTO environment variable. '
73*f203080bSVladimir Sementsov-Ogievskiy        'At most one choice is allowed, default is "file"')
74*f203080bSVladimir Sementsov-Ogievskiy    mg = g_prt.add_mutually_exclusive_group()
75*f203080bSVladimir Sementsov-Ogievskiy    for prt in protocol_list:
76*f203080bSVladimir Sementsov-Ogievskiy        mg.add_argument('-' + prt, dest='imgproto', action='store_const',
77*f203080bSVladimir Sementsov-Ogievskiy                        const=prt, help=f'test {prt}')
7870ff5b07SAlex Bennée
79*f203080bSVladimir Sementsov-Ogievskiy    g_bash = p.add_argument_group('bash tests options',
80*f203080bSVladimir Sementsov-Ogievskiy                                  'The following options are ignored by '
81*f203080bSVladimir Sementsov-Ogievskiy                                  'python tests.')
82*f203080bSVladimir Sementsov-Ogievskiy    # TODO: make support for the following options in iotests.py
83*f203080bSVladimir Sementsov-Ogievskiy    g_bash.add_argument('-o', dest='imgopts',
84*f203080bSVladimir Sementsov-Ogievskiy                        help='options to pass to qemu-img create/convert, '
85*f203080bSVladimir Sementsov-Ogievskiy                        'sets IMGOPTS environment variable')
86*f203080bSVladimir Sementsov-Ogievskiy    g_bash.add_argument('-valgrind', action='store_true',
87*f203080bSVladimir Sementsov-Ogievskiy                        help='use valgrind, sets VALGRIND_QEMU environment '
88*f203080bSVladimir Sementsov-Ogievskiy                        'variable')
8909d653e6SPaolo Bonzini
90*f203080bSVladimir Sementsov-Ogievskiy    g_sel = p.add_argument_group('test selecting options',
91*f203080bSVladimir Sementsov-Ogievskiy                                 'The following options specify test set '
92*f203080bSVladimir Sementsov-Ogievskiy                                 'to run.')
93*f203080bSVladimir Sementsov-Ogievskiy    g_sel.add_argument('-g', '--groups', metavar='group1,...',
94*f203080bSVladimir Sementsov-Ogievskiy                       help='include tests from these groups')
95*f203080bSVladimir Sementsov-Ogievskiy    g_sel.add_argument('-x', '--exclude-groups', metavar='group1,...',
96*f203080bSVladimir Sementsov-Ogievskiy                       help='exclude tests from these groups')
97*f203080bSVladimir Sementsov-Ogievskiy    g_sel.add_argument('--start-from', metavar='TEST',
98*f203080bSVladimir Sementsov-Ogievskiy                       help='Start from specified test: make sorted sequence '
99*f203080bSVladimir Sementsov-Ogievskiy                       'of tests as usual and then drop tests from the first '
100*f203080bSVladimir Sementsov-Ogievskiy                       'one to TEST (not inclusive). This may be used to '
101*f203080bSVladimir Sementsov-Ogievskiy                       'rerun failed ./check command, starting from the '
102*f203080bSVladimir Sementsov-Ogievskiy                       'middle of the process.')
103*f203080bSVladimir Sementsov-Ogievskiy    g_sel.add_argument('tests', metavar='TEST_FILES', nargs='*',
104*f203080bSVladimir Sementsov-Ogievskiy                       help='tests to run')
10509d653e6SPaolo Bonzini
106*f203080bSVladimir Sementsov-Ogievskiy    return p
10709d653e6SPaolo Bonzini
10809d653e6SPaolo Bonzini
109*f203080bSVladimir Sementsov-Ogievskiyif __name__ == '__main__':
110*f203080bSVladimir Sementsov-Ogievskiy    args = make_argparser().parse_args()
11109d653e6SPaolo Bonzini
112*f203080bSVladimir Sementsov-Ogievskiy    env = TestEnv(imgfmt=args.imgfmt, imgproto=args.imgproto,
113*f203080bSVladimir Sementsov-Ogievskiy                  aiomode=args.aiomode, cachemode=args.cachemode,
114*f203080bSVladimir Sementsov-Ogievskiy                  imgopts=args.imgopts, misalign=args.misalign,
115*f203080bSVladimir Sementsov-Ogievskiy                  debug=args.debug, valgrind=args.valgrind)
11609d653e6SPaolo Bonzini
117*f203080bSVladimir Sementsov-Ogievskiy    testfinder = TestFinder(test_dir=env.source_iotests)
1188803714bSEric Blake
119*f203080bSVladimir Sementsov-Ogievskiy    groups = args.groups.split(',') if args.groups else None
120*f203080bSVladimir Sementsov-Ogievskiy    x_groups = args.exclude_groups.split(',') if args.exclude_groups else None
12109d653e6SPaolo Bonzini
122*f203080bSVladimir Sementsov-Ogievskiy    group_local = os.path.join(env.source_iotests, 'group.local')
123*f203080bSVladimir Sementsov-Ogievskiy    if os.path.isfile(group_local):
124*f203080bSVladimir Sementsov-Ogievskiy        try:
125*f203080bSVladimir Sementsov-Ogievskiy            testfinder.add_group_file(group_local)
126*f203080bSVladimir Sementsov-Ogievskiy        except ValueError as e:
127*f203080bSVladimir Sementsov-Ogievskiy            sys.exit(f"Failed to parse group file '{group_local}': {e}")
12809d653e6SPaolo Bonzini
129*f203080bSVladimir Sementsov-Ogievskiy    try:
130*f203080bSVladimir Sementsov-Ogievskiy        tests = testfinder.find_tests(groups=groups, exclude_groups=x_groups,
131*f203080bSVladimir Sementsov-Ogievskiy                                      tests=args.tests,
132*f203080bSVladimir Sementsov-Ogievskiy                                      start_from=args.start_from)
133*f203080bSVladimir Sementsov-Ogievskiy        if not tests:
134*f203080bSVladimir Sementsov-Ogievskiy            raise ValueError('No tests selected')
135*f203080bSVladimir Sementsov-Ogievskiy    except ValueError as e:
136*f203080bSVladimir Sementsov-Ogievskiy        sys.exit(e)
13709d653e6SPaolo Bonzini
138*f203080bSVladimir Sementsov-Ogievskiy    if args.dry_run:
139*f203080bSVladimir Sementsov-Ogievskiy        print('\n'.join(tests))
140*f203080bSVladimir Sementsov-Ogievskiy    else:
141*f203080bSVladimir Sementsov-Ogievskiy        with TestRunner(env, makecheck=args.makecheck,
142*f203080bSVladimir Sementsov-Ogievskiy                        color=args.color) as tr:
143*f203080bSVladimir Sementsov-Ogievskiy            tr.run_tests([os.path.join(env.source_iotests, t) for t in tests])
144