libstdc++: Allow seeding random engines in testsuite
authorJonathan Wakely <jwakely@redhat.com>
Thu, 25 Mar 2021 13:51:08 +0000 (13:51 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 25 Mar 2021 18:21:19 +0000 (18:21 +0000)
commitc7fc73ee459045edabb99816658f14f32d23bf92
tree6c0c963982b3afa80752298c38556ebdd6913773
parentaac12084fc07319d5c8232c51dafa4e297bd5415
libstdc++: Allow seeding random engines in testsuite

The testsuite utilities that use random numbers use a
default-constructed mersenne_twister_engine, meaning the values are
reproducable. This adds support for seeding them, controlledby an
environment variable. Defining GLIBCXX_SEED_TEST_RNG=val in the
environment will cause the engines to be seeded with atoi(val) if that
is non-zero, or with a value read from std::random_device otherwise.

Running with different seeds revealed some bugs in the tests, where a
randomly selected iterator was past-the-end (which can't be erased), or
where the randomly populated container was empty, and then we tried to
remove elements from it unconditionally.

libstdc++-v3/ChangeLog:

* testsuite/util/exception/safety.h (setup_base::generate):
Support seeding random engine.
(erase_point, erase_range): Adjust range of random numbers to
ensure dereferenceable iterators are used where required.
(generation_prohibited::run): Do not try to erase from empty
containers.
* testsuite/util/testsuite_containergen.h (test_containers):
Support seeding random engine.
libstdc++-v3/testsuite/util/exception/safety.h
libstdc++-v3/testsuite/util/testsuite_containergen.h