Skip to content
Merged
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
15 changes: 14 additions & 1 deletion tests/common2/test_performancemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
* - Constructor_NewInstance_LogsCreated → B4
*
* 隔离:QDateTime::currentDateTime 全部 stub 为固定队列时间(确定性时间差),
* qInfo/qDebug 经 qInstallMessageHandler 捕获后断言(TearDown 恢复默认 handler)。
* qInfo/qDebug 经 qInstallMessageHandler 捕获后断言(TearDown 恢复默认 handler);
* 夹具内用 setFilterRules 显式放开 appLog 的 debug/info,避免运行脚本的
* QT_LOGGING_RULES 全局关日志导致断言失败(TearDown 恢复环境原规则)。
*/

#include <gtest/gtest.h>

Check warning on line 25 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "stubext.h"

#include "performancemonitor.h"

#include <QCoreApplication>

Check warning on line 30 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDateTime>

Check warning on line 31 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDateTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 32 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 33 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStringList>

Check warning on line 34 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStringList> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QVector>

Check warning on line 35 in tests/common2/test_performancemonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVector> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace {

Expand Down Expand Up @@ -64,6 +67,13 @@
void SetUp() override
{
ensureApp();
// 运行脚本会导出 QT_LOGGING_RULES="*.debug=false;*.info=false" 压日志量,
// 该规则会让 qCDebug/qCInfo(appLog) 整体短路:消息到不了捕获 handler,
// 流表达式里的 currentDateTime() 副作用也随之消失(timeCalls 少计)。
// setFilterRules 优先级高于环境变量,夹具内显式放开 appLog,保证用例
// 不随运行环境的日志配置漂移;TearDown 恢复原规则。
QLoggingCategory::setFilterRules(QStringLiteral(
"org.deepin.editor.debug=true\norg.deepin.editor.info=true"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Unrelated logs reach the platform cap

When an unrelated category emits debug or info messages while a PerformanceMonitor test runs, setFilterRules replaces the runner’s rules and drops its *.debug=false and *.info=false filters, so other categories use Qt’s enabled defaults and their messages reach the test log, potentially hitting the platform cap.

Preserve the runner’s filters when adding the org.deepin.editor overrides.

Prompt for AI agents
In `tests/common2/test_performancemonitor.cpp` at line 76:

**Unrelated logs reach the platform cap**

When an unrelated category emits debug or info messages while a PerformanceMonitor test runs, `setFilterRules` replaces the runner’s rules and drops its `*.debug=false` and `*.info=false` filters, so other categories use Qt’s enabled defaults and their messages reach the test log, potentially hitting the platform cap.

Preserve the runner’s filters when adding the `org.deepin.editor` overrides.

stub.clear();
logs.clear();
timeQueue.clear();
Expand All @@ -80,6 +90,9 @@

void TearDown() override
{
// 先恢复运行环境自带的日志规则(无则清空回到进程默认),再恢复默认
// handler,避免中间窗口 debug/info 直接打到 stderr
QLoggingCategory::setFilterRules(QString::fromLatin1(qgetenv("QT_LOGGING_RULES")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Runner log filters are not restored

When the runner provides multiple logging rules separated by semicolons, QLoggingCategory::setFilterRules receives the runner’s semicolon-separated QT_LOGGING_RULES value as-is; the rules are not restored as separate filters, so later tests run without the debug/info suppression and emit excess logs.

Convert semicolons to newlines before passing the saved environment value to setFilterRules.

Prompt for AI agents
In `tests/common2/test_performancemonitor.cpp` at line 95:

**Runner log filters are not restored**

When the runner provides multiple logging rules separated by semicolons, `QLoggingCategory::setFilterRules` receives the runner’s semicolon-separated `QT_LOGGING_RULES` value as-is; the rules are not restored as separate filters, so later tests run without the debug/info suppression and emit excess logs.

Convert semicolons to newlines before passing the saved environment value to `setFilterRules`.

qInstallMessageHandler(nullptr); // 恢复默认 handler
g_capturedLogs = nullptr;
stub.clear();
Expand Down
Loading