Skip to content

Commit

Permalink
Change certificate class schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Nov 15, 2024
1 parent 7c9e587 commit 82d1340
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 59 deletions.
61 changes: 32 additions & 29 deletions arch/certificate_class/MC.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
MC:
name: MC
long_name: Microcontroller Certificate Class
# yaml-language-server: $schema=../../schemas/cert_class_schema.json

introduction: |
This certification class specifies requirements for microcontrollers.
It targets microcontrollers running low-level software on an RTOS or bare-metal.
This CRD is not intended for the smallest possible microcontrollers but rather for applications
benefiting from a standardized microcontroller.
See the https://docs.google.com/document/d/133SZKc18tLsQcT1o6gEmBUkjwrtg2ow63me54RQ1jiY[RISC-V CRDs]
document for information relevant to all RISC-V CRDs.
$schema: cert_class_schema.json#
kind: certificate class
name: MC
long_name: Microcontroller Certificate Class

naming_scheme: |
The MC (M = Microcontroller, C = Certificate) has the following naming scheme (suffixes after MC
are optional but in the below order):
introduction: |
This certification class specifies requirements for microcontrollers.
It targets microcontrollers running low-level software on an RTOS or bare-metal.
This CRD is not intended for the smallest possible microcontrollers but rather for applications
benefiting from a standardized microcontroller.
See the https://docs.google.com/document/d/133SZKc18tLsQcT1o6gEmBUkjwrtg2ow63me54RQ1jiY[RISC-V CRDs]
document for information relevant to all RISC-V CRDs.
MC<model>[v<version>]
naming_scheme: |
The MC (M = Microcontroller, C = Certificate) has the following naming scheme (suffixes after MC
are optional but in the below order):
Where:
MC<model>[v<version>]
* Left & right square braces denote optional.
* \<model> is a 3 digit integer. It is changed only when mandatory extensions are added to a CRD.
** The one's digit is incremented when a small mandatory extension is added (e.g., Zicond)
** The ten's digit is incremented when a medium mandatory extension is addded (e.g., PMP)
** The hundreds's digit is incremented when a large mandatory extension is addded (e.g., V or H)
* \<version> is a semantic version (see semver.org) formatted as <major>[.<minor>.[patch]]. If \<version> is omitted, the reference applies equally to all versions.
** A <major> release indicates support for a new optional extension.
** A <minor> release indicates one or more of the following changes to the certification tests associated with the CRD.
*** Fix test bug or increase test coverage
*** Add more allowed parameter values
*** Support new extension version
** A <patch> release indicates just CRD specification changes without any difference in functional behavior
Where:
mandatory_priv_modes:
- M
* Left & right square braces denote optional.
* \<model> is a 3 digit integer. It is changed only when mandatory extensions are added to a CRD.
** The one's digit is incremented when a small mandatory extension is added (e.g., Zicond)
** The ten's digit is incremented when a medium mandatory extension is addded (e.g., PMP)
** The hundreds's digit is incremented when a large mandatory extension is addded (e.g., V or H)
* \<version> is a semantic version (see semver.org) formatted as <major>[.<minor>.[patch]]. If \<version> is omitted, the reference applies equally to all versions.
** A <major> release indicates support for a new optional extension.
** A <minor> release indicates one or more of the following changes to the certification tests associated with the CRD.
*** Fix test bug or increase test coverage
*** Add more allowed parameter values
*** Support new extension version
** A <patch> release indicates just CRD specification changes without any difference in functional behavior
mandatory_priv_modes:
- M
21 changes: 11 additions & 10 deletions arch/certificate_class/MockCertificateClass.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
MockCertificateClass:
name: MockCertificateClass
long_name: Mock Certificate Class Long Name
# yaml-language-server: $schema=../../schemas/cert_class_schema.json

introduction: |
Here's the Mock Certificate Class introduction.
$schema: cert_class_schema.json#
kind: certificate class
name: MockCertificateClass
long_name: Mock Certificate Class Long Name

naming_scheme: |
Here's the Mock Certificate Class naming scheme.
introduction: |
Here's the Mock Certificate Class introduction.
mandatory_priv_modes:
- M
naming_scheme: |
Here's the Mock Certificate Class naming scheme.
description: Here's the Mock Certificate Class description.
mandatory_priv_modes:
- M
12 changes: 5 additions & 7 deletions backends/arch_gen/lib/arch_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,11 @@ def gen_arch_def
profile_release_obj[profile_release_name]["__source"] = f
[profile_release_name, profile_release_obj[profile_release_name]]
end.to_h
cert_class_hash = Dir.glob($root / "arch" / "certificate_class" / "**" / "*.yaml").map do |f|
cert_class_ary = Dir.glob($root / "arch" / "certificate_class" / "**" / "*.yaml").map do |f|
cert_class_obj = YamlLoader.load(f, permitted_classes:[Date])
cert_class_name = cert_class_obj.keys[0]
cert_class_obj[cert_class_name]["name"] = cert_class_name
cert_class_obj[cert_class_name]["__source"] = f
[cert_class_name, cert_class_obj[cert_class_name]]
end.to_h
cert_class_obj["__source"] = f
cert_class_obj
end
cert_model_hash = Dir.glob($root / "arch" / "certificate_model" / "**" / "*.yaml").map do |f|
cert_model_obj = YamlLoader.load(f, permitted_classes:[Date])
cert_model_name = cert_model_obj.keys[0]
Expand Down Expand Up @@ -342,7 +340,7 @@ def gen_arch_def
"implemented_csrs" => @implemented_csrs,
"profile_classes" => profile_class_hash,
"profile_releases" => profile_release_hash,
"certificate_classes" => cert_class_hash,
"certificate_classes" => cert_class_ary,
"certificate_models" => cert_model_hash,
"manuals" => manual_hash
}
Expand Down
13 changes: 5 additions & 8 deletions backends/arch_gen/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ file "#{$root}/.stamps/arch-gen.stamp" => (
] + Dir.glob($root / "arch" / "**" / "*.yaml")
) do |t|
csr_ary = Dir.glob($root / "arch" / "csr" / "**" / "*.yaml").map do |f|
puts f
csr_obj = YamlLoader.load(f, permitted_classes:[Date])
csr_obj["fields"].map do |k, v|
v["name"] = k
Expand Down Expand Up @@ -67,13 +66,11 @@ puts f
profile_release_obj[profile_release_name]["__source"] = f
[profile_release_name, profile_release_obj[profile_release_name]]
end.to_h
cert_class_hash = Dir.glob($root / "arch" / "certificate_class" / "**" / "*.yaml").map do |f|
cert_class_ary = Dir.glob($root / "arch" / "certificate_class" / "**" / "*.yaml").map do |f|
cert_class_obj = YamlLoader.load(f, permitted_classes:[Date])
cert_class_name = cert_class_obj.keys[0]
cert_class_obj[cert_class_name]["name"] = cert_class_name
cert_class_obj[cert_class_name]["__source"] = f
[cert_class_name, cert_class_obj[cert_class_name]]
end.to_h
cert_class_obj["__source"] = f
cert_class_obj
end
cert_model_hash = Dir.glob($root / "arch" / "certificate_model" / "**" / "*.yaml").map do |f|
cert_model_obj = YamlLoader.load(f, permitted_classes:[Date])
cert_model_name = cert_model_obj.keys[0]
Expand Down Expand Up @@ -109,7 +106,7 @@ puts f
"csrs" => csr_ary,
"profile_classes" => profile_class_hash,
"profile_releases" => profile_release_hash,
"certificate_classes" => cert_class_hash,
"certificate_classes" => cert_class_ary,
"certificate_models" => cert_model_hash,
"manuals" => manual_hash
}
Expand Down
2 changes: 1 addition & 1 deletion lib/arch_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ def unconfigured_data
"profile_classes" => profile_classes.map { |f| [f.name, f.data] }.to_h,
"profile_releases" => profile_releases.map { |p| [p.name, p.data] }.to_h,
"manuals" => manuals.map { |m| [m.name, m.data] }.to_h,
"certificate_classes" => cert_classes.map { |f| [f.name, f.data] }.to_h,
"certificate_classes" => cert_classes.map(&:data),
"certificate_models" => cert_models.map { |c| [c.name, c.data] }.to_h
}
end
Expand Down
9 changes: 6 additions & 3 deletions lib/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Validator
ext: $root / "schemas" / "ext_schema.json",
csr: $root / "schemas" / "csr_schema.json",
cfg_impl_ext: $root / "schemas" / "implemented_exts_schema.json",
manual_version: $root / "schemas" / "manual_version_schema.json"
manual_version: $root / "schemas" / "manual_version_schema.json",
cert_class: $root / "schemas" / "cert_class_schema.json"
}.freeze

# types of objects that can be validated
Expand Down Expand Up @@ -196,6 +197,8 @@ def validate(path, type: nil)
type = :csr
when %r{.*arch/manual/.*/.*contents\.yaml$}
type = :manual_version
when %r{.*arch/certificate_class/.*\.yaml$}
type = :cert_class
else
warn "Cannot determine type from YAML path '#{path}'; skipping"
return
Expand All @@ -204,8 +207,8 @@ def validate(path, type: nil)
begin
obj = validate_str(File.read(path.to_s), path:, type:, schema_path:)

# check that the top key matches the filename
if [:inst, :csr, :ext].include?(type) && obj["name"] != File.basename(path, ".yaml").to_s
# check that the name matches the filename
if [:inst, :csr, :ext, :cert_class].include?(type) && obj["name"] != File.basename(path, ".yaml").to_s
raise ValidationError, "In #{path}, object name '#{obj.keys.first}' does not match filename '#{File.basename(path)}'"
end
obj
Expand Down
5 changes: 4 additions & 1 deletion schemas/arch_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@
"type": "object"
},
"certificate_classes": {
"type": "object"
"type": "array",
"items": {
"$ref": "cert_class_schema.json#"
}
},
"certificate_models": {
"type": "object"
Expand Down
47 changes: 47 additions & 0 deletions schemas/cert_class_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",

"type": "object",
"required": ["$schema", "kind", "name", "long_name", "introduction"],
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string",
"const": "cert_class_schema.json#"
},
"kind": {
"type": "string",
"const": "certificate class"
},
"name": {
"type": "string",
"pattern": "^[A-Z][a-zA-Z0-9_]*$",
"description": "The short name of the class, used as a database key"
},
"long_name": {
"type": "string",
"description": "Descriptive name of the class"
},
"introduction": {
"type": "string",
"description": "Asciidoc text containing the introduction prose for the class"
},
"naming_scheme": {
"type": "string",
"description": "Asciidoc text describing the naming scheme for the class"
},
"mandatory_priv_modes": {
"type": "array",
"items": {
"type": "string",
"enum": ["M", "S", "U", "VS", "VU"]
},
"uniqueItems": true,
"minItems": 1,
"description": "List of mandatory privilege modes for the class"
},
"__source": {
"$ref": "schema_defs.json#/$defs/__source"
}
}
}
5 changes: 5 additions & 0 deletions schemas/schema_defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"title": "Common patterns used by all schemas",

"$defs": {
"__source": {
"type": "string",
"format": "uri-reference",
"description": "Path to the source file containing this object"
},
"semantic_version": {
"type": "string",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
Expand Down

0 comments on commit 82d1340

Please sign in to comment.