blob: de881e097ab14d31e25550992b980c06bb7cf98c [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7from oeqa.core.exception import OEQAMissingVariable
8
9from . import OETestDecorator, registerDecorator
10
11def has_feature(td, feature):
12 """
13 Checks for feature in DISTRO_FEATURES or IMAGE_FEATURES.
14 """
15
Patrick Williams45852732022-04-02 08:58:32 -050016 if (feature in td.get('DISTRO_FEATURES', '').split() or
17 feature in td.get('IMAGE_FEATURES', '').split()):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018 return True
19 return False
20
Brad Bishop1d80a2e2019-11-15 16:35:03 -050021def has_machine(td, machine):
22 """
23 Checks for MACHINE.
24 """
25
Patrick Williams45852732022-04-02 08:58:32 -050026 if (machine == td.get('MACHINE', '')):
Brad Bishop1d80a2e2019-11-15 16:35:03 -050027 return True
28 return False
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030@registerDecorator
31class 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
50class 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 Bishop1a4b7ee2018-12-16 17:11:34 -080069class 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 Bishop6e60e8b2018-02-01 10:27:11 -050083class 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 Bishopd5ae7d92018-06-14 09:52:03 -070090 msg = ('Checking if %r value contains %r to run '
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 'the test' % (self.var, self.value))
92 self.logger.debug(msg)
Brad Bishopd5ae7d92018-06-14 09:52:03 -070093 if not self.value in (self.case.td.get(self.var) or ""):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 self.case.skipTest(self.msg)
95
96@registerDecorator
97class 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
109class 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 Bishop64c979e2019-11-04 13:55:29 -0500125
126@registerDecorator
127class 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 Bishop1d80a2e2019-11-15 16:35:03 -0500143
144@registerDecorator
145class 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
162class 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
179class skipIfNotQemu(OETestDecorator):
180 """
Patrick Williams45852732022-04-02 08:58:32 -0500181 Skip test if MACHINE is not qemu*
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500182 """
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500183 def setUpDecorator(self):
Patrick Williams45852732022-04-02 08:58:32 -0500184 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 Bishop1d80a2e2019-11-15 16:35:03 -0500187
188@registerDecorator
189class skipIfQemu(OETestDecorator):
190 """
Patrick Williams45852732022-04-02 08:58:32 -0500191 Skip test if MACHINE is qemu*
192 """
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500193 def setUpDecorator(self):
Patrick Williams45852732022-04-02 08:58:32 -0500194 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 Williams7784c422022-11-17 07:29:11 -0600197
198@registerDecorator
199class 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
211class 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)