diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-05-12 14:40:21 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-06 19:02:43 +0100 |
commit | 157c3be2ca93f076033f725ec1ee912df91f7488 (patch) | |
tree | 8ef896ff7adf78d63b34059cd5b017a4f0a3419a /meta/lib/oeqa/selftest/cases/tinfoil.py | |
parent | 10c512b60d1167122b5fe778b93838dca3def717 (diff) | |
download | poky-157c3be2ca93f076033f725ec1ee912df91f7488.tar.gz |
oeqa/selftest/cases: Migrate test cases into the new oe-qa framework
New framework has different classes/decorators so adapt current test cases to
support these. Changes include changes on base classes and decorators.
Also include paths in selftest/__init__.py isn't needed because the
loader is the standard unittest one.
(From OE-Core rev: ddbbefdd124604d10bd47dd0266b55a764fcc0ab)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/tinfoil.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/tinfoil.py | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/tinfoil.py b/meta/lib/oeqa/selftest/cases/tinfoil.py new file mode 100644 index 0000000000..1394d426e7 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/tinfoil.py | |||
@@ -0,0 +1,189 @@ | |||
1 | import os | ||
2 | import re | ||
3 | import bb.tinfoil | ||
4 | |||
5 | from oeqa.selftest.case import OESelftestTestCase | ||
6 | from oeqa.utils.commands import runCmd | ||
7 | from oeqa.core.decorator.oeid import OETestID | ||
8 | |||
9 | class TinfoilTests(OESelftestTestCase): | ||
10 | """ Basic tests for the tinfoil API """ | ||
11 | |||
12 | @OETestID(1568) | ||
13 | def test_getvar(self): | ||
14 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
15 | tinfoil.prepare(True) | ||
16 | machine = tinfoil.config_data.getVar('MACHINE') | ||
17 | if not machine: | ||
18 | self.fail('Unable to get MACHINE value - returned %s' % machine) | ||
19 | |||
20 | @OETestID(1569) | ||
21 | def test_expand(self): | ||
22 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
23 | tinfoil.prepare(True) | ||
24 | expr = '${@os.getpid()}' | ||
25 | pid = tinfoil.config_data.expand(expr) | ||
26 | if not pid: | ||
27 | self.fail('Unable to expand "%s" - returned %s' % (expr, pid)) | ||
28 | |||
29 | @OETestID(1570) | ||
30 | def test_getvar_bb_origenv(self): | ||
31 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
32 | tinfoil.prepare(True) | ||
33 | origenv = tinfoil.config_data.getVar('BB_ORIGENV', False) | ||
34 | if not origenv: | ||
35 | self.fail('Unable to get BB_ORIGENV value - returned %s' % origenv) | ||
36 | self.assertEqual(origenv.getVar('HOME', False), os.environ['HOME']) | ||
37 | |||
38 | @OETestID(1571) | ||
39 | def test_parse_recipe(self): | ||
40 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
41 | tinfoil.prepare(config_only=False, quiet=2) | ||
42 | testrecipe = 'mdadm' | ||
43 | best = tinfoil.find_best_provider(testrecipe) | ||
44 | if not best: | ||
45 | self.fail('Unable to find recipe providing %s' % testrecipe) | ||
46 | rd = tinfoil.parse_recipe_file(best[3]) | ||
47 | self.assertEqual(testrecipe, rd.getVar('PN')) | ||
48 | |||
49 | @OETestID(1572) | ||
50 | def test_parse_recipe_copy_expand(self): | ||
51 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
52 | tinfoil.prepare(config_only=False, quiet=2) | ||
53 | testrecipe = 'mdadm' | ||
54 | best = tinfoil.find_best_provider(testrecipe) | ||
55 | if not best: | ||
56 | self.fail('Unable to find recipe providing %s' % testrecipe) | ||
57 | rd = tinfoil.parse_recipe_file(best[3]) | ||
58 | # Check we can get variable values | ||
59 | self.assertEqual(testrecipe, rd.getVar('PN')) | ||
60 | # Check that expanding a value that includes a variable reference works | ||
61 | self.assertEqual(testrecipe, rd.getVar('BPN')) | ||
62 | # Now check that changing the referenced variable's value in a copy gives that | ||
63 | # value when expanding | ||
64 | localdata = bb.data.createCopy(rd) | ||
65 | localdata.setVar('PN', 'hello') | ||
66 | self.assertEqual('hello', localdata.getVar('BPN')) | ||
67 | |||
68 | @OETestID(1573) | ||
69 | def test_parse_recipe_initial_datastore(self): | ||
70 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
71 | tinfoil.prepare(config_only=False, quiet=2) | ||
72 | testrecipe = 'mdadm' | ||
73 | best = tinfoil.find_best_provider(testrecipe) | ||
74 | if not best: | ||
75 | self.fail('Unable to find recipe providing %s' % testrecipe) | ||
76 | dcopy = bb.data.createCopy(tinfoil.config_data) | ||
77 | dcopy.setVar('MYVARIABLE', 'somevalue') | ||
78 | rd = tinfoil.parse_recipe_file(best[3], config_data=dcopy) | ||
79 | # Check we can get variable values | ||
80 | self.assertEqual('somevalue', rd.getVar('MYVARIABLE')) | ||
81 | |||
82 | @OETestID(1574) | ||
83 | def test_list_recipes(self): | ||
84 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
85 | tinfoil.prepare(config_only=False, quiet=2) | ||
86 | # Check pkg_pn | ||
87 | checkpns = ['tar', 'automake', 'coreutils', 'm4-native', 'nativesdk-gcc'] | ||
88 | pkg_pn = tinfoil.cooker.recipecaches[''].pkg_pn | ||
89 | for pn in checkpns: | ||
90 | self.assertIn(pn, pkg_pn) | ||
91 | # Check pkg_fn | ||
92 | checkfns = {'nativesdk-gcc': '^virtual:nativesdk:.*', 'coreutils': '.*/coreutils_.*.bb'} | ||
93 | for fn, pn in tinfoil.cooker.recipecaches[''].pkg_fn.items(): | ||
94 | if pn in checkpns: | ||
95 | if pn in checkfns: | ||
96 | self.assertTrue(re.match(checkfns[pn], fn), 'Entry for %s: %s did not match %s' % (pn, fn, checkfns[pn])) | ||
97 | checkpns.remove(pn) | ||
98 | if checkpns: | ||
99 | self.fail('Unable to find pkg_fn entries for: %s' % ', '.join(checkpns)) | ||
100 | |||
101 | @OETestID(1575) | ||
102 | def test_wait_event(self): | ||
103 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
104 | tinfoil.prepare(config_only=True) | ||
105 | # Need to drain events otherwise events that will be masked will still be in the queue | ||
106 | while tinfoil.wait_event(0.25): | ||
107 | pass | ||
108 | tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted']) | ||
109 | pattern = 'conf' | ||
110 | res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine') | ||
111 | self.assertTrue(res) | ||
112 | |||
113 | eventreceived = False | ||
114 | waitcount = 5 | ||
115 | while waitcount > 0: | ||
116 | event = tinfoil.wait_event(1) | ||
117 | if event: | ||
118 | if isinstance(event, bb.command.CommandCompleted): | ||
119 | break | ||
120 | elif isinstance(event, bb.event.FilesMatchingFound): | ||
121 | self.assertEqual(pattern, event._pattern) | ||
122 | self.assertIn('qemuarm.conf', event._matches) | ||
123 | eventreceived = True | ||
124 | else: | ||
125 | self.fail('Unexpected event: %s' % event) | ||
126 | |||
127 | waitcount = waitcount - 1 | ||
128 | |||
129 | self.assertNotEqual(waitcount, 0, 'Timed out waiting for CommandCompleted event from bitbake server') | ||
130 | self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server') | ||
131 | |||
132 | @OETestID(1576) | ||
133 | def test_setvariable_clean(self): | ||
134 | # First check that setVariable affects the datastore | ||
135 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
136 | tinfoil.prepare(config_only=True) | ||
137 | tinfoil.run_command('setVariable', 'TESTVAR', 'specialvalue') | ||
138 | self.assertEqual(tinfoil.config_data.getVar('TESTVAR'), 'specialvalue', 'Value set using setVariable is not reflected in client-side getVar()') | ||
139 | |||
140 | # Now check that the setVariable's effects are no longer present | ||
141 | # (this may legitimately break in future if we stop reinitialising | ||
142 | # the datastore, in which case we'll have to reconsider use of | ||
143 | # setVariable entirely) | ||
144 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
145 | tinfoil.prepare(config_only=True) | ||
146 | self.assertNotEqual(tinfoil.config_data.getVar('TESTVAR'), 'specialvalue', 'Value set using setVariable is still present!') | ||
147 | |||
148 | # Now check that setVar on the main datastore works (uses setVariable internally) | ||
149 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
150 | tinfoil.prepare(config_only=True) | ||
151 | tinfoil.config_data.setVar('TESTVAR', 'specialvalue') | ||
152 | value = tinfoil.run_command('getVariable', 'TESTVAR') | ||
153 | self.assertEqual(value, 'specialvalue', 'Value set using config_data.setVar() is not reflected in config_data.getVar()') | ||
154 | |||
155 | def test_datastore_operations(self): | ||
156 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
157 | tinfoil.prepare(config_only=True) | ||
158 | # Test setVarFlag() / getVarFlag() | ||
159 | tinfoil.config_data.setVarFlag('TESTVAR', 'flagname', 'flagval') | ||
160 | value = tinfoil.config_data.getVarFlag('TESTVAR', 'flagname') | ||
161 | self.assertEqual(value, 'flagval', 'Value set using config_data.setVarFlag() is not reflected in config_data.getVarFlag()') | ||
162 | # Test delVarFlag() | ||
163 | tinfoil.config_data.setVarFlag('TESTVAR', 'otherflag', 'othervalue') | ||
164 | tinfoil.config_data.delVarFlag('TESTVAR', 'flagname') | ||
165 | value = tinfoil.config_data.getVarFlag('TESTVAR', 'flagname') | ||
166 | self.assertEqual(value, None, 'Varflag deleted using config_data.delVarFlag() is not reflected in config_data.getVarFlag()') | ||
167 | value = tinfoil.config_data.getVarFlag('TESTVAR', 'otherflag') | ||
168 | self.assertEqual(value, 'othervalue', 'Varflag deleted using config_data.delVarFlag() caused unrelated flag to be removed') | ||
169 | # Test delVar() | ||
170 | tinfoil.config_data.setVar('TESTVAR', 'varvalue') | ||
171 | value = tinfoil.config_data.getVar('TESTVAR') | ||
172 | self.assertEqual(value, 'varvalue', 'Value set using config_data.setVar() is not reflected in config_data.getVar()') | ||
173 | tinfoil.config_data.delVar('TESTVAR') | ||
174 | value = tinfoil.config_data.getVar('TESTVAR') | ||
175 | self.assertEqual(value, None, 'Variable deleted using config_data.delVar() appears to still have a value') | ||
176 | # Test renameVar() | ||
177 | tinfoil.config_data.setVar('TESTVAROLD', 'origvalue') | ||
178 | tinfoil.config_data.renameVar('TESTVAROLD', 'TESTVARNEW') | ||
179 | value = tinfoil.config_data.getVar('TESTVAROLD') | ||
180 | self.assertEqual(value, None, 'Variable renamed using config_data.renameVar() still seems to exist') | ||
181 | value = tinfoil.config_data.getVar('TESTVARNEW') | ||
182 | self.assertEqual(value, 'origvalue', 'Variable renamed using config_data.renameVar() does not appear with new name') | ||
183 | # Test overrides | ||
184 | tinfoil.config_data.setVar('TESTVAR', 'original') | ||
185 | tinfoil.config_data.setVar('TESTVAR_overrideone', 'one') | ||
186 | tinfoil.config_data.setVar('TESTVAR_overridetwo', 'two') | ||
187 | tinfoil.config_data.appendVar('OVERRIDES', ':overrideone') | ||
188 | value = tinfoil.config_data.getVar('TESTVAR') | ||
189 | self.assertEqual(value, 'one', 'Variable overrides not functioning correctly') | ||