Skip to content

Commit 486e58f

Browse files
author
Derek Hower
committed
Merge remote-tracking branch 'rvi/crd-james' into crd-james
2 parents 0c6bbf0 + 066b99e commit 486e58f

File tree

5 files changed

+98
-18
lines changed

5 files changed

+98
-18
lines changed

arch/crd/MockCRD-1.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ MockCRD-1:
3535
MOCK_1_BIT_INT: {}
3636
MOCK_2_BIT_INT: {}
3737
MOCK_25_BIT_INT: {}
38+
MOCK_32_BIT_INT:
39+
schema:
40+
const: 0xdeadbeef
3841
MOCK_64_BIT_INT: {}
3942
MOCK_INT_RANGE_0_TO_127: {}
4043
MOCK_INT_RANGE_0_TO_128: {}
4144
MOCK_INT_RANGE_1_TO_128: {}
45+
MOCK_INT_RANGE_0_TO_999: {}
46+
MOCK_INT_RANGE_0_TO_1023: {}
47+
MOCK_INT_RANGE_1000_TO_2048: {}
4248
MOCK_ARRAY_INT_ENUM: {}
4349
MOCK_ARRAY_BOOL_ARRAY_OF_8_FIRST_2_FALSE: {}
44-
MOCK_ARRAY_STRING_ENUM:
50+
MOCK_ARRAY_STRING_ENUM1:
51+
schema:
52+
const : DEF
53+
MOCK_ARRAY_STRING_ENUM2:
4554
schema:
4655
contains: { const : DEF }
4756
- name: I

arch/ext/MockExt.yaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ MockExt:
2626
description: foo
2727
schema:
2828
type: boolean
29+
MOCK_32_BIT_INT:
30+
description: foo
31+
schema:
32+
type: integer
33+
minimum: 0
34+
maximum: 0xffffffff
2935
MOCK_64_BIT_INT:
3036
description: foo
3137
schema:
@@ -62,6 +68,24 @@ MockExt:
6268
type: integer
6369
minimum: 0
6470
maximum: 127
71+
MOCK_INT_RANGE_0_TO_999:
72+
description: foo
73+
schema:
74+
type: integer
75+
minimum: 0
76+
maximum: 999
77+
MOCK_INT_RANGE_0_TO_1023:
78+
description: foo
79+
schema:
80+
type: integer
81+
minimum: 0
82+
maximum: 1023
83+
MOCK_INT_RANGE_1000_TO_2048:
84+
description: foo
85+
schema:
86+
type: integer
87+
minimum: 1000
88+
maximum: 2048
6589
MOCK_INT_RANGE_0_TO_128:
6690
description: foo
6791
schema:
@@ -100,7 +124,14 @@ MockExt:
100124
type: integer
101125
enum: [0, 1]
102126
maxItems: 10
103-
MOCK_ARRAY_STRING_ENUM:
127+
MOCK_ARRAY_STRING_ENUM1:
128+
description: foo
129+
schema:
130+
type: array
131+
items:
132+
type: string
133+
enum: [ABC, DEF, GHI]
134+
MOCK_ARRAY_STRING_ENUM2:
104135
description: foo
105136
schema:
106137
type: array

backends/crd_doc/templates/crd.adoc.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ not provided in the associated standard.
111111
=== IN-SCOPE Parameters
112112
113113
These implementation-dependent options defined by MANDATORY or OPTIONAL extensions are IN-SCOPE.
114-
An implementation must abide by the "Allowed Value(s)" to obtain a certificate.
114+
An implementation must abide by the "Allowed Value(s)" to obtain a certificate.
115+
If the "Allowed Value(s)" is "Any" then any value allowed by the type is acceptable.
115116
116117
<%- if crd.all_in_scope_ext_params.empty? -%>
117118
None
@@ -123,7 +124,7 @@ None
123124
<%- crd.all_in_scope_ext_params.sort.each do |in_scope_ext_param| -%>
124125
| <%= in_scope_ext_param.name %>
125126
| <%= in_scope_ext_param.param_db.schema_type %>
126-
| <%= in_scope_ext_param.schema_pretty_crd_merged_with_param_db %>
127+
| <%= in_scope_ext_param.allowed_values %>
127128
| <%- 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 -%>
128129
a| <%= in_scope_ext_param.note %>
129130
<%- end # do -%>

lib/arch_obj_models/crd.rb

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ class InScopeExtensionParameter
191191

192192
def initialize(param_db, schema_hash, note)
193193
raise ArgumentError, "Expecting ExtensionParameter" unless param_db.is_a?(ExtensionParameter)
194-
raise ArgumentError, "Expecting schema_hash to be a hash" unless schema_hash.is_a?(Hash)
194+
195+
if schema_hash.nil?
196+
schema_hash = {}
197+
else
198+
raise ArgumentError, "Expecting schema_hash to be a hash" unless schema_hash.is_a?(Hash)
199+
end
195200

196201
@param_db = param_db
197202
@schema_crd = Schema.new(schema_hash)
@@ -216,9 +221,26 @@ def value
216221
@schema_crd.value
217222
end
218223

219-
# Pretty convert CRD's parameter constraint merged into extension schema to a string.
220-
def schema_pretty_crd_merged_with_param_db
221-
Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
224+
# @return [String] - # What parameter values are allowed by the CRD.
225+
#
226+
# Old implementation:
227+
# def schema_pretty_crd_merged_with_param_db
228+
# Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
229+
# end
230+
def allowed_values
231+
if (@schema_crd.empty?)
232+
# CRD doesn't add any constraints on parameter's value.
233+
return "Any"
234+
end
235+
236+
# Create a Schema object just using information in the parameter database.
237+
schema_obj = Schema.new(@param_db.schema)
238+
239+
# Merge in constraints imposed by the CRD on the parameter.
240+
schema_obj.merge!(@schema_crd)
241+
242+
# Create string showing allowed values of parameter with CRD constraints added
243+
schema_obj.to_pretty_s
222244
end
223245

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

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

283305
ext_params <<
284-
InScopeExtensionParameter.new(ext_param_db, param_data["schema"] || {}, param_data["note"])
306+
InScopeExtensionParameter.new(ext_param_db, param_data["schema"], param_data["note"])
285307
end
286308

287309
ext_params

lib/arch_obj_models/schema.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ def to_pretty_s(schema_hash = @schema_hash)
1212
raise ArgumentError, "Expecting non-empty hash" if schema_hash.empty?
1313

1414
if schema_hash.key?("const")
15-
"#{schema_hash["const"]}"
15+
large2hex(schema_hash["const"])
1616
elsif schema_hash.key?("enum")
1717
"[#{schema_hash["enum"].join(', ')}]"
1818
elsif schema_hash.key?("type")
1919
case schema_hash["type"]
2020
when "integer"
2121
min = schema_hash["minimum"]
22+
minstr = large2hex(min)
2223
max = schema_hash["maximum"]
24+
maxstr = large2hex(max)
2325
if min && max
2426
sz = num_bits(min, max)
25-
(sz > 0) ? "#{sz}-bit integer" : "#{min} to #{max}"
27+
(sz > 0) ? "#{sz}-bit integer" : "#{minstr} to #{maxstr}"
2628
elsif min
27-
"&#8805; #{min}"
29+
"&#8805; #{minstr}"
2830
elsif max
29-
"&#8804; #{max}"
31+
"&#8804; #{maxstr}"
3032
else
3133
"integer"
3234
end
@@ -90,14 +92,29 @@ def to_pretty_s(schema_hash = @schema_hash)
9092
end
9193
end
9294

95+
# Convert large integers to hex str.
96+
def large2hex(value)
97+
if value.nil?
98+
""
99+
elsif value.is_a?(Integer)
100+
(value > 999) ? "0x" + value.to_s(16) : value.to_s
101+
else
102+
value.to_s
103+
end
104+
end
105+
93106
def merge!(other_schema)
94-
raise ArgumentError, "Expecting Schema" unless (other_schema.is_a?(Schema) || other_schema.is_a?(Hash))
107+
raise ArgumentError, "Expecting Schema" unless (other_schema.is_a?(Schema) || other_schema.is_a?(Hash))
108+
109+
hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema
95110

96-
hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema
111+
@schema_hash.merge!(hash)
97112

98-
@schema_hash.merge!(hash)
113+
self
114+
end
99115

100-
self
116+
def empty?
117+
@schema_hash.empty?
101118
end
102119

103120
def single_value?

0 commit comments

Comments
 (0)