Skip to content

More scenario checks#14

Open
junjiemao1 wants to merge 7 commits intomainfrom
more_scenario_checks
Open

More scenario checks#14
junjiemao1 wants to merge 7 commits intomainfrom
more_scenario_checks

Conversation

@junjiemao1
Copy link
Owner

No description provided.

Today the XML validation logic is embedded in scenario_cfg_gen.py which is
highly entangled with the Python-internal representation of
configurations. Such representation is used by the current configurator,
but will soon be obsolete when the new configurator is introduced.

In order to avoid unnecessary work on this internal representation when we
refine the schema of scenario XML files, this patch separates the
validation logic into a new script which can either be used from the
command line or imported in other Python-based applications. At build time
this script will be used instead to validate the XML files given by users.

This change makes it easier to refine the current configuration items for
better developer experience.

Migration of existing checks in scenario_cfg_gen.py to XML schema will be
done by a following series.

v1 -> v2:
 * Remove "all rights reserved" from the license header
 * Upgrade the severity of the message indicating lack of xmlschema as
   error according to our latest definitions of log severities, as
   validation violations could indicate build time or boot time failures.

Tracked-On: projectacrn#6690
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Junjie Mao <junjie.mao@intel.com>

<xs:assert test="every $vm in /acrn-config/vm satisfies
count(distinct-values($vm//cpu_affinity/pcpu_id)) = count($vm//cpu_affinity/pcpu_id)">
<xs:annotation acrn:severity="warning">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can acrn:severity values be defined somewhere in a schema? Are there any schema validation checks on these values? Does the assert allow a severity indication? What happens if someone misspells a severity, say as acrn:severity="waring"? Is there a default severity?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to have an XML schema for an XML schema file. I can draft one to ensure correct annotation to the assertions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed another commit which adds XML schema files that checks the checker. The script misc/config_tools/schema/checks/check_the_checkers.sh will apply that schema to all the XSD files under misc/config_tools/schema/checks using xmllint.

Of course you need xmllint (which is part of libxml2) for this. I'm not using xmlschema-validate (which is provided by the xmlschema Python module) because that tool does not allow redefinition of XSD elements such as xs:element.

junjiemao1 and others added 2 commits February 7, 2022 08:46
Co-authored-by: David Kinder <david.b.kinder@intel.com>
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
<xs:assert test="every $vm in /acrn-config/vm satisfies
starts-with($vm//vm_type, 'PRE') or not($vm//mmio_resources/p2sb = 'y')">
<xs:annotation acrn:severity="error">
<xs:documentation>VM {$vm/@id} is not a pre-launched VM and cannot have a P2SB (Primary-to-Sideband bridge) passed through to it. Remove the mmio_resources.p2sb value for this VM.</xs:documentation>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this message appear in the context of the ACRN Configurator UI? If so, consider writing the action in that context. For example, instead of "Remove the mmio_resources.p2sb value for this VM" say "Clear this option" (assuming it's a checkbox in the UI). Same comment for all messages.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These documentation can appear in three places:

  1. As error messages in the ACRN configurator.
  2. As build-time errors in terminal.
  3. In web pages on https://projectacrn.github.io/.

Only in the first case will an error be related to one (or more) widget.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell which messages will be in the UI, but let's consider whether an additional UI message field is needed for those messages.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revisit this once the UI has integrated the validation rules and shown validation errors. Based on what we have at that time, we can see if any message about additional actions is needed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks

Copy link
Collaborator

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more questions...

@@ -0,0 +1,6 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should put a copyright and SPDX header comment in scripts too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should also put a copyright and SPDX header comment in all our xsd files?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to all XSD files for data checks. For the schema XSDs I'll update them the next time I update them (which will happen in a few days).

<xs:assert test="every $vm in /acrn-config/vm satisfies
starts-with($vm//vm_type, 'PRE') or not($vm//mmio_resources/p2sb = 'y')">
<xs:annotation acrn:severity="error">
<xs:documentation>VM {$vm/@id} is not a pre-launched VM and cannot have a P2SB (Primary-to-Sideband bridge) passed through to it. Remove the mmio_resources.p2sb value for this VM.</xs:documentation>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, shouldn't this show the name of the VM and not its ID number? All VMs have a name, right?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will replace with VM names.

<xs:assert test="every $vm in /acrn-config/vm satisfies
not($vm//mmio_resources/TPM2 = 'y') or not($vm//mmio_resources/p2sb = 'y')">
<xs:annotation acrn:severity="error">
<xs:documentation>VM {$vm/@id} is assigned both a TPM2 and P2SB (Primary-to-Sideband bridge), which is not a supported configuration. Remove one of these choices.</xs:documentation>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here (show the name not the ID number)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


<xs:assert test="count(/acrn-config/vm[vm_type = 'SERVICE_VM']) &lt; 2">
<xs:annotation acrn:severity="error">
<xs:documentation>There can be at most one service VM, but more than one was configured. Verify there is only one VM with vm_type set to SERVICE_VM. </xs:documentation>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does one get more than one Service VM Can someone change the vm_type to SERVICE_VM for any VM in the configurator, and this is the assert that will catch that error (eventually)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users cannot hit this when using the configurator.

Meanwhile, these checks are also applied at an early stage of building, so that errors in manually-edited XMLs can be caught early. VM type errors could exist in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good you're thinking of errors that could be introduced by editing the xml file. Have you considered the configurator adding a test to detect manual edits (hash or checksum kind of test)?

every $svm in /acrn-config/vm[vm_type = 'SERVICE_VM'] satisfies
$pre_vm/@id &lt; $svm/@id">
<xs:annotation acrn:severity="error">
<xs:documentation>This pre-launched VM (ID: {$pre_vm/@id}) must have a VM ID value less than the service VM (ID: {$svm/@id}). Adjust the VM ID values to fix this.</xs:documentation>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this situation happen? How does the developer change a VM ID in the configurator? I don't think we have a way in the UI do do this? For example, you can't drag and drop a VM tab to move them around, right?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the response above.

every $svm in /acrn-config/vm[vm_type = 'SERVICE_VM'] satisfies
$post_vm/@id &gt; $svm/@id">
<xs:annotation acrn:severity="error">
<xs:documentation>This post-launched VM (ID: {$post_vm/@id}) must have a VM ID value greater than the service VM (ID: {$svm/@id}). Adjust the VM ID values to fix this.</xs:documentation>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the response above.

Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants