diff options
| author | Yoann Congal <yoann.congal@smile.fr> | 2025-10-24 02:16:19 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-10-27 17:20:42 +0000 |
| commit | 41438346ce051fc12369ee5e2501bf8c2cb6b4a4 (patch) | |
| tree | 3789ff9e029392fe7498037352f877861d6fafee | |
| parent | 57976f570937d636ff003f22a12e8872ac9fc3b8 (diff) | |
| download | poky-41438346ce051fc12369ee5e2501bf8c2cb6b4a4.tar.gz | |
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>
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/bblayers.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py index 982287c9a5..5b13c9dffe 100644 --- a/meta/lib/oeqa/selftest/cases/bblayers.py +++ b/meta/lib/oeqa/selftest/cases/bblayers.py | |||
| @@ -20,6 +20,11 @@ class BitbakeLayers(OESelftestTestCase): | |||
| 20 | bitbake("python3-jsonschema-native") | 20 | bitbake("python3-jsonschema-native") |
| 21 | bitbake("-c addto_recipe_sysroot python3-jsonschema-native") | 21 | bitbake("-c addto_recipe_sysroot python3-jsonschema-native") |
| 22 | 22 | ||
| 23 | # Fetch variables used in multiple test cases | ||
| 24 | bb_vars = get_bb_vars(['COREBASE']) | ||
| 25 | cls.corebase = bb_vars['COREBASE'] | ||
| 26 | cls.jsonschema_staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native') | ||
| 27 | |||
| 23 | def test_bitbakelayers_layerindexshowdepends(self): | 28 | def test_bitbakelayers_layerindexshowdepends(self): |
| 24 | result = runCmd('bitbake-layers layerindex-show-depends meta-poky') | 29 | result = runCmd('bitbake-layers layerindex-show-depends meta-poky') |
| 25 | find_in_contents = re.search("openembedded-core", result.output) | 30 | find_in_contents = re.search("openembedded-core", result.output) |
| @@ -58,7 +63,7 @@ class BitbakeLayers(OESelftestTestCase): | |||
| 58 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) | 63 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) |
| 59 | 64 | ||
| 60 | def test_bitbakelayers_add_remove(self): | 65 | def test_bitbakelayers_add_remove(self): |
| 61 | test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton') | 66 | test_layer = os.path.join(self.corebase, 'meta-skeleton') |
| 62 | result = runCmd('bitbake-layers show-layers') | 67 | result = runCmd('bitbake-layers show-layers') |
| 63 | self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output) | 68 | self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output) |
| 64 | result = runCmd('bitbake-layers add-layer %s' % test_layer) | 69 | result = runCmd('bitbake-layers add-layer %s' % test_layer) |
| @@ -136,14 +141,24 @@ class BitbakeLayers(OESelftestTestCase): | |||
| 136 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) | 141 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) |
| 137 | return os.path.basename(recipe_file) | 142 | return os.path.basename(recipe_file) |
| 138 | 143 | ||
| 144 | def validate_json(self, json, jsonschema): | ||
| 145 | python = os.path.join(self.jsonschema_staging_bindir, 'nativepython3') | ||
| 146 | jsonvalidator = os.path.join(self.jsonschema_staging_bindir, 'jsonschema') | ||
| 147 | schemas_dir = os.path.join(self.corebase, "meta/files/") | ||
| 148 | if not os.path.isabs(jsonschema): | ||
| 149 | jsonschema = os.path.join(schemas_dir, jsonschema) | ||
| 150 | |||
| 151 | result = runCmd( | ||
| 152 | "{} {} -i {} --base-uri file://{}/ {}".format( | ||
| 153 | python, jsonvalidator, json, schemas_dir, jsonschema | ||
| 154 | ) | ||
| 155 | ) | ||
| 156 | |||
| 139 | def validate_layersjson(self, json): | 157 | def validate_layersjson(self, json): |
| 140 | python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3') | 158 | self.validate_json(json, "layers.schema.json") |
| 141 | jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema') | ||
| 142 | jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json') | ||
| 143 | result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema)) | ||
| 144 | 159 | ||
| 145 | def test_validate_examplelayersjson(self): | 160 | def test_validate_examplelayersjson(self): |
| 146 | json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json") | 161 | json = os.path.join(self.corebase, "meta/files/layers.example.json") |
| 147 | self.validate_layersjson(json) | 162 | self.validate_layersjson(json) |
| 148 | 163 | ||
| 149 | def test_bitbakelayers_setup(self): | 164 | def test_bitbakelayers_setup(self): |
| @@ -173,7 +188,7 @@ class BitbakeLayers(OESelftestTestCase): | |||
| 173 | 188 | ||
| 174 | # As setup-layers checkout out an old revision of poky, there is no setup-build symlink, | 189 | # As setup-layers checkout out an old revision of poky, there is no setup-build symlink, |
| 175 | # and we need to run oe-setup-build directly from the current poky tree under test | 190 | # and we need to run oe-setup-build directly from the current poky tree under test |
| 176 | oe_setup_build = os.path.join(get_bb_var('COREBASE'), 'scripts/oe-setup-build') | 191 | oe_setup_build = os.path.join(self.corebase, 'scripts/oe-setup-build') |
| 177 | oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build') | 192 | oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build') |
| 178 | os.symlink(oe_setup_build,oe_setup_build_l) | 193 | os.symlink(oe_setup_build,oe_setup_build_l) |
| 179 | 194 | ||
