tool: add genode xml schema to xmllint check

Fixes #2513
This commit is contained in:
Alexander Boettcher 2017-09-05 23:05:43 +02:00 committed by Christian Helmuth
parent f04ef8ed40
commit be753ee863
5 changed files with 166 additions and 5 deletions

View File

@ -32,7 +32,7 @@ set build_components {
# specified using an '<inline>' node but it is no valid XML. I.e., xmllint
# complains about the sequence '&&'.
#
proc check_xml_syntax {xml_file} { }
proc check_xml_with_schema {xml_file} { }
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components

View File

@ -142,7 +142,7 @@ set config_of_app {
</start>
<start name="noux" priority="-1" caps="600">
<resource name="RAM" quantum="32M" caps="200"/>
<resource name="RAM" quantum="32M"/>
<config>
<fstab>
<tar name="coreutils.tar"/>

View File

@ -209,7 +209,7 @@ append_if [expr $use_cpu_load] config {
</route>
</start>
<start name="top" priorirty="-1">
<start name="top" priority="-1">
<resource name="RAM" quantum="2M"/>
<config period_ms="10000"/>
<route>

141
tool/run/genode.xsd Normal file
View File

@ -0,0 +1,141 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="template_service">
<xs:choice minOccurs="1" maxOccurs="3">
<xs:element name="parent"/>
<xs:element name="any-child"/>
<xs:element name="child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="xs:string" />
<xs:attribute name="label_prefix" type="xs:string" />
<xs:attribute name="label_suffix" type="xs:string" />
</xs:complexType>
<xs:complexType name="template_route">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="service" type="template_service"/>
<xs:element name="any-service" type="template_service"/>
</xs:choice>
</xs:complexType>
<xs:element name="config">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="affinity-space">
<xs:complexType>
<xs:attribute name="width" type="xs:int" />
<xs:attribute name="height" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "affinity-space" -->
<xs:element name="parent-provides">
<xs:complexType>
<xs:sequence>
<xs:element name="service" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element> <!-- "parent-provides" -->
<xs:element name="alias">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="child" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "alias" -->
<xs:element name="default-route" type="template_route"/>
<xs:element name="default">
<xs:complexType>
<xs:attribute name="caps" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "default" -->
<xs:element name="resource">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="preserve" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "resource" -->
<xs:element name="start" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="binary">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "binary" -->
<xs:element name="affinity">
<xs:complexType>
<xs:attribute name="xpos" type="xs:int" />
<xs:attribute name="ypos" type="xs:int" />
<xs:attribute name="width" type="xs:int" />
<xs:attribute name="height" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "affinity" -->
<xs:element name="resource">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="quantum" type="xs:string" />
<xs:attribute name="constrain_phys" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "resource" -->
<xs:element name="configfile">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "configfile" -->
<xs:element name="provides">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="service">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element> <!-- "provides" -->
<xs:element name="route" type="template_route"/>
<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip" />
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element> <!-- "config" -->
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="caps" type="xs:int" />
<xs:attribute name="priority" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "start" -->
</xs:choice>
<xs:attribute name="prio_levels" type="xs:int" />
<xs:attribute name="verbose" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "config" -->
</xs:schema>

View File

@ -106,14 +106,34 @@ proc check_xml_syntax {xml_file} {
##
# Install content of specfied variable as init config file
# Validate file to match Genode's XML schema using xmllint
#
proc check_xml_with_schema {xml_file} {
if {![have_installed xmllint]} {
puts "Warning: Cannot validate config syntax (please install xmllint)"
return;
}
if {[catch {exec xmllint --noout -schema [genode_dir]/tool/run/genode.xsd $xml_file} result]} {
if {$result != "$xml_file validates"} {
puts stderr "$result"
puts stderr "Error: Invalid XML syntax in $xml_file"
exit 1
}
}
}
##
# Install content of specified variable as init config file
#
proc install_config { args } {
set fh [open "[run_dir]/genode/config" "WRONLY CREAT TRUNC"]
puts $fh [join $args {}]
close $fh
check_xml_syntax [run_dir]/genode/config
check_xml_with_schema [run_dir]/genode/config
}