Fix: ctf-testsuite variant-missing-fields
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 3 Aug 2017 18:52:27 +0000 (14:52 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 9 Aug 2017 21:59:10 +0000 (17:59 -0400)
It is valid for an enumeration to contain labels that are missing in the
variant fields. For instance, an enumeration can be used for many
purposes in addition to being used as a selector for a variant, so we
don't want to enforce that a variant needs to have field names for cases
we never expect as enum field input.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/ctf-ir/field-types.c
tests/lib/test_bt_ctf_field_type_validation.c

index 06d8c76717571d136e5d9e3a9d529125e6d5b830..23093ebdab7a8a3c1e86eaa23474178290859daa 100644 (file)
@@ -697,25 +697,6 @@ bt_bool bt_ctf_field_type_enumeration_has_overlapping_ranges(
        return enumeration_type->has_overlapping_ranges;
 }
 
-static
-int bt_ctf_field_type_enumeration_get_mapping_name(
-               struct bt_ctf_field_type *enum_field_type,
-               uint64_t index,
-               const char **mapping_name)
-{
-       int ret = 0;
-       struct enumeration_mapping *mapping;
-
-       assert(enum_field_type);
-       mapping = get_enumeration_mapping(enum_field_type, index);
-       assert(mapping);
-       if (mapping_name) {
-               *mapping_name = g_quark_to_string(mapping->string);
-       }
-
-       return ret;
-}
-
 static
 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
 {
@@ -726,7 +707,6 @@ int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
                container_of(type, struct bt_ctf_field_type_variant,
                        parent);
        int64_t i;
-       int64_t tag_mappings_count;
 
        if (variant->tag_name->len == 0) {
                BT_LOGW("Invalid variant field type: no tag field name: "
@@ -753,44 +733,20 @@ int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
                goto end;
        }
 
-       tag_mappings_count =
-               bt_ctf_field_type_enumeration_get_mapping_count(
-                       (struct bt_ctf_field_type *) variant->tag);
-       assert(tag_mappings_count >= 0);
-
        /*
-        * Validate that each mapping found in the tag has a name which
-        * is also the name of a field in this variant field type.
+        * It is valid to have a variant field type which does not have
+        * the fields corresponding to each label in the associated
+        * enumeration.
         *
-        * The opposite is accepted: variant FT fields which cannot be
-        * selected because the variant FT tag has no mapping named as
-        * such. This scenario, while not ideal, cannot cause any error.
+        * It is also valid to have variant field type fields which
+        * cannot be selected because the variant field type tag has no
+        * mapping named as such. This scenario, while not ideal, cannot
+        * cause any error.
+        *
+        * If a non-existing field happens to be selected by an
+        * enumeration while reading a variant field, an error will be
+        * generated at that point (while reading the stream).
         */
-       for (i = 0; i < tag_mappings_count; ++i) {
-               const char *label;
-               struct bt_ctf_field_type *ft;
-
-               ret = bt_ctf_field_type_enumeration_get_mapping_name(
-                       (struct bt_ctf_field_type *) variant->tag,
-                       i, &label);
-               assert(ret == 0);
-               assert(label);
-               ft = bt_ctf_field_type_variant_get_field_type_by_name(
-                       type, label);
-               if (!ft) {
-                       BT_LOGW("Invalid variant field type: "
-                               "enumeration tag field type contains a mapping which does not name a variant field type field: "
-                               "variant-ft-addr=%p, tag-field-name=\"%s\", "
-                               "enum-ft-addr=%p, mapping-name=\"%s\"",
-                               type, variant->tag_name->str, variant->tag,
-                               label);
-                       ret = -1;
-                       goto end;
-               }
-
-               BT_PUT(ft);
-       }
-
        field_count = bt_ctf_field_type_variant_get_field_count(type);
        if (field_count < 0) {
                BT_LOGW("Invalid variant field type: no fields: "
index ab1f782fbab68201afc7a8f679d92b8002d5ca5f..7e4a7eed8d9f1c27d007b81a7a303a2579cc1352 100644 (file)
@@ -2868,7 +2868,7 @@ void test_fail_variant_tag_mismatch_mappings(void)
        ep = test_fail_variant_tag_mismatch_mappings_get_ep();
        assert(ep);
        event = create_event_with_context_and_payload(NULL, ep);
-       ok(!event, "Variant FT with mismatching tag FT is invalid");
+       ok(event, "Variant FT with mismatching tag FT is valid");
 
        BT_PUT(ep);
        BT_PUT(event);
This page took 0.034848 seconds and 4 git commands to generate.