devtool: selftest: add test for devtool plugin loading
Test that devtool plugins are loaded in a well defined order. (From OE-Core rev: 0de81f0c8b29d8b442b3d099c3bec3fd345b6bfe) Signed-off-by: Ola x Nilsson <ola.x.nilsson@axis.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
2b7abbb383
commit
9170a88cbd
|
@ -0,0 +1,44 @@
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
already_loaded = False
|
||||||
|
kept_context = None
|
||||||
|
|
||||||
|
def plugin_name(filename):
|
||||||
|
return os.path.splitext(os.path.basename(filename))[0]
|
||||||
|
|
||||||
|
def plugin_init(plugins):
|
||||||
|
global already_loaded
|
||||||
|
already_loaded = plugin_name(__file__) in (plugin_name(p.__name__) for p in plugins)
|
||||||
|
|
||||||
|
def print_name(args, config, basepath, workspace):
|
||||||
|
print (__file__)
|
||||||
|
|
||||||
|
def print_bbdir(args, config, basepath, workspace):
|
||||||
|
print (__file__.replace('/lib/devtool/bbpath.py',''))
|
||||||
|
|
||||||
|
def print_registered(args, config, basepath, workspace):
|
||||||
|
global kept_context
|
||||||
|
print(kept_context.loaded)
|
||||||
|
|
||||||
|
def multiloaded(args, config, basepath, workspace):
|
||||||
|
global already_loaded
|
||||||
|
print("yes" if already_loaded else "no")
|
||||||
|
|
||||||
|
def register_commands(subparsers, context):
|
||||||
|
global kept_context
|
||||||
|
kept_context = context
|
||||||
|
if 'loaded' in context.__dict__:
|
||||||
|
context.loaded += 1
|
||||||
|
else:
|
||||||
|
context.loaded = 1
|
||||||
|
|
||||||
|
def addparser(name, helptxt, func):
|
||||||
|
parser = subparsers.add_parser(name, help=helptxt,
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
parser.set_defaults(func=func)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
addparser('pluginfile', 'Print the filename of this plugin', print_name)
|
||||||
|
addparser('bbdir', 'Print the BBPATH directory of this plugin', print_bbdir)
|
||||||
|
addparser('count', 'How many times have this plugin been registered.', print_registered)
|
||||||
|
addparser('multiloaded', 'How many times have this plugin been initialized', multiloaded)
|
|
@ -1263,6 +1263,49 @@ class DevtoolTests(DevtoolBase):
|
||||||
result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
|
result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
|
||||||
self.assertEqual(result.output, s[::-1])
|
self.assertEqual(result.output, s[::-1])
|
||||||
|
|
||||||
|
def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
|
||||||
|
dstdir = basedstdir
|
||||||
|
self.assertTrue(os.path.exists(dstdir))
|
||||||
|
for p in paths:
|
||||||
|
dstdir = os.path.join(dstdir, p)
|
||||||
|
if not os.path.exists(dstdir):
|
||||||
|
os.makedirs(dstdir)
|
||||||
|
self.track_for_cleanup(dstdir)
|
||||||
|
dstfile = os.path.join(dstdir, os.path.basename(srcfile))
|
||||||
|
if srcfile != dstfile:
|
||||||
|
shutil.copy(srcfile, dstfile)
|
||||||
|
self.track_for_cleanup(dstfile)
|
||||||
|
|
||||||
|
def test_devtool_load_plugin(self):
|
||||||
|
"""Test that devtool loads only the first found plugin in BBPATH."""
|
||||||
|
|
||||||
|
self.track_for_cleanup(self.workspacedir)
|
||||||
|
self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
|
||||||
|
|
||||||
|
devtool = runCmd("which devtool")
|
||||||
|
fromname = runCmd("devtool --quiet pluginfile")
|
||||||
|
srcfile = fromname.output
|
||||||
|
bbpath = get_bb_var('BBPATH')
|
||||||
|
searchpath = bbpath.split(':') + [os.path.dirname(devtool.output)]
|
||||||
|
plugincontent = []
|
||||||
|
with open(srcfile) as fh:
|
||||||
|
plugincontent = fh.readlines()
|
||||||
|
try:
|
||||||
|
self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
|
||||||
|
for path in searchpath:
|
||||||
|
self._copy_file_with_cleanup(srcfile, path, 'lib', 'devtool')
|
||||||
|
result = runCmd("devtool --quiet count")
|
||||||
|
self.assertEqual(result.output, '1')
|
||||||
|
result = runCmd("devtool --quiet multiloaded")
|
||||||
|
self.assertEqual(result.output, "no")
|
||||||
|
for path in searchpath:
|
||||||
|
result = runCmd("devtool --quiet bbdir")
|
||||||
|
self.assertEqual(result.output, path)
|
||||||
|
os.unlink(os.path.join(result.output, 'lib', 'devtool', 'bbpath.py'))
|
||||||
|
finally:
|
||||||
|
with open(srcfile, 'w') as fh:
|
||||||
|
fh.writelines(plugincontent)
|
||||||
|
|
||||||
def _setup_test_devtool_finish_upgrade(self):
|
def _setup_test_devtool_finish_upgrade(self):
|
||||||
# Check preconditions
|
# Check preconditions
|
||||||
self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
|
self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
|
||||||
|
|
Loading…
Reference in New Issue