Commit graph

414 commits

Author SHA1 Message Date
1bbbd5e27f Remove a blank line before "fairland rips open"
One blank line before and after now, looks better.
2013-05-08 06:55:21 +02:00
39c26f4238 Switch PRNG from BSD random() to Mersenne Twister
random() may yield different pseudo-random number sequences for the
same seed on another system.  For instance, at least some versions of
MinGW provide a random() in -liberty that differs from traditional BSD
(see commit c8231b12).  Rather inconvenient for regression testing.

MT19937 Mersenne Twister is a proven, high-quality PRNG.  Actual code
is reference code provided by the inventors[*].  Quick tests show
performance comparable to random().

Like random(), MT is not cryptographically secure: observing enough of
its output permits guessing its state, and thus its future output.  I
don't think players can do that.

Drop the copy of BSD random() we added for Windows.

Like the previous commit, this changes the server's die rolls, and
makes fairland create a different random map for the same seed.  Update
expected smoke test results accordingly.

[*] mt19937ar.sep.tgz downloaded from
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
2013-05-08 06:55:21 +02:00
b5d8806eb1 Fix tiny error in distribution of die rolls
"random() % n" is sound only when n is a power of two.  The error is
hardly relevant in Empire, because random() yields 31 bits, and our n
are always much smaller than 2^31.  Fix it anyway.

Use smallest the 2^m >= n instead of n, and discard numbers exceeding
n.

Bonus: faster for me even in the worst case n = 2^m+1.

Like the recent change to damage(), this changes some of the server's
die rolls, only this time the effect is pretty pervasive.  Worse,
fairland now creates a completely different random map for the same
seed.  Update expected smoke test results accordingly.
2013-05-08 06:55:20 +02:00
c53158eee0 Make damage() use roundavg()
Turns damage() into a one-liner.

damage() now uses random() % 32768 in chance() instead of random() %
100 inline, therefore can round differently for the same pseudo-random
number.  Update expected smoke test results accordingly.

Aside: "random() % n" distributes evenly only when n is a power of
two.  100 isn't.  However, because random() yields at least 31 bits,
and 100 is so much smaller than 2^31, the error is vanishingly small.
2013-05-08 06:55:20 +02:00
cf5ba2cec1 Make smoke test's tech production more robust
The tech center doesn't have enough workers to use all materials in
some updates.  How much get made depends on a die roll then.  Tech
variations are inconvenient because they ripple through the rest of
the smoke test.
2013-05-08 06:55:19 +02:00
df9cc9d9eb Limit che action in smoke test some
Too easily upset by random variations.  Kill them off with anti after
two updates, and occupy with a few more military.

While there, enlist the military in a highway rather than an lcm
plant.
2013-05-08 06:55:19 +02:00
e9fdc200e4 Make smoke test's plane build more robust
The airfield is a sector taken from player 8.  How many updates it
takes to convert is highly variable.  If it converts late, the
airfield may not be constructed in time.  This is currently the case
for me.

Move the airfield to a more dependable sector.

For me, the smoke test now fails frequently, because of differences in
news.  To be fixed next.
2013-05-08 06:55:19 +02:00
b54380938c Remove fairland from smoke test
Import xdump instead.  To decouple the smoke test from future fairland
changes that result in different worlds.
2013-05-08 06:55:19 +02:00
ed8eead0ba Add fairland test to make check 2013-05-08 06:55:18 +02:00
4dd0720fc0 Add files test to make check 2013-05-08 06:55:18 +02:00
d161b6d9e4 Factor tests/test-common.sh out of tests/smoke-test
For reuse by future tests.
2013-05-08 06:55:18 +02:00
108c9408dc Make smoke test check the final empdump -x 2013-05-08 06:55:18 +02:00
56a9d46ab1 Get rid of shell boilerplate in smoke test Empire batch files 2013-05-08 06:55:18 +02:00
49b2b13a90 New make target check
Just a smoke test so far, extracted from src/scripts/nightly/.  This
makes the existing smoke test more easily accessible.  Noteworthy
differences:

* Instead of patching the code to make output more stable, postprocess
  the output to normalize it.

* Compare actual results to expected results instead of the previous
  test run's results.

* Much faster.  The old test harness used sleep liberally to "ensure"
  things always happen in the same order.

Known shortcomings:

* The smoke test hangs when the server fails to complete startup, or
  fails to terminate.

* Normalization of xdump hardcodes columns instead of getting them
  from xdump meta.

* Normalization of time values in xdump is an ugly hack.

* xdump meta column type isn't normalized.  Actual values can vary
  between systems, because the width of enumeration types is
  implementation-defined.  The smoke test works only when they're
  represented as int, which is the case on common systems.

* Currently expected to work only with thread package LWP and a
  random() that behaves exactly like the one on my development system,
  because:

  - Thread scheduling is reliably deterministic only with LWP

  - The PRN sequence produced by random() isn't portable

  - Shell builtin kill appears not to do the job in MinGW

  - The Windows server tries to run as service when -d isn't
    specified

Further work is needed to address these shortcomings.

Getting C programs behave exactly the same on all systems is hard.
We'll likely run into system-dependent differences that upset the
smoke test.  Floating-point computation seems particularly vulnerable.

Instead of updating src/scripts/nightly/ to use "make check", retire
it.  It hasn't been used in quite a while.  Investing more into our
homegrown auto-builder doesn't make sense, as canned auto-builders
such as Travis CI and Jenkins are readily available.

The shell scripts src/scripts/nightly/tests/?? become Empire batch
files tests/smoke/.  The shell scripts are actually shell boilerplate
around Empire batch files.  To make sure git recognizes the move, this
commit moves them unchanged.  tests/smoke-test strips the boilerplate
before it feeds the batch files to the client.  The next commit will
get rid fo that.
2013-05-08 06:55:11 +02:00