tests: Make update robust against variations in PRNG use

Tests need repeatable pseudo-random numbers to yield repeatable
results.  Commit 73f1ac8 (v4.3.33) reseeds the PRNG with the count of
commands right before executing a command when running_test_suite is
on.  This doesn't help the update: whenever update code exercised by a
test is changed to consume fewer or more PRNs, all subsequent users
get different numbers regardless.  The ensuing test result changes are
extremely tedious to review.

To address this problem, reseed the PRNG in the update's two most
important loops with the iteration count when running_test_suite.
This way, the effect of perturbing the PRN sequence lasts only until
the next iteration.

There are many more loops, but reseeding in all of them seems
impractical.

Perturbs test results across the board.  Hopefully, that'll happen
less frequently now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-05 14:36:15 +02:00
parent c8e2a02d2f
commit 876d061875
16 changed files with 2907 additions and 2851 deletions

View file

@ -35,6 +35,7 @@
#include <config.h>
#include "budg.h"
#include "chance.h"
#include "item.h"
#include "land.h"
#include "player.h"
@ -75,6 +76,15 @@ prepare_sects(int etu, struct bp *bp)
if (sp->sct_type == SCT_WATER)
continue;
/*
* When running the test suite, reseed PRNG for each sector
* with its UID, to keep results stable even when the number
* of PRNs consumed changes.
*/
if (running_test_suite)
seed_prng(sp->sct_uid);
bp_set_from_sect(bp, sp);
np = getnatp(sp->sct_own);