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