mirror of
git://git.yoctoproject.org/poky
synced 2026-04-02 02:49:11 +00:00
selftest/bblayers: Refactor JSON schema validation
* Extract a function "validate_json" * Read bitbake variables in setUpClass to avoid makeing repeated calls to bitbake * Allow to specify the schema relative to $COREBASE/meta/files/ * Specify the Base URI to allow schema to reference each other (From OE-Core rev: b10b4d5b6376fd828c1cb843ea2e24da298657b6) Signed-off-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
57976f5709
commit
41438346ce
@ -20,6 +20,11 @@ class BitbakeLayers(OESelftestTestCase):
|
|||||||
bitbake("python3-jsonschema-native")
|
bitbake("python3-jsonschema-native")
|
||||||
bitbake("-c addto_recipe_sysroot python3-jsonschema-native")
|
bitbake("-c addto_recipe_sysroot python3-jsonschema-native")
|
||||||
|
|
||||||
|
# Fetch variables used in multiple test cases
|
||||||
|
bb_vars = get_bb_vars(['COREBASE'])
|
||||||
|
cls.corebase = bb_vars['COREBASE']
|
||||||
|
cls.jsonschema_staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native')
|
||||||
|
|
||||||
def test_bitbakelayers_layerindexshowdepends(self):
|
def test_bitbakelayers_layerindexshowdepends(self):
|
||||||
result = runCmd('bitbake-layers layerindex-show-depends meta-poky')
|
result = runCmd('bitbake-layers layerindex-show-depends meta-poky')
|
||||||
find_in_contents = re.search("openembedded-core", result.output)
|
find_in_contents = re.search("openembedded-core", result.output)
|
||||||
@ -58,7 +63,7 @@ class BitbakeLayers(OESelftestTestCase):
|
|||||||
self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output)
|
self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output)
|
||||||
|
|
||||||
def test_bitbakelayers_add_remove(self):
|
def test_bitbakelayers_add_remove(self):
|
||||||
test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton')
|
test_layer = os.path.join(self.corebase, 'meta-skeleton')
|
||||||
result = runCmd('bitbake-layers show-layers')
|
result = runCmd('bitbake-layers show-layers')
|
||||||
self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
|
self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
|
||||||
result = runCmd('bitbake-layers add-layer %s' % test_layer)
|
result = runCmd('bitbake-layers add-layer %s' % test_layer)
|
||||||
@ -136,14 +141,24 @@ class BitbakeLayers(OESelftestTestCase):
|
|||||||
self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
|
self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
|
||||||
return os.path.basename(recipe_file)
|
return os.path.basename(recipe_file)
|
||||||
|
|
||||||
|
def validate_json(self, json, jsonschema):
|
||||||
|
python = os.path.join(self.jsonschema_staging_bindir, 'nativepython3')
|
||||||
|
jsonvalidator = os.path.join(self.jsonschema_staging_bindir, 'jsonschema')
|
||||||
|
schemas_dir = os.path.join(self.corebase, "meta/files/")
|
||||||
|
if not os.path.isabs(jsonschema):
|
||||||
|
jsonschema = os.path.join(schemas_dir, jsonschema)
|
||||||
|
|
||||||
|
result = runCmd(
|
||||||
|
"{} {} -i {} --base-uri file://{}/ {}".format(
|
||||||
|
python, jsonvalidator, json, schemas_dir, jsonschema
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def validate_layersjson(self, json):
|
def validate_layersjson(self, json):
|
||||||
python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3')
|
self.validate_json(json, "layers.schema.json")
|
||||||
jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema')
|
|
||||||
jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
|
|
||||||
result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
|
|
||||||
|
|
||||||
def test_validate_examplelayersjson(self):
|
def test_validate_examplelayersjson(self):
|
||||||
json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
|
json = os.path.join(self.corebase, "meta/files/layers.example.json")
|
||||||
self.validate_layersjson(json)
|
self.validate_layersjson(json)
|
||||||
|
|
||||||
def test_bitbakelayers_setup(self):
|
def test_bitbakelayers_setup(self):
|
||||||
@ -173,7 +188,7 @@ class BitbakeLayers(OESelftestTestCase):
|
|||||||
|
|
||||||
# As setup-layers checkout out an old revision of poky, there is no setup-build symlink,
|
# As setup-layers checkout out an old revision of poky, there is no setup-build symlink,
|
||||||
# and we need to run oe-setup-build directly from the current poky tree under test
|
# and we need to run oe-setup-build directly from the current poky tree under test
|
||||||
oe_setup_build = os.path.join(get_bb_var('COREBASE'), 'scripts/oe-setup-build')
|
oe_setup_build = os.path.join(self.corebase, 'scripts/oe-setup-build')
|
||||||
oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build')
|
oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build')
|
||||||
os.symlink(oe_setup_build,oe_setup_build_l)
|
os.symlink(oe_setup_build,oe_setup_build_l)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user