mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-26 07:17:10 +00:00
tools: binman: ti_board_cfg: Check for linting problems
Use yamllint for checking whether YAML configuration files are adhering to default yamllint rules. Signed-off-by: Neha Malcom Francis <n-francis@ti.com> Suggested-by: Nishanth Menon <nm@ti.com>
This commit is contained in:
parent
0cc7a701e9
commit
10fee88d42
6 changed files with 46 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import yaml
|
import yaml
|
||||||
|
import yamllint
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
|
@ -18,6 +19,7 @@ from binman.entry import Entry
|
||||||
from binman.etype.section import Entry_section
|
from binman.etype.section import Entry_section
|
||||||
from dtoc import fdt_util
|
from dtoc import fdt_util
|
||||||
from u_boot_pylib import tools
|
from u_boot_pylib import tools
|
||||||
|
from yamllint import config
|
||||||
|
|
||||||
BOARDCFG = 0xB
|
BOARDCFG = 0xB
|
||||||
BOARDCFG_SEC = 0xD
|
BOARDCFG_SEC = 0xD
|
||||||
|
@ -244,6 +246,9 @@ class Entry_ti_board_config(Entry_section):
|
||||||
with open(self._schema_file, 'r') as sch:
|
with open(self._schema_file, 'r') as sch:
|
||||||
self.schema_yaml = yaml.safe_load(sch)
|
self.schema_yaml = yaml.safe_load(sch)
|
||||||
|
|
||||||
|
yaml_config = config.YamlLintConfig("extends: default")
|
||||||
|
for p in yamllint.linter.run(open(self._config_file, "r"), yaml_config):
|
||||||
|
self.Raise(f"Yamllint error: {p.line}: {p.rule}")
|
||||||
try:
|
try:
|
||||||
validate(self.file_yaml, self.schema_yaml)
|
validate(self.file_yaml, self.schema_yaml)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -7030,6 +7030,12 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
|
||||||
data = self._DoReadFile('293_ti_board_cfg.dts')
|
data = self._DoReadFile('293_ti_board_cfg.dts')
|
||||||
self.assertEqual(TI_BOARD_CONFIG_DATA, data)
|
self.assertEqual(TI_BOARD_CONFIG_DATA, data)
|
||||||
|
|
||||||
|
def testTIBoardConfigLint(self):
|
||||||
|
"""Test that an incorrectly linted config file would generate error"""
|
||||||
|
with self.assertRaises(ValueError) as e:
|
||||||
|
data = self._DoReadFile('323_ti_board_cfg_phony.dts')
|
||||||
|
self.assertIn("Yamllint error", str(e.exception))
|
||||||
|
|
||||||
def testTIBoardConfigCombined(self):
|
def testTIBoardConfigCombined(self):
|
||||||
"""Test that a schema validated combined board config file can be generated"""
|
"""Test that a schema validated combined board config file can be generated"""
|
||||||
data = self._DoReadFile('294_ti_board_cfg_combined.dts')
|
data = self._DoReadFile('294_ti_board_cfg_combined.dts')
|
||||||
|
|
14
tools/binman/test/323_ti_board_cfg_phony.dts
Normal file
14
tools/binman/test/323_ti_board_cfg_phony.dts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
|
||||||
|
binman {
|
||||||
|
ti-board-config {
|
||||||
|
config = "yaml/config_phony.yaml";
|
||||||
|
schema = "yaml/schema.yaml";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
18
tools/binman/test/yaml/config_phony.yaml
Normal file
18
tools/binman/test/yaml/config_phony.yaml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0+
|
||||||
|
#
|
||||||
|
# Test config
|
||||||
|
#
|
||||||
|
---
|
||||||
|
|
||||||
|
main-branch :
|
||||||
|
obj :
|
||||||
|
a : 0x0
|
||||||
|
b: 0
|
||||||
|
arr: [0, 0, 0, 0]
|
||||||
|
another-arr:
|
||||||
|
- # 1
|
||||||
|
c: 0
|
||||||
|
d: 0
|
||||||
|
- # 2
|
||||||
|
c: 0
|
||||||
|
d: 0
|
|
@ -1,2 +1,3 @@
|
||||||
jsonschema==4.17.3
|
jsonschema==4.17.3
|
||||||
pyyaml==6.0
|
pyyaml==6.0
|
||||||
|
yamllint==1.26.3
|
||||||
|
|
Loading…
Add table
Reference in a new issue