summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta-selftest/lib/devtool/bbpath.py44
-rw-r--r--meta/lib/oeqa/selftest/devtool.py43
2 files changed, 87 insertions, 0 deletions
diff --git a/meta-selftest/lib/devtool/bbpath.py b/meta-selftest/lib/devtool/bbpath.py
new file mode 100644
index 0000000000..5e8ffb3af6
--- /dev/null
+++ b/meta-selftest/lib/devtool/bbpath.py
@@ -0,0 +1,44 @@
1import argparse
2
3already_loaded = False
4kept_context = None
5
6def plugin_name(filename):
7 return os.path.splitext(os.path.basename(filename))[0]
8
9def plugin_init(plugins):
10 global already_loaded
11 already_loaded = plugin_name(__file__) in (plugin_name(p.__name__) for p in plugins)
12
13def print_name(args, config, basepath, workspace):
14 print (__file__)
15
16def print_bbdir(args, config, basepath, workspace):
17 print (__file__.replace('/lib/devtool/bbpath.py',''))
18
19def print_registered(args, config, basepath, workspace):
20 global kept_context
21 print(kept_context.loaded)
22
23def multiloaded(args, config, basepath, workspace):
24 global already_loaded
25 print("yes" if already_loaded else "no")
26
27def register_commands(subparsers, context):
28 global kept_context
29 kept_context = context
30 if 'loaded' in context.__dict__:
31 context.loaded += 1
32 else:
33 context.loaded = 1
34
35 def addparser(name, helptxt, func):
36 parser = subparsers.add_parser(name, help=helptxt,
37 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
38 parser.set_defaults(func=func)
39 return parser
40
41 addparser('pluginfile', 'Print the filename of this plugin', print_name)
42 addparser('bbdir', 'Print the BBPATH directory of this plugin', print_bbdir)
43 addparser('count', 'How many times have this plugin been registered.', print_registered)
44 addparser('multiloaded', 'How many times have this plugin been initialized', multiloaded)
diff --git a/meta/lib/oeqa/selftest/devtool.py b/meta/lib/oeqa/selftest/devtool.py
index 7db286fc15..3abba0805e 100644
--- a/meta/lib/oeqa/selftest/devtool.py
+++ b/meta/lib/oeqa/selftest/devtool.py
@@ -1263,6 +1263,49 @@ class DevtoolTests(DevtoolBase):
1263 result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s) 1263 result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
1264 self.assertEqual(result.output, s[::-1]) 1264 self.assertEqual(result.output, s[::-1])
1265 1265
1266 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
1267 dstdir = basedstdir
1268 self.assertTrue(os.path.exists(dstdir))
1269 for p in paths:
1270 dstdir = os.path.join(dstdir, p)
1271 if not os.path.exists(dstdir):
1272 os.makedirs(dstdir)
1273 self.track_for_cleanup(dstdir)
1274 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
1275 if srcfile != dstfile:
1276 shutil.copy(srcfile, dstfile)
1277 self.track_for_cleanup(dstfile)
1278
1279 def test_devtool_load_plugin(self):
1280 """Test that devtool loads only the first found plugin in BBPATH."""
1281
1282 self.track_for_cleanup(self.workspacedir)
1283 self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
1284
1285 devtool = runCmd("which devtool")
1286 fromname = runCmd("devtool --quiet pluginfile")
1287 srcfile = fromname.output
1288 bbpath = get_bb_var('BBPATH')
1289 searchpath = bbpath.split(':') + [os.path.dirname(devtool.output)]
1290 plugincontent = []
1291 with open(srcfile) as fh:
1292 plugincontent = fh.readlines()
1293 try:
1294 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
1295 for path in searchpath:
1296 self._copy_file_with_cleanup(srcfile, path, 'lib', 'devtool')
1297 result = runCmd("devtool --quiet count")
1298 self.assertEqual(result.output, '1')
1299 result = runCmd("devtool --quiet multiloaded")
1300 self.assertEqual(result.output, "no")
1301 for path in searchpath:
1302 result = runCmd("devtool --quiet bbdir")
1303 self.assertEqual(result.output, path)
1304 os.unlink(os.path.join(result.output, 'lib', 'devtool', 'bbpath.py'))
1305 finally:
1306 with open(srcfile, 'w') as fh:
1307 fh.writelines(plugincontent)
1308
1266 def _setup_test_devtool_finish_upgrade(self): 1309 def _setup_test_devtool_finish_upgrade(self):
1267 # Check preconditions 1310 # Check preconditions
1268 self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory') 1311 self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')