From: Philippe Proulx Date: Fri, 25 Mar 2016 17:53:25 +0000 (-0400) Subject: Support empty payload type, as long as the event is not empty X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=13eaac62855381011b6694ea81ff68896f37bcfd;p=deliverable%2Fbarectf.git Support empty payload type, as long as the event is not empty Signed-off-by: Philippe Proulx --- diff --git a/barectf/config.py b/barectf/config.py index 74de0ca..401810e 100644 --- a/barectf/config.py +++ b/barectf/config.py @@ -309,16 +309,13 @@ class _BarectfMetadataValidator: self._cur_entity = _Entity.EVENT_PAYLOAD - if ev.payload_type is None: - raise ConfigError('missing payload type in event "{}"'.format(ev_name), e) - try: self._validate_entity(ev.payload_type) except Exception as e: raise ConfigError('invalid payload type in event "{}"'.format(ev_name), e) - if not ev.payload_type.fields: - raise ConfigError('empty payload type in event "{}"'.format(ev_name), e) + if stream.is_event_empty(ev): + raise ConfigError('event "{}" is empty'.format(ev_name)) except Exception as e: raise ConfigError('invalid stream "{}"'.format(stream_name), e) @@ -1110,14 +1107,6 @@ class _MetadataTypesHistologyValidator: raise ConfigError('invalid event context type for event "{}"'.format(ev_name), e) # validate event payload type - if ev.payload_type is None: - raise ConfigError('event payload type must exist in event "{}"'.format(ev_name)) - - # TODO: also check arrays, sequences, and variants - if type(ev.payload_type) is metadata.Struct: - if not ev.payload_type.fields: - raise ConfigError('event payload type must have at least one field for event "{}"'.format(ev_name)) - try: self._validate_entity_type_histology(ev.payload_type) except Exception as e: @@ -2193,10 +2182,7 @@ class _YamlConfigParser: event.context_type = t - if 'payload-type' not in event_node: - raise ConfigError('missing "payload-type" property in event object') - - if event_node['payload-type'] is not None: + if 'payload-type' in event_node and event_node['payload-type'] is not None: try: t = self._create_type(event_node['payload-type']) except Exception as e: diff --git a/barectf/metadata.py b/barectf/metadata.py index 92cd293..fa938d8 100644 --- a/barectf/metadata.py +++ b/barectf/metadata.py @@ -406,6 +406,9 @@ class Struct(Type): def __getitem__(self, key): return self.fields[key] + def __len__(self): + return len(self._fields) + class Variant(Type): def __init__(self): @@ -736,6 +739,23 @@ class Stream: def events(self): return self._events + def is_event_empty(self, event): + total_fields = 0 + + if self.event_header_type: + total_fields += len(self.event_header_type) + + if self.event_context_type: + total_fields += len(self.event_context_type) + + if event.context_type: + total_fields += len(event.context_type) + + if event.payload_type: + total_fields += len(event.payload_type) + + return total_fields == 0 + class Metadata: def __init__(self): diff --git a/barectf/tsdl182gen.py b/barectf/tsdl182gen.py index 35a515a..586d9ab 100644 --- a/barectf/tsdl182gen.py +++ b/barectf/tsdl182gen.py @@ -312,6 +312,10 @@ def _gen_event_block(stream, ev, cg): if ev.payload_type is not None: _gen_entity('fields', ev.payload_type, cg) + else: + fake_payload = metadata.Struct() + fake_payload.min_align = 8 + _gen_entity('fields', fake_payload, cg) _gen_end_block(cg) diff --git a/tests/config/fail/event/fail.bats b/tests/config/fail/event/fail.bats index 0722f01..e911649 100644 --- a/tests/config/fail/event/fail.bats +++ b/tests/config/fail/event/fail.bats @@ -33,17 +33,7 @@ load ../../common barectf_config_check_fail } -@test 'no "payload-type" property in event object makes barectf fail' { - barectf_assert_file_exists pt-no.yaml - barectf_config_check_fail -} - @test 'invalid "payload-type" property field type (not a structure) in event object makes barectf fail' { barectf_assert_file_exists pt-not-struct.yaml barectf_config_check_fail } - -@test 'empty struct type as "payload-type" property in event object makes barectf fail' { - barectf_assert_file_exists pt-empty.yaml - barectf_config_check_fail -} diff --git a/tests/config/fail/event/pt-empty.yaml b/tests/config/fail/event/pt-empty.yaml deleted file mode 100644 index 84f1113..0000000 --- a/tests/config/fail/event/pt-empty.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: '2.1' -metadata: - type-aliases: - uint16: - class: int - size: 16 - trace: - byte-order: le - streams: - my_stream: - packet-context-type: - class: struct - fields: - packet_size: uint16 - content_size: uint16 - events: - my_event: - payload-type: - class: struct diff --git a/tests/config/fail/event/pt-no.yaml b/tests/config/fail/event/pt-no.yaml deleted file mode 100644 index 3cf2693..0000000 --- a/tests/config/fail/event/pt-no.yaml +++ /dev/null @@ -1,21 +0,0 @@ -version: '2.1' -metadata: - type-aliases: - uint16: - class: int - size: 16 - trace: - byte-order: le - streams: - my_stream: - packet-context-type: - class: struct - fields: - packet_size: uint16 - content_size: uint16 - events: - my_event: - context-type: - class: struct - fields: - allo: uint16