Changeset View
Changeset View
Standalone View
Standalone View
src/tests/gdbbacktracelinetest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2020 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <QTest> | ||||
22 | | ||||
23 | #include "../parser/backtraceparsergdb.h" | ||||
24 | | ||||
25 | class GdbBacktraceLineTest : public QObject | ||||
26 | { | ||||
27 | Q_OBJECT | ||||
28 | private Q_SLOTS: | ||||
29 | | ||||
30 | // rating() is often times somewhat misleading because it is an exclusive state | ||||
31 | // but in practise a frame may have multiple issues. for purposes of rating all | ||||
32 | // issues are considered equal. it's not ideal though, a frame that is missing | ||||
33 | // multiple elements is objectively worse than a frame that is just missing one. | ||||
34 | | ||||
35 | void testComplete() | ||||
36 | { | ||||
37 | BacktraceLineGdb line( | ||||
38 | "#7 0x00007f468b177bfa in KMime::DateFormatterPrivate::localized (t=t@entry=1579263464, shortFormat=shortFormat@entry=true, lang=...) at /usr/src/debug/kmime-19.12.1-lp151.150.1.x86_64/src/kmime_dateformatter.cpp:310\n" | ||||
39 | ); | ||||
40 | QCOMPARE(line.type(), BacktraceLine::StackFrame); | ||||
41 | QCOMPARE(line.frameNumber(), 7); | ||||
42 | QCOMPARE(line.functionName(), "KMime::DateFormatterPrivate::localized"); | ||||
43 | QCOMPARE(line.fileName(), "/usr/src/debug/kmime-19.12.1-lp151.150.1.x86_64/src/kmime_dateformatter.cpp:310"); | ||||
44 | QCOMPARE(line.libraryName(), ""); | ||||
45 | QCOMPARE(line.rating(), BacktraceLine::Good); | ||||
46 | } | ||||
47 | | ||||
48 | void testPoorFile() | ||||
49 | { | ||||
50 | BacktraceLineGdb line("#41 0x00007f4684ae4e87 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0\n"); | ||||
51 | QCOMPARE(line.type(), BacktraceLine::StackFrame); | ||||
52 | QCOMPARE(line.frameNumber(), 41); | ||||
53 | QCOMPARE(line.functionName(), "g_main_context_dispatch"); | ||||
54 | QCOMPARE(line.fileName(), ""); | ||||
55 | QCOMPARE(line.libraryName(), "/usr/lib64/libglib-2.0.so.0"); | ||||
56 | QCOMPARE(line.rating(), BacktraceLine::MissingSourceFile); | ||||
57 | } | ||||
58 | | ||||
59 | void testNoFunctionPoorFile() | ||||
60 | { | ||||
61 | // Also uses 'at' keyword while referring to a library, this used to trip up | ||||
62 | // the parser and make it think there's a source file, when in reality there | ||||
63 | // is not. | ||||
64 | // Lacking a function name further tripped up the parsing because originally | ||||
65 | // couldn't deal with the function name being missing entirely. | ||||
66 | // As a result this line used to rate as 'Good' -.- | ||||
67 | // https://bugs.kde.org/show_bug.cgi?id=416923 | ||||
68 | BacktraceLineGdb line("#13 0x00007fe6059971b1 in () at /usr/lib/libglib-2.0.so.0\n"); | ||||
69 | QCOMPARE(line.type(), BacktraceLine::StackFrame); | ||||
70 | QCOMPARE(line.frameNumber(), 13); | ||||
71 | QCOMPARE(line.functionName(), ""); | ||||
72 | QCOMPARE(line.fileName(), ""); | ||||
73 | QCOMPARE(line.libraryName(), "/usr/lib/libglib-2.0.so.0"); | ||||
74 | QCOMPARE(line.rating(), BacktraceLine::MissingSourceFile); | ||||
75 | } | ||||
76 | | ||||
77 | void testOnlyFunctionNofile() | ||||
78 | { | ||||
79 | BacktraceLineGdb line("#20 0x0000557e978c1b7e in _start ()\n"); | ||||
80 | QCOMPARE(line.type(), BacktraceLine::StackFrame); | ||||
81 | QCOMPARE(line.frameNumber(), 20); | ||||
82 | QCOMPARE(line.functionName(), "_start"); | ||||
83 | QCOMPARE(line.fileName(), ""); | ||||
84 | QCOMPARE(line.libraryName(), ""); | ||||
85 | QCOMPARE(line.rating(), BacktraceLine::MissingLibrary); | ||||
86 | } | ||||
87 | | ||||
88 | void testInferiorMarker() | ||||
89 | { | ||||
90 | BacktraceLineGdb line("[Inferior 1 (process 72692) detached]\n"); | ||||
91 | QCOMPARE(line.type(), BacktraceLine::Unknown); | ||||
92 | QCOMPARE(line.rating(), BacktraceLine::InvalidRating); | ||||
93 | } | ||||
94 | }; | ||||
95 | | ||||
96 | QTEST_GUILESS_MAIN(GdbBacktraceLineTest) | ||||
97 | | ||||
98 | #include "gdbbacktracelinetest.moc" |