Commit 29667ff1 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Properly seed the RNG for cctest/test-types.

This was broken since r21879, as the RandomNumberGenerator constructor
does no longer look at FLAG_random_seed implicitly.

TEST=cctest/test-types
R=jochen@chromium.org

Review URL: https://codereview.chromium.org/370973002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22222 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7fe8e6ec
......@@ -6,6 +6,7 @@
#define V8_ARGUMENTS_H_
#include "src/allocation.h"
#include "src/isolate.h"
namespace v8 {
namespace internal {
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "src/base/utils/random-number-generator.h"
#include "src/hydrogen-types.h"
#include "src/isolate-inl.h"
#include "src/types.h"
#include "test/cctest/cctest.h"
......@@ -127,7 +104,8 @@ struct HeapRep {
template<class Type, class TypeHandle, class Region>
class Types {
public:
Types(Region* region, Isolate* isolate) : region_(region) {
Types(Region* region, Isolate* isolate)
: region_(region), rng_(isolate->random_number_generator()) {
#define DECLARE_TYPE(name, value) \
name = Type::name(region); \
types.push_back(name);
......@@ -274,18 +252,18 @@ class Types {
}
TypeHandle Random() {
return types[rng_.NextInt(static_cast<int>(types.size()))];
return types[rng_->NextInt(static_cast<int>(types.size()))];
}
TypeHandle Fuzz(int depth = 5) {
switch (rng_.NextInt(depth == 0 ? 3 : 20)) {
switch (rng_->NextInt(depth == 0 ? 3 : 20)) {
case 0: { // bitset
int n = 0
#define COUNT_BITSET_TYPES(type, value) + 1
BITSET_TYPE_LIST(COUNT_BITSET_TYPES)
#undef COUNT_BITSET_TYPES
;
int i = rng_.NextInt(n);
int i = rng_->NextInt(n);
#define PICK_BITSET_TYPE(type, value) \
if (i-- == 0) return Type::type(region_);
BITSET_TYPE_LIST(PICK_BITSET_TYPE)
......@@ -293,15 +271,15 @@ class Types {
UNREACHABLE();
}
case 1: { // class
int i = rng_.NextInt(static_cast<int>(maps.size()));
int i = rng_->NextInt(static_cast<int>(maps.size()));
return Type::Class(maps[i], region_);
}
case 2: { // constant
int i = rng_.NextInt(static_cast<int>(values.size()));
int i = rng_->NextInt(static_cast<int>(values.size()));
return Type::Constant(values[i], region_);
}
case 3: { // context
int depth = rng_.NextInt(3);
int depth = rng_->NextInt(3);
TypeHandle type = Type::Internal(region_);
for (int i = 0; i < depth; ++i) type = Type::Context(type, region_);
return type;
......@@ -315,7 +293,7 @@ class Types {
case 7: { // function
TypeHandle result = Fuzz(depth / 2);
TypeHandle receiver = Fuzz(depth / 2);
int arity = rng_.NextInt(3);
int arity = rng_->NextInt(3);
TypeHandle type = Type::Function(result, receiver, arity, region_);
for (int i = 0; i < type->AsFunction()->Arity(); ++i) {
TypeHandle parameter = Fuzz(depth - 1);
......@@ -323,7 +301,7 @@ class Types {
}
}
default: { // union
int n = rng_.NextInt(10);
int n = rng_->NextInt(10);
TypeHandle type = None;
for (int i = 0; i < n; ++i) {
TypeHandle operand = Fuzz(depth - 1);
......@@ -339,7 +317,7 @@ class Types {
private:
Region* region_;
v8::base::RandomNumberGenerator rng_;
v8::base::RandomNumberGenerator* rng_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment