Changeset View
Changeset View
Standalone View
Standalone View
debuggers/gdb/unittests/test_gdb.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | |||||
249 | 249 | | |||
250 | #define WAIT_FOR(session, condition) \ | 250 | #define WAIT_FOR(session, condition) \ | ||
251 | do { \ | 251 | do { \ | ||
252 | TestWaiter w((session), #condition, __FILE__, __LINE__); \ | 252 | TestWaiter w((session), #condition, __FILE__, __LINE__); \ | ||
253 | while (w.waitUnless((condition))) /* nothing */ ; \ | 253 | while (w.waitUnless((condition))) /* nothing */ ; \ | ||
254 | } while(0) | 254 | } while(0) | ||
255 | 255 | | |||
256 | #define COMPARE_DATA(index, expected) \ | 256 | #define COMPARE_DATA(index, expected) \ | ||
257 | compareData((index), (expected), __FILE__, __LINE__) | 257 | do { if(!compareData((index), (expected), __FILE__, __LINE__)) return; } while (0) | ||
258 | 258 | | |||
259 | void compareData(QModelIndex index, QString expected, const char *file, int line) | 259 | bool compareData(QModelIndex index, QString expected, const char *file, int line) | ||
260 | { | 260 | { | ||
261 | QString s = index.model()->data(index, Qt::DisplayRole).toString(); | 261 | QString s = index.model()->data(index, Qt::DisplayRole).toString(); | ||
262 | if (s != expected) { | 262 | if (s != expected) { | ||
263 | QFAIL(qPrintable(QString("'%0' didn't match expected '%1' in %2:%3").arg(s).arg(expected).arg(file).arg(line))); | 263 | QTest::qFail(qPrintable(QString("'%0' didn't match expected '%1' in %2:%3") | ||
264 | .arg(s).arg(expected).arg(file).arg(line)), | ||||
265 | file, line); | ||||
266 | return false; | ||||
264 | } | 267 | } | ||
268 | return true; | ||||
265 | } | 269 | } | ||
266 | 270 | | |||
267 | static const QString debugeeFileName = findSourceFile("debugee.cpp"); | 271 | static const QString debugeeFileName = findSourceFile("debugee.cpp"); | ||
268 | 272 | | |||
269 | KDevelop::BreakpointModel* breakpoints() | 273 | KDevelop::BreakpointModel* breakpoints() | ||
270 | { | 274 | { | ||
271 | return KDevelop::ICore::self()->debugController()->breakpointModel(); | 275 | return KDevelop::ICore::self()->debugController()->breakpointModel(); | ||
272 | } | 276 | } | ||
▲ Show 20 Lines • Show All 1716 Lines • ▼ Show 20 Line(s) | 1982 | #ifdef HAVE_PATH_WITH_SPACES_TEST | |||
1989 | session->run(); | 1993 | session->run(); | ||
1990 | WAIT_FOR_STATE(session, DebugSession::EndedState); | 1994 | WAIT_FOR_STATE(session, DebugSession::EndedState); | ||
1991 | #endif | 1995 | #endif | ||
1992 | } | 1996 | } | ||
1993 | 1997 | | |||
1994 | bool GdbTest::waitForState(GDBDebugger::DebugSession *session, DebugSession::DebuggerState state, | 1998 | bool GdbTest::waitForState(GDBDebugger::DebugSession *session, DebugSession::DebuggerState state, | ||
1995 | const char *file, int line, bool waitForIdle) | 1999 | const char *file, int line, bool waitForIdle) | ||
1996 | { | 2000 | { | ||
1997 | QPointer<GDBDebugger::DebugSession> s(session); //session can get deleted in DebugController | 2001 | QPointer<DebugSession> s(session); //session can get deleted in DebugController | ||
1998 | QTime stopWatch; | 2002 | QTime stopWatch; | ||
1999 | stopWatch.start(); | 2003 | stopWatch.start(); | ||
2000 | while (s.data()->state() != state || (waitForIdle && s->stateIsOn(s_dbgBusy))) { | 2004 | | ||
2005 | // legacy behavior for tests that implicitly may require waiting for idle, | ||||
2006 | // but which were written before waitForIdle was added | ||||
2007 | waitForIdle = waitForIdle || state != DebugSession::EndedState; | ||||
2008 | | ||||
2009 | while (s && (s->state() != state || (waitForIdle && s->stateIsOn(s_dbgBusy)))) { | ||||
2001 | if (stopWatch.elapsed() > 5000) { | 2010 | if (stopWatch.elapsed() > 5000) { | ||
2002 | qWarning() << "current state" << s.data()->state() << "waiting for" << state; | 2011 | qWarning() << "current state" << s->state() << "waiting for" << state; | ||
2003 | QTest::qFail(qPrintable(QString("Timeout before reaching state %0").arg(state)), | 2012 | QTest::qFail(qPrintable(QString("Timeout before reaching state %0").arg(state)), | ||
2004 | file, line); | 2013 | file, line); | ||
2005 | return false; | 2014 | return false; | ||
2006 | } | 2015 | } | ||
2007 | QTest::qWait(20); | 2016 | QTest::qWait(20); | ||
2008 | if (!s) { | 2017 | } | ||
2009 | if (state == DebugSession::EndedState) | 2018 | | ||
2010 | break; | 2019 | // NOTE: don't wait anymore after leaving the loop. Waiting re-enters event loop and | ||
2020 | // may change session state. | ||||
2021 | | ||||
2022 | if (!s && state != DebugSession::EndedState) { | ||||
2011 | QTest::qFail(qPrintable(QString("Session ended before reaching state %0").arg(state)), | 2023 | QTest::qFail(qPrintable(QString("Session ended before reaching state %0").arg(state)), | ||
2012 | file, line); | 2024 | file, line); | ||
2013 | return false; | 2025 | return false; | ||
2014 | } | 2026 | } | ||
2015 | } | | |||
2016 | if (!waitForIdle && state != DebugSession::EndedState) { | | |||
2017 | // legacy behavior for tests that implicitly may require waiting for idle, | | |||
2018 | // but which were written before waitForIdle was added | | |||
2019 | QTest::qWait(100); | | |||
2020 | } | | |||
2021 | 2027 | | |||
2022 | qDebug() << "Reached state " << state << " in " << file << ':' << line; | 2028 | qDebug() << "Reached state " << state << " in " << file << ':' << line; | ||
2023 | return true; | 2029 | return true; | ||
2024 | } | 2030 | } | ||
2025 | 2031 | | |||
2026 | } | 2032 | } | ||
2027 | 2033 | | |||
2028 | QTEST_MAIN(GDBDebugger::GdbTest) | 2034 | QTEST_MAIN(GDBDebugger::GdbTest) | ||
2029 | 2035 | | |||
2030 | 2036 | | |||
2031 | #include "test_gdb.moc" | 2037 | #include "test_gdb.moc" | ||
2032 | #include "moc_test_gdb.cpp" | 2038 | #include "moc_test_gdb.cpp" | ||
2033 | 2039 | |