コード例 #1
0
def test_qos_inheritance():
    qos = Qos(Policy.Durability.Volatile)
    qos2 = Qos(Policy.Deadline(10), base=qos)
    qos3 = Qos(Policy.Durability.Transient, base=qos)
    assert qos2 == Qos(Policy.Durability.Volatile, Policy.Deadline(10)) == Qos(Policy.Deadline(10), Policy.Durability.Volatile)
    assert qos3 == Qos(Policy.Durability.Transient)
    assert qos3 != Qos()
    assert qos3 != Qos(Policy.Durability.Volatile)
コード例 #2
0
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
コード例 #3
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)
コード例 #4
0
def test_qos_raise_wrong_usage():
    with pytest.raises(NotImplementedError):
        Policy()

    with pytest.raises(NotImplementedError):
        Policy.Durability()

    with pytest.raises(TypeError):
        Policy.Durability.Persistent()

    with pytest.raises(TypeError):
        Qos(1)

    with pytest.raises(ValueError):
        Qos(Policy.Durability.Persistent, Policy.Durability.Volatile)

    with pytest.raises(ValueError):
        Qos.fromdict({"Durability": {}})
コード例 #5
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
コード例 #6
0
def test_data_representation_writer_dualreader_match():
    qosv0 = Qos(Policy.DataRepresentation(use_cdrv0_representation=True))
    qosv2 = Qos(Policy.DataRepresentation(use_xcdrv2_representation=True))
    qosv0v2 = Qos(
        Policy.DataRepresentation(use_cdrv0_representation=True,
                                  use_xcdrv2_representation=True))

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

    msg1 = Message("Hello")
    dwv0.write(msg1)
    assert dr.read_next() == msg1

    msg2 = Message("Hi!")
    dwv2.write(msg2)
    assert dr.read_next() == msg2
コード例 #7
0
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
コード例 #8
0
import pytest
import itertools
from cyclonedds.qos import Policy, Qos, _CQos


some_qosses = [
    Qos(Policy.Reliability.BestEffort),
    Qos(Policy.Reliability.Reliable(22)),
    Qos(Policy.Durability.Volatile),
    Qos(Policy.Durability.TransientLocal),
    Qos(Policy.Durability.Transient),
    Qos(Policy.Durability.Persistent),
    Qos(Policy.History.KeepAll),
    Qos(Policy.History.KeepLast(10)),
    Qos(Policy.ResourceLimits(3, 4, 5)),
    Qos(Policy.PresentationAccessScope.Instance(False, True)),
    Qos(Policy.PresentationAccessScope.Topic(True, True)),
    Qos(Policy.PresentationAccessScope.Group(False, False)),
    Qos(Policy.Lifespan(12001)),
    Qos(Policy.Deadline(2129981)),
    Qos(Policy.LatencyBudget(1337)),
    Qos(Policy.Ownership.Shared),
    Qos(Policy.Ownership.Exclusive),
    Qos(Policy.OwnershipStrength(8)),
    Qos(Policy.Liveliness.Automatic(898989)),
    Qos(Policy.Liveliness.ManualByParticipant(898989)),
    Qos(Policy.Liveliness.ManualByTopic(898989)),
    Qos(Policy.TimeBasedFilter(999900999)),
    Qos(Policy.Partition(["a", "b", "8isdfijsdifij3e8"])),
    Qos(Policy.TransportPriority(9)),
    Qos(Policy.DestinationOrder.ByReceptionTimestamp),
コード例 #9
0
def check_py_c_key_equivalence(log: Stream, ctx: FullContext, typename: str,
                               num_samples: int) -> bool:
    datatype = ctx.get_datatype(typename)
    if datatype.__idl__.keyless:
        return True

    samples = [
        generate_random_instance(datatype, seed=i) for i in range(num_samples)
    ]

    # We need to make sure the samples all have unique keys to make sure that we agree
    # on sample ordering with C
    keysamples = {}
    for s in samples:
        keysamples[datatype.__idl__.key(s)] = s
    samples = list(keysamples.values())

    dp = DomainParticipant()
    tp = Topic(dp, typename, datatype)
    dw = DataWriter(
        dp,
        tp,
        qos=Qos(Policy.DataRepresentation(use_xcdrv2_representation=True),
                Policy.History.KeepLast(len(samples)),
                Policy.Reliability.Reliable(duration(seconds=2)),
                Policy.DestinationOrder.BySourceTimestamp))
    dw.set_status_mask(DDSStatus.PublicationMatched)
    dw.take_status()

    ctx.c_app.run(typename, len(samples))

    now = time.time()
    while (dw.take_status() & DDSStatus.PublicationMatched) == 0:
        if time.time() - now > 4:
            # timeout if C app did not start up within 4 seconds
            ctx.c_app.result()
            log << f"C-app did not communicate with Python:" << log.endl << log.indent
            log << ctx.c_app.last_error << log.endl
            log << log.dedent
            return False
        time.sleep(0.001)

    time.sleep(0.5)

    for sample in samples:
        dw.write(sample)
        time.sleep(0.002)

    hashes = ctx.c_app.result()
    success = True

    if not hashes:
        log << f"C-app did not return output, stderr:" << log.endl << log.indent
        log << ctx.c_app.last_error << log.endl
        log << f"stdout:" << log.endl
        log << ctx.c_app.last_out << log.endl
        log << log.dedent << "Example sample sent:" << log.endl << log.indent
        log << samples[0] << log.endl << samples[0].serialize()
        log << log.dedent
        return False

    if len(hashes) != len(samples):
        log << f"C-app did not return as many samples as were sent, stderr:" << log.endl << log.indent
        log << ctx.c_app.last_error << log.endl
        log << f"stdout:" << log.endl
        log << ctx.c_app.last_out << log.endl << log.dedent
        log << log.dedent << "Example sample sent:" << log.endl << log.indent
        log << samples[0] << log.endl << samples[0].serialize()
        success = False

    for i in range(min(len(hashes), len(samples))):
        c_key = hashes[i]
        py_key = datatype.__idl__.key(samples[i], use_version_2=True)

        if not py_key == c_key:
            log << "PY-C Keys do not match!" << log.endl << log.indent
            log << "Instance: " << samples[i] << log.endl
            log << "Serialized Instance:" << log.endl << samples[i].serialize()
            log << "Python key:" << log.endl << py_key
            log << "C key:" << log.endl << c_key
            log << log.dedent
            return False

    return success