summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-12-13 20:09:46 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-14 12:30:50 +0000
commit66adb6bdf72a256a0bed6077cdfa4c61ee7919e5 (patch)
treefa14485c189f05003b7a00193a004ccd0869b827 /meta
parent0cba3cbcb4178edd554fa2433f525ff2e67a4797 (diff)
downloadpoky-66adb6bdf72a256a0bed6077cdfa4c61ee7919e5.tar.gz
oe-selftest: add basic tinfoil tests
Add some tests to verify that the new tinfoil API is operating correctly. (From OE-Core rev: 16afda66b861ba028c1152dcdcab2b7ebfbff965) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/selftest/tinfoil.py146
1 files changed, 146 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/tinfoil.py b/meta/lib/oeqa/selftest/tinfoil.py
new file mode 100644
index 0000000000..4f70e0d2f7
--- /dev/null
+++ b/meta/lib/oeqa/selftest/tinfoil.py
@@ -0,0 +1,146 @@
1import unittest
2import os
3import re
4import bb.tinfoil
5
6from oeqa.selftest.base import oeSelfTest
7from oeqa.utils.commands import runCmd, get_bb_var
8from oeqa.utils.decorators import testcase
9
10class TinfoilTests(oeSelfTest):
11 """ Basic tests for the tinfoil API """
12
13 def test_getvar(self):
14 with bb.tinfoil.Tinfoil() as tinfoil:
15 tinfoil.prepare(True)
16 machine = tinfoil.config_data.getVar('MACHINE', True)
17 if not machine:
18 self.fail('Unable to get MACHINE value - returned %s' % machine)
19
20 def test_expand(self):
21 with bb.tinfoil.Tinfoil() as tinfoil:
22 tinfoil.prepare(True)
23 expr = '${@os.getpid()}'
24 pid = tinfoil.config_data.expand(expr)
25 if not pid:
26 self.fail('Unable to expand "%s" - returned %s' % (expr, pid))
27
28 def test_getvar_bb_origenv(self):
29 with bb.tinfoil.Tinfoil() as tinfoil:
30 tinfoil.prepare(True)
31 origenv = tinfoil.config_data.getVar('BB_ORIGENV', False)
32 if not origenv:
33 self.fail('Unable to get BB_ORIGENV value - returned %s' % origenv)
34 self.assertEqual(origenv.getVar('HOME', False), os.environ['HOME'])
35
36 def test_parse_recipe(self):
37 with bb.tinfoil.Tinfoil() as tinfoil:
38 tinfoil.prepare(config_only=False, quiet=2)
39 testrecipe = 'mdadm'
40 best = tinfoil.find_best_provider(testrecipe)
41 if not best:
42 self.fail('Unable to find recipe providing %s' % testrecipe)
43 rd = tinfoil.parse_recipe_file(best[3])
44 self.assertEqual(testrecipe, rd.getVar('PN', True))
45
46 def test_parse_recipe_copy_expand(self):
47 with bb.tinfoil.Tinfoil() as tinfoil:
48 tinfoil.prepare(config_only=False, quiet=2)
49 testrecipe = 'mdadm'
50 best = tinfoil.find_best_provider(testrecipe)
51 if not best:
52 self.fail('Unable to find recipe providing %s' % testrecipe)
53 rd = tinfoil.parse_recipe_file(best[3])
54 # Check we can get variable values
55 self.assertEqual(testrecipe, rd.getVar('PN', True))
56 # Check that expanding a value that includes a variable reference works
57 self.assertEqual(testrecipe, rd.getVar('BPN', True))
58 # Now check that changing the referenced variable's value in a copy gives that
59 # value when expanding
60 localdata = bb.data.createCopy(rd)
61 localdata.setVar('PN', 'hello')
62 self.assertEqual('hello', localdata.getVar('BPN', True))
63
64 def test_parse_recipe_initial_datastore(self):
65 with bb.tinfoil.Tinfoil() as tinfoil:
66 tinfoil.prepare(config_only=False, quiet=2)
67 testrecipe = 'mdadm'
68 best = tinfoil.find_best_provider(testrecipe)
69 if not best:
70 self.fail('Unable to find recipe providing %s' % testrecipe)
71 dcopy = bb.data.createCopy(tinfoil.config_data)
72 dcopy.setVar('MYVARIABLE', 'somevalue')
73 rd = tinfoil.parse_recipe_file(best[3], config_data=dcopy)
74 # Check we can get variable values
75 self.assertEqual('somevalue', rd.getVar('MYVARIABLE', True))
76
77 def test_list_recipes(self):
78 with bb.tinfoil.Tinfoil() as tinfoil:
79 tinfoil.prepare(config_only=False, quiet=2)
80 # Check pkg_pn
81 checkpns = ['tar', 'automake', 'coreutils', 'm4-native', 'nativesdk-gcc']
82 pkg_pn = tinfoil.cooker.recipecaches[''].pkg_pn
83 for pn in checkpns:
84 self.assertIn(pn, pkg_pn)
85 # Check pkg_fn
86 checkfns = {'nativesdk-gcc': '^virtual:nativesdk:.*', 'coreutils': '.*/coreutils_.*.bb'}
87 for fn, pn in tinfoil.cooker.recipecaches[''].pkg_fn.items():
88 if pn in checkpns:
89 if pn in checkfns:
90 self.assertTrue(re.match(checkfns[pn], fn), 'Entry for %s: %s did not match %s' % (pn, fn, checkfns[pn]))
91 checkpns.remove(pn)
92 if checkpns:
93 self.fail('Unable to find pkg_fn entries for: %s' % ', '.join(checkpns))
94
95 def test_wait_event(self):
96 with bb.tinfoil.Tinfoil() as tinfoil:
97 tinfoil.prepare(config_only=True)
98 # Need to drain events otherwise events that will be masked will still be in the queue
99 while tinfoil.wait_event(0.25):
100 pass
101 tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted'])
102 pattern = 'conf'
103 res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine')
104 self.assertTrue(res)
105
106 eventreceived = False
107 waitcount = 5
108 while waitcount > 0:
109 event = tinfoil.wait_event(1)
110 if event:
111 if isinstance(event, bb.command.CommandCompleted):
112 break
113 elif isinstance(event, bb.event.FilesMatchingFound):
114 self.assertEqual(pattern, event._pattern)
115 self.assertIn('qemuarm.conf', event._matches)
116 eventreceived = True
117 else:
118 self.fail('Unexpected event: %s' % event)
119
120 waitcount = waitcount - 1
121
122 self.assertNotEqual(waitcount, 0, 'Timed out waiting for CommandCompleted event from bitbake server')
123 self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server')
124
125 def test_setvariable_clean(self):
126 # First check that setVariable affects the datastore
127 with bb.tinfoil.Tinfoil() as tinfoil:
128 tinfoil.prepare(config_only=True)
129 tinfoil.run_command('setVariable', 'TESTVAR', 'specialvalue')
130 self.assertEqual(tinfoil.config_data.getVar('TESTVAR', True), 'specialvalue', 'Value set using setVariable is not reflected in client-side getVar()')
131
132 # Now check that the setVariable's effects are no longer present
133 # (this may legitimately break in future if we stop reinitialising
134 # the datastore, in which case we'll have to reconsider use of
135 # setVariable entirely)
136 with bb.tinfoil.Tinfoil() as tinfoil:
137 tinfoil.prepare(config_only=True)
138 self.assertNotEqual(tinfoil.config_data.getVar('TESTVAR', True), 'specialvalue', 'Value set using setVariable is still present!')
139
140 # Now check that setVar on the main datastore works (uses setVariable internally)
141 with bb.tinfoil.Tinfoil() as tinfoil:
142 tinfoil.prepare(config_only=True)
143 tinfoil.config_data.setVar('TESTVAR', 'specialvalue')
144 value = tinfoil.run_command('getVariable', 'TESTVAR')
145 self.assertEqual(value, 'specialvalue', 'Value set using config_data.setVar() is not reflected in config_data.getVar()')
146