Skip to content

Commit

Permalink
Merge remote-tracking branch 'rvi/crd-james' into crd-james
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Oct 15, 2024
2 parents 0c6bbf0 + 066b99e commit 486e58f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 18 deletions.
11 changes: 10 additions & 1 deletion arch/crd/MockCRD-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ MockCRD-1:
MOCK_1_BIT_INT: {}
MOCK_2_BIT_INT: {}
MOCK_25_BIT_INT: {}
MOCK_32_BIT_INT:
schema:
const: 0xdeadbeef
MOCK_64_BIT_INT: {}
MOCK_INT_RANGE_0_TO_127: {}
MOCK_INT_RANGE_0_TO_128: {}
MOCK_INT_RANGE_1_TO_128: {}
MOCK_INT_RANGE_0_TO_999: {}
MOCK_INT_RANGE_0_TO_1023: {}
MOCK_INT_RANGE_1000_TO_2048: {}
MOCK_ARRAY_INT_ENUM: {}
MOCK_ARRAY_BOOL_ARRAY_OF_8_FIRST_2_FALSE: {}
MOCK_ARRAY_STRING_ENUM:
MOCK_ARRAY_STRING_ENUM1:
schema:
const : DEF
MOCK_ARRAY_STRING_ENUM2:
schema:
contains: { const : DEF }
- name: I
Expand Down
33 changes: 32 additions & 1 deletion arch/ext/MockExt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ MockExt:
description: foo
schema:
type: boolean
MOCK_32_BIT_INT:
description: foo
schema:
type: integer
minimum: 0
maximum: 0xffffffff
MOCK_64_BIT_INT:
description: foo
schema:
Expand Down Expand Up @@ -62,6 +68,24 @@ MockExt:
type: integer
minimum: 0
maximum: 127
MOCK_INT_RANGE_0_TO_999:
description: foo
schema:
type: integer
minimum: 0
maximum: 999
MOCK_INT_RANGE_0_TO_1023:
description: foo
schema:
type: integer
minimum: 0
maximum: 1023
MOCK_INT_RANGE_1000_TO_2048:
description: foo
schema:
type: integer
minimum: 1000
maximum: 2048
MOCK_INT_RANGE_0_TO_128:
description: foo
schema:
Expand Down Expand Up @@ -100,7 +124,14 @@ MockExt:
type: integer
enum: [0, 1]
maxItems: 10
MOCK_ARRAY_STRING_ENUM:
MOCK_ARRAY_STRING_ENUM1:
description: foo
schema:
type: array
items:
type: string
enum: [ABC, DEF, GHI]
MOCK_ARRAY_STRING_ENUM2:
description: foo
schema:
type: array
Expand Down
5 changes: 3 additions & 2 deletions backends/crd_doc/templates/crd.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ not provided in the associated standard.
=== IN-SCOPE Parameters
These implementation-dependent options defined by MANDATORY or OPTIONAL extensions are IN-SCOPE.
An implementation must abide by the "Allowed Value(s)" to obtain a certificate.
An implementation must abide by the "Allowed Value(s)" to obtain a certificate.
If the "Allowed Value(s)" is "Any" then any value allowed by the type is acceptable.
<%- if crd.all_in_scope_ext_params.empty? -%>
None
Expand All @@ -123,7 +124,7 @@ None
<%- crd.all_in_scope_ext_params.sort.each do |in_scope_ext_param| -%>
| <%= in_scope_ext_param.name %>
| <%= in_scope_ext_param.param_db.schema_type %>
| <%= in_scope_ext_param.schema_pretty_crd_merged_with_param_db %>
| <%= in_scope_ext_param.allowed_values %>
| <%- crd.all_in_scope_exts_with_param(in_scope_ext_param.param_db).sort.each do |ext_db| -%><<ext-<%= ext_db.name %>-param-<%= in_scope_ext_param.name %>-def,<%= ext_db.name %>>> <%- end # do ext_db -%>
a| <%= in_scope_ext_param.note %>
<%- end # do -%>
Expand Down
34 changes: 28 additions & 6 deletions lib/arch_obj_models/crd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ class InScopeExtensionParameter

def initialize(param_db, schema_hash, note)
raise ArgumentError, "Expecting ExtensionParameter" unless param_db.is_a?(ExtensionParameter)
raise ArgumentError, "Expecting schema_hash to be a hash" unless schema_hash.is_a?(Hash)

if schema_hash.nil?
schema_hash = {}
else
raise ArgumentError, "Expecting schema_hash to be a hash" unless schema_hash.is_a?(Hash)
end

@param_db = param_db
@schema_crd = Schema.new(schema_hash)
Expand All @@ -216,9 +221,26 @@ def value
@schema_crd.value
end

# Pretty convert CRD's parameter constraint merged into extension schema to a string.
def schema_pretty_crd_merged_with_param_db
Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
# @return [String] - # What parameter values are allowed by the CRD.
#
# Old implementation:
# def schema_pretty_crd_merged_with_param_db
# Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
# end
def allowed_values
if (@schema_crd.empty?)
# CRD doesn't add any constraints on parameter's value.
return "Any"
end

# Create a Schema object just using information in the parameter database.
schema_obj = Schema.new(@param_db.schema)

# Merge in constraints imposed by the CRD on the parameter.
schema_obj.merge!(@schema_crd)

# Create string showing allowed values of parameter with CRD constraints added
schema_obj.to_pretty_s
end

# sorts by name
Expand Down Expand Up @@ -252,7 +274,7 @@ def all_in_scope_ext_params
raise "There is no param '#{param_name}' in extension '#{ext_crd["name"]}" if param_db.nil?

@all_in_scope_ext_params <<
InScopeExtensionParameter.new(param_db, param_data["schema"] || {}, param_data["note"])
InScopeExtensionParameter.new(param_db, param_data["schema"], param_data["note"])
end
end
@all_in_scope_ext_params
Expand Down Expand Up @@ -281,7 +303,7 @@ def in_scope_ext_params(ext_req)
raise "There is no param '#{param_name}' in extension '#{ext_crd["name"]}" if ext_param_db.nil?

ext_params <<
InScopeExtensionParameter.new(ext_param_db, param_data["schema"] || {}, param_data["note"])
InScopeExtensionParameter.new(ext_param_db, param_data["schema"], param_data["note"])
end

ext_params
Expand Down
33 changes: 25 additions & 8 deletions lib/arch_obj_models/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ def to_pretty_s(schema_hash = @schema_hash)
raise ArgumentError, "Expecting non-empty hash" if schema_hash.empty?

if schema_hash.key?("const")
"#{schema_hash["const"]}"
large2hex(schema_hash["const"])
elsif schema_hash.key?("enum")
"[#{schema_hash["enum"].join(', ')}]"
elsif schema_hash.key?("type")
case schema_hash["type"]
when "integer"
min = schema_hash["minimum"]
minstr = large2hex(min)
max = schema_hash["maximum"]
maxstr = large2hex(max)
if min && max
sz = num_bits(min, max)
(sz > 0) ? "#{sz}-bit integer" : "#{min} to #{max}"
(sz > 0) ? "#{sz}-bit integer" : "#{minstr} to #{maxstr}"
elsif min
"&#8805; #{min}"
"&#8805; #{minstr}"
elsif max
"&#8804; #{max}"
"&#8804; #{maxstr}"
else
"integer"
end
Expand Down Expand Up @@ -90,14 +92,29 @@ def to_pretty_s(schema_hash = @schema_hash)
end
end

# Convert large integers to hex str.
def large2hex(value)
if value.nil?
""
elsif value.is_a?(Integer)
(value > 999) ? "0x" + value.to_s(16) : value.to_s
else
value.to_s
end
end

def merge!(other_schema)
raise ArgumentError, "Expecting Schema" unless (other_schema.is_a?(Schema) || other_schema.is_a?(Hash))
raise ArgumentError, "Expecting Schema" unless (other_schema.is_a?(Schema) || other_schema.is_a?(Hash))

hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema

hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema
@schema_hash.merge!(hash)

@schema_hash.merge!(hash)
self
end

self
def empty?
@schema_hash.empty?
end

def single_value?
Expand Down

0 comments on commit 486e58f

Please sign in to comment.