src.dualinventive.com/dinet/sec-multi-proxy/libdi/tests/can_log.cpp

60 lines
1.8 KiB
C++

/**
* @file tests/can_rpc.cpp
* @brief brief
* @date Aug 25, 2015
* @author rheijden
* @copyright 2015 Dual Inventive Technology Centre B.V.
*
* descr
*/
#define DI_LOG_ENABLE_FROM_DEBUG
#define DI_LOG_MODULE DI_LOG_MODULE_LIBDI_TEST
#include <di/log.h>
#include <di/can/log.h>
#include <di/time.h>
#include <stdio.h>
#include <gtest/gtest.h>
#include "fixtures/CANTest.hpp"
/**
* Verify DI_LOG_* macros send the correct messages with the di_can_log_writer
*/
void test_can_log_DI_LOG_check_msg(struct di_can_ctx *ctx, const enum di_log_level level)
{
struct di_can_msg *msg = di_can_recv(ctx, DI_CAN_MSGTYPE_LOG);
ASSERT_NE(nullptr, msg);
ASSERT_EQ(DI_CAN_MSGTYPE_LOG, DI_CAN_GET_MSGTYPE(msg->canid));
ASSERT_EQ(level, DI_CAN_GET_DATATYPE(msg->canid));
di_can_msg_free(&msg);
}
TEST_F(DI_CAN, log) {
di_log_init(DI_LOG_LEVEL_DEBUG, di_can_log_writer, &_ctx);
DI_LOG_CRIT("CAN log msg crit");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_CRIT);
DI_LOG_ERROR("CAN log msg error");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_ERROR);
DI_LOG_WARN("CAN log msg warn");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_WARN);
DI_LOG_INFO("CAN log msg info");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_INFO);
DI_LOG_DEBUG("CAN log msg debug");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_DEBUG);
}
/**
* Bug DINET-86
* When the CAN-msg destination id filter is enabled it was possible
* the message gets silently dropped when src_id is unset. So the
* new implementation sets it to ctx->nodeid.
*/
TEST_F(DI_CAN, ISSUE_DINET_86) {
di_log_init(DI_LOG_LEVEL_DEBUG, di_can_log_writer, &_ctx);
di_can_msg_enable_dst_id_filter(&_ctx, true);
DI_LOG_DEBUG("CAN log msg debug");
test_can_log_DI_LOG_check_msg(&_ctx, DI_LOG_LEVEL_DEBUG);
}