Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making logs smaller by getting it only for the time of test execution #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions log/logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2025 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

import logging
import os
import re
import sys
from contextlib import contextmanager
from datetime import datetime
Expand Down Expand Up @@ -45,6 +47,7 @@ class Log(HtmlLogManager, metaclass=Singleton):
logger = None
LOG_FORMAT = '%(asctime)s %(levelname)s:\t%(message)s'
DATE_FORMAT = "%Y/%m/%d %H:%M:%S"
unique_test_identifier = "TEST_IDENTIFIER_TEMPLATE"
command_id = 0
lock = Lock()

Expand Down Expand Up @@ -189,15 +192,23 @@ def step_info(self, step_name):
def get_additional_logs(self):
from core.test_run import TestRun
from test_tools.fs_tools import check_if_file_exists

messages_log = "/var/log/messages"
if not check_if_file_exists(messages_log):
messages_log = "/var/log/syslog"
log_files = {"messages.log": messages_log,

log_files = {"messages.log": "/tmp/messages",
"dmesg.log": "/tmp/dmesg"}
extra_logs = TestRun.config.get("extra_logs", {})
log_files.update(extra_logs)

TestRun.executor.run(f"dmesg > {log_files['dmesg.log']}")
# Escape special characters from test identifier to be properly processed by awk
test_identifier = re.escape(TestRun.LOGGER.unique_test_identifier)

TestRun.executor.run(
f"dmesg | awk '/{test_identifier}/,0' > {log_files['dmesg.log']}")
TestRun.executor.run(
f"awk '/{test_identifier}/,0' {messages_log} > {log_files['messages.log']}")
Comment on lines +206 to +211
Copy link
Contributor

@Deixx Deixx Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the identifier is set to the template and no one calls print_test_identifier_to_logs() then there is no identifier in logs and awk returns empty string.
I'd suggest default empty value - then if identifier is not set awk will gather everything and collect from the identifier otherwise


dut_identifier = TestRun.dut.ip if TestRun.dut.ip else TestRun.dut.config["host"]
for log_name, log_source_path in log_files.items():
Expand Down Expand Up @@ -228,3 +239,11 @@ def generate_summary(self, item, meta):
}
}
json.dump(data, summary)

def print_test_identifier_to_logs(self):
from core.test_run import TestRun
# Add test identifier to dmesg
TestRun.executor.run(f"echo {self.unique_test_identifier} > /dev/kmsg")

# Add test identifier to messages log
TestRun.executor.run(f"logger {self.unique_test_identifier}")