summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QTest: rip out qxp::function_ref from compare_helper()Thiago Macieira9 days1-8/+33
| | | | | | | | | | | | | | | | [ChangeLog][QtTest] The QCOMPARE_xx macros can now only find QTest::toString() expansions that are either found via Argument Dependent Lookup on the type in question or are an instatiation of the QTest::toString<T>() template. This matches the behavior of the QCOMPARE() macro. This changes the way how the toString() overloads are selected, so we need to explicilty constraint the main QTest::toString() template in order to pick the free functions when they exist. Change-Id: Ie28eadac333c4bcd8c08fffd17c54e768c5cffd0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QTest: rip out qxp::function_ref from reportResult()Thiago Macieira9 days1-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is causing huge code bloat because everything is a local lambda. Instead, pass direct type-erased function and data pointers to the replacement function. Testing with tst_qcborvalue, this reduces the compilation time and the output binary size significantly: Before After Compiler Time Size Time Size GCC 13.2 136.99 s 202.3 MB 13.88 s 14.3 MB GCC 14.0 131.49 s 202.7 MB 14.69 s 14.4 MB Clang 17 77.2 s 146.7 MB 13.62 s 12.2 MB Clang 18 141.9 s 187.1 MB 13.62 s 12.4 MB This causes a difference in how toString() overloads are found. Previously it would match far more overloads because the toString() calls were expanded by the macro. Now, we depend on Argument-Dependent Lookup and associated namespaces, so toString() overloads should not be in the QTest namespace any more. With this patch applied, the testlib testcase of tst_selftest started failing, because nullptr is now handled differently. However, I consider it as a bugfix, because previously it was falling back to a default implementation, and now it is using the QTest::toString(std::nullptr_t) overload, which is a desired behavior. Update the reference files for tst_selftest with the new expected output. Task-number: QTBUG-124272 Change-Id: Ie28eadac333c4bcd8c08fffd17c5484186accdf6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QTest: add removed_api.cpp and move deprecated functions to itThiago Macieira9 days1-5/+0
| | | | | | | | | | | | | QtTest is not under the same Binary Compatibility guarantees as the other modules, but let's try and do it where it's easy. The toString() method can simply be removed from the header because it's not a member function. Its deprecation wasn't marked with a version number, so it starts now with 6.8. Change-Id: Ie28eadac333c4bcd8c08fffd17c54faca7057b9c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QTest: expose API needed for Qt Quick Test to print crash backtracesMitch Curtis2024-04-041-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | As discussed in QTQAINFRA-6146, there were two potential approaches to enabling backtraces in Qt Quick tests: - Either via a thorough refactoring of quicktest.cpp so that each testcase is a Slot in a programmatically-created QObject-derived class, which will be executed via QTest::qExec() similar to the documented QTest way. This way the pre-existing code in QTest::qRun() will setup the fatal signal handler. - Or as a quick fix, modify quick_test_main_with_setup() to setup a FatalSignalHandler class and invoke prepareStackTrace() like it's already done in QTest::qRun(). This would require exporting these symbols in the private header. This patch enables the implementation of the latter, as it has a fairly light footprint, is easily revertable (should we need to), and allows us to immediately gain insight into crashes in CI. Task-number: QTQAINFRA-6146 Change-Id: Iedffc968acb3e570214df34884ab0afcb6b30850 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTest: move crash-handling code out into qtestcrashhandler_p.hMitch Curtis2024-04-041-735/+8
| | | | | | | | | | In preparation for reusing it in Qt Quick, which currently doesn't print backtraces upon crashes. Task-number: QTQAINFRA-6146 Change-Id: Ib0384f514b348a398f53529ff3bcc7d4ac2daba7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Port to QDirListingAhmad Samir2024-03-031-14/+15
| | | | | | | | | | | Use QDirListing in the Bootstrap build instead of QDirIterator. Drive-by changes: - more const variables - use emplace_back() instead of append() where appropriate Change-Id: Ie1f0d03856e557c4bfabfff38a87edc7da86d091 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTest: add -[no]throwon{fail,skip} command line argumentsMarc Mutz2024-01-271-0/+12
| | | | | | | | | | | | ... to complement QTEST_THROW_ON_FAIl/SKIP environment variables. This allows to conveniently test both modes by running each test twice. Task-number: QTBUG-66320 Change-Id: I8b2810e8345061c98472d846017de910a11e0657 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTest: add opt-in changing QCOMPARE etc to exit with throw, not returnMarc Mutz2024-01-271-1/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add exception classes and use them to change the control flow for QTEST_{FAIL,SKIP}_ACTION from return'ing from just the immediate function to the full way to the QTestLib infrastructure, here we filter them out. There are three modes: - If QT_NO_EXCEPTION, then we return - If QTEST_THROW_ON_... is also defined, #error out - Otherwise, if QTEST_THROW_ON_... is defined, always throw - Otherwise, the decision is made at runtime (with defaults read from QTEST_THROW_ON_... environment variables). Three selftests depend on the old behavior, as they explicitly check that multiple FAIL SKIP etc emerge, which the new framework, of course, prevents. Locally disable throwing at the test function level. Add initial docs and enable exceptions in all of the selftest subprograms to facilitate switching between the two runtime-selectable modes. [ChangeLog][QtTest] Added QTEST_THROW_ON_FAIL and QTEST_THROW_ON_SKIP C++ macros and environment variables that, when defined, change how QCOMPARE/QVERIFY/QSKIP etc exit the test function on failure. Instead of a return, exiting only the immediately-surrounding function, they throw a special exception instead, thereby exiting from subfunctions of the test function, all the way to QtTestLib. Fixes: QTBUG-66320 Change-Id: I96c38d2a1dcdd9de84942cf448a8bbf3ab6d3679 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTest: hold WatchDog in optional<> instead of QScopedPointerMarc Mutz2024-01-271-5/+6
| | | | | | | | | | Means we don't need to allocate it on the heap and optional<> fits the semantics of an optional object better. Pick-to: 6.7 Change-Id: Id02c4847c2357c3033dce94b68787ed37d6ca276 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTest: DRY test function invocationMarc Mutz2024-01-261-22/+17
| | | | | | | | | | | | | | Wrap the QMetaMethod::invoke() calls in a helper function in preparation of filtering execeptions as part of QTBUG-66320. Rename the existing helper function to make the old documentation comment redundant. Pick this back to LTS branch in order to avoid needless code divergence going forward. Pick-to: 6.7 6.6 6.5 Change-Id: I34ae24bf23ea21d7063016257908f925fc087298 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QTest: replace naked returns with QTEST_{FAIL,SKIP}_ACTION macrosMarc Mutz2024-01-251-4/+4
| | | | | | | | | | | | | ... defaulting to "return". This allows customizing these actions, incl. to eventually make them throwing exceptions instead (but that won't work for QVERIFY_THROWS_EXCEPTION, yet). Change-Id: I078a4ce48135bda2cf98fce78318a12d757d7aa5 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTest: Extract Method qCaught() from THROWS_(NO_)EXCEPTIONMarc Mutz2024-01-231-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | We've already done a lot in 59600a514ba99ed62b46237d8f160dea84474190, but we can do more: Thanks to std::exception_ptr, we can drag the handling of unexpected exceptions completely to out-of-line code, leaving only the catch(...) as inline. As a nice side-effect, we no longer need the nested try blocks in QVERIFY_THROWS_EXCEPTION to work around GCC -Wexceptions or MSVC C2312 complaining about two handlers for the same exception type (which can happen when exceptiontype is std::exception itself). This may not handle __cxxabi::__forced_unwind correctly, but it doesn't need to: Tests should not need to call THROWS_EXECPTION on code that could emit a pthread cancellation; tests are controlled environments. Keep the old qCaught() function for BC. We don't promise BC in QtTestLib, but it doesn't cost much. Pick-to: 6.7 Change-Id: I1e1627c6341b09197a8a79669fde061c47e6ba47 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTest: Extract Method writePrettyUnicodeChar from toPrettyUnicodeMarc Mutz2023-12-071-38/+46
| | | | | | | | | Easier to reason about by separating the concerns into separate functions. Pick-to: 6.6 6.5 Change-Id: I34666766ac2879577faea17bbd2b700bcb803f51 Reviewed-by: Jason McDonald <macadder1@gmail.com>
* QTest::toPrettyUnicode: remove magic numbersMarc Mutz2023-12-061-4/+8
| | | | | | | | | | Derive them from the chosen output buffer size instead, itself a symbolic constant. Pick-to: 6.6 6.5 Change-Id: I33aa351ba358b106b448f886b92e952e53bc75f9 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Jason McDonald <macadder1@gmail.com>
* Rename EINTR_LOOP -> QT_EINTR_LOOPMarc Mutz2023-11-301-1/+1
| | | | | | | | | | | | | | | This non-namespaced macro was defined in a header, and while that header is private, we shouldn't define non-namespaced macros in our headers. The macro also clashed with one of the same name defined in forkfd.c, which broke unity-builds including the forkfd_qt.cpp TU. This rename fixes that, too, so we can now remove forkfd_qt.cpp from NO_UNITY_BUILD_SOURCES. Pick-to: 6.6 6.5 Change-Id: Ic4bb4e4d7a632ca87905e48913db788a7c202314 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* qtestlib: Add option to skip blacklisted testsKalle Viironen2023-11-221-12/+25
| | | | | | | | | | | | | | | Add a command-line option "-skipblacklisted" to testlib to skip blacklisted test cases. Currently, blacklisted test cases are run, but results are ignored. For test code coverage measurements, it's important to see the code coverage of the actually tested code in comparison to the code that was run but not actually tested. The default approach remains unchanged, meaning that blacklisted tests are run with the results ignored. Fixes: QTBUG-112793 Change-Id: I6fe0a6353cb1c021e0232c79bb4f404632fb0bce Reviewed-by: Jason McDonald <macadder1@gmail.com>
* Move the remaining blacklist setting into TestMethods::invokeTest()Kalle Viironen2023-11-201-2/+4
| | | | | | | | | | Move the remaining QTestResult::setBlacklistCurrentTest() call from checkBlackLists() into TestMethods::invokeTest() Change-Id: I6f0bb26ef612e707ad013d1e42e47b06f40482a0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Jason McDonald <macadder1@gmail.com> Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
* Add QTest option for repeating the entire test executionJøger Hansegård2023-11-151-7/+28
| | | | | | | | | | | | | | | | | Repeated test execution can be useful, under a debugger, to catch an intermittent failure or, under memory instrumentation, to make memory leaks easier to recognize. The new -repeat flag allows running the entire test suite multiple times within the same process. It works by executing all tests sequentially before repeating the execution again. This switch is a developer tool, and is not intended for CI. It can only be used with the plain text logger. Change-Id: I2439462c5c44d1c8aa3d3b5656de3eef44898c68 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* wasm: Fix test runner for asynchronous testsPiotr Wierciński2023-10-261-0/+12
| | | | | | | | | | | | | | | | | Test runner was not properly handling tests which return the control back to browser event loop. It was treating such tests as if they exited with code 0, marking them as succesfull even if they were eventually failing or hanging. This commit adds a callback to TestCase so the runner is notified when a test truly has finished. As a side effect, two tests need to be disabled for now as they are failing for wasm, which was not properly detected previously. Change-Id: I0eb9383e5bb9cd660431c18747b9e94413629d1e Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtTest: block almost all Unix signals in the WatchDog threadThiago Macieira2023-10-011-4/+28
| | | | | | | | | | | | | | Signals delivered via kill(2) are delivered to any thread that is running, so let's make sure the WatchDog thread doesn't get them. This may be hiding bugs in the user's handler code, but in simple unit tests the user may not be expecting there to be multiple threads in the first place. Pick-to: 6.6 Change-Id: I512648fd617741199e67fffd17822cdcdf30926c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QEXTRACTTESTDATA: include the errorString() in case of failureThiago Macieira2023-08-051-4/+9
| | | | | | | | | | | | | In case we fail to copy or set the permissions, get the error string from QFile. This necessitated fixing QFile so it would copy the error from QTemporaryFile in case the latter failed to open. Drive-by use %ls to avoid going through the locale codec in QtTest. Change-Id: Ifbf974a4d10745b099b1fffd1777c7e6e00c25af Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Exclude VxWorks platform from stack trace generationKrzysztof Sommerfeld2023-07-271-2/+2
| | | | | Change-Id: I71c2e542ef144f544610edb9245dcbc38ea7db3f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: Remove std::mutex and std::condition_variable fallbacksThiago Macieira2023-06-121-3/+3
| | | | | | | | | | | | They existed because INTEGRITY hadn't yet been updated to the C++11 Standard Library, with a minor for broken MinGW cross-compilation builds that forgot to enable gthreads support in libstdc++. The former appears to have been since fixed and the latter is a massive toolchain configuration mistake. Change-Id: I63b988479db546dabffcfffd1766b55132371f9b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Detect when Xcode is presenting os_log as structured log messagesTor Arne Vestbø2023-06-071-2/+2
| | | | | | | | | In that case, just like when os_log mirrors to stderr by itself, we want to disable Qt's fallback stderr handler. Pick-to: 6.6 6.5 Change-Id: Ia373b19788edbce616d4f0d3d9f0b217ddc1e5c0 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Testlib: fix the last few s/Q_OS_MAC/Q_OS_DARWIN/wEdward Welbourne2023-03-201-1/+1
| | | | | Change-Id: I6fe6a865aea37c6a2d153bd2c3aace5242362c88 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* Cross-reference newRow() and addRow() in QTest docs and improve wordingEdward Welbourne2023-01-311-12/+22
| | | | | | | | | | | | Mitch helpfully pointed out, in review of my change to the "Data Driven Testing" doc that the two functions didn't \sa each other, so I added that. Which naturally prompted a review of their language. Also, split a long line in the code. Pick-to: 6.5 Change-Id: I5f3e973052e0107bd5bdaeecaebe218e043380ff Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Jason McDonald <macadder1@gmail.com>
* Doc: Mark qRegisterTestCase as new in Qt 6.5Kai Köhne2023-01-161-1/+3
| | | | | | | | | Also remove reference to QTestCaseEvent loop class, which is not documented. Pick-to: 6.5 Change-Id: Ic09b3b102db535dfb090b9a4072ad29515a911ae Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
* QTest::WatchDog: fix missing timeout resets on test function changeMarc Mutz2022-12-161-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | Since e0cad1aab53119a0e47467f2236f019ce8d6da2a, the code suffered from an ABA problem where the TestFunctionStart expectation is set in testFinished(), but by the time WatchDog::run() gets around to examining the state when returning from condition_variable::wait() in waitFor(), the next beginTest() has already set the expectation back to TestFunctionEnd. There are several known solutions for ABA problems. Embedding a generation count into the expectation state seemed to be the most straight-forward fix, and can be done without DWCAS support, because the state is just 2 bits, leaving the other 30 or 62 bits for the generation counter, so do that. [ChangeLog][QTestLib] Fixed a bug which caused QTEST_FUNCTION_TIMEOUT to be applied to the whole test execution, as opposed to each test function. Fixes: QTBUG-109466 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: If71ade932330407b85d204d45c74350c651325fe Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QTest::WatchDog: Extract Method setExpectation()Marc Mutz2022-12-161-11/+10
| | | | | | | | | | Keeps the code DRY and enables a follow-up commit to fix QTBUG-109466. Task-number: QTBUG-109466 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I2b904ea7b38286b07049524ba63c2c5028e680bb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QPlainTestLogger: don't print "RESULT" before each additional resultThiago Macieira2022-11-091-6/+2
| | | | | | | | | | | | | | | | | We do that by passing the full list of results to the logger, to a virtual that is present in the base class to call the existing function. For all but the plain logger, we'll just print multiple results. The plain logger now prints: RESULT : tst_MyClass::QString_toInt() 383 nsecs per iteration (total: 3,837,324, iterations: 10000) 1,069 CPU cycles per iteration (total: 10,692,457, iterations: 10000) 3,123 instructions per iteration (total: 31,230,101, iterations: 10000) 536 branch instructions per iteration (total: 5,360,022, iterations: 10000) Change-Id: I3c79b7e08fa346988dfefffd17203cb5802693dd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QBenchlib: add support for a measurer reporting multiple resultsThiago Macieira2022-11-091-24/+32
| | | | | | | | | | | | | | | | | Implemented for the Linux Perf measurer, with four measurements by default. RESULT : tst_MyClass::QString_toInt(): 149.574444 CPU cycles per iteration (total: 149,574,445, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 620.000181 instructions per iteration (total: 620,000,182, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 131.000046 branch instructions per iteration (total: 131,000,047, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 32.118771 nsecs per iteration (total: 32,118,771, iterations: 1000000) Change-Id: I3c79b7e08fa346988dfefffd17202cda3df8431b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QBenchlib: use QBenchmarkMeasurerBase::Measurement in QBenchmarkResultThiago Macieira2022-11-091-11/+5
| | | | | Change-Id: I3c79b7e08fa346988dfefffd17202a818cde1d84 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QBenchlib: force the warmup to run a single iterationThiago Macieira2022-10-251-0/+2
| | | | | | | | | | | | The purpose of warming up is to get all code paths executed, so any lazy function resolving is processed, statics are allocated, etc. There's no reason to run it more than once -- if you're trying to train the Branch Predictor Unit, you'd want to do it another way anyway. This is useful when benchmarking with -iterations N, because QBenchlib currently runs 2*N iterations because of the warm up. That just wastes time. Change-Id: I3c79b7e08fa346988dfefffd172030c889b31a1f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-1/+1
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add QTest::currentTestResolved() and use in testlibEdward Welbourne2022-09-221-2/+22
| | | | | | | | | | | | | | | | | | The QTRY_* macros and QTestEventLoop have (since 6.3) been exiting their loops early if the test has failed. Where that was appropriate, they should also have been exiting early on skip. [ChangeLog][QtTest] Added QTest::currentTestResolved(), which is true if the test has failed or skipped. The QTRY_*() macros and QTestEventLoop now use this, rather than QTest::currentTestFailed(), to test whether they should stop looping, so that they also do so on a skip. Task-number: QTBUG-104441 Change-Id: Ibf3d5a095b35e6670bc3daf756f05b66f7f3ef9b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Jason McDonald <macadder1@gmail.com>
* QDoc-ify QTest::runningTest()'s commentEdward Welbourne2022-09-221-1/+3
| | | | | | | | | | | While it's being picked into 6.3, it's not present in 6.3.[01], so I've left it out of QDoc's sight (even though it's still \internal) for the version picked to 6.3, but let's include it in internal docs as "from 6.4" since that's the first minor release to contain it. Pick-to: 6.4 Change-Id: I1704a1ca4ba1231d0213e9ca236ef8401a59ddd0 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Skip early return from test loops during cleanup()Edward Welbourne2022-09-221-0/+14
| | | | | | | | | | | | | | | | The QTRY_* macros and QTestEventLoop exit early if the test has resolved; however, in the cleanup phase of a test, even if the test has failed, these loops should continue as normal. [ChangeLog][QtTest] During the cleanup() phase of a test, the QTRY_* macros and QTestEventLoop now ignore the test resolution, in contrast to when they are used from the test itself, which (since 6.3.0) exits the loops early if the test has failed. Pick-to: 6.4 6.3 Fixes: QTBUG-104441 Change-Id: I2673161967cbbc57815155af698a9338ab98a686 Reviewed-by: Jason McDonald <macadder1@gmail.com>
* Implement the batch_tests featureMikolaj Boc2022-08-241-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | An approach of test batching (joining multiple tests into a single binary) has been taken, due to long linking times/binary size on certain platforms, including WASM. This change adds a new feature 'batch_test_support' in Qt testlib. Based on the value of the feature, test batching may become enabled with the -batch-tests switch. Batching works for every target added via qt_internal_add_test. When first such target is being processed, a new combined target for all of the future test sources is created under the name of 'test_batch'. CMake attempts to merge the parameters of each of the tests, and some basic checks are run for parameter differences that are impossible to reconcile. On the C++ level, convenience macros instantiating the tests are redefined when batch_tests is on. The new, changed behavior triggered by the changes in the macros registers the tests in a central test registry, where they are available for execution based solely on their test name. The test name is interoperable with the names CMake is aware of, so CTest is able to run the tests one by one in the combined binary. Task-number: QTBUG-105273 Change-Id: I2b6071d58be16979bd967eab2d405249f5a4e658 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Include current test name in crash reportsEdward Welbourne2022-08-121-5/+9
| | | | | | | | | | | | | | | | Previously a crashing test's output would end with the last completed test's output followed by a crash report, leading readers (understandably enough) to conclude that the last-named test is the one that crashed. In fact the crashing test is typically the next one in the class definition. Include the current test function's name (when non-null) in the output accompanying crash logs. This always goes to stderr so does not show up in the expected output. Pick-to: 6.4 Change-Id: Icab0ccd1fe434827ee92459ab0c97f9dc034754e Reviewed-by: Jason McDonald <macadder1@gmail.com>
* WindowsFaultHandler: print the backtrace to stderr, not stdoutThiago Macieira2022-07-271-12/+11
| | | | | | | | | Otherwise the contents that vary per architecture and build will make it impossible to self-check (tst_selftests) Change-Id: Ibcde9b9795ad42ac9978fffd16f2cbc352c3503c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Replace 0 with \nullptr in QTest::currentDataTag()'s docEdward Welbourne2022-07-111-1/+1
| | | | | | | The function's return type is a pointer, not an integer. Change-Id: Iab6686ac7e4e24b9b1bd0127346c5854cf593a57 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Improve formatting of QTest message on missing functionEdward Welbourne2022-07-111-6/+15
| | | | | | | | | | | | | | | | | | | If there were no matches to the name given on the command line, the message reported included a "Possible matches:" preamble for a list of functions containing the requested function name. This looked incongruous when no actual functions matched. Turn that preamble into an optional parameter to qPrintTestSlots(), that it'll output before the first match if it finds one, rework qPrintTestSlots() to package its matching condition in a lambda and return true if it found any matches. Change this caller to output a newline in place of the preamble (which ended in a newline), if no match was found. Change-Id: I9716ffa29c3c46e3c7e7fcf25a676c0356dab91c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Dimitrios Apostolou <jimis@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* qtestlib: exit with error if a test is invoked with unknown data tagDimitrios Apostolou2022-06-281-21/+22
| | | | | | | | | | | | | | Previously trying to execute a test function with an unknown data tag would print an error message but exit with 0. This patch stores a test failure, and continues trying to execute the rest of the command line arguments, if any. In the end the process exits with the usual exit code (number of failed tests) which is now !=0. Pick-to: 6.4 6.3 6.2 Fixes: QTBUG-24240 Change-Id: Id4d422035f173e01e77ca88028dfd94dc0f9085c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* FatalSignalHandler: print some more information from siginfo_tThiago Macieira2022-06-281-6/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | The siginfo_t parameter allows us to show what process sent a signal or the crashing address. Additionally, it allows us to determine if the crashing signal was indeed sent due to a crash. The selftest tst_crashes produces now: $ QTEST_DISABLE_STACK_DUMP=1 ./crashes ********* Start testing of tst_Crashes ********* Config: Using QtTest library 6.4.0, Qt 6.4.0 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 11.2.1 20220420 [revision 691af15031e00227ba6d5935c1d737026cda4129]), opensuse-tumbleweed 20220428 PASS : tst_Crashes::initTestCase() Received signal 11 (SIGSEGV), code 1, for address 0x0000000000000004 Function time: 0ms, total time: 0ms [1] 201995 segmentation fault (core dumped) QTEST_DISABLE_STACK_DUMP=1 ./crashes The last line comes from the shell. The code isn't decoded, but on Linux it's a SEGV_MAPERR. macOS prints exactly the same thing. I've updated one of the expected_crashes_*.txt output that doesn't seem possible (the "Received a fatal error" message does not appear in Qt anywhere). Pick-to: 6.4 Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16ebc8391234f0e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTest: switch some text-conversion functions to use qsizetypeMårten Nordheim2022-06-281-10/+8
| | | | | | | | | To avoid potential narrowing. Pick-to: 6.4 Task-number: QTBUG-104125 Change-Id: I37bfc5c49e7c919f5204a76a905758a92527d864 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Fix typos in docs and commentsKai Köhne2022-06-151-2/+2
| | | | | | | | | Found by codespell Pick-to: 6.4 Change-Id: Ie3e301a23830c773a2e9aff487c702a223d246eb Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Don't exit(1) on unrecognised test function name, just report a failureEdward Welbourne2022-06-151-9/+23
| | | | | | | | | | This way, if you name several test functions on the command-line, you'll at least get the ones that do exist run (and you'll be told all of the ones that don't exist, rather than only the first). Pick-to: 6.4 6.3 6.2 Change-Id: I14a515fcfacb6ca49e0470b236c05475b25db4f2 Reviewed-by: Dimitrios Apostolou <jimis@qt.io>