Fix: YAML: force enumeration FT objects to have at least one mapping
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 24 Sep 2020 17:23:34 +0000 (13:23 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 24 Sep 2020 21:46:26 +0000 (17:46 -0400)
As per CTF 1.8.3:

> Enumerations need to contain at least one entry.

Before this patch, ythose were legal:

    class: uenum
    size: 8

    class: uenum
    size: 8
    mappings: {}

    class: uenum
    size: 8
    mappings:
      A: []

CTF consumers would not like the resulting metadata stream. For
example, Babeltrace 2.1.0-rc1 [v1.2.0-3520-g73f74ae1f]:

    09-24 13:26:41.740 80492 80492 E PLUGIN/CTF/META/PARSER yyerror@parser.y:925 At line 109 in metadata stream: syntax error, unexpected CTF_RBRAC: token="}"
    09-24 13:26:41.740 80492 80492 E PLUGIN/CTF/META/DECODER ctf_metadata_decoder_append_content@decoder.c:280 [N/A] Cannot create the metadata AST out of the metadata text: mdec-addr=0x559dd9546a10
    09-24 13:26:41.740 80492 80492 W PLUGIN/SRC.CTF.FS/QUERY support_info_query@query.c:459 cannot append metadata content: metadata-decoder-status=-2
    09-24 13:26:41.741 80492 80492 W LIB/QUERY-EXECUTOR bt_query_executor_query@query-executor.c:231 Component class's "query" method failed: query-exec-addr=0x559dd9548070, cc-addr=0x559dd95233e0, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from the file sy", cc-is-frozen=0, cc-so-handle-addr=0x559dd9522770, cc-so-handle-path="lib/babeltrace2/plugins/babeltrace-plugin-ctf.so", object="babeltrace.support-info", params-addr=0x559dd9545f10, params-type=MAP, params-element-count=2, log-level=WARNING
    09-24 13:26:41.741 80492 80492 E CLI-CFG-SRC-AUTO-DISC support_info_query_all_sources@autodisc.c:493 babeltrace.support-info query failed.
    09-24 13:26:41.741 80492 80492 E CLI main@babeltrace2.c:2644 Command-line error: retcode=1

    ERROR:    [Babeltrace CLI] (babeltrace2.c:2644)
      Command-line error: retcode=1
    CAUSED BY [Source auto-discovery] (autodisc.c:493)
      babeltrace.support-info query failed.
    CAUSED BY [libbabeltrace2] (query-executor.c:231)
      Component class's "query" method failed: query-exec-addr=0x559dd9548070, cc-addr=0x559dd95233e0, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from
      the file sy", cc-is-frozen=0, cc-so-handle-addr=0x559dd9522770, cc-so-handle-path="babeltrace2/plugins/babeltrace-plugin-ctf.so",
      object="babeltrace.support-info", params-addr=0x559dd9545f10, params-type=MAP, params-element-count=2, log-level=WARNING

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/config_parse_v3.py
barectf/schemas/config/2/field-type.yaml
barectf/schemas/config/3/field-type.yaml
docs/modules/yaml/pages/enum-ft-obj.adoc

index 95de5c1052e443c30fc0d7c90f9fd0ae271745ed..5fe35ecd89b64da94a0a49785f1249842b5cd9d3 100644 (file)
@@ -173,7 +173,7 @@ class _Parser(barectf_config_parse_common._Parser):
         }[ft_node['class']]
         mappings = collections.OrderedDict()
 
-        for label, mapping_node in ft_node.get('mappings', {}).items():
+        for label, mapping_node in ft_node['mappings'].items():
             ranges = set()
 
             for range_node in mapping_node:
index 2df28850f82aaa22e4c3a4a2e15d40bc43c51cfe..7366c9c5fa554de92ce91b6a0ed3a039445ba915 100644 (file)
@@ -155,6 +155,7 @@ definitions:
         $ref: '#/definitions/int-ft'
       members:
         type: array
+        minItems: 1
         items:
           if:
             type: object
index 92c550219135aed58077daa58d882971c98a5d23..d3b5fca65f9f1128c05b88fa16a2e0e2540b1a53 100644 (file)
@@ -90,6 +90,10 @@ definitions:
     additionalProperties: false
   enum-ft:
     properties:
+      class: true
+      size: true
+      alignment: true
+      preferred-display-base: true
       mappings:
         if:
           type: object
@@ -97,6 +101,7 @@ definitions:
           patternProperties:
             '.*':
               type: array
+              minItems: 1
               items:
                 if:
                   type: array
@@ -107,15 +112,12 @@ definitions:
                   maxItems: 2
                 else:
                   type: integer
+          minProperties: 1
         else:
           type: 'null'
-    properties:
-      class: true
-      size: true
-      alignment: true
-      preferred-display-base: true
-      mappings: true
     additionalProperties: false
+    required:
+      - mappings
   uenum-ft-class-prop:
     type: string
     enum:
index 6cacd52c0764633cff7e91020eff559484cf6d77..6b4eae9151dffa9f3934724bfeb23e65d6937b63 100644 (file)
@@ -7,9 +7,9 @@ streams].
 An enumeration data field is an integer data field.
 
 An enumeration field type is an integer field type with
-<<mappings-prop,_mappings_>>. An enumeration field type mapping is a labeled
-set of integer ranges. An enumeration data field can have zero or more
-labels depending on its value.
+<<mappings-prop,_mappings_>>. An enumeration field type mapping is a
+labeled set of integer ranges. An enumeration data field can have zero
+or more labels depending on its value.
 
 [[props]]
 == Properties
@@ -42,8 +42,10 @@ include::partial$int-ft-obj-base-props.adoc[]
 |Mappings of this enumeration field type.
 
 Each mapping assigns a label to a set of integer ranges.
-|No
-|No mappings
+
+This mapping must contain at least one entry.
+|Yes
+|
 |===
 
 [[enum-ft-mapping-seq]]
@@ -61,18 +63,22 @@ An integer::
 +
 In other words, `17` is equivalent to `+[17, 17]+`.
 
+This sequence must contain at least one item.
+
 == Generated C{nbsp}types
 
 include::partial$int-ft-obj-c-types-table.adoc[]
 
 == Examples
 
-.Basic <<size-prop,8-bit>> unsigned enumeration field type object.
+.Basic <<size-prop,8-bit>> unsigned enumeration field type object with a single <<mappings-prop,mapping>>
 ====
 [source,yaml]
 ----
 class: unsigned-enumeration
 size: 8
+mappings:
+  A: [0]
 ----
 ====
 
This page took 0.027084 seconds and 4 git commands to generate.