summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* Add cxx11_future in QPromise tests and disable it for VxWorksKrzysztof Sommerfeld2024-01-311-0/+22
| | | | | | | | | | | cxx11_future flag should be disabled for VxWorks. VxWorks still does have some bugs related to this std features and some parts of code needs to be excluded. At least till the 24.03 VxWorks release as for now this is the expected release that should contain fixes. Task-number: QTBUG-115777 Change-Id: Ic652403697d727f4ae05ae7287ff8285075d3802 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CI: Enable some tests under corelib/thread for Wasm platformPiotr Wierciński2023-09-141-0/+4
| | | | | | | | | | | | | This is part of our testing effort where we try enabling more tests for Web Assembly platform on CI. Not all tests work out of box, so some of them will require followup work. This commmit also introduces a new mechanism of automatically renaming files when they are added many times with the same filename to single translation unit. Change-Id: I620536494ea83aeb9b294c4a35ef72b51e85a38b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* CMake: remove check for cxx11_futureThiago Macieira2023-08-021-42/+0
| | | | | | | | | | | Everyone must have this by now. This test was 1193 ms of CMake time. Since this was a PUBLIC feature, I've left it around with a constant condition. Change-Id: Ifbf974a4d10745b099b1fffd177754538bbff245 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QPromise: Propagate cancellation through failure handlersArno Rehn2023-06-201-0/+33
| | | | | | | | | | | | | | | Previously, failure handlers did not propagate cancellation. This would lead to crashes when a QPromise was cancelled without having generated any result. Subsequent continuations would be invoked and try to access the result (which was nonexistent) and then crash. This patch propagates cancellation through failure handlers to prevent subsequent continuations from being called in the first place. Fixes: QTBUG-114606 Pick-to: 6.6 Pick-to: 6.5 Change-Id: I23b28a8e70a76e1ba6416be4440360c6dbaef2a3 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix segfault when using qfuture continuations with move only typesAhmed Essam2023-06-101-11/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using move-only types, continuations args are set using takeResult function, which has the side effect of invalidating the QFutureInterface associated with the promise/futures by: 1. setting isValid to false 2. setting the state to NoState And when the promise is destroyed, it tries to run the continuations if `finished()` is not called, which is done by checking the Finished bit in the state. But since the continuation has been run before, and the state has been set to NoState it tries to run the continuation again causing a segfault. Multiple solutions come in mind: 1. don't run the continuation if the state is NoState, but this would break the case when an empty promise is destroyed 2. check inside the continuation if it has been run before, and if so don't run it again, but this seems hacky since we don't want the continuation to be run twice, and it should break if it did. 3. when invalidating the promise leave the state as is, and change isValid only to false, which changes the current behavior, but is still compatible with the documentation which states only that isValid will return false if takeResult is called I chose option 3 I also extended some tests to test for move only types, and added a test that continuations run when a promise is finished. This simple case would segfault before with move only types. Fixes: QTBUG-112513 Pick-to: 6.5 6.6 Change-Id: Ie225ac4fdf618e4edfb0efd663d6c7fd6b916dbd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Long live QPromise::emplaceResult/At()!Marc Mutz2023-04-121-0/+8
| | | | | | | | | | | | And implement the rvalue overload of addResult() using it. [ChangeLog][QtCore][QPromise] Added emplaceResult() and emplaceResultAt() member functions. Fixes: QTBUG-112270 Change-Id: Id369542215a60c0818f1afa8d564498be84732e8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QPromise: add support for addResult(braced-initializer)Marc Mutz2023-03-281-0/+15
| | | | | | | | | | | | | The usual problem, the usual fix: default the addResult() template argument to the class template argument, cf. e.g. wg21.link/p2218. [ChangeLog][QtCore][QPromise] Added support for calls to addResult() with braced initializers. Fixes: QTBUG-111826 Change-Id: I9ad7294dbcefbc5d2609ca3d9e7304dbeb8b3f41 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QThread: add sleep(std::chrono::nanoseconds) overloadAhmad Samir2023-03-131-5/+7
| | | | | | | | | | | | | | All the other overloads are implemented using the new one. Windows change relies on the pre-check in the code review making sure it compiles. [ChangeLog][QtCore][QThread] Added sleep(std::chrono::nanoseconds) overload. Task-number: QTBUG-110059 Change-Id: I9a4f4bf09041788ec9275093b6b8d0386521e286 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live QPromise::addResults()!Marc Mutz2022-12-301-0/+9
| | | | | | | | | | | | Makes the pre-existing QFutureInterface functionality available via the public QPromise API. [ChangeLog][QtCore][QPromise] Added addResults() to report multiple results at once. Change-Id: I18e6ef2781df422020b9022d78d6c45107b01668 Reviewed-by: Sona Kurazyan <kurazyan.sona@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QPromise: run continuation(s) on destructionSona Kurazyan2022-06-221-0/+20
| | | | | | | | | | | | | | | | | | If the QFuture is canceled because the associated QPromise has been destroyed, we still need to run its continuations (i.e. onCanceled handler, if it's attached), so replaced the cleanContinuation() call inside ~QPromise() with runContinuation(), which will also take care of cleaning the continuation. [ChangeLog][QtCore][Important Behavior Changes] QFuture now runs its continuations when its associated QPromise has been destroyed. Previously, if a QFuture was canceled because the associated QPromise has been destroyed, its continuations were skipped. Fixes: QTBUG-103992 Pick-to: 6.4 6.3 6.2 Change-Id: Ie05bc760c96c349aade8adb8d2fe5263aff8efac Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-27/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Always cancel unfinished QPromises on destructionSona Kurazyan2022-03-251-0/+14
| | | | | | | | | | | | | | | | | | If the QPromise is being destroyed, we should signal the associated futures to stop waiting. No matter in which state the promise is, if it's not finished, we should always cancel to avoid infinite waits. This is also what docs state: "The promise implicitly transitions to a canceled state on destruction unless finish() is called beforehand by the user." Fixes: QTBUG-101284 Pick-to: 6.3 6.2 Change-Id: I65ebfefe03b79b41afacda78a4f49938c54d8b37 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFuture/QPromise: don't check for is_copy_constructibleGiuseppe D'Angelo2021-05-211-1/+0
| | | | | | | | | | | | | The check is over-arching. is_move_constructible is sufficient; we don't have to support "ridiculous" types that are copiable but have deleted move operations (such types are fundamentally broken). This is in line with the Move* (legacy) named requirements. Change-Id: Idc7116b39013501b9be39628a4e7afd35fe15530 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* tst_qpromise: build fixGiuseppe D'Angelo2021-04-201-4/+4
| | | | | | | | | | | | | | The test use aggregate initialization on some classes which however are no longer aggregates in C++20 (the rules changed again; in C++20 having a user-*declared* constructor makes a class not an aggregate). Just add a constructor so the code keeps compiling in both 17 and 20. Fixes: QTBUG-92963 Pick-to: 6.0 6.1 Change-Id: I52371c5ee34c84358987b5ae8bee9ab9c49c8eab Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Replace QtTest headers with QTestDavid Skoland2020-12-221-1/+1
| | | | | | | | | | | Complete search and replace of QtTest and QtTest/QtTest with QTest, as QtTest includes the whole module. Replace all such instances with correct header includes. See Jira task for more discussion. Fixes: QTBUG-88831 Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Clean-up warnings in corelib/thread testsSona Kurazyan2020-12-171-2/+2
| | | | | | | | | | | | | | Fixed the following warnings: - empty expression statement has no effect; remove unnecessary ';' to silence this warning - zero as null pointer constant - no previous extern declaration for non-static variable - use of old-style cast - integer conversion warnings Change-Id: Ieb31b127ce8e3b543aaf88a8e8fc463dcc8bc4e3 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Track progress range in QFutureInterface::setProgressValueIvan Solovev2020-11-171-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously QFutureInterface::setProgressValue was silently ignoring the progress range and allowed to set any progress value. Also no checks were performed in QFutureInterface::setProgressRange, which allowed the user to set minimum > maximum. Add checking of the current progress range, when settings the progress value. Add checks for minimum and maximum values while setting the progress range. The implementation of the checks is mostly based on the logic that is used in QProgressBar. - If maximum is smaller than minimum, minimum becomes the only legal value. - If the current progress value falls outside the new range, the progress value is set to be minimum. - If both progressMinimum() and progressMaximum() return 0, the current progress range is considered to be unused, and any progress value can be set. - When setting the value using setProgressValue(), if the value falls out of the progress range, the method has no effect. Task-number: QTBUG-84729 Change-Id: I29cf4f94b8e98e1af30dd46fbdba39c421cf66bf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Conditionally disable tests that depend on cxx11_future flagSona Kurazyan2020-11-121-0/+46
| | | | | | | Fixes: QTBUG-88392 Change-Id: I33b8ffd72be8a653e0923ef1e57305ffaf6b0428 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Rename QPromise starting and finishing methods to start and finishAndrei Golubev2020-10-161-29/+29
| | | | | | | | | Proposed during API review Change-Id: I9c43e1915c50803ab69bfe07a91c05d2224b86c4 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Make QPromise::addResult() return boolean status of operationAndrei Golubev2020-10-161-11/+11
| | | | | | | | | | | | | | | Changed QPromise::addResult() to return bool value. True is returned when result is added and false is returned when e.g. promise is in final state (canceled or finished) or when addResult() is called twice with the same index as argument (in which case new value is rejected) Updated QFutureInterface::reportFinished() that accepts optional result as argument to align with other result adding methods. This function is "internal" only (as of now), so no documentation update is needed Change-Id: I2d63069246e5e5c8cf04529c22bb296faaaae53d Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Reject overwrites by the same index in QPromise::addResult()Andrei Golubev2020-10-131-6/+13
| | | | | | | | | | | | One can call addResult(value, index) twice and consequently set the value twice by the same index. This seems rather strange and probably should not be allowed. This commit rejects setting results when there's already a valid result by that index. Consequently, this fixes memory leaks caused by N-times-called addResult(..., index) Fixes: QTBUG-86828 Change-Id: I77494f2cb73ce727ffad721cfcdcaa420899eb25 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Introduce swap functions for QPromise/QFutureInterfaceAndrei Golubev2020-08-031-5/+13
| | | | | | | | | | Made QPromise::swap public, added free standing swap() for QFutureInterface and QPromise. Updated QPromise special member functions. Extended tests Task-number: QTBUG-84977 Change-Id: I5daf6876df306d082441dbcdf5ae4dee3bfc0ead Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Document QPromise APIAndrei Golubev2020-06-181-0/+22
| | | | | | | | | Documented QPromise. Added snippets under auto tests to ensure they are compiled and run in CI. Task-number: QTBUG-81586 Change-Id: I20084e38f9d2f6fc8540f95ee03ec3d2827177e8 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Add QPromise implementationAndrei Golubev2020-06-091-0/+577
QPromise and QFuture created from it share the same internal state (namely, QFutureInterface object). QPromise provides high-level management of the shared resource, ensuring thread-safe behavior on construction and destruction (also taking into account QFuture::waitForFinished() semantics). QFuture acts as a primary controller of QPromise via action initiating methods such as suspend() or cancel(). QPromise is equipped with methods to check the status, but the actual handling of QFuture action "requests" is user-defined. [ChangeLog][QtCore][QPromise] Added QPromise class to accompany QFuture. It allows one to communicate computation results and progress to the QFuture via a shared state. Task-number: QTBUG-81586 Change-Id: Ibab9681d35fe63754bf394ad0e7923e2683e2457 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>