diff options
author | Lieven Hey <lieven.hey@kdab.com> | 2021-08-24 16:26:18 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2022-06-08 20:18:05 +0000 |
commit | 17f5814ffe62697096d0482a43cbc35f4953e123 (patch) | |
tree | 7adf62465a7f7b0510eb69a87f3990b54ae0ca1e | |
parent | a1cf7a0fdb9bdf853cb59ae289f377d2e3e92776 (diff) |
add unit test for finding debug symbols
Change-Id: I285127ea9abd41f0aa50333e49ad4174d973f437
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | tests/auto/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/auto.pro | 3 | ||||
-rw-r--r-- | tests/auto/auto.qbs | 2 | ||||
-rw-r--r-- | tests/auto/finddebugsym/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/auto/finddebugsym/finddebugsym.pro | 19 | ||||
-rw-r--r-- | tests/auto/finddebugsym/finddebugsym.qbs | 11 | ||||
-rw-r--r-- | tests/auto/finddebugsym/tst_finddebugsym.cpp | 100 |
7 files changed, 138 insertions, 2 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 8608d7f..01185b8 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(elfmap) add_subdirectory(kallsyms) add_subdirectory(perfdata) add_subdirectory(perfstdin) +add_subdirectory(finddebugsym) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 484c867..c192fb0 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -4,6 +4,7 @@ SUBDIRS = \ elfmap \ kallsyms \ perfdata \ - perfstdin + perfstdin \ + finddebugsym OTHER_FILES += auto.qbs diff --git a/tests/auto/auto.qbs b/tests/auto/auto.qbs index 43e061f..f695d2a 100644 --- a/tests/auto/auto.qbs +++ b/tests/auto/auto.qbs @@ -4,6 +4,6 @@ Project { name: "PerfParserAutotests" condition: project.withAutotests references: [ - "addresscache", "elfmap", "kallsyms", "perfdata", "perfstdin" + "addresscache", "elfmap", "kallsyms", "perfdata", "perfstdin", "finddebugsym" ] } diff --git a/tests/auto/finddebugsym/CMakeLists.txt b/tests/auto/finddebugsym/CMakeLists.txt new file mode 100644 index 0000000..d91a0df --- /dev/null +++ b/tests/auto/finddebugsym/CMakeLists.txt @@ -0,0 +1,4 @@ +add_qtc_test(tst_finddebugsym + DEPENDS Qt5::Core Qt5::Test perfparser_lib + SOURCES tst_finddebugsym.cpp +) diff --git a/tests/auto/finddebugsym/finddebugsym.pro b/tests/auto/finddebugsym/finddebugsym.pro new file mode 100644 index 0000000..094785c --- /dev/null +++ b/tests/auto/finddebugsym/finddebugsym.pro @@ -0,0 +1,19 @@ +QT += testlib +QT -= gui + +CONFIG += testcase strict_flags warn_on + +INCLUDEPATH += ../../../app + +TARGET = tst_finddebugsym + +include(../../../elfutils.pri) + +SOURCES += \ + tst_finddebugsym.cpp \ + ../../../app/perfsymboltable.cpp + +HEADERS += \ + ../../../app/perfsymboltable.h + +OTHER_FILES += finddebugsym.qbs diff --git a/tests/auto/finddebugsym/finddebugsym.qbs b/tests/auto/finddebugsym/finddebugsym.qbs new file mode 100644 index 0000000..2a68e3a --- /dev/null +++ b/tests/auto/finddebugsym/finddebugsym.qbs @@ -0,0 +1,11 @@ +import qbs + +QtcAutotest { + name: "finddebugsym Autotest" + files: [ + "tst_finddebugsym.cpp", + "../../../app/perfkallsyms.cpp", + "../../../app/perfkallsyms.h" + ] + cpp.includePaths: base.concat(["../../../app"]) +} diff --git a/tests/auto/finddebugsym/tst_finddebugsym.cpp b/tests/auto/finddebugsym/tst_finddebugsym.cpp new file mode 100644 index 0000000..c298749 --- /dev/null +++ b/tests/auto/finddebugsym/tst_finddebugsym.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Lieven Hey +*<lieven.hey@kdab.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Enterprise Perf Profiler Add-on. +** +** GNU General Public License Usage +** This file may be used under the terms of the GNU General Public License +** version 3 as published by the Free Software Foundation and appearing in +** the file LICENSE.GPLv3 included in the packaging of this file. Please +** review the following information to ensure the GNU General Public License +** requirements will be met: https://www.gnu.org/licenses/gpl.html. +** +** If you have questions regarding the use of this file, please use +** contact form at http://www.qt.io/contact-us +** +****************************************************************************/ + +#include "perfkallsyms.h" + +#include <QDebug> +#include <QObject> +#include <QTemporaryDir> +#include <QTest> + +#include <QThread> + +#include "perfsymboltable.h" + +QFileInfo findDebugInfoFile(const QString& root, const QString& file, const QString& debugLinkString); + +class TestFindDebugSymbols : public QObject +{ + Q_OBJECT +private slots: + void initTestCase() + { + const auto files = {QStringLiteral("/usr/bin/python3.8"), + QStringLiteral("/usr/bin/.debug/096cdc8214a805dca8d174fe072684b0f21645.debug"), + QStringLiteral("/usr/lib/libm.so"), + QStringLiteral("/usr/lib/libqt.so"), + QStringLiteral("/usr/lib/debug/libm.so"), + QStringLiteral("/usr/lib/debug/lib/x64/libc.so"), + QStringLiteral("/usr/lib/debug/lib/test.so"), + QStringLiteral("/usr/lib/debug/usr/lib/test2.so")}; + + QDir dir(tempDir.path()); + for (const auto& file : files) { + auto path = QFileInfo(tempDir.path() + file).path(); + dir.mkpath(path); + QVERIFY(dir.exists(path)); + + QFile f(tempDir.path() + file); + f.open(QIODevice::WriteOnly); + f.write(file.toUtf8()); + QVERIFY(f.exists()); + } + } + + void findDebugSymbols_data() + { + QTest::addColumn<QString>("root"); + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("debugLinkString"); + + QTest::addRow("/usr/bin") << QStringLiteral("/usr/bin/python3.8") + << QStringLiteral("096cdc8214a805dca8d174fe072684b0f21645.debug") + << QStringLiteral("/usr/bin/.debug/096cdc8214a805dca8d174fe072684b0f21645.debug"); + QTest::addRow("/usr/lib/debug") << QStringLiteral("/usr/lib/libm.so") << QStringLiteral("libm.so") + << QStringLiteral("/usr/lib/debug/libm.so"); + QTest::addRow("/usr/lib/debug") << QStringLiteral("/usr/lib/x64/libc.so") << QStringLiteral("libc.so") + << QStringLiteral("/usr/lib/debug/lib/x64/libc.so"); + QTest::addRow("no debug file") << QStringLiteral("/usr/lib/libqt.so") << QStringLiteral("libqt.so") + << QStringLiteral("/usr/lib/libqt.so"); + QTest::addRow("/us/lib/") << QStringLiteral("/usr/lib/test.so") << QStringLiteral("test.so") + << QStringLiteral("test.so"); + QTest::addRow("/us/lib/") << QStringLiteral("/usr/lib/test2.so") << QStringLiteral("test2.so") + << QStringLiteral("test2.so"); + } + + void findDebugSymbols() + { + QFETCH(QString, root); + QFETCH(QString, file); + QFETCH(QString, debugLinkString); + + auto debugFile = findDebugInfoFile(tempDir.path() + QDir::separator(), root, file); + + QCOMPARE(debugFile.absoluteFilePath(), QFileInfo(tempDir.path() + debugLinkString).absoluteFilePath()); + } + +private: + QTemporaryDir tempDir; +}; + +QTEST_GUILESS_MAIN(TestFindDebugSymbols) + +#include "tst_finddebugsym.moc" |