Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/tests/logmanagertest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

Expand All @@ -21,7 +21,9 @@ TEST_F(LogManagerTest, setSystemlog)
// EXPECT_EQ(DBMLogManager::setSystemLog(),true);

DBMLogManager::setSystemLog(true);

// 恢复状态,避免影响后续 registerFileAppender 测试
// systemLog=true 时日志路径切换到 /var/log/deepin/,普通用户无写权限
DBMLogManager::setSystemLog(false);
}

TEST_F(LogManagerTest, registerConsoleAppender)
Expand Down
30 changes: 29 additions & 1 deletion src/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

#include <QCoreApplication>

Check warning on line 5 in src/tests/main.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.

Check warning on line 5 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 6 in src/tests/main.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.

Check warning on line 6 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 7 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 7 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <csignal> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#ifdef QT_DEBUG
#include <sanitizer/asan_interface.h>

Check warning on line 9 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in src/tests/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <sanitizer/asan_interface.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

// 覆盖率数据刷新:确保程序退出(含异常退出)时 .gcda 文件被正确写入
extern "C" void __gcov_dump();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Guard __gcov_dump usage so the test binary still links when coverage is not enabled

Unconditional declaration/calls to __gcov_dump() will fail to link when tests are built without gcov instrumentation (e.g. non-coverage CI or local debug builds). Please wrap the declaration and all uses in a feature macro (e.g. #ifdef USE_GCOV_DUMP, #ifdef __GNUC__, or a project-specific #ifdef ENABLE_COVERAGE) and enable it only in coverage builds so tests remain runnable in all configurations.


static void flushCoverage()
{
__gcov_dump();
}

// 信号处理:捕获段错误等致命信号,先刷新覆盖率数据再退出
static void crashHandler(int sig)
{
__gcov_dump();
_exit(128 + sig);
}

int main(int argc, char *argv[])
{
// 注册信号处理器,确保崩溃时覆盖率数据不丢失
signal(SIGSEGV, crashHandler);
signal(SIGABRT, crashHandler);
signal(SIGBUS, crashHandler);

// 注册 atexit 回调,在程序正常退出时刷新覆盖率数据
atexit(flushCoverage);

QCoreApplication a(argc, argv);
a.setOrganizationName("deepin");
a.setApplicationName("deepin-boot-maker");

::testing::InitGoogleTest(&argc,argv);
int ret = RUN_ALL_TESTS();

// 主动刷新覆盖率数据
__gcov_dump();

#ifdef QT_DEBUG
__sanitizer_set_report_path("asan_loader.log");
#endif
Expand Down
37 changes: 21 additions & 16 deletions src/tests/test-recoverage.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
#!/bin/bash

# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-only

BUILD_DIR=build
REPORT_DIR=report

cd ../../
# 自动检测 qmake6 / qmake
if command -v qmake6 &>/dev/null; then
QMAKE=qmake6
else
QMAKE=qmake
fi

rm -rf $BUILD_DIR
mkdir $BUILD_DIR

cd $BUILD_DIR
echo "Using qmake: $QMAKE ($($QMAKE --version 2>&1 | tail -1))"

qmake ../
make
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

cd ../src/tests/
rm -rf $BUILD_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR

qmake CONFIG+=debug ../

TESTARGS="--gtest_output=xml:deepin_test_report_boot_maker.xml" make check -j$(nproc)
# 覆盖率构建不用 CONFIG+=debug,避免 ASAN 导致退出时崩溃、.gcda 文件丢失
$QMAKE CONFIG+=release ../tests.pro

mv asan_loader.log* asan_dde-boot-maker.log
TESTARGS="--gtest_output=xml:deepin_test_report_boot_maker.xml" make check -j$(nproc)

[ -e asan_loader.log* ] && mv asan_loader.log* asan_dde-boot-maker.log || touch asan_dde-boot-maker.log
# ASAN 日志处理
if ls asan_loader.log* 1>/dev/null 2>&1; then
mv asan_loader.log* asan_dde-boot-maker.log
else
touch asan_dde-boot-maker.log
fi

# 生成覆盖率报告
lcov -d ./ -c -o coverage_all.info

lcov --remove coverage_all.info "*/tests/*" "*/usr/include*" --output-file coverage.info
cd ..
genhtml -o $REPORT_DIR $BUILD_DIR/coverage.info
#rm -rf $BUILD_DIR

exit 0
exit 0
4 changes: 2 additions & 2 deletions src/tests/unittestobj.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

Expand All @@ -16,9 +16,9 @@
m_pBMinterFace = &BMInterface::ref();
}

void UnitTestObj::TearDownTestCase()

Check warning on line 19 in src/tests/unittestobj.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'TearDownTestCase' is never used.

Check warning on line 19 in src/tests/unittestobj.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'TearDownTestCase' is never used.
{
delete m_pBMinterFace;
// BMInterface::ref() 返回单例引用,不能 delete,由 DSingleton 自动管理生命周期
m_pBMinterFace = nullptr;
}

Expand Down
Loading