xref: /openbmc/openbmc/poky/meta/lib/patchtest/data.py (revision ac13d5f3)
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# patchtestdata: module used to share command line arguments between
5#                patchtest & test suite and a data store between test cases
6#
7# Copyright (C) 2016 Intel Corporation
8#
9# SPDX-License-Identifier: GPL-2.0-only
10#
11# NOTE: Strictly speaking, unit test should be isolated from outside,
12#       but patchtest test suites uses command line input data and
13#       pretest and test test cases may use the datastore defined
14#       on this module
15
16import os
17import argparse
18import collections
19import logging
20
21logger=logging.getLogger('patchtest')
22info=logger.info
23
24default_testdir = os.path.abspath(os.path.dirname(__file__) + "/tests")
25default_repodir = os.path.abspath(os.path.dirname(__file__) + "/../../..")
26
27# Data store commonly used to share values between pre and post-merge tests
28PatchTestDataStore = collections.defaultdict(str)
29
30class PatchTestInput(object):
31    """Abstract the patchtest argument parser"""
32
33    @classmethod
34    def set_namespace(cls):
35        parser = cls.get_parser()
36        parser.parse_args(namespace=cls)
37
38    @classmethod
39    def get_parser(cls):
40        parser = argparse.ArgumentParser()
41
42        target_patch_group = parser.add_mutually_exclusive_group(required=True)
43
44        target_patch_group.add_argument('--patch', metavar='PATCH', dest='patch_path',
45                            help='The patch to be tested')
46
47        target_patch_group.add_argument('--directory', metavar='DIRECTORY', dest='patch_path',
48                            help='The directory containing patches to be tested')
49
50        parser.add_argument('--repodir', metavar='REPO',
51                            default=default_repodir,
52                            help="Name of the repository where patch is merged")
53
54        parser.add_argument('--testdir', metavar='TESTDIR',
55                            default=default_testdir,
56                            help="Directory where test cases are located")
57
58        parser.add_argument('--top-level-directory', '-t',
59                            dest='topdir',
60                            default=None,
61                            help="Top level directory of project (defaults to start directory)")
62
63        parser.add_argument('--pattern', '-p',
64                            dest='pattern',
65                            default='test*.py',
66                            help="Pattern to match test files")
67
68        parser.add_argument('--base-branch', '-b',
69                            dest='basebranch',
70                            help="Branch name used by patchtest to branch from. By default, it uses the current one.")
71
72        parser.add_argument('--base-commit', '-c',
73                            dest='basecommit',
74                            help="Commit ID used by patchtest to branch from. By default, it uses HEAD.")
75
76        parser.add_argument('--debug', '-d',
77                            action='store_true',
78                            help='Enable debug output')
79
80        parser.add_argument('--log-results',
81                            action='store_true',
82                            help='Enable logging to a file matching the target patch name with ".testresult" appended')
83
84
85        return parser
86
87