diff options
30 files changed, 471 insertions, 199 deletions
diff --git a/cmake/QtBuildHelpers.cmake b/cmake/QtBuildHelpers.cmake index 91983636712..3ef292b27bc 100644 --- a/cmake/QtBuildHelpers.cmake +++ b/cmake/QtBuildHelpers.cmake @@ -6,6 +6,7 @@ function(qt_internal_validate_cmake_generator) if(NOT warning_shown AND NOT CMAKE_GENERATOR MATCHES "Ninja" + AND NOT (IOS AND QT_INTERNAL_IS_STANDALONE_TEST) AND NOT QT_SILENCE_CMAKE_GENERATOR_WARNING AND NOT DEFINED ENV{QT_SILENCE_CMAKE_GENERATOR_WARNING}) set_property(GLOBAL PROPERTY _qt_validate_cmake_generator_warning_shown TRUE) diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 06228ac41de..781bdf4143a 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -1240,7 +1240,7 @@ function(qt_internal_add_test_finalizers target) # specific platforms. # TODO: Remove once we confirm that the new way of running test finalizers for all platforms # doesn't cause any issues. - if(QT_INTERNAL_SKIP_TEST_FINALIZERS_V2) + if(NOT QT_INTERNAL_SKIP_TEST_FINALIZERS_V2) return() endif() diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake index 348a3c25603..b2a5575f130 100644 --- a/cmake/QtToolchainHelpers.cmake +++ b/cmake/QtToolchainHelpers.cmake @@ -183,6 +183,7 @@ endif()") list(LENGTH CMAKE_OSX_ARCHITECTURES _qt_osx_architectures_count) if(cmake_sysroot_name AND (MACOS OR (UIKIT AND NOT _qt_osx_architectures_count GREATER 1))) list(APPEND init_platform " +set(__qt_initial_apple_sdk \"${QT_APPLE_SDK}\") if(NOT DEFINED CMAKE_OSX_SYSROOT) set(CMAKE_OSX_SYSROOT \"${cmake_sysroot_name}\" CACHE STRING \"\") endif()") @@ -254,7 +255,8 @@ endif()") qt_internal_get_first_osx_arch(osx_first_arch) list(APPEND init_platform "if((NOT CMAKE_GENERATOR STREQUAL \"Xcode\" AND NOT __qt_toolchain_building_qt_repo) - OR (CMAKE_GENERATOR STREQUAL \"Xcode\" AND __qt_apple_sdk AND NOT QT_NO_SET_OSX_ARCHITECTURES))") + OR (CMAKE_GENERATOR STREQUAL \"Xcode\" AND __qt_initial_apple_sdk + AND NOT QT_NO_SET_OSX_ARCHITECTURES))") list(APPEND init_platform " set(CMAKE_OSX_ARCHITECTURES \"${osx_first_arch}\" CACHE STRING \"\")") list(APPEND init_platform "endif()") diff --git a/coin/instructions/cmake_run_ctest.yaml b/coin/instructions/cmake_run_ctest.yaml index 43963fc172b..03312101117 100644 --- a/coin/instructions/cmake_run_ctest.yaml +++ b/coin/instructions/cmake_run_ctest.yaml @@ -92,19 +92,10 @@ instructions: variableName: CTEST_ARGS variableValue: " --no-label-summary" - # Enable CTest's JUnit XML summary + # Enable CTest's JUnit XML summary, supported in CMake >= v3.21 - type: AppendToEnvironmentVariable variableName: CTEST_ARGS variableValue: " --output-junit {{.Env.COIN_CTEST_RESULTSDIR}}{{.Env.CI_PATH_SEP}}test_summary.ctest_junit_xml" - disable_if: # CMake < v3.21 does not support it - condition: and - conditions: - - condition: runtime - env_var: CMAKE_MIN_SUPPORTED_BIN_PATH - not_equals_value: null - - condition: runtime - env_var: PATH - contains_value: "{{.Env.CMAKE_MIN_SUPPORTED_BIN_PATH}}" - !include "{{qt/qtbase}}/coin_module_test_android_start_emulator.yaml" diff --git a/doc/global/externalsites/external-resources.qdoc b/doc/global/externalsites/external-resources.qdoc index 51756842ad0..7a04cca52ce 100644 --- a/doc/global/externalsites/external-resources.qdoc +++ b/doc/global/externalsites/external-resources.qdoc @@ -476,6 +476,6 @@ */ /*! - \externalpage https://specifications.freedesktop.org/trash-spec/1.0/ + \externalpage https://specifications.freedesktop.org/trash/1.0/ \title FreeDesktop.org Trash specification version 1.0 */ diff --git a/mkspecs/common/clang.conf b/mkspecs/common/clang.conf index 82c6173a037..83867e66f94 100644 --- a/mkspecs/common/clang.conf +++ b/mkspecs/common/clang.conf @@ -32,14 +32,14 @@ QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG QMAKE_CXXFLAGS_LTCG_FATOBJECTS = $$QMAKE_CFLAGS_LTCG_FATOBJECTS QMAKE_CXXFLAGS_DISABLE_LTCG = $$QMAKE_CFLAGS_DISABLE_LTCG QMAKE_CXXFLAGS_CXX11 = -std=c++11 -QMAKE_CXXFLAGS_CXX14 = -std=c++1y -QMAKE_CXXFLAGS_CXX1Z = -std=c++1z +QMAKE_CXXFLAGS_CXX14 = -std=c++14 +QMAKE_CXXFLAGS_CXX1Z = -std=c++17 QMAKE_CXXFLAGS_CXX2A = -std=c++2a QMAKE_CXXFLAGS_CXX2B = -std=c++2b QMAKE_CXXFLAGS_CXX2C = -std=c++2c QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11 -QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++1y -QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++1z +QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++14 +QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++17 QMAKE_CXXFLAGS_GNUCXX2A = -std=gnu++2a QMAKE_CXXFLAGS_GNUCXX2B = -std=gnu++2b QMAKE_CXXFLAGS_GNUCXX2C = -std=gnu++2c diff --git a/mkspecs/common/g++-base.conf b/mkspecs/common/g++-base.conf index e12e41506ae..66248fb7d01 100644 --- a/mkspecs/common/g++-base.conf +++ b/mkspecs/common/g++-base.conf @@ -30,14 +30,14 @@ QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE QMAKE_CFLAGS_GNUC99 = -std=gnu99 QMAKE_CFLAGS_GNUC11 = -std=gnu11 QMAKE_CXXFLAGS_CXX11 = -std=c++11 -QMAKE_CXXFLAGS_CXX14 = -std=c++1y -QMAKE_CXXFLAGS_CXX1Z = -std=c++1z +QMAKE_CXXFLAGS_CXX14 = -std=c++14 +QMAKE_CXXFLAGS_CXX1Z = -std=c++17 QMAKE_CXXFLAGS_CXX2A = -std=c++2a QMAKE_CXXFLAGS_CXX2B = -std=c++2b QMAKE_CXXFLAGS_CXX2C = -std=c++2c QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11 -QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++1y -QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++1z +QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++14 +QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++17 QMAKE_CXXFLAGS_GNUCXX2A = -std=gnu++2a QMAKE_CXXFLAGS_GNUCXX2B = -std=gnu++2b QMAKE_CXXFLAGS_GNUCXX2C = -std=gnu++2c diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index b69d0285de2..c1f9aee0180 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -3677,21 +3677,6 @@ macro(qt6_standard_project_setup) if(NOT DEFINED QT_I18N_SOURCE_LANGUAGE) set(QT_I18N_SOURCE_LANGUAGE ${__qt_sps_arg_I18N_SOURCE_LANGUAGE}) endif() - - if(CMAKE_GENERATOR STREQUAL "Xcode") - # Ensure we always use device SDK for Xcode for single-arch Qt builds - set(qt_osx_arch_count 0) - if(QT_OSX_ARCHITECTURES) - list(LENGTH QT_OSX_ARCHITECTURES qt_osx_arch_count) - endif() - if(NOT qt_osx_arch_count GREATER 1 AND "${CMAKE_OSX_SYSROOT}" MATCHES "^[a-z]+simulator$") - # Xcode expects the base SDK to be the device SDK - set(simulator_sysroot "${CMAKE_OSX_SYSROOT}") - string(REGEX REPLACE "simulator" "os" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}") - set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}" CACHE STRING "" FORCE) - set(CMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS "${simulator_sysroot}") - endif() - endif() endif() endmacro() diff --git a/src/corelib/itemmodels/qrangemodel_impl.h b/src/corelib/itemmodels/qrangemodel_impl.h index f6b08099fe7..7eca3094a66 100644 --- a/src/corelib/itemmodels/qrangemodel_impl.h +++ b/src/corelib/itemmodels/qrangemodel_impl.h @@ -239,17 +239,15 @@ namespace QRangeModelDetails : std::true_type {}; - // we use std::rotate in moveRows/Columns, which requires std::swap and the - // iterators to be at least a forward iterator - template <typename It, typename = void> - struct test_rotate : std::false_type {}; - + // we use std::rotate in moveRows/Columns, which requires the values (which + // might be const if we only get a const iterator) to be swappable, and the + // iterator type to be at least a forward iterator template <typename It> - struct test_rotate<It, std::void_t<decltype(std::swap(*std::declval<It>(), - *std::declval<It>()))>> - : std::is_base_of<std::forward_iterator_tag, - typename std::iterator_traits<It>::iterator_category> - {}; + using test_rotate = std::conjunction< + std::is_swappable<decltype(*std::declval<It>())>, + std::is_base_of<std::forward_iterator_tag, + typename std::iterator_traits<It>::iterator_category> + >; template <typename C, typename = void> struct test_splice : std::false_type {}; diff --git a/src/corelib/itemmodels/qrangemodeladapter.h b/src/corelib/itemmodels/qrangemodeladapter.h index 2a23e01eba2..0234c402248 100644 --- a/src/corelib/itemmodels/qrangemodeladapter.h +++ b/src/corelib/itemmodels/qrangemodeladapter.h @@ -19,13 +19,11 @@ class QT_TECH_PREVIEW_API QRangeModelAdapter #ifdef Q_QDOC using range_type = Range; - using const_row_reference = typename std::iterator_traits<Range>::const_reference; - using row_reference = typename std::iterator_traits<Range>::reference; #else using range_type = QRangeModelDetails::wrapped_t<Range>; +#endif using const_row_reference = typename Impl::const_row_reference; using row_reference = typename Impl::row_reference; -#endif using range_features = typename QRangeModelDetails::range_traits<range_type>; using row_type = std::remove_reference_t<row_reference>; using row_features = QRangeModelDetails::range_traits<typename Impl::wrapped_row_type>; @@ -78,16 +76,22 @@ class QT_TECH_PREVIEW_API QRangeModelAdapter template <typename C> using if_compatible_row_range = std::enable_if_t<is_compatible_row_range<C>, bool>; template <typename Data> - static constexpr bool is_compatible_data = true; - // std::is_convertible_v<Data, decltype(*std::begin(std::declval<const_row_reference>()))>; + static constexpr bool is_compatible_data = std::is_convertible_v<Data, data_type>; template <typename Data> using if_compatible_data = std::enable_if_t<is_compatible_data<Data>, bool>; template <typename C> static constexpr bool is_compatible_data_range = is_compatible_data< + typename QRangeModelDetails::data_type< + typename QRangeModelDetails::row_traits< decltype(*std::begin(std::declval<C&>())) - >; + >::item_type + >::type + >; + template <typename C> + using if_compatible_column_data = std::enable_if_t<is_compatible_data<C> + || is_compatible_data_range<C>, bool>; template <typename C> - using if_compatible_data_range = std::enable_if_t<is_compatible_data_range<C>, bool>; + using if_compatible_column_range = std::enable_if_t<is_compatible_data_range<C>, bool>; template <typename R> using if_assignable_range = std::enable_if_t<std::is_assignable_v<range_type, R>, bool>; @@ -1262,12 +1266,12 @@ public: decltype(auto) operator[](int row) const { return at(row); } template <typename I = Impl, if_table<I> = true, if_writable<I> = true> - decltype(auto) at(int row) + auto at(int row) { return RowReference{index(row, 0), this}; } template <typename I = Impl, if_table<I> = true, if_writable<I> = true> - decltype(auto) operator[](int row) { return at(row); } + auto operator[](int row) { return at(row); } // at/operator[int, int] for table: returns value at row/column template <typename I = Impl, unless_list<I> = true> @@ -1445,15 +1449,15 @@ public: return storage.m_model->insertColumn(before); } - template <typename D = row_type, typename I = Impl, - if_canInsertColumns<I> = true, if_compatible_data<D> = true> + template <typename D, typename I = Impl, + if_canInsertColumns<I> = true, if_compatible_column_data<D> = true> bool insertColumn(int before, D &&data) { return insertColumnImpl(before, storage.root(), std::forward<D>(data)); } template <typename C, typename I = Impl, - if_canInsertColumns<I> = true, if_compatible_data_range<C> = true> + if_canInsertColumns<I> = true, if_compatible_column_range<C> = true> bool insertColumns(int before, C &&data) { return insertColumnsImpl(before, storage.root(), std::forward<C>(data)); diff --git a/src/corelib/itemmodels/qrangemodeladapter.qdoc b/src/corelib/itemmodels/qrangemodeladapter.qdoc index ff595529d34..88872589299 100644 --- a/src/corelib/itemmodels/qrangemodeladapter.qdoc +++ b/src/corelib/itemmodels/qrangemodeladapter.qdoc @@ -277,14 +277,6 @@ */ /*! - \typedef QRangeModelAdapter::const_row_reference -*/ - -/*! - \typedef QRangeModelAdapter::row_reference -*/ - -/*! \typedef QRangeModelAdapter::range_type */ @@ -531,8 +523,8 @@ */ /*! - \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> QRangeModelAdapter<Range, Protocol, Model>::const_row_reference QRangeModelAdapter<Range, Protocol, Model>::at(int row) const - \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> QRangeModelAdapter<Range, Protocol, Model>::const_row_reference QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) const + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::at(int row) const + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) const \return a constant reference to the row at \a row, as stored in \c Range. @@ -540,8 +532,8 @@ */ /*! - \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> QRangeModelAdapter<Range, Protocol, Model>::row_reference QRangeModelAdapter<Range, Protocol, Model>::at(int row) - \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> QRangeModelAdapter<Range, Protocol, Model>::row_reference QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row) + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) \return a mutable reference to the row at \a row, as stored in \c Range. @@ -597,6 +589,16 @@ */ /*! + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path) const + \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path) const + + \return a constant reference to the row specified by \a path, as stored in + \c Range. + + \constraints \c Range is a tree. +*/ + +/*! \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path) \fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path) @@ -833,7 +835,7 @@ */ /*! - \fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_data<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before, D &&data) + \fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_data<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before, D &&data) \overload Inserts a single column constructed from \a data before the column specified @@ -861,7 +863,7 @@ */ /*! - \fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_data_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumns(int before, C &&data) + \fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumns(int before, C &&data) Inserts columns constructed from the elements in \a data before the column specified by \a before into all rows, and returns whether the insertion was diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 371ee524d72..d6c185cd704 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -845,7 +845,7 @@ struct UnwrapHandler using NestedType = typename QtPrivate::Future<ResultType>::type; QFutureInterface<NestedType> promise(QFutureInterfaceBase::State::Pending); - outer->then([promise](const QFuture<ResultType> &outerFuture) mutable { + auto chain = outer->then([promise](const QFuture<ResultType> &outerFuture) mutable { // We use the .then([](QFuture<ResultType> outerFuture) {...}) version // (where outerFuture == *outer), to propagate the exception if the // outer future has failed. @@ -883,6 +883,13 @@ struct UnwrapHandler promise.reportCanceled(); promise.reportFinished(); }); + + // Inject the promise into the chain. + // We use a fake function as a continuation, since the promise is + // managed by the outer future + chain.d.setContinuation(ContinuationWrapper(std::move([](const QFutureInterfaceBase &) {})), + promise.d, QFutureInterfaceBase::ContinuationType::Then); + return promise.future(); } }; diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index 0b88013800e..ff17560d3a1 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -42,6 +42,8 @@ template<class Function, class ResultType> class FailureHandler; #endif +struct UnwrapHandler; + #if QT_CORE_REMOVED_SINCE(6, 10) void Q_CORE_EXPORT watchContinuationImpl(const QObject *context, QtPrivate::QSlotObjectBase *slotObj, @@ -187,6 +189,8 @@ private: friend class QtPrivate::FailureHandler; #endif + friend struct QtPrivate::UnwrapHandler; + #if QT_CORE_REMOVED_SINCE(6, 10) friend Q_CORE_EXPORT void QtPrivate::watchContinuationImpl( const QObject *context, QtPrivate::QSlotObjectBase *slotObj, QFutureInterfaceBase &fi); diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 96e35dcb965..2a1af2315ca 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -234,14 +234,14 @@ QBasicReadWriteLock::contendedTryLockForRead(QDeadlineTimer timeout, void *dd) return d->recursiveLockForRead(timeout); auto lock = qt_unique_lock(d->mutex); - if (d != d_ptr.loadRelaxed()) { + if (QReadWriteLockPrivate *dd = d_ptr.loadAcquire(); d != dd) { // d_ptr has changed: this QReadWriteLock was unlocked before we had // time to lock d->mutex. // We are holding a lock to a mutex within a QReadWriteLockPrivate // that is already released (or even is already re-used). That's ok // because the QFreeList never frees them. // Just unlock d->mutex (at the end of the scope) and retry. - d = d_ptr.loadAcquire(); + d = dd; continue; } return d->lockForRead(lock, timeout); @@ -340,11 +340,11 @@ QBasicReadWriteLock::contendedTryLockForWrite(QDeadlineTimer timeout, void *dd) return d->recursiveLockForWrite(timeout); auto lock = qt_unique_lock(d->mutex); - if (d != d_ptr.loadRelaxed()) { + if (QReadWriteLockPrivate *dd = d_ptr.loadAcquire(); d != dd) { // The mutex was unlocked before we had time to lock the mutex. // We are holding to a mutex within a QReadWriteLockPrivate that is already released // (or even is already re-used) but that's ok because the QFreeList never frees them. - d = d_ptr.loadAcquire(); + d = dd; continue; } return d->lockForWrite(lock, timeout); diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index de68a0042ac..ce35e8ccffe 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -332,8 +332,6 @@ struct TCBPoint qreal _c; qreal _b; - TCBPoint() {} - TCBPoint(QPointF point, qreal t, qreal c, qreal b) : _point(point), _t(t), _c(c), _b(b) {} bool operator==(const TCBPoint &other) const { @@ -1381,7 +1379,7 @@ void QEasingCurve::addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qre if (!d_ptr->config) d_ptr->config = curveToFunctionObject(d_ptr->type); - d_ptr->config->_tcbPoints.append(TCBPoint(nextPoint, t, c, b)); + d_ptr->config->_tcbPoints.append(TCBPoint{nextPoint, t, c, b}); if (nextPoint == QPointF(1.0, 1.0)) { d_ptr->config->_bezierCurves = tcbToBezier(d_ptr->config->_tcbPoints); diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index b517d85c5fb..161d95db49c 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -28,7 +28,16 @@ using namespace Qt::StringLiterals; -#define EXIT_ERROR -1 + +// QTest-based test processes may exit with up to 127 for normal test failures +static constexpr int HIGHEST_QTEST_EXITCODE = 127; +// Something went wrong in androidtestrunner, in general +static constexpr int EXIT_ERROR = 254; +// More specific exit codes for failures in androidtestrunner: +static constexpr int EXIT_NOEXITCODE = 253; // Failed to transfer exit code from device +static constexpr int EXIT_ANR = 252; // Android ANR error (Application Not Responding) +static constexpr int EXIT_NORESULTS = 251; // Failed to transfer result files from device + struct Options { @@ -71,6 +80,13 @@ struct TestInfo static TestInfo g_testInfo; +// QTest-based processes return 0 if all tests PASSed, or the number of FAILs up to 127. +// Other exitcodes signify abnormal termination and are system-dependent. +static bool isTestExitCodeNormal(const int ec) +{ + return (ec >= 0 && ec <= HIGHEST_QTEST_EXITCODE); +} + static bool execCommand(const QString &program, const QStringList &args, QByteArray *output = nullptr, bool verbose = false) { @@ -744,9 +760,9 @@ void printLogcatCrash(const QByteArray &logcat) } if (!crashLogcat.startsWith("********** Crash dump")) - qDebug() << "********** Crash dump: **********"; + qDebug() << "[androidtestrunner] ********** BEGIN crash dump **********"; qDebug().noquote() << crashLogcat.trimmed(); - qDebug() << "********** End crash dump **********"; + qDebug() << "[androidtestrunner] ********** END crash dump **********"; } void analyseLogcat(const QString &timeStamp, int *exitCode) @@ -781,10 +797,13 @@ void analyseLogcat(const QString &timeStamp, int *exitCode) // Check for ANRs const bool anrOccurred = logcat.contains("ANR in %1"_L1.arg(g_options.package).toUtf8()); if (anrOccurred) { - // Treat a found ANR as a test failure. - *exitCode = *exitCode < 1 ? 1 : *exitCode; - qCritical("An ANR has occurred while running the test %s. The logcat will include " - "additional logs from the system_server process.", + // Rather improbable, but if the test managed to return a non-crash exitcode then overwrite + // it to signify that something blew up. Same if we didn't manage to collect an exit code. + // Preserve all other exitcodes, they might be useful crash information from the device. + if (isTestExitCodeNormal(*exitCode) || *exitCode == EXIT_NOEXITCODE) + *exitCode = EXIT_ANR; + qCritical("[androidtestrunner] An ANR has occurred while running the test '%s';" + " consult logcat for additional logs from the system_server process", qPrintable(g_options.package)); } @@ -818,13 +837,14 @@ void analyseLogcat(const QString &timeStamp, int *exitCode) } } - // If we have a crash, attempt to print both logcat and the crash buffer which - // includes the crash stacktrace that is not included in the default logcat. - const bool testCrashed = *exitCode == EXIT_ERROR && !g_testInfo.isTestRunnerInterrupted.load(); + // If we have an unpredictable exitcode, possibly a crash, attempt to print both logcat and the + // crash buffer which includes the crash stacktrace that is not included in the default logcat. + const bool testCrashed = ( !isTestExitCodeNormal(*exitCode) + && !g_testInfo.isTestRunnerInterrupted.load()); if (testCrashed) { - qDebug() << "********** logcat dump **********"; + qDebug() << "[androidtestrunner] ********** BEGIN logcat dump **********"; qDebug().noquote() << testLogcat.join(u'\n').trimmed(); - qDebug() << "********** End logcat dump **********"; + qDebug() << "[androidtestrunner] ********** END logcat dump **********"; if (!crashLogcat.isEmpty()) printLogcatCrash(crashLogcat); @@ -839,7 +859,7 @@ static QString getCurrentTimeString() QStringList dateArgs = { "shell"_L1, "date"_L1, "+'%1'"_L1.arg(timeFormat) }; QByteArray output; if (!execAdbCommand(dateArgs, &output, false)) { - qWarning() << "Date/time adb command failed"; + qWarning() << "[androidtestrunner] ERROR in command: adb shell date"; return {}; } @@ -851,14 +871,15 @@ static int testExitCode() QByteArray exitCodeOutput; const QString exitCodeCmd = "cat files/qtest_last_exit_code 2> /dev/null"_L1; if (!execAdbCommand({ "shell"_L1, runCommandAsUserArgs(exitCodeCmd) }, &exitCodeOutput, false)) { - qCritical() << "Failed to retrieve the test exit code."; - return EXIT_ERROR; + qCritical() << "[androidtestrunner] ERROR in command: adb shell cat files/qtest_last_exit_code"; + return EXIT_NOEXITCODE; } + qDebug() << "[androidtestrunner] Test exitcode: " << exitCodeOutput; bool ok; int exitCode = exitCodeOutput.toInt(&ok); - return ok ? exitCode : EXIT_ERROR; + return ok ? exitCode : EXIT_NOEXITCODE; } static bool uninstallTestPackage() @@ -899,7 +920,7 @@ void sigHandler(int signal) // a main event loop. Since, there's no other alternative to do this, // let's do the cleanup anyway. if (!g_testInfo.isPackageInstalled.load()) - _exit(-1); + _exit(EXIT_ERROR); g_testInfo.isTestRunnerInterrupted.store(true); } @@ -1031,7 +1052,9 @@ int main(int argc, char *argv[]) if (g_options.showLogcatOutput) analyseLogcat(formattedStartTime, &exitCode); - exitCode = pullResults() ? exitCode : EXIT_ERROR; + const bool pullRes = pullResults(); + if (!pullRes && isTestExitCodeNormal(exitCode)) + exitCode = EXIT_NORESULTS; if (!uninstallTestPackage()) return EXIT_ERROR; diff --git a/src/tools/configure.cmake b/src/tools/configure.cmake index 27ea90b89ac..07e11dd935b 100644 --- a/src/tools/configure.cmake +++ b/src/tools/configure.cmake @@ -37,7 +37,7 @@ qt_feature("qmake" PRIVATE QT_FEATURE_datestring AND QT_FEATURE_regularexpression AND QT_FEATURE_temporaryfile) qt_feature("qtwaylandscanner" PRIVATE - CONDITION TARGET Wayland::Scanner + CONDITION TARGET Wayland::Scanner AND NOT INTEGRITY AND NOT ANDROID AND NOT WASM AND NOT IOS AND NOT QNX AND NOT VXWORKS ) qt_configure_add_summary_section(NAME "Core tools") diff --git a/src/widgets/accessible/qaccessiblecolorwell.cpp b/src/widgets/accessible/qaccessiblecolorwell.cpp index ca08e511e9a..64fcd2a7fd1 100644 --- a/src/widgets/accessible/qaccessiblecolorwell.cpp +++ b/src/widgets/accessible/qaccessiblecolorwell.cpp @@ -3,6 +3,8 @@ #include "private/qaccessiblecolorwell_p.h" +#include <QtCore/qcoreapplication.h> + QT_REQUIRE_CONFIG(accessibility); #if QT_CONFIG(colordialog) @@ -14,6 +16,7 @@ class QAccessibleColorWellItem : public QAccessibleInterface { QAccessibleColorWell *m_parent; + Q_DECLARE_TR_FUNCTIONS(QAccessibleColorWellItem) public: QAccessibleColorWellItem(QAccessibleColorWell *parent); @@ -79,7 +82,7 @@ QString QAccessibleColorWellItem::text(QAccessible::Text t) const if (t == QAccessible::Name) { QRgb color = m_parent->colorWell()->rgbValues()[m_parent->indexOfChild(this)]; //: Color specified via its 3 RGB components (red, green, blue) - return QObject::tr("RGB %1, %2, %3") + return tr("RGB %1, %2, %3") .arg(QString::number(qRed(color)), QString::number(qGreen(color)), QString::number(qBlue(color))); } diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 3417d93d587..97332cd7d5d 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -6,15 +6,12 @@ #include <qapplication.h> #include <qevent.h> -#include <qpointer.h> #include <qstyle.h> #include <qstyleoption.h> #include <qstylepainter.h> #if QT_CONFIG(effects) #include <private/qeffects_p.h> #endif -#include <qtextdocument.h> -#include <qdebug.h> #include <qpa/qplatformscreen.h> #include <qpa/qplatformcursor.h> #if QT_CONFIG(style_stylesheet) @@ -23,12 +20,9 @@ #include <qpa/qplatformwindow.h> #include <qpa/qplatformwindow_p.h> -#include <qlabel.h> #include <QtWidgets/private/qlabel_p.h> #include <QtGui/private/qhighdpiscaling_p.h> #include <qtooltip.h> - -#include <QtCore/qbasictimer.h> #include <QtWidgets/private/qtooltip_p.h> QT_BEGIN_NAMESPACE @@ -190,10 +184,10 @@ void QTipLabel::resizeEvent(QResizeEvent *e) void QTipLabel::mouseMoveEvent(QMouseEvent *e) { if (!rect.isNull()) { - QPoint pos = e->globalPosition().toPoint(); + QPointF pos = e->globalPosition(); if (widget) pos = widget->mapFromGlobal(pos); - if (!rect.contains(pos)) + if (!rect.contains(pos.toPoint())) hideTip(); } QLabel::mouseMoveEvent(e); diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 90c1cfb4b86..592b70ef8ba 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1994,12 +1994,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget); if (!tab->icon.isNull()) { - QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, QStyleHelper::getDpr(p), - (tab->state & State_Enabled) ? QIcon::Normal - : QIcon::Disabled, - (tab->state & State_Selected) ? QIcon::On - : QIcon::Off); - p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon); + const auto mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; + const auto state = (tab->state & State_Selected) ? QIcon::On : QIcon::Off; + tab->icon.paint(p, iconRect, Qt::AlignCenter, mode, state); } proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index ac8aece707b..7dd9340f51b 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -4,6 +4,9 @@ # Order by dependency [*], then alphabetic. [*] If bugs in part A of # our source would break tests of part B, then test A before B. + +add_subdirectory(util/testrunner) + set(run_dbus_tests OFF) if (QT_FEATURE_dbus) set(run_dbus_tests ON) diff --git a/tests/auto/corelib/itemmodels/qrangemodeladapter/tst_qrangemodeladapter.cpp b/tests/auto/corelib/itemmodels/qrangemodeladapter/tst_qrangemodeladapter.cpp index ef4a535dcac..29e26f99bdd 100644 --- a/tests/auto/corelib/itemmodels/qrangemodeladapter/tst_qrangemodeladapter.cpp +++ b/tests/auto/corelib/itemmodels/qrangemodeladapter/tst_qrangemodeladapter.cpp @@ -220,8 +220,8 @@ API_TEST(moveRows, moveRows(0, 0, 0)) API_TEST(moveTreeRows, moveRows(QList<int>{0, 0}, 0, QList<int>{0, 0})) API_TEST(insertColumn, insertColumn(0)) -API_TEST(insertColumnWithData, insertColumn(0, {})) -API_TEST(insertColumns, insertColumns(0, std::declval<Range&>())) +API_TEST(insertColumnWithData, insertColumn(0, QList<int>{0})) +API_TEST(insertColumns, insertColumns(0, QList<int>{0})) API_TEST(removeColumn, removeColumn(0)) API_TEST(removeColumns, removeColumns(0, 0)) API_TEST(moveColumn, moveColumn(0, 0)) @@ -849,7 +849,7 @@ void tst_QRangeModelAdapter::insertColumn_API() static_assert(has_insertColumnWithData(d.tableOfNumbers)); static_assert(!has_insertColumnWithData(d.constTableOfNumbers)); - static_assert(has_insertColumnWithData(d.tableOfPointers)); + static_assert(!has_insertColumnWithData(d.tableOfPointers)); } void tst_QRangeModelAdapter::insertColumns_API() @@ -863,7 +863,7 @@ void tst_QRangeModelAdapter::insertColumns_API() static_assert(has_insertColumns(d.tableOfNumbers)); static_assert(!has_insertColumns(d.constTableOfNumbers)); - static_assert(has_insertColumns(d.tableOfPointers)); + static_assert(!has_insertColumns(d.tableOfPointers)); static_assert(!has_insertColumns(d.tableOfRowPointers)); static_assert(!has_insertColumns(d.listOfNamedRoles)); static_assert(!has_insertColumns(d.m_tree)); diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 806b6b43161..f7d98eb15e2 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -5656,6 +5656,12 @@ void tst_QFuture::cancelChainWithContext() int onCancelCnt = 0; bool unexpectedThread = false; + // For in-other-thread case we need a semaphore to make sure that + // the needed continuation is executed. + // Fot the in-main-thread case it's guaranteed by the unwrap() + // implementation. + QSemaphore sem; + auto f = p1.future() .then(context, [&]() { if (QThread::currentThread() != thread) @@ -5666,6 +5672,8 @@ void tst_QFuture::cancelChainWithContext() if (QThread::currentThread() != thread) unexpectedThread = true; ++thenCnt; + if (inOtherThread) + sem.release(); return f; }).unwrap() .then(context, [&]{ @@ -5685,6 +5693,8 @@ void tst_QFuture::cancelChainWithContext() }); p1.finish(); + if (inOtherThread) + sem.acquire(); f.cancelChain(); p2.finish(); f.waitForFinished(); @@ -5737,6 +5747,75 @@ void tst_QFuture::cancelChainWithContext() QCOMPARE_EQ(thenCnt, 4); QCOMPARE_EQ(onCancelCnt, 0); } + // cancelling propagates through unwrap() + { + QPromise<void> p1, p2; + p1.start(); + p2.start(); + + int thenCnt = 0; + int onCancelCnt = 0; + bool unexpectedThread = false; + + // For in-other-thread case we need a semaphore to make sure that + // the first continuation is executed. + // Fot the in-main-thread case it's guaranteed by the unwrap() + // implementation. + QSemaphore sem; + + auto f = p1.future() + .then(context, [&, f2 = p2.future()]() { + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++thenCnt; + if (inOtherThread) + sem.release(); + return f2; + }).unwrap() + .onCanceled(context, [&] { + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++onCancelCnt; + }) + .then([&]() { + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++thenCnt; + return QtFuture::makeReadyVoidFuture(); + }).unwrap() + .onCanceled([&] { + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++onCancelCnt; + }) + .then(context, [&]{ + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++thenCnt; + return QtFuture::makeReadyVoidFuture(); + }).unwrap() + .onCanceled([&] { + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++onCancelCnt; + }) + .then(context, [&]{ + if (QThread::currentThread() != thread) + unexpectedThread = true; + ++thenCnt; + }); + + p1.finish(); + if (inOtherThread) + sem.acquire(); + f.cancelChain(); + p2.finish(); + f.waitForFinished(); + + QVERIFY(!unexpectedThread); + QCOMPARE_EQ(thenCnt, 1); + QCOMPARE_EQ(onCancelCnt, 3); + } } void tst_QFuture::cancelChainOnAnOverwrittenFuture() diff --git a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index 86dfa5faffc..4c089091f8d 100644 --- a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -57,6 +57,7 @@ private slots: void multipleReadersLoop(); void multipleWritersLoop(); void multipleReadersWritersLoop(); + void heavyLoadLocks(); void countingTest(); void limitedReaders(); void deleteOnUnlock(); @@ -603,6 +604,111 @@ public: } }; +class HeavyLoadLockThread : public QThread +{ +public: + QReadWriteLock &testRwlock; + const qsizetype iterations; + const int numThreads; + inline HeavyLoadLockThread(QReadWriteLock &l, qsizetype iters, int numThreads, QVector<QAtomicInt *> &counters): + testRwlock(l), + iterations(iters), + numThreads(numThreads), + counters(counters) + { } + +private: + QVector<QAtomicInt *> &counters; + QAtomicInt *getCounter(qsizetype index) + { + QReadLocker locker(&testRwlock); + /* + The index is increased monotonically, so the index + being requested should be always within or at the end of the + counters vector. + */ + Q_ASSERT(index <= counters.size()); + if (counters.size() <= index || counters[index] == nullptr) { + locker.unlock(); + QWriteLocker wlocker(&testRwlock); + if (counters.size() <= index) + counters.resize(index + 1, nullptr); + if (counters[index] == nullptr) + counters[index] = new QAtomicInt(0); + return counters[index]; + } + return counters[index]; + } + void releaseCounter(qsizetype index) + { + QWriteLocker locker(&testRwlock); + delete counters[index]; + counters[index] = nullptr; + } + +public: + void run() override + { + for (qsizetype i = 0; i < iterations; ++i) { + QAtomicInt *counter = getCounter(i); + /* + Here each counter is accessed by each thread + and increaed only once. As a result, when the + counter reaches numThreads, i.e. the fetched + value before the increment is numThreads-1, + we know all threads have accessed this counter + and we can delete it safely. + */ + int prev = counter->fetchAndAddRelaxed(1); + if (prev == numThreads - 1) { +#ifdef QT_BUILDING_UNDER_TSAN + /* + Under TSAN, deleting and freeing an object + will trigger a write operation on the memory + of the object. Since we used fetchAndAddRelaxed + to update the counter, TSAN will report a data + race when deleting the counter here. To avoid + the false positive, we simply reset the counter + to 0 here, with ordered semantics to establish + the sequence to ensure the the free-ing option + happens after all fetchAndAddRelaxed operations + in other threads. + + When not building under TSAN, deleting the counter + will not result in any data read or written to the + memory region of the counter, so no data race will + happen. + */ + counter->fetchAndStoreOrdered(0); +#endif + releaseCounter(i); + } + } + } +}; + +/* + Multiple threads racing acquiring and releasing + locks on the same indices. +*/ + +void tst_QReadWriteLock::heavyLoadLocks() +{ + constexpr qsizetype iterations = 65536 * 4; + constexpr int numThreads = 8; + QVector<QAtomicInt *> counters; + QReadWriteLock testLock; + std::array<std::unique_ptr<HeavyLoadLockThread>, numThreads> threads; + for (auto &thread : threads) + thread = std::make_unique<HeavyLoadLockThread>(testLock, iterations, numThreads, counters); + for (auto &thread : threads) + thread->start(); + for (auto &thread : threads) + thread->wait(); + QVERIFY(counters.size() == iterations); + for (qsizetype i = 0; i < iterations; ++i) + QVERIFY(counters[i] == nullptr); +} /* A writer acquires a read-lock, a reader locks diff --git a/tests/auto/util/testrunner/CMakeLists.txt b/tests/auto/util/testrunner/CMakeLists.txt new file mode 100644 index 00000000000..5ca8406f854 --- /dev/null +++ b/tests/auto/util/testrunner/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2025 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + + +# Run the qt-testrunner test only inside the CI. +if(DEFINED ENV{COIN_UNIQUE_JOB_ID} AND NOT IOS) + qt_internal_create_test_script( + NAME tst_qt_testrunner + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tst_qt_testrunner.py" ARGS -v + WORKING_DIRECTORY "${test_working_dir}" + OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/tst_qt_testrunner_Wrapper$<CONFIG>.cmake" + ENVIRONMENT "TESTRUNNER" "" + ) +endif() diff --git a/util/testrunner/tests/qt_mock_test-log.xml b/tests/auto/util/testrunner/qt_mock_test-log.xml index a164bec9f9c..a164bec9f9c 100644 --- a/util/testrunner/tests/qt_mock_test-log.xml +++ b/tests/auto/util/testrunner/qt_mock_test-log.xml diff --git a/util/testrunner/tests/qt_mock_test.py b/tests/auto/util/testrunner/qt_mock_test.py index eb6e33727f8..af8fdf24509 100755 --- a/util/testrunner/tests/qt_mock_test.py +++ b/tests/auto/util/testrunner/qt_mock_test.py @@ -42,7 +42,7 @@ import sys import os import traceback -from tst_testrunner import write_xml_log +from tst_qt_testrunner import write_xml_log MY_NAME = os.path.basename(sys.argv[0]) @@ -106,6 +106,15 @@ def log_test(testcase, result, testsuite=MY_NAME.rpartition(".")[0]): print("%-7s: %s::%s()" % (result, testsuite, testcase)) +def log_xml(fail_list): + if XML_OUTPUT_FILE and XML_TEMPLATE is not None: + if XML_TEMPLATE == "": + # If the template is an empty file, then write an empty output file + with open(XML_OUTPUT_FILE, "w"): + pass + else: + write_xml_log(XML_OUTPUT_FILE, failure=fail_list) + # Return the exit code def run_test(testname): if testname == "initTestCase": @@ -159,13 +168,7 @@ def no_args_run(): fail_list.append(test) total_result = total_result and (test_exit_code == 0) - if XML_OUTPUT_FILE: - if XML_TEMPLATE: - write_xml_log(XML_OUTPUT_FILE, failure=fail_list) - # If the template is an empty file, then write an empty output file - elif XML_TEMPLATE == "": - with open(XML_OUTPUT_FILE, "w"): - pass + log_xml(fail_list) if CRASH_CLEANLY: # Crash despite all going well and writing all output files cleanly. @@ -198,8 +201,14 @@ def main(): if len(args) == 0: no_args_run() assert False, "Unreachable!" - else: - sys.exit(run_test(args[0])) + else: # run single test function + exit_code = run_test(args[0]) + # Write "fail" in the XML log only if the specific run has failed. + if exit_code != 0: + log_xml([args[0]]) + else: + log_xml([]) + sys.exit(exit_code) # TODO write XPASS test that does exit(1) diff --git a/util/testrunner/tests/tst_testrunner.py b/tests/auto/util/testrunner/tst_qt_testrunner.py index fc3f97b6ece..1134fa0427f 100755 --- a/util/testrunner/tests/tst_testrunner.py +++ b/tests/auto/util/testrunner/tst_qt_testrunner.py @@ -14,7 +14,8 @@ from tempfile import TemporaryDirectory, mkstemp MY_NAME = os.path.basename(__file__) my_dir = os.path.dirname(__file__) -testrunner = os.path.join(my_dir, "..", "qt-testrunner.py") +testrunner = os.path.join(my_dir, "..", "..", "..", "..", + "util", "testrunner", "qt-testrunner.py") mock_test = os.path.join(my_dir, "qt_mock_test.py") xml_log_template = os.path.join(my_dir, "qt_mock_test-log.xml") @@ -26,7 +27,7 @@ import unittest def setUpModule(): global TEMPDIR - TEMPDIR = TemporaryDirectory(prefix="tst_testrunner-") + TEMPDIR = TemporaryDirectory(prefix="tst_qt_testrunner-") global EMPTY_FILE EMPTY_FILE = os.path.join(TEMPDIR.name, "EMPTY") @@ -40,6 +41,7 @@ def setUpModule(): os.environ["QT_MOCK_TEST_STATE_FILE"] = filename os.environ["QT_MOCK_TEST_XML_TEMPLATE_FILE"] = xml_log_template + os.environ["QT_TESTRUNNER_TESTING"] = "1" def tearDownModule(): print("\ntearDownModule(): Cleaning up temporary directory:", @@ -49,22 +51,32 @@ def tearDownModule(): # Helper to run a command and always capture output -def run(*args, **kwargs): +def run(args : list, **kwargs): + if args[0].endswith(".py"): + # Make sure we run python executables with the same python version. + # It also helps on Windows, that .py files are not directly executable. + args = [ sys.executable, *args ] if DEBUG: print("Running: ", args, flush=True) - proc = subprocess.run(*args, stdout=PIPE, stderr=STDOUT, **kwargs) + proc = subprocess.run(args, stdout=PIPE, stderr=STDOUT, **kwargs) if DEBUG and proc.stdout: print(proc.stdout.decode(), flush=True) return proc # Helper to run qt-testrunner.py with proper testing arguments. -def run_testrunner(xml_filename=None, testrunner_args=None, +# Always append --log-dir=TEMPDIR unless specifically told not to. +def run_testrunner(xml_filename=None, log_dir=None, + testrunner_args=None, wrapper_script=None, wrapper_args=None, qttest_args=None, env=None): args = [ testrunner ] if xml_filename: args += [ "--parse-xml-testlog", xml_filename ] + if log_dir == None: + args += [ "--log-dir", TEMPDIR.name ] + elif log_dir != "": + args += [ "--log-dir", log_dir ] if testrunner_args: args += testrunner_args @@ -156,7 +168,7 @@ class Test_qt_mock_test(unittest.TestCase): # Test it will write an empty XML file if template is empty def test_empty_xml_file_is_written(self): my_env = { - "QT_MOCK_TEST_STATE_FILE": os.environ["QT_MOCK_TEST_STATE_FILE"], + **os.environ, "QT_MOCK_TEST_XML_TEMPLATE_FILE": EMPTY_FILE } filename = os.path.join(TEMPDIR.name, "testlog.xml") @@ -167,13 +179,26 @@ class Test_qt_mock_test(unittest.TestCase): self.assertEqual(os.path.getsize(filename), 0) os.remove(filename) def test_crash_cleanly(self): - proc = run(mock_test, - env= os.environ | {"QT_MOCK_TEST_CRASH_CLEANLY":"1"} ) + proc = run([mock_test], + env={ **os.environ, "QT_MOCK_TEST_CRASH_CLEANLY":"1" }) if DEBUG: print("returncode:", proc.returncode) self.assertProcessCrashed(proc) +# Find in @path, files that start with @testname and end with @pattern, +# where @pattern is a glob-like string. +def find_test_logs(testname=None, path=None, pattern="-*[0-9].xml"): + if testname is None: + testname = os.path.basename(mock_test) + if path is None: + path = TEMPDIR.name + pattern = os.path.join(path, testname + pattern) + logfiles = glob.glob(pattern) + if DEBUG: + print(f"Test ({testname}) logfiles found: ", logfiles) + return logfiles + # Test regular invocations of qt-testrunner. class Test_testrunner(unittest.TestCase): def setUp(self): @@ -181,14 +206,11 @@ class Test_testrunner(unittest.TestCase): if os.path.exists(state_file): os.remove(state_file) # The mock_test honors only the XML output arguments, the rest are ignored. - old_logfiles = glob.glob(os.path.basename(mock_test) + "*.xml", - root_dir=TEMPDIR.name) + old_logfiles = find_test_logs(pattern="*.xml") for fname in old_logfiles: os.remove(os.path.join(TEMPDIR.name, fname)) - self.env = dict() - self.env["QT_MOCK_TEST_XML_TEMPLATE_FILE"] = os.environ["QT_MOCK_TEST_XML_TEMPLATE_FILE"] - self.env["QT_MOCK_TEST_STATE_FILE"] = state_file - self.testrunner_args = [ "--log-dir", TEMPDIR.name ] + self.env = dict(os.environ) + self.testrunner_args = [] def prepare_env(self, run_list=None): if run_list is not None: self.env['QT_MOCK_TEST_RUN_LIST'] = ",".join(run_list) @@ -205,11 +227,7 @@ class Test_testrunner(unittest.TestCase): self.assertEqual(proc.returncode, 0) def test_output_files_are_generated(self): proc = self.run2() - xml_output_files = glob.glob(os.path.basename(mock_test) + "-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("Output files found: ", - xml_output_files) + xml_output_files = find_test_logs() self.assertEqual(len(xml_output_files), 1) def test_always_fail(self): self.prepare_env(run_list=["always_fail"]) @@ -242,9 +260,33 @@ class Test_testrunner(unittest.TestCase): proc = self.run2() self.assertEqual(proc.returncode, 3) + # By testing --no-extra-args, we ensure qt-testrunner works for + # tst_selftests and the other NON_XML_GENERATING_TESTS. + def test_no_extra_args_pass(self): + self.testrunner_args += ["--no-extra-args"] + proc = self.run2() + self.assertEqual(proc.returncode, 0) + def test_no_extra_args_fail(self): + self.prepare_env(run_list=["always_fail"]) + self.testrunner_args += ["--no-extra-args"] + proc = self.run2() + self.assertEqual(proc.returncode, 3) + def test_no_extra_args_reruns_only_once_1(self): + self.prepare_env(run_list=["fail_then_pass:1"]) + self.testrunner_args += ["--no-extra-args"] + proc = self.run2() + # The 1st rerun PASSed. + self.assertEqual(proc.returncode, 0) + def test_no_extra_args_reruns_only_once_2(self): + self.prepare_env(run_list=["fail_then_pass:2"]) + self.testrunner_args += ["--no-extra-args"] + proc = self.run2() + # We never re-run more than once, so the exit code shows FAIL. + self.assertEqual(proc.returncode, 3) + # If no XML file is found by qt-testrunner, it is usually considered a # CRASH and the whole test is re-run. Even when the return code is zero. - # It is a PASS only if the test is not capable of XML output (see no_extra_args, TODO test it). + # It is a PASS only if the test is not capable of XML output (see no_extra_args above). def test_no_xml_log_written_pass_crash(self): del self.env["QT_MOCK_TEST_XML_TEMPLATE_FILE"] self.prepare_env(run_list=["always_pass"]) @@ -363,8 +405,6 @@ class Test_testrunner(unittest.TestCase): if not content: content='exec "$@"' filename = os.path.join(TEMPDIR.name, filename) - # if os.path.exists(filename): - # os.remove(filename) with open(filename, "w") as f: f.write(f'#!/bin/sh\n{content}\n') self.wrapper_script = f.name @@ -381,10 +421,7 @@ class Test_testrunner(unittest.TestCase): self.assertEqual(proc.returncode, 3) # Verify that a full executable re-run happened that re-runs 2 times, # instead of individual functions that re-run 5 times. - xml_output_files = glob.glob(os.path.basename(mock_test) + "-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("XML output files found: ", xml_output_files) + xml_output_files = find_test_logs() self.assertEqual(len(xml_output_files), 2) # Test that qt-testrunner detects the correct executable name even if we @@ -393,13 +430,9 @@ class Test_testrunner(unittest.TestCase): def test_wrapper(self): self.create_wrapper("coin_vxworks_qemu_runner.sh") proc = run_testrunner(wrapper_script=self.wrapper_script, - testrunner_args=["--log-dir",TEMPDIR.name], env=self.env) self.assertEqual(proc.returncode, 0) - xml_output_files = glob.glob(os.path.basename(mock_test) + "-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("XML output files found: ", xml_output_files) + xml_output_files = find_test_logs() self.assertEqual(len(xml_output_files), 1) # The "androidtestrunner" wrapper is special. It expects the QTest arguments after "--". @@ -412,48 +445,47 @@ class Test_testrunner(unittest.TestCase): @unittest.skipUnless(os.name == "posix", "Wrapper script needs POSIX shell") def test_androidtestrunner_with_aab(self): self.create_mock_anroidtestrunner_wrapper() - # Copied verbatim from our CI logs. The only relevant option is --aab. - androidtestrunner_args= ['--path', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup', '--adb', '/opt/android/sdk/platform-tools/adb', '--skip-install-root', '--ndk-stack', '/opt/android/android-ndk-r27c/ndk-stack', '--manifest', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup/app/AndroidManifest.xml', '--make', '"/opt/cmake-3.30.5/bin/cmake" --build /home/qt/work/qt/qtdeclarative_standalone_tests --target tst_qquickpopup_make_aab', '--aab', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup/tst_qquickpopup.aab', '--bundletool', '/opt/bundletool/bundletool', '--timeout', '1425'] + # Copied from our CI logs. The only relevant option is --aab. + androidtestrunner_args= [ + '--path', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup', + '--adb', '/opt/android/sdk/platform-tools/adb', '--skip-install-root', + '--ndk-stack', '/opt/android/android-ndk-r27c/ndk-stack', + '--manifest', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup/app/AndroidManifest.xml', + '--make', '"/opt/cmake-3.30.5/bin/cmake" --build /home/qt/work/qt/qtdeclarative_standalone_tests --target tst_qquickpopup_make_aab', + '--aab', '/home/qt/work/qt/qtdeclarative_standalone_tests/tests/auto/quickcontrols/qquickpopup/android-build-tst_qquickpopup/tst_qquickpopup.aab', + '--bundletool', '/opt/bundletool/bundletool', '--timeout', '1425' + ] # In COIN CI, TESTRUNNER="qt-testrunner.py --". That's why we append "--". - proc = run_testrunner(testrunner_args=["--log-dir", TEMPDIR.name, "--"], + proc = run_testrunner(testrunner_args=["--"], wrapper_script=self.wrapper_script, wrapper_args=androidtestrunner_args, env=self.env) self.assertEqual(proc.returncode, 0) - xml_output_files = glob.glob("tst_qquickpopup-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("XML output files found: ", xml_output_files) + xml_output_files = find_test_logs("tst_qquickpopup") self.assertEqual(len(xml_output_files), 1) # similar to above but with "--apk" @unittest.skipUnless(os.name == "posix", "Wrapper script needs POSIX shell") def test_androidtestrunner_with_apk(self): self.create_mock_anroidtestrunner_wrapper() androidtestrunner_args= ['--blah', '--apk', '/whatever/waza.apk', 'blue'] - proc = run_testrunner(testrunner_args=["--log-dir", TEMPDIR.name, "--"], + proc = run_testrunner(testrunner_args=["--"], wrapper_script=self.wrapper_script, wrapper_args=androidtestrunner_args, env=self.env) self.assertEqual(proc.returncode, 0) - xml_output_files = glob.glob("waza-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("XML output files found: ", xml_output_files) + xml_output_files = find_test_logs("waza") self.assertEqual(len(xml_output_files), 1) # similar to above but with neither "--apk" nor "--aab". qt-testrunner throws error. @unittest.skipUnless(os.name == "posix", "Wrapper script needs POSIX shell") def test_androidtestrunner_fail_to_detect_filename(self): self.create_mock_anroidtestrunner_wrapper() androidtestrunner_args= ['--blah', '--argh', '/whatever/waza.apk', 'waza.aab'] - proc = run_testrunner(testrunner_args=["--log-dir", TEMPDIR.name, "--"], + proc = run_testrunner(testrunner_args=["--"], wrapper_script=self.wrapper_script, wrapper_args=androidtestrunner_args, env=self.env) self.assertEqual(proc.returncode, 1) - xml_output_files = glob.glob("waza-*[0-9].xml", - root_dir=TEMPDIR.name) - if DEBUG: - print("XML output files found: ", xml_output_files) + xml_output_files = find_test_logs("waza") self.assertEqual(len(xml_output_files), 0) @@ -477,28 +509,32 @@ class Test_testrunner_with_xml_logfile(unittest.TestCase): (_handle, self.xml_file) = mkstemp( suffix=".xml", prefix="qt_mock_test-log-", dir=TEMPDIR.name) + os.close(_handle) if os.path.exists(os.environ["QT_MOCK_TEST_STATE_FILE"]): os.remove(os.environ["QT_MOCK_TEST_STATE_FILE"]) def tearDown(self): os.remove(self.xml_file) del self.xml_file + # Run testrunner specifically for the tests here, with --parse-xml-testlog. + def run3(self, testrunner_args=None): + return run_testrunner(self.xml_file, + testrunner_args=testrunner_args) def test_no_failure(self): write_xml_log(self.xml_file, failure=None) - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 0) def test_always_pass_failed(self): write_xml_log(self.xml_file, failure="always_pass") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 0) def test_always_pass_failed_max_repeats_0(self): write_xml_log(self.xml_file, failure="always_pass") - proc = run_testrunner(self.xml_file, - testrunner_args=["--max-repeats", "0"]) + proc = self.run3(testrunner_args=["--max-repeats", "0"]) self.assertEqual(proc.returncode, 2) def test_always_fail_failed(self): write_xml_log(self.xml_file, failure="always_fail") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 2) # Assert that one of the re-runs was in verbose mode matches = re.findall("VERBOSE RUN", @@ -508,20 +544,20 @@ class Test_testrunner_with_xml_logfile(unittest.TestCase): self.assertIn("QT_LOGGING_RULES", proc.stdout.decode()) def test_always_crash_crashed(self): write_xml_log(self.xml_file, failure="always_crash") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 3) def test_fail_then_pass_2_failed(self): write_xml_log(self.xml_file, failure="fail_then_pass:2") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 0) def test_fail_then_pass_5_failed(self): write_xml_log(self.xml_file, failure="fail_then_pass:5") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 2) def test_with_two_failures(self): write_xml_log(self.xml_file, failure=["always_pass", "fail_then_pass:2"]) - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 0) # Check that test output is properly interleaved with qt-testrunner's logging. matches = re.findall(r"(PASS|FAIL!).*\n.*Test process exited with code", @@ -529,7 +565,7 @@ class Test_testrunner_with_xml_logfile(unittest.TestCase): self.assertEqual(len(matches), 4) def test_initTestCase_fail_crash(self): write_xml_log(self.xml_file, failure="initTestCase") - proc = run_testrunner(self.xml_file) + proc = self.run3() self.assertEqual(proc.returncode, 3) diff --git a/util/testrunner/README b/util/testrunner/README index 5758e325140..cb6722ac807 100644 --- a/util/testrunner/README +++ b/util/testrunner/README @@ -15,10 +15,4 @@ It offers the following functionality The script itself has a testsuite that is simply run by invoking -qtbase/util/testrunner/tests/tst_testrunner.py - -Please *run this manually* before submitting a change to qt-testrunner and -make sure it's passing. The reason it does not run automatically during the -usual qtbase test run, is because -+ the test run should not depend on Python -+ we don't want to wrap the testrunner tests with testrunner. +qtbase/tests/auto/util/testrunner/tst_qt_testrunner.py diff --git a/util/testrunner/qt-testrunner.py b/util/testrunner/qt-testrunner.py index 6437c3fe7f1..1573534cee9 100755 --- a/util/testrunner/qt-testrunner.py +++ b/util/testrunner/qt-testrunner.py @@ -4,10 +4,9 @@ # !!!IMPORTANT!!! If you change anything to this script, run the testsuite -# manually and make sure it still passes, as it doesn't run automatically. -# Just execute the command line as such: +# and make sure it still passes: # -# ./util/testrunner/tests/tst_testrunner.py -v [--debug] +# qtbase/tests/auto/util/testrunner/tst_qt_testrunner.py -v [--debug] # # ======== qt-testrunner ======== # @@ -92,6 +91,8 @@ class WhatFailed(NamedTuple): class ReRunCrash(Exception): pass +class BadXMLCrash(Exception): + pass # In the last test re-run, we add special verbosity arguments, in an attempt @@ -255,7 +256,7 @@ def parse_log(results_file) -> WhatFailed: root = tree.getroot() if root.tag != "TestCase": - raise AssertionError( + raise BadXMLCrash( f"The XML test log must have <TestCase> as root tag, but has: <{root.tag}>") failures = [] @@ -299,6 +300,12 @@ def parse_log(results_file) -> WhatFailed: def run_test(arg_list: List[str], **kwargs): + if (os.environ.get("QT_TESTRUNNER_TESTING", "0") == "1" + and os.name == "nt" + and arg_list[0].endswith(".py") + ): + # For executing qt_mock_test.py under the same Python interpreter when testing. + arg_list = [ sys.executable ] + arg_list L.debug("Running test command line: %s", arg_list) proc = subprocess.run(arg_list, **kwargs) L.info("Test process exited with code: %d", proc.returncode) @@ -380,8 +387,19 @@ def rerun_failed_testcase(test_basename, testargs: List[str], output_dir: str, proc = run_test(testargs + output_args + VERBOSE_ARGS + [failed_arg], timeout=timeout, env={**os.environ, **VERBOSE_ENV}) + # There are platforms that run tests wrapped with some test-runner + # script, that can possibly fail to extract a process exit code. + # Because of these cases, we *also* parse the XML file and signify + # CRASH in case of QFATAL/empty/corrupt result. + what_failed = parse_log(f"{pathname_stem}.xml") + if what_failed.qfatal_message: + raise ReRunCrash(f"CRASH! returncode:{proc.returncode} " + f"QFATAL:'{what_failed.qfatal_message}'") if proc.returncode < 0 or proc.returncode >= 128: raise ReRunCrash(f"CRASH! returncode:{proc.returncode}") + if proc.returncode == 0 and len(what_failed.failed_tests) > 0: + raise ReRunCrash("CRASH! returncode:0 but failures were found: " + + what_failed.failed_tests) if proc.returncode == 0: n_passes += 1 if n_passes == passes_needed: @@ -451,6 +469,8 @@ def main(): assert len(failed_functions) > 0 and retcode != 0 break # all is fine, goto re-running individual failed testcases + except AssertionError: + raise except Exception as e: L.error("exception:%s %s", type(e).__name__, e) L.error("The test executable probably crashed, see above for details") @@ -466,9 +486,11 @@ def main(): ret = rerun_failed_testcase(args.test_basename, args.testargs, args.log_dir, test_result, args.max_repeats, args.passes_needed, dryrun=args.dry_run, timeout=args.timeout) - except ReRunCrash as e: + except AssertionError: + raise + except Exception as e: L.error("exception:%s", e) - L.error("The testcase re-run crashed, giving up") + L.error("The testcase re-run probably crashed, giving up") sys.exit(3) # Test re-run CRASH if not ret: |
