board_inspector: add schema-based board checks

This patch adds schema-based board checks mechanism.
This provides integrators with a mechanism that XSD does
the actual board data check.

Tracked-On: #6689
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-01-20 21:21:26 +08:00 committed by acrnsi-robot
parent d66c994d33
commit 29e3dd7163
4 changed files with 72 additions and 0 deletions

View File

@ -16,6 +16,8 @@ from cpuparser import parse_cpuid, get_online_cpu_ids, get_offline_cpu_ids
script_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(script_dir))
from inspectorlib import validator
def check_deps():
# Check that the required tools are installed on the system
BIN_LIST = ['cpuid', 'rdmsr', 'lspci', ' dmidecode', 'blkid', 'stty']
@ -113,6 +115,11 @@ def main(board_name, board_xml, args):
continue
module.extract(args, board_etree)
# Validate the XML against XSD assertions
count = validator.validate_board("schema/boardchecks.xsd", board_etree)
if count == 0:
logging.info("All board checks passed.")
# Finally overwrite the output with the updated XML
board_etree.write(board_xml, pretty_print=True)
print("SUCCESS: Board configuration file {} generated successfully and saved to {}" \

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
#
# Copyright (C) 2022 Intel Corporation.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys, os
import argparse
import lxml.etree as etree
import logging
import xmlschema
logging_fn = {
"error": logging.error,
"warning": logging.warning,
"info": logging.info,
}
def validate_board(xsd_path, board_etree):
schema_etree = etree.parse(xsd_path)
schema_etree.xinclude()
schema = xmlschema.XMLSchema11(schema_etree)
it = schema.iter_errors(board_etree)
count = 0
for error in it:
anno = error.validator.annotation
severity = anno.elem.get("{https://projectacrn.org}severity")
description = anno.elem.find("{http://www.w3.org/2001/XMLSchema}documentation").text
logging_fn[severity](description)
if severity in ["error", "warning"]:
count += 1
return count

View File

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<xs:schema
xmlns:xi="http://www.w3.org/2003/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="acrn-config">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
<xi:include href="checks/platform_capabilities.xsd" xpointer="xpointer(id('root')/*)" />
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="every $model in processors/model satisfies exists($model/capability[@id='vmx'])">
<xs:annotation acrn:severity="error">
<xs:documentation>Intel(R) Virtualization Technology Extension shall be enabled in BIOS.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>