diff options
Diffstat (limited to 'meta/lib/patchtest/data.py')
| -rw-r--r-- | meta/lib/patchtest/data.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/meta/lib/patchtest/data.py b/meta/lib/patchtest/data.py new file mode 100644 index 0000000000..b661dd6479 --- /dev/null +++ b/meta/lib/patchtest/data.py | |||
| @@ -0,0 +1,95 @@ | |||
| 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 | # This program is free software; you can redistribute it and/or modify | ||
| 10 | # it under the terms of the GNU General Public License version 2 as | ||
| 11 | # published by the Free Software Foundation. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License along | ||
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 21 | # | ||
| 22 | # Author: Leo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | ||
| 23 | # | ||
| 24 | # NOTE: Strictly speaking, unit test should be isolated from outside, | ||
| 25 | # but patchtest test suites uses command line input data and | ||
| 26 | # pretest and test test cases may use the datastore defined | ||
| 27 | # on this module | ||
| 28 | |||
| 29 | import os | ||
| 30 | import argparse | ||
| 31 | import collections | ||
| 32 | import tempfile | ||
| 33 | import logging | ||
| 34 | |||
| 35 | logger=logging.getLogger('patchtest') | ||
| 36 | info=logger.info | ||
| 37 | |||
| 38 | # Data store commonly used to share values between pre and post-merge tests | ||
| 39 | PatchTestDataStore = collections.defaultdict(str) | ||
| 40 | |||
| 41 | class PatchTestInput(object): | ||
| 42 | """Abstract the patchtest argument parser""" | ||
| 43 | |||
| 44 | @classmethod | ||
| 45 | def set_namespace(cls): | ||
| 46 | parser = cls.get_parser() | ||
| 47 | parser.parse_args(namespace=cls) | ||
| 48 | |||
| 49 | @classmethod | ||
| 50 | def get_parser(cls): | ||
| 51 | parser = argparse.ArgumentParser() | ||
| 52 | |||
| 53 | target_patch_group = parser.add_mutually_exclusive_group(required=True) | ||
| 54 | |||
| 55 | target_patch_group.add_argument('--patch', metavar='PATCH', dest='patch_path', | ||
| 56 | help='The patch to be tested') | ||
| 57 | |||
| 58 | target_patch_group.add_argument('--directory', metavar='DIRECTORY', dest='patch_path', | ||
| 59 | help='The directory containing patches to be tested') | ||
| 60 | |||
| 61 | parser.add_argument('repodir', metavar='REPO', | ||
| 62 | help="Name of the repository where patch is merged") | ||
| 63 | |||
| 64 | parser.add_argument('startdir', metavar='TESTDIR', | ||
| 65 | help="Directory where test cases are located") | ||
| 66 | |||
| 67 | parser.add_argument('--top-level-directory', '-t', | ||
| 68 | dest='topdir', | ||
| 69 | default=None, | ||
| 70 | help="Top level directory of project (defaults to start directory)") | ||
| 71 | |||
| 72 | parser.add_argument('--pattern', '-p', | ||
| 73 | dest='pattern', | ||
| 74 | default='test*.py', | ||
| 75 | help="Pattern to match test files") | ||
| 76 | |||
| 77 | parser.add_argument('--base-branch', '-b', | ||
| 78 | dest='basebranch', | ||
| 79 | help="Branch name used by patchtest to branch from. By default, it uses the current one.") | ||
| 80 | |||
| 81 | parser.add_argument('--base-commit', '-c', | ||
| 82 | dest='basecommit', | ||
| 83 | help="Commit ID used by patchtest to branch from. By default, it uses HEAD.") | ||
| 84 | |||
| 85 | parser.add_argument('--debug', '-d', | ||
| 86 | action='store_true', | ||
| 87 | help='Enable debug output') | ||
| 88 | |||
| 89 | parser.add_argument('--log-results', | ||
| 90 | action='store_true', | ||
| 91 | help='Enable logging to a file matching the target patch name with ".testresult" appended') | ||
| 92 | |||
| 93 | |||
| 94 | return parser | ||
| 95 | |||
