merged random_seed assert into trunk

This commit is contained in:
Arvid Norberg 2014-07-19 02:17:19 +00:00
parent d2fccd8ae7
commit 30d561d0c5
5 changed files with 23 additions and 0 deletions

View File

@ -30,7 +30,9 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/random.hpp"
#include "libtorrent/assert.hpp"
namespace libtorrent
{
@ -38,17 +40,25 @@ namespace libtorrent
namespace
{
boost::uint32_t x = 123456789;
#ifdef TORRENT_USE_ASSERTS
bool seeded = false;
#endif
}
void random_seed(boost::uint32_t v)
{
x = v;
#ifdef TORRENT_USE_ASSERTS
seeded = true;
#endif
}
// this is an xorshift random number generator
// see: http://en.wikipedia.org/wiki/Xorshift
boost::uint32_t random()
{
TORRENT_ASSERT(seeded);
static boost::uint32_t y = 362436069;
static boost::uint32_t z = 521288629;
static boost::uint32_t w = 88675123;

View File

@ -434,6 +434,8 @@ bool get_item_cb(dht::item& i)
// TODO: 3 test obfuscated_get_peers
int test_main()
{
random_seed(time_now_hires().time_since_epoch().count());
dht_settings sett;
sett.max_torrents = 4;
sett.max_dht_items = 4;

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hasher.hpp"
#include "libtorrent/pe_crypto.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/random.hpp"
#include "setup_transfer.hpp"
#include "test.hpp"
@ -181,6 +182,8 @@ int test_main()
const int repcount = 128;
#endif
random_seed(time_now_hires().time_since_epoch().count());
for (int rep = 0; rep < repcount; ++rep)
{
dh_key_exchange DH1, DH2;

View File

@ -34,6 +34,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_peer.hpp"
#include "libtorrent/bitfield.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/random.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <algorithm>
@ -269,6 +271,9 @@ int test_pick(boost::shared_ptr<piece_picker> const& p, int options = piece_pick
int test_main()
{
random_seed(time_now_hires().time_since_epoch().count());
tcp::endpoint endp;
piece_picker::downloading_piece st;
#if TORRENT_USE_ASSERTS
tmp0.in_use = true;

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/ip_voter.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/random.hpp"
#include "test.hpp"
#include "setup_transfer.hpp"
@ -132,6 +133,8 @@ private:
int test_main()
{
random_seed(time_now_hires().time_since_epoch().count());
torrent_peer_allocator allocator;
external_ip ext_ip;