Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | # Copyright (C) 2016 Intel Corporation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | |
| 7 | from oeqa.core.exception import OEQAMissingVariable |
| 8 | |
| 9 | from . import OETestDecorator, registerDecorator |
| 10 | |
| 11 | def has_feature(td, feature): |
| 12 | """ |
| 13 | Checks for feature in DISTRO_FEATURES or IMAGE_FEATURES. |
| 14 | """ |
| 15 | |
| 16 | if (feature in td.get('DISTRO_FEATURES', '') or |
| 17 | feature in td.get('IMAGE_FEATURES', '')): |
| 18 | return True |
| 19 | return False |
| 20 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame^] | 21 | def has_machine(td, machine): |
| 22 | """ |
| 23 | Checks for MACHINE. |
| 24 | """ |
| 25 | |
| 26 | if (machine in td.get('MACHINE', '')): |
| 27 | return True |
| 28 | return False |
| 29 | |
| 30 | def is_qemu(td, qemu): |
| 31 | """ |
| 32 | Checks if MACHINE is qemu. |
| 33 | """ |
| 34 | |
| 35 | machine = td.get('MACHINE', '') |
| 36 | if (qemu in td.get('MACHINE', '') or |
| 37 | machine.startswith('qemu')): |
| 38 | return True |
| 39 | return False |
| 40 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | @registerDecorator |
| 42 | class skipIfDataVar(OETestDecorator): |
| 43 | """ |
| 44 | Skip test based on value of a data store's variable. |
| 45 | |
| 46 | It will get the info of var from the data store and will |
| 47 | check it against value; if are equal it will skip the test |
| 48 | with msg as the reason. |
| 49 | """ |
| 50 | |
| 51 | attrs = ('var', 'value', 'msg') |
| 52 | |
| 53 | def setUpDecorator(self): |
| 54 | msg = ('Checking if %r value is %r to skip test' % |
| 55 | (self.var, self.value)) |
| 56 | self.logger.debug(msg) |
| 57 | if self.case.td.get(self.var) == self.value: |
| 58 | self.case.skipTest(self.msg) |
| 59 | |
| 60 | @registerDecorator |
| 61 | class skipIfNotDataVar(OETestDecorator): |
| 62 | """ |
| 63 | Skip test based on value of a data store's variable. |
| 64 | |
| 65 | It will get the info of var from the data store and will |
| 66 | check it against value; if are not equal it will skip the |
| 67 | test with msg as the reason. |
| 68 | """ |
| 69 | |
| 70 | attrs = ('var', 'value', 'msg') |
| 71 | |
| 72 | def setUpDecorator(self): |
| 73 | msg = ('Checking if %r value is not %r to skip test' % |
| 74 | (self.var, self.value)) |
| 75 | self.logger.debug(msg) |
| 76 | if not self.case.td.get(self.var) == self.value: |
| 77 | self.case.skipTest(self.msg) |
| 78 | |
| 79 | @registerDecorator |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | class skipIfInDataVar(OETestDecorator): |
| 81 | """ |
| 82 | Skip test if value is in data store's variable. |
| 83 | """ |
| 84 | |
| 85 | attrs = ('var', 'value', 'msg') |
| 86 | def setUpDecorator(self): |
| 87 | msg = ('Checking if %r value contains %r to skip ' |
| 88 | 'the test' % (self.var, self.value)) |
| 89 | self.logger.debug(msg) |
| 90 | if self.value in (self.case.td.get(self.var)): |
| 91 | self.case.skipTest(self.msg) |
| 92 | |
| 93 | @registerDecorator |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | class skipIfNotInDataVar(OETestDecorator): |
| 95 | """ |
| 96 | Skip test if value is not in data store's variable. |
| 97 | """ |
| 98 | |
| 99 | attrs = ('var', 'value', 'msg') |
| 100 | def setUpDecorator(self): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 101 | msg = ('Checking if %r value contains %r to run ' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | 'the test' % (self.var, self.value)) |
| 103 | self.logger.debug(msg) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 104 | if not self.value in (self.case.td.get(self.var) or ""): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 105 | self.case.skipTest(self.msg) |
| 106 | |
| 107 | @registerDecorator |
| 108 | class OETestDataDepends(OETestDecorator): |
| 109 | attrs = ('td_depends',) |
| 110 | |
| 111 | def setUpDecorator(self): |
| 112 | for v in self.td_depends: |
| 113 | try: |
| 114 | value = self.case.td[v] |
| 115 | except KeyError: |
| 116 | raise OEQAMissingVariable("Test case need %s variable but"\ |
| 117 | " isn't into td" % v) |
| 118 | |
| 119 | @registerDecorator |
| 120 | class skipIfNotFeature(OETestDecorator): |
| 121 | """ |
| 122 | Skip test based on DISTRO_FEATURES. |
| 123 | |
| 124 | value must be in distro features or it will skip the test |
| 125 | with msg as the reason. |
| 126 | """ |
| 127 | |
| 128 | attrs = ('value', 'msg') |
| 129 | |
| 130 | def setUpDecorator(self): |
| 131 | msg = ('Checking if %s is in DISTRO_FEATURES ' |
| 132 | 'or IMAGE_FEATURES' % (self.value)) |
| 133 | self.logger.debug(msg) |
| 134 | if not has_feature(self.case.td, self.value): |
| 135 | self.case.skipTest(self.msg) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 136 | |
| 137 | @registerDecorator |
| 138 | class skipIfFeature(OETestDecorator): |
| 139 | """ |
| 140 | Skip test based on DISTRO_FEATURES. |
| 141 | |
| 142 | value must not be in distro features or it will skip the test |
| 143 | with msg as the reason. |
| 144 | """ |
| 145 | |
| 146 | attrs = ('value', 'msg') |
| 147 | |
| 148 | def setUpDecorator(self): |
| 149 | msg = ('Checking if %s is not in DISTRO_FEATURES ' |
| 150 | 'or IMAGE_FEATURES' % (self.value)) |
| 151 | self.logger.debug(msg) |
| 152 | if has_feature(self.case.td, self.value): |
| 153 | self.case.skipTest(self.msg) |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame^] | 154 | |
| 155 | @registerDecorator |
| 156 | class skipIfNotMachine(OETestDecorator): |
| 157 | """ |
| 158 | Skip test based on MACHINE. |
| 159 | |
| 160 | value must be match MACHINE or it will skip the test |
| 161 | with msg as the reason. |
| 162 | """ |
| 163 | |
| 164 | attrs = ('value', 'msg') |
| 165 | |
| 166 | def setUpDecorator(self): |
| 167 | msg = ('Checking if %s is not this MACHINE' % self.value) |
| 168 | self.logger.debug(msg) |
| 169 | if not has_machine(self.case.td, self.value): |
| 170 | self.case.skipTest(self.msg) |
| 171 | |
| 172 | @registerDecorator |
| 173 | class skipIfMachine(OETestDecorator): |
| 174 | """ |
| 175 | Skip test based on Machine. |
| 176 | |
| 177 | value must not be this machine or it will skip the test |
| 178 | with msg as the reason. |
| 179 | """ |
| 180 | |
| 181 | attrs = ('value', 'msg') |
| 182 | |
| 183 | def setUpDecorator(self): |
| 184 | msg = ('Checking if %s is this MACHINE' % self.value) |
| 185 | self.logger.debug(msg) |
| 186 | if has_machine(self.case.td, self.value): |
| 187 | self.case.skipTest(self.msg) |
| 188 | |
| 189 | @registerDecorator |
| 190 | class skipIfNotQemu(OETestDecorator): |
| 191 | """ |
| 192 | Skip test based on MACHINE. |
| 193 | |
| 194 | value must be a qemu MACHINE or it will skip the test |
| 195 | with msg as the reason. |
| 196 | """ |
| 197 | |
| 198 | attrs = ('value', 'msg') |
| 199 | |
| 200 | def setUpDecorator(self): |
| 201 | msg = ('Checking if %s is not this MACHINE' % self.value) |
| 202 | self.logger.debug(msg) |
| 203 | if not is_qemu(self.case.td, self.value): |
| 204 | self.case.skipTest(self.msg) |
| 205 | |
| 206 | @registerDecorator |
| 207 | class skipIfQemu(OETestDecorator): |
| 208 | """ |
| 209 | Skip test based on Qemu Machine. |
| 210 | |
| 211 | value must not be a qemu machine or it will skip the test |
| 212 | with msg as the reason. |
| 213 | """ |
| 214 | |
| 215 | attrs = ('value', 'msg') |
| 216 | |
| 217 | def setUpDecorator(self): |
| 218 | msg = ('Checking if %s is this MACHINE' % self.value) |
| 219 | self.logger.debug(msg) |
| 220 | if is_qemu(self.case.td, self.value): |
| 221 | self.case.skipTest(self.msg) |
| 222 | |