summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-04-02 21:36:21 -0700
committerThiago Macieira <thiago.macieira@intel.com>2021-10-26 11:38:56 -0700
commit0077eac4e4794cb956531ff89a9007dfc5dc78c3 (patch)
tree48aefae6bb537a48fbb77264ec8f5789191f9bdf /tests/auto/corelib/tools
parent6adaaa77452d8ddc33bcad9a49a2603dc118a1fe (diff)
QHash: double the size of the stored seed
There's now another half of the seed which will be used by the hashers. This is not stored in QHash, so it is never changed for the lifetime of the application (not even when QHashSeed::setDeterministicGlobalSeed() is called). However, we will not use it when we're in deterministic mode. This commit uses the compiler thread-safe statics to implement the initialization of more than one atomic word, thus freeing us from having to have a reserved value. As a bonus, the QT_HASH_SEED warning will only be printed once. Change-Id: Id2983978ad544ff79911fffd16723f1673f9a5b4 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
index 60f3fe9e3c..3d3b529f29 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
@@ -134,8 +134,12 @@ void tst_QHashSeed::reseeding()
void tst_QHashSeed::quality()
{
+ // this "bad seed" is used internally in qhash.cpp and should never leak!
+ constexpr size_t BadSeed = size_t(Q_UINT64_C(0x5555'5555'5555'5555));
+
constexpr int Iterations = 16;
int oneThird = 0;
+ int badSeeds = 0;
size_t ored = 0;
for (int i = 0; i < Iterations; ++i) {
@@ -146,6 +150,8 @@ void tst_QHashSeed::quality()
if (bits >= std::numeric_limits<size_t>::digits / 3)
++oneThird;
+ if (seed == BadSeed)
+ ++badSeeds;
}
// report out
@@ -161,6 +167,12 @@ void tst_QHashSeed::quality()
// at least one third of the seeds must have one third of all the bits set
QVERIFY(oneThird > (16/3));
+
+ // at most one seed can be the bad seed, if 32-bit, none on 64-bit
+ if (std::numeric_limits<size_t>::digits > 32)
+ QCOMPARE(badSeeds, 0);
+ else
+ QVERIFY(badSeeds <= 1);
}
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)