diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2019-12-12 14:40:29 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2020-04-15 21:34:40 +0200 |
commit | cbbb6c38fa9b64e9e4eb98af0bf687ef469aa327 (patch) | |
tree | a9597612804d552fa1711a4157ce8bf251d37b3d | |
parent | bdec52548ca739e5533792c3bf656b8e2cf9fcb6 (diff) | |
download | qtwebchannel-cbbb6c38fa9b64e9e4eb98af0bf687ef469aa327.tar.gz |
tst_webchannel: Don't use QSignalSpy for inter-thread signals
Fixes data races reported by helgrind due to direct signal connection
within QSignalSpy without any sort of serialization.
```
==840094== Possible data race during write of size 4 at 0x1FFEFFD160 by thread #3
==840094== Locks held: none
==840094== at 0x4F7DE5C: QListData::detach_grow(int*, int) (qlist.cpp:121)
==840094== by 0x125380: QList<QList<QVariant> >::detach_helper_grow(int, int) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x125598: QList<QList<QVariant> >::append(QList<QVariant> const&) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x127CEC: QSignalSpy::qt_metacall(QMetaObject::Call, int, void**) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x5149278: QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) (qmetaobject.cpp:316)
==840094== by 0x518BE13: QMetaObject::activate(QObject*, int, int, void**) (qobject.cpp:3825)
==840094== by 0x518B571: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3660)
==840094== by 0x1281F5: TestObject::propChanged(QString const&) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x1298BB: TestObject::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x5183FEC: QMetaCallEvent::placeMetaCall(QObject*) (qobject.cpp:520)
==840094== by 0x5184FFB: QObject::event(QEvent*) (qobject.cpp:1260)
==840094== by 0x513F8D7: QCoreApplicationPrivate::notify_helper(QObject*, QEvent*) (qcoreapplication.cpp:1256)
==840094==
==840094== This conflicts with a previous read of size 4 by thread #1
==840094== Locks held: none
==840094== at 0x1213FF: TestWebChannel::testAsyncObject() (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x128E03: TestWebChannel::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (in /ssd2/milian/projects/qt5/src/qtwebchannel/build/tests/auto/webchannel/tst_webchannel)
==840094== by 0x514D345: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.cpp:2308)
==840094== by 0x4DBE6E2: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.h:122)
==840094== by 0x4DB735A: QTest::TestMethods::invokeTestOnData(int) const (qtestcase.cpp:941)
==840094== by 0x4DB7EA8: QTest::TestMethods::invokeTest(int, char const*, QTest::WatchDog*) const (qtestcase.cpp:1140)
==840094== by 0x4DB92DE: QTest::TestMethods::invokeTests(QObject*) const (qtestcase.cpp:1484)
==840094== by 0x4DB9F3F: QTest::qRun() (qtestcase.cpp:1922)
==840094== Address 0x1ffeffd160 is on thread #1's stack
==840094== in frame #3, created by TestWebChannel::testAsyncObject() (???:)
```
Change-Id: Ie0d18e1d7ec970fd7fb46a5ef10699d239008f53
Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index f9719cf..a1e824b 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -955,10 +955,13 @@ void TestWebChannel::testAsyncObject() args.append(QJsonValue("message")); { - QSignalSpy spy(&obj, &TestObject::propChanged); + int received = 0; + connect(&obj, &TestObject::propChanged, this, [&](const QString &arg) { + QCOMPARE(arg, args.at(0).toString()); + ++received; + }); channel.d_func()->publisher->invokeMethod(&obj, "setProp", args); - QTRY_COMPARE(spy.count(), 1); - QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString()); + QTRY_COMPARE(received, 1); } channel.registerObject("myObj", &obj); @@ -971,12 +974,13 @@ void TestWebChannel::testAsyncObject() channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport); { - QSignalSpy spy(&obj, &TestObject::replay); + int received = 0; + connect(&obj, &TestObject::replay, this, [&]() { ++received; }); QMetaObject::invokeMethod(&obj, "fire"); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(received, 1); channel.deregisterObject(&obj); QMetaObject::invokeMethod(&obj, "fire"); - QTRY_COMPARE(spy.count(), 2); + QTRY_COMPARE(received, 2); } thread.quit(); |