Beispiel #1
0
def test_quick_start():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    # Create DLT message
    msg1 = DltMessage.create_verbose_message(
        [ArgumentString("hello, pydlt!")],
        MessageType.DLT_TYPE_LOG,
        MessageLogInfo.DLT_LOG_INFO,
        "App",
        "Ctx",
        message_counter=0,
        str_header=StorageHeader(0, 0, "Ecu"),
    )
    msg2 = DltMessage.create_non_verbose_message(
        0,
        b"\x01\x02\x03",
        message_counter=1,
        str_header=StorageHeader(0, 0, "Ecu"),
    )
    # Write DLT messages to file
    with DltFileWriter(path) as writer:
        writer.write_messages([msg1, msg2])

    print()

    # Read each DLT message from file
    for msg in DltFileReader(path):
        # Print overview of each DLT message
        print(msg)
Beispiel #2
0
def test_message_verbose_payload_sint():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _make_verbose_payload_message([
        ArgumentSInt8(-111),
        ArgumentSInt16(-11111),
        ArgumentSInt32(-1111111111),
        ArgumentSInt64(-1111111111111111111),
    ])
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert cast(ArgumentSInt8,
                dlt_message2.verbose_payload.arguments[0]).data == -111
    assert (cast(ArgumentSInt16,
                 dlt_message2.verbose_payload.arguments[1]).data == -11111)
    assert (cast(
        ArgumentSInt32,
        dlt_message2.verbose_payload.arguments[2]).data == -1111111111)
    assert (cast(
        ArgumentSInt64,
        dlt_message2.verbose_payload.arguments[3]).data == -1111111111111111111
            )
Beispiel #3
0
def _dlt_std_header_msbf_non_verbose_make_messsage(msbf: bool) -> DltMessage:
    return DltMessage.create_non_verbose_message(
        0xDEADBEAF,  # 3735928495
        b"\x01\x02\x03",
        msb_first=msbf,
        str_header=StorageHeader(0, 0, "ECU"),
    )
Beispiel #4
0
def test_message_std_header_no_option():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = DltMessage.create_non_verbose_message(
        0,
        b"\x00",
        str_header=StorageHeader(0, 0, "ECU"),
    )
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert dlt_message2.std_header.timestamp is None
    assert dlt_message2.std_header.session_id is None
    assert dlt_message2.std_header.ecu_id is None
    assert dlt_message2.std_header.message_counter == 0
Beispiel #5
0
def test_message_std_header_msbf_verbose_true():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _dlt_std_header_msbf_verbose_make_messsage(True)
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    _dlt_std_header_msbf_verbose_validation(dlt_message2)
Beispiel #6
0
def _make_verbose_payload_message(args: List[Argument],
                                  msbf: bool = False) -> DltMessage:
    return DltMessage.create_verbose_message(
        args,
        MessageType.DLT_TYPE_LOG,
        MessageLogInfo.DLT_LOG_INFO,
        "App",
        "Ctx",
        msb_first=msbf,
        str_header=StorageHeader(0, 0, "ECU"),
    )
Beispiel #7
0
def test_message_ext_header_max():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = DltMessage.create_verbose_message(
        [],
        MessageType.DLT_TYPE_NW_TRACE,
        MessageBusInfo.DLT_NW_TRACE_MOST,
        "AppX",
        "CtxX",
        str_header=StorageHeader(0, 0, "ECU"),
    )
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert dlt_message2.ext_header.message_type == MessageType.DLT_TYPE_NW_TRACE
    assert dlt_message2.ext_header.message_log_info == MessageBusInfo.DLT_NW_TRACE_MOST
    assert dlt_message2.ext_header.application_id == "AppX"
    assert dlt_message2.ext_header.context_id == "CtxX"
Beispiel #8
0
def test_message_ext_header_min():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = DltMessage.create_verbose_message(
        [],
        MessageType.DLT_TYPE_LOG,
        MessageLogInfo.DLT_LOG_FATAL,
        "",
        "",
        str_header=StorageHeader(0, 0, "ECU"),
    )
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert dlt_message2.ext_header.message_type == MessageType.DLT_TYPE_LOG
    assert dlt_message2.ext_header.message_log_info == MessageLogInfo.DLT_LOG_FATAL
    assert dlt_message2.ext_header.application_id == ""
    assert dlt_message2.ext_header.context_id == ""
Beispiel #9
0
def test_message_std_header():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = DltMessage.create_non_verbose_message(
        0,
        b"\x00",
        timestamp=11111,  # 1.1111 sec
        session_id=12345,
        ecu_id="Ecu",
        message_counter=111,
        str_header=StorageHeader(0, 0, "ECU"),
    )
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert dlt_message2.std_header.timestamp == 11111
    assert dlt_message2.std_header.session_id == 12345
    assert dlt_message2.std_header.ecu_id == "Ecu"
    assert dlt_message2.std_header.message_counter == 111
Beispiel #10
0
def test_message_verbose_payload_raw():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _make_verbose_payload_message(
        [ArgumentRaw(b"\x01\x02\x03")])
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert (cast(
        ArgumentRaw,
        dlt_message2.verbose_payload.arguments[0]).data == b"\x01\x02\x03")
Beispiel #11
0
def test_message_verbose_payload_bool():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _make_verbose_payload_message(
        [ArgumentBool(False), ArgumentBool(True)])
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert cast(ArgumentBool,
                dlt_message2.verbose_payload.arguments[0]).data is False
    assert cast(ArgumentBool,
                dlt_message2.verbose_payload.arguments[1]).data is True
Beispiel #12
0
def test_message_verbose_payload_string():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _make_verbose_payload_message(
        [ArgumentString("abc123XYZ!", False),
         ArgumentString("あいうえお", True)])
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert (cast(
        ArgumentString,
        dlt_message2.verbose_payload.arguments[0]).data == "abc123XYZ!")
    assert (cast(ArgumentString,
                 dlt_message2.verbose_payload.arguments[1]).data == "あいうえお")
Beispiel #13
0
def test_message_verbose_payload_float():
    path = TEST_RESULTS_DIR_PATH / Path(
        f"{sys._getframe().f_code.co_name}.dlt")

    dlt_message1 = _make_verbose_payload_message(
        [ArgumentFloat32(1.11), ArgumentFloat64(1.11)])
    dlt_bytes = dlt_message1.to_bytes()
    path.write_bytes(dlt_bytes)

    dlt_message2 = DltMessage.create_from_bytes(dlt_bytes, True)
    assert (cast(
        ArgumentFloat32,
        dlt_message2.verbose_payload.arguments[0]).data == struct.unpack(
            ">f", struct.pack(">f", 1.11))[0])
    assert (cast(
        ArgumentFloat64,
        dlt_message2.verbose_payload.arguments[1]).data == struct.unpack(
            ">d", struct.pack(">d", 1.11))[0])
Beispiel #14
0
def _make_dlt_message():
    std_header = DltMessage._create_standard_header(0, None, None, None, None,
                                                    0, 1, False)
    return DltMessage(StorageHeader(0, 0, "ECU"), std_header, None, None)