Skip to content

Commit

Permalink
tests: fix unit tests on gcc15
Browse files Browse the repository at this point in the history
Issue-ID: APRICOT-631667
Signed-off-by: Alexander Mohr <[email protected]>
  • Loading branch information
alexmohr committed Oct 20, 2024
1 parent 4e7ecb4 commit 96966fb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
43 changes: 31 additions & 12 deletions tests/gtest_dlt_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const int _trace_load_send_size = 100;

static void init_daemon(DltDaemon* daemon, char* ecu) {
DltGateway gateway;
strcpy(ecu, "ECU1");
strncpy(ecu, "ECU1", DLT_ID_SIZE);

EXPECT_EQ(0,
dlt_daemon_init(daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE,
Expand All @@ -64,33 +64,33 @@ static void setup_trace_load_settings(DltDaemon& daemon)
memset(daemon.preconfigured_trace_load_settings, 0, daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings));

// APP0 only has app id
strcpy(daemon.preconfigured_trace_load_settings[0].apid, "APP0");
strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP0", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[0].soft_limit = 1000;
daemon.preconfigured_trace_load_settings[0].hard_limit = 2987;

// APP1 has only three contexts, no app id
strcpy(daemon.preconfigured_trace_load_settings[1].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[1].ctid, "CT01");
strncpy(daemon.preconfigured_trace_load_settings[1].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[1].ctid, "CT01", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[1].soft_limit = 100;
daemon.preconfigured_trace_load_settings[1].hard_limit = 200;

strcpy(daemon.preconfigured_trace_load_settings[2].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[2].ctid, "CT02");
strncpy(daemon.preconfigured_trace_load_settings[2].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[2].ctid, "CT02", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[2].soft_limit = 300;
daemon.preconfigured_trace_load_settings[2].hard_limit = 400;

strcpy(daemon.preconfigured_trace_load_settings[3].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[3].ctid, "CT03");
strncpy(daemon.preconfigured_trace_load_settings[3].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[3].ctid, "CT03", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[3].soft_limit = 500;
daemon.preconfigured_trace_load_settings[3].hard_limit = 600;

// APP2 has app id and context
strcpy(daemon.preconfigured_trace_load_settings[4].apid, "APP2");
strcpy(daemon.preconfigured_trace_load_settings[4].ctid, "CT01");
strncpy(daemon.preconfigured_trace_load_settings[4].apid, "APP2", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[4].ctid, "CT01", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[4].soft_limit = 700;
daemon.preconfigured_trace_load_settings[4].hard_limit = 800;

strcpy(daemon.preconfigured_trace_load_settings[5].apid, "APP2");
strncpy(daemon.preconfigured_trace_load_settings[5].apid, "APP2", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[5].soft_limit = 900;
daemon.preconfigured_trace_load_settings[5].hard_limit = 1000;

Expand Down Expand Up @@ -385,6 +385,10 @@ TEST(t_trace_load_keep_message, normal) {
int fd = 15;
const char *desc = "HELLO_TEST";

for (auto& app_id : app_ids) {
dlt_register_app(app_id, app_id);
}

const auto set_extended_header = [&daemon_local]() {
daemon_local.msg.extendedheader = (DltExtendedHeader *)(daemon_local.msg.headerbuffer + sizeof(DltStorageHeader) +
sizeof(DltStandardHeader));
Expand All @@ -402,6 +406,7 @@ TEST(t_trace_load_keep_message, normal) {
const auto check_debug_and_trace_can_log = [&](DltDaemonApplication* app) {
// messages for debug and verbose logs are never dropped
set_extended_header_log_level(DLT_LOG_VERBOSE);

EXPECT_TRUE(trace_load_keep_message(app,
app->trace_load_settings->hard_limit * 10,
&daemon, &daemon_local, 0));
Expand All @@ -427,14 +432,16 @@ TEST(t_trace_load_keep_message, normal) {
apps[0], apps[0]->trace_load_settings->soft_limit, &daemon, &daemon_local, 0));

set_extended_header();
check_debug_and_trace_can_log(apps[0]);
memcpy(daemon_local.msg.extendedheader->apid, apps[0], DLT_ID_SIZE);

// messages for apps that have not been registered should be dropped
DltDaemonApplication app = {};
EXPECT_FALSE(trace_load_keep_message(&app, 42, &daemon, &daemon_local, 0));

// Test if hard limit is reached for applications that only configure an application id
// Meaning that the limit is shared between all contexts
dlt_daemon_context_add(&daemon, apps[0]->apid, "CT01", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);
dlt_daemon_context_add(&daemon, apps[0]->apid, "CT02", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);
memcpy(daemon_local.msg.extendedheader->ctid, "CT01", DLT_ID_SIZE);
log_until_hard_limit_reached(apps[0]);
EXPECT_FALSE(trace_load_keep_message(apps[0], _trace_load_send_size, &daemon, &daemon_local, 0));
Expand All @@ -445,6 +452,11 @@ TEST(t_trace_load_keep_message, normal) {

// APP1 has only three contexts, no app id
memcpy(daemon_local.msg.extendedheader->ctid, "CT01", DLT_ID_SIZE);
memcpy(daemon_local.msg.extendedheader->apid, apps[1], DLT_ID_SIZE);

dlt_daemon_context_add(&daemon, apps[1]->apid, "CT02", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);
dlt_daemon_context_add(&daemon, apps[1]->apid, "CT02", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);

log_until_hard_limit_reached(apps[1]);
EXPECT_FALSE(trace_load_keep_message(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0));
// CT01 has reached its limit, make sure CT02 still can log
Expand All @@ -457,6 +469,10 @@ TEST(t_trace_load_keep_message, normal) {
// APP2 has context and app id configured
// Exhaust app limit first
memcpy(daemon_local.msg.extendedheader->ctid, "CTXX", DLT_ID_SIZE);
memcpy(daemon_local.msg.extendedheader->apid, apps[2], DLT_ID_SIZE);
dlt_daemon_context_add(&daemon, apps[2]->apid, "CTXX", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);
dlt_daemon_context_add(&daemon, apps[2]->apid, "CT01", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);

log_until_hard_limit_reached(apps[2]);
EXPECT_FALSE(trace_load_keep_message(apps[2], _trace_load_send_size, &daemon, &daemon_local, 0));
// Context logging should still be possible
Expand All @@ -465,6 +481,9 @@ TEST(t_trace_load_keep_message, normal) {

// Test not configured context
memcpy(daemon_local.msg.extendedheader->ctid, "CTXX", DLT_ID_SIZE);
memcpy(daemon_local.msg.extendedheader->apid, apps[1], DLT_ID_SIZE);
dlt_daemon_context_add(&daemon, apps[1]->apid, "CTXX", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0);

EXPECT_EQ(
trace_load_keep_message(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0),
DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT != 0);
Expand Down
28 changes: 14 additions & 14 deletions tests/gtest_dlt_daemon_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, app_id_not_found)
memset(daemon.preconfigured_trace_load_settings, 0,
sizeof(DltTraceLoadSettings));

strcpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2");
strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings_count = 1;

EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings(
Expand All @@ -1798,35 +1798,35 @@ static void setup_trace_load_settings(DltDaemon &daemon)
memset(daemon.preconfigured_trace_load_settings, 0,
daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings));

strcpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2");
strcpy(daemon.preconfigured_trace_load_settings[0].ctid, "CTID");
strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[0].ctid, "CTID", DLT_ID_SIZE);

strcpy(daemon.preconfigured_trace_load_settings[1].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[1].ctid, "CTID");
strncpy(daemon.preconfigured_trace_load_settings[1].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[1].ctid, "CTID", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[1].soft_limit = 21;
daemon.preconfigured_trace_load_settings[1].hard_limit = 42;

strcpy(daemon.preconfigured_trace_load_settings[2].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[2].ctid, "CT02");
strncpy(daemon.preconfigured_trace_load_settings[2].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[2].ctid, "CT02", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[2].soft_limit = 11;
daemon.preconfigured_trace_load_settings[2].hard_limit = 22;

strcpy(daemon.preconfigured_trace_load_settings[3].apid, "APP1");
strncpy(daemon.preconfigured_trace_load_settings[3].apid, "APP1", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[3].soft_limit = 44;
daemon.preconfigured_trace_load_settings[3].hard_limit = 55;

strcpy(daemon.preconfigured_trace_load_settings[4].apid, "APP3");
strcpy(daemon.preconfigured_trace_load_settings[4].ctid, "CT03");
strncpy(daemon.preconfigured_trace_load_settings[4].apid, "APP3", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[4].ctid, "CT03", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[4].soft_limit = 111;
daemon.preconfigured_trace_load_settings[4].hard_limit = 222;

strcpy(daemon.preconfigured_trace_load_settings[5].apid, "APP3");
strcpy(daemon.preconfigured_trace_load_settings[5].ctid, "CT01");
strncpy(daemon.preconfigured_trace_load_settings[5].apid, "APP3", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[5].ctid, "CT01", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[5].soft_limit = 333;
daemon.preconfigured_trace_load_settings[5].hard_limit = 444;

strcpy(daemon.preconfigured_trace_load_settings[6].apid, "APP1");
strcpy(daemon.preconfigured_trace_load_settings[6].ctid, "CT03");
strncpy(daemon.preconfigured_trace_load_settings[6].apid, "APP1", DLT_ID_SIZE);
strncpy(daemon.preconfigured_trace_load_settings[6].ctid, "CT03", DLT_ID_SIZE);
daemon.preconfigured_trace_load_settings[6].soft_limit = 555;
daemon.preconfigured_trace_load_settings[6].hard_limit = 666;

Expand Down

0 comments on commit 96966fb

Please sign in to comment.