Example #1
0
def test_scoped_qos(common_setup):
    with pytest.raises(TypeError):
        DomainParticipant(qos=Qos().topic())
    DomainParticipant(qos=Qos().domain_participant())

    with pytest.raises(TypeError):
        Topic(common_setup.dp,
              'Message',
              Message,
              qos=Qos().domain_participant())
    Topic(common_setup.dp, 'Message', Message, qos=Qos().topic())

    with pytest.raises(TypeError):
        Publisher(common_setup.dp, qos=Qos().subscriber())
    Publisher(common_setup.dp, qos=Qos().publisher())

    with pytest.raises(TypeError):
        Subscriber(common_setup.dp, qos=Qos().publisher())
    Subscriber(common_setup.dp, qos=Qos().subscriber())

    with pytest.raises(TypeError):
        DataWriter(common_setup.pub, common_setup.tp, qos=Qos().datareader())
    DataWriter(common_setup.pub, common_setup.tp, qos=Qos().datawriter())

    with pytest.raises(TypeError):
        DataReader(common_setup.sub, common_setup.tp, qos=Qos().datawriter())
    DataReader(common_setup.sub, common_setup.tp, qos=Qos().datareader())
def test_get_participant():
    dp = DomainParticipant(0)

    assert dp.participant == dp.get_participant() == dp

    tp = Topic(dp, "Message", Message)

    assert isgoodentity(tp)
    assert tp.participant == tp.get_participant() == dp

    sub = Subscriber(dp)

    assert isgoodentity(sub)
    assert sub.participant == sub.get_participant() == dp

    pub = Publisher(dp)

    assert isgoodentity(pub)
    assert pub.participant == pub.get_participant() == dp

    dr = DataReader(sub, tp)

    assert isgoodentity(dr)
    assert dr.participant == dr.get_participant() == dp

    dw = DataWriter(pub, tp)

    assert isgoodentity(dw)
    assert dw.participant == dw.get_participant() == dp
Example #3
0
 def __init__(self, args, dp, qos, waitset):
     self.topic_name = args.topic
     self.seq = -1
     try:
         int_topic = Topic(dp, self.topic_name + "int", Integer, qos=qos)
         str_topic = Topic(dp, self.topic_name, String, qos=qos)
         self.int_writer = DataWriter(dp, int_topic, qos=qos)
         self.int_reader = DataReader(dp, int_topic, qos=qos)
         self.str_writer = DataWriter(dp, str_topic, qos=qos)
         self.str_reader = DataReader(dp, str_topic, qos=qos)
     except DDSException:
         raise SystemExit("Error: The arguments inputted are considered invalid for cyclonedds.")
     self.read_cond = ReadCondition(self.int_reader, ViewState.Any | InstanceState.Alive | SampleState.NotRead)
     waitset.attach(self.read_cond)
Example #4
0
def test_initialize_writer():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    assert isgoodentity(dw)
Example #5
0
def test_dynamic_publish_complex():
    dp = DomainParticipant()
    tp = Topic(dp, 'DynTest', XStruct)
    rd = DataReader(dp, tp)

    type_id = XStruct.__idl__.get_type_id()
    datatype, tmap = get_types_for_typeid(dp, type_id, duration(seconds=1))
    assert datatype
    assert datatype.__idl__.get_type_id() == XStruct.__idl__.get_type_id()

    tp = Topic(dp, 'DynTest', datatype)
    wr = DataWriter(dp, tp)

    wr.write(datatype(A=tmap['XUnion'](A=tmap['XEnum'].V1), k=1))

    assert rd.read()[0].k == 1
Example #6
0
def test_reader_take():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    dr = DataReader(sub, tp)

    assert len(dr.take()) == 0
Example #7
0
def test_all_entities_json_reported():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageTopic", Message)
    dw = DataWriter(dp, tp)
    dr = DataReader(dp, tp)
    time.sleep(1)

    data = run_ddsls(["--json", "-a"])
    json_data = json.loads(data["stdout"])

    assert str(dw.guid) in data["stdout"]
    assert str(dr.guid) in data["stdout"]
    assert str(dp.guid) in data["stdout"]
    assert tp.name in data["stdout"]
    assert tp.typename in data["stdout"]

    writer_check, reader_check = False, False
    for sample in json_data:
        for val in sample["value"]:
            if val["key"] == str(dw.guid):
                assert (dw.get_qos()).asdict() == val["qos"]
                writer_check = True
            if val["key"] == str(dr.guid):
                assert (dr.get_qos()).asdict() == val["qos"]
                reader_check = True
    assert reader_check and writer_check
Example #8
0
 def tp(self, qos=None, listener=None):
     self._tp = Topic(self.dp,
                      'Message',
                      Message,
                      qos=qos,
                      listener=listener)
     return self._tp
Example #9
0
def test_reader_waitforhistoricaldata():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    dr = DataReader(sub, tp)

    assert dr.wait_for_historical_data(duration(milliseconds=5))
Example #10
0
def test_dynamic_subscribe_complex():
    dp = DomainParticipant()
    tp = Topic(dp, 'DynTest', XStruct)
    wr = DataWriter(dp, tp)

    type_id = XStruct.__idl__.get_type_id()
    datatype, tmap = get_types_for_typeid(dp, type_id, duration(seconds=1))
    assert datatype
    assert datatype.__idl__.get_type_id() == XStruct.__idl__.get_type_id()

    tp = Topic(dp, 'DynTest', datatype)
    dr = DataReader(dp, tp)

    wr.write(XStruct(A=XUnion(A=XEnum.V1), k=1))

    assert dr.read()[0].k == 1
Example #11
0
def test_reader_initialize():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    sub = Subscriber(dp)
    dr = DataReader(sub, tp)

    assert isgoodentity(dr)
Example #12
0
def test_get_children():
    dp = DomainParticipant(0)

    assert len(dp.children) == len(dp.get_children()) == 0

    tp = Topic(dp, "Message", Message)

    assert isgoodentity(tp)
    assert len(dp.children) == len(dp.get_children()) == 1
    assert dp.children[0] == dp.get_children()[0] == tp
    assert len(tp.children) == len(tp.get_children()) == 0

    sub = Subscriber(dp)

    assert isgoodentity(sub)
    assert len(dp.children) == len(dp.get_children()) == 2
    assert set(dp.children) == set([sub, tp])
    assert len(sub.children) == len(sub.get_children()) == 0

    pub = Publisher(dp)

    assert isgoodentity(pub)
    assert len(dp.children) == len(dp.get_children()) == 3
    assert set(dp.children) == set([pub, sub, tp])
    assert len(pub.children) == len(pub.get_children()) == 0

    dr = DataReader(sub, tp)

    assert isgoodentity(dr)
    assert set(dp.children) == set([pub, sub, tp])
    assert len(sub.children) == 1
    assert sub.children[0] == dr

    dw = DataWriter(pub, tp)

    assert isgoodentity(dw)
    assert set(dp.children) == set([pub, sub, tp])
    assert len(pub.children) == 1
    assert pub.children[0] == dw

    del dw
    del dr
    del pub
    del sub
    del tp

    assert len(dp.children) == len(dp.get_children()) == 0
def test_data_representation_writer_error_invalid_v0():
    qos = Qos(Policy.DataRepresentation(use_cdrv0_representation=True))

    dp = DomainParticipant(0)
    tp = Topic(dp, "XMessage", XMessage)

    with pytest.raises(DDSException):
        DataWriter(dp, tp, qos=qos)
Example #14
0
def test_writer_writedispose():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageKeyed", MessageKeyed)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    msg = MessageKeyed(user_id=1, message="Hello")

    dw.write_dispose(msg)
Example #15
0
def test_reader_resizebuffer():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    dr = DataReader(sub, tp)

    assert len(dr.read(N=100)) == 0
    assert len(dr.read(N=200)) == 0
    assert len(dr.read(N=100)) == 0
Example #16
0
def test_find_topic():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)

    assert isgoodentity(tp)
    
    xtp = dp.find_topic("Message")

    assert xtp.typename == tp.typename
    assert xtp.name == tp.name
Example #17
0
def test_writeto_writer():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    msg = Message(message="TestMessage")

    dw.write(msg)
    assert dw.wait_for_acks(duration(seconds=1))
Example #18
0
def check_enforced_non_communication(log: Stream, ctx: FullContext,
                                     typename: str) -> bool:
    datatype_regular = ctx.get_datatype(typename)
    if datatype_regular.__idl__.keyless:
        return True

    narrow_ctx = ctx.narrow_context_of(typename)
    new_scope = deepcopy(narrow_ctx.scope)
    non_valid_mutation(new_scope, typename)
    mutated_ctx = FullContext(new_scope)
    mutated_datatype = mutated_ctx.get_datatype(typename)

    normal_without_header_idl = "\n".join(narrow_ctx.idl_file.splitlines()[1:])
    mutated_without_header_idl = "\n".join(
        mutated_ctx.idl_file.splitlines()[1:])

    if normal_without_header_idl == mutated_without_header_idl:
        # No mutation took place (only unions) just assume it is good
        return True

    dp = DomainParticipant()

    try:
        tp = Topic(dp, typename, mutated_datatype)
    except DDSException:
        # Sometimes the type gets so mangled (like empty structs/unions)
        # that it is not a valid topic type anymore. We'll consider this a
        # successful test.
        return True

    dw = DataWriter(
        dp,
        tp,
        qos=Qos(Policy.DataRepresentation(use_xcdrv2_representation=True),
                Policy.Reliability.Reliable(duration(seconds=2)),
                Policy.DestinationOrder.BySourceTimestamp))
    dw.set_status_mask(DDSStatus.PublicationMatched)
    dw.take_status()

    ctx.c_app.run(typename, 1)

    now = time.time()
    while (dw.take_status() & DDSStatus.PublicationMatched) == 0:
        if time.time() - now > 0.5:
            ctx.c_app.process.kill()
            return True
        time.sleep(0.001)

    ctx.c_app.process.kill()

    log << f"C-app agreed to communicate with non-valid mutation" << log.endl << log.indent
    log << log.dedent << "[Mutated IDL]:" << log.indent << log.endl
    log << mutated_ctx.idl_file << log.endl
    log << log.dedent
    return False
Example #19
0
    def __init__(self, domain_id=0):
        self.qos = Qos(Policy.Reliability.Reliable(duration(seconds=2)), Policy.History.KeepLast(10))

        self.dp = DomainParticipant(domain_id)
        self.tp = Topic(self.dp, 'Message', Message)
        self.pub = Publisher(self.dp)
        self.sub = Subscriber(self.dp)
        self.dw = DataWriter(self.pub, self.tp, qos=self.qos)
        self.dr = DataReader(self.sub, self.tp, qos=self.qos)
        self.msg = Message(message="hi")
        self.msg2 = Message(message="hi2")
Example #20
0
def test_reader_invalid():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    dr = DataReader(sub, tp)

    with pytest.raises(TypeError):
        dr.read(-1)

    with pytest.raises(TypeError):
        dr.take(-1)
def test_data_representation_writer_v2_v0_unmatch():
    qosv0 = Qos(Policy.DataRepresentation(use_cdrv0_representation=True))
    qosv2 = Qos(Policy.DataRepresentation(use_xcdrv2_representation=True))

    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    dr = DataReader(dp, tp, qos=qosv2)
    dw = DataWriter(dp, tp, qos=qosv0)

    msg = Message("Hello")
    dw.write(msg)
    assert dr.read_next() == None
Example #22
0
def test_writer_instance_handle():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageKeyed", MessageKeyed)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    msg = MessageKeyed(user_id=1, message="Hello")

    handle = dw.register_instance(msg)
    assert handle > 0
    dw.write(msg)
    dw.unregister_instance_handle(handle)
Example #23
0
def test_subscription_reported():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageTopic", Message)
    dr = DataReader(dp, tp)
    time.sleep(1)

    data = run_ddsls(["-t", "dcpssubscription"])

    assert str(dr.guid) in data["stdout"]
    assert str(dp.guid) in data["stdout"]
    assert tp.name in data["stdout"]
    assert tp.typename in data["stdout"]
    assert str(dr.get_qos()) in data["stdout"]
Example #24
0
def test_dynamic_subscribe(common_setup):
    type_id = common_setup.tp.data_type.__idl__.get_type_id()

    dp = DomainParticipant(common_setup.dp.domain_id)
    datatype, _ = get_types_for_typeid(dp, type_id, duration(seconds=1))
    assert datatype

    tp = Topic(dp, common_setup.tp.name, datatype)
    dr = DataReader(dp, tp)

    common_setup.dw.write(common_setup.msg)

    assert dr.read()[0].message == common_setup.msg.message
def test_keyed_type_alignment():
    dp = DomainParticipant()
    tp = Topic(dp, "Test", KeyedArrayType)
    dw = DataWriter(dp, tp)
    dr = DataReader(dp, tp)

    samp1 = KeyedArrayType(['u' * 17, 's' * 13, 'b' * 23],
                           ['u' * 3, 's' * 5, 'b' * 7], [-1] * 3, [-1] * 3,
                           [-1] * 3, [-1] * 3)

    dw.write(samp1)
    samp2 = dr.read()[0]
    assert KeyedArrayType.cdr.key(samp1) == KeyedArrayType.cdr.key(samp2)
def test_data_representation_writer_v2_match():
    qos = Qos(Policy.DataRepresentation(use_xcdrv2_representation=True))

    dp = DomainParticipant(0)
    tp = Topic(dp, "XMessage", XMessage)
    dr = DataReader(dp, tp, qos=qos)
    dw = DataWriter(dp, tp, qos=qos)

    assert dw._use_version_2 == True

    msg = XMessage("Hello")
    dw.write(msg)
    assert dr.read_next() == msg
Example #27
0
def test_publication_reported():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageTopic", Message)
    dw = DataWriter(dp, tp)
    time.sleep(1)

    data = run_ddsls(["-t", "dcpspublication"])

    assert str(dw.guid) in data["stdout"]
    assert str(dp.guid) in data["stdout"]
    assert tp.name in data["stdout"]
    assert tp.typename in data["stdout"]
    assert str(dw.get_qos()) in data["stdout"]
Example #28
0
def test_writer_lookup():
    dp = DomainParticipant(0)
    tp = Topic(dp, "MessageKeyed", MessageKeyed)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    keymsg1 = MessageKeyed(user_id=1000, message="Hello!")
    keymsg2 = MessageKeyed(user_id=2000, message="Hello!")
    assert None == dw.lookup_instance(keymsg1)
    assert None == dw.lookup_instance(keymsg2)
    handle1 = dw.register_instance(keymsg1)
    handle2 = dw.register_instance(keymsg2)
    assert handle1 > 0 and handle2 > 0 and handle1 != handle2
    assert handle1 == dw.lookup_instance(keymsg1)
    assert handle2 == dw.lookup_instance(keymsg2)
Example #29
0
def test_get_pubsub():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    sub = Subscriber(dp)
    pub = Publisher(dp)
    dr = DataReader(sub, tp)
    dw = DataWriter(pub, tp)

    assert dr.subscriber == dr.get_subscriber() == sub
    assert dw.publisher == dw.get_publisher() == pub

    with pytest.raises(DDSException) as exc:
        dp.get_subscriber()

    assert exc.value.code == DDSException.DDS_RETCODE_ILLEGAL_OPERATION
Example #30
0
def test_reader_readnext_takenext():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    pub = Publisher(dp)
    dr = DataReader(sub, tp)
    dw = DataWriter(pub, tp)

    msg = Message("Hello")
    dw.write(msg)

    assert dr.read_next() == msg
    assert dr.read_next() is None
    dw.write(msg)
    assert dr.take_next() == msg
    assert dr.take_next() is None