From 84c9fcffeeb088d37d014f1f7b7f26f8d3a6a907 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 23 Nov 2021 10:41:52 -0800 Subject: tst_QHashSeed: improve quality of the quality() test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We expect to produce all-bits-set in the combined OR'ed value of the seed, so instead of counting how many bits got set and reporting that, simply compare to -1 and count how long it took to get that far. To make sure, I've increased the number of iterations by 50%. Change-Id: I89446ea06b5742efb194fffd16ba37b2d93c19ef Reviewed-by: MÃ¥rten Nordheim --- .../auto/corelib/tools/qhashseed/tst_qhashseed.cpp | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'tests/auto/corelib/tools/qhashseed') diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp index f726a29d97..f91ecced76 100644 --- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp +++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp @@ -137,9 +137,10 @@ 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; + constexpr int Iterations = 24; // nicely divisible by 3 int oneThird = 0; int badSeeds = 0; + int seedsToMinus1 = 0; size_t ored = 0; for (int i = 0; i < Iterations; ++i) { @@ -152,29 +153,33 @@ void tst_QHashSeed::quality() ++oneThird; if (seed == BadSeed) ++badSeeds; + if (ored != size_t(-1)) + ++seedsToMinus1; QHashSeed::resetRandomGlobalSeed(); } // report out + qInfo() << "Number of seeds until all bits became set:" << seedsToMinus1 << '/' << Iterations; qInfo() << "Number of seeds with at least one third of the bits set:" << oneThird << '/' << Iterations; - qInfo() << "Number of bits in OR'ed value:" << qPopulationCount(quintptr(ored)) - << '/' << std::numeric_limits::digits; - if (std::numeric_limits::digits > 32) { - quint32 upper = quint64(ored) >> 32; - qInfo() << "Number of bits in the upper half:" << qPopulationCount(upper) << "/ 32"; - QVERIFY(qPopulationCount(upper) > (32/3)); - } + + // we must have set all bits after all the iterations + QCOMPARE(ored, size_t(-1)); // at least one third of the seeds must have one third of all the bits set - QVERIFY(oneThird > (16/3)); + QVERIFY(oneThird > (Iterations/3)); // at most one seed can be the bad seed, if 32-bit, none on 64-bit if (std::numeric_limits::digits > 32) QCOMPARE(badSeeds, 0); else - QVERIFY(badSeeds <= 1); + QVERIFY2(badSeeds <= 1, "badSeeds = " + QByteArray::number(badSeeds)); + + // we must have taken at most two thirds of the iterations to have set each + // bit at least once + QVERIFY2(seedsToMinus1 < 2*Iterations/3, + "seedsToMinus1 = " + QByteArray::number(seedsToMinus1)); } #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) -- cgit v1.2.3