v8/test/mjsunit/random-bit-correlations.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.9 KiB
JavaScript
Raw Normal View History

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Reland^5 "[flags] warn about contradictory flags" This is a reland of 2000aea58aed517a755178ebb4712c18acb0c88b Changes compared to last reland: - Add rule in variants.py for --enable_experimental_regexp_engine. - Make sure --abort-on-contradictory-flags works as well as --fuzzing to disable the checking for fuzzers, including for d8 flags. Original change's description: > Reland^4 "[flags] warn about contradictory flags" > > This is a reland of 0ba115e6a9ef0a8aa2af9ce22a1a4521a4a0b363 > Changes compared to last reland: > - Fix Python code trying to write to expected_outcomes, which is now a > computed property. > - Fix remaining place in d8.cc that ignored the --fuzzing flag. > - Expect flag contradictions for --cache in code_serializer variant. > > Original change's description: > > Reland^3 "[flags] warn about contradictory flags" > > > > Changes: > > - Also allow second parameter influenced by --cache to be reassigned. > > - Fix --stress-opt to only --always-opt in the last iteration as before. > > > > Original change's description: > > > Reland^2 "[flags] warn about contradictory flags" > > > > > > This is a reland of d8f8a7e2105305921ca31450ecc38e009bc075c3 > > > Change compared to last reland: > > > - Do not check for d8 flag contradictions in the presence of --fuzzing > > > - Allow identical re-declaration of --cache=* > > > > > > Original change's description: > > > > Reland "[flags] warn about contradictory flags" > > > > > > > > This is a reland of b8f91666649b637e87a338f884d7987b169f6692 > > > > Difference to previous CL: Additional functionality to specify > > > > incompatible flags based on GN variables and extra-flags, used > > > > to fix the issues that came up on the waterfall. > > > > > > > > This also changes the rules regarding repeated flags: While > > > > explicitly repeated flags are allowed for boolean values as long > > > > as they are identical, repeated flags or explicit flags in the > > > > presence of an active implication are disallowed for non-boolean > > > > flags. The latter simplifies specifying conflict rules in > > > > variants.py. Otherwise a rule like > > > > > > > > INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG = { > > > > "--gc-interval=*": ["--gc-interval=*"], > > > > } > > > > > > > > wouldn't work because specifying the same GC interval twice > > > > wouldn't actually count as a conflict. This was an issue with > > > > test/mjsunit/wasm/gc-buffer.js, which specifies > > > > --gc-interval=500 exactly like the extra flag by the stress bot. > > > > > > > > Also, this now expands contradictory flags checking to d8 flags > > > > for consistency. > > > > > > > > Original change's description: > > > > > [flags] warn about contradictory flags > > > > > > > > > > Design Doc: https://docs.google.com/document/d/1lkvu8crkK7Ei39qjkPCFijpNyxWXsOktG9GB-7K34jM/ > > > > > > > > > > Bug: v8:10577 > > > > > Change-Id: Ib9cfdffa401c48c895bf31caed5ee03545beddab > > > > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2154792 > > > > > Reviewed-by: Clemens Backes <clemensb@chromium.org> > > > > > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > > > > > Reviewed-by: Georg Neis <neis@chromium.org> > > > > > Reviewed-by: Tamer Tas <tmrts@chromium.org> > > > > > Commit-Queue: Tobias Tebbi <tebbi@chromium.org> > > > > > Cr-Commit-Position: refs/heads/master@{#68168} > > > > > > > > Bug: v8:10577 > > > > Change-Id: I268e590ee18a535b13dee14eeb15ddd0a9ee8341 > > > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235115 > > > > Commit-Queue: Tobias Tebbi <tebbi@chromium.org> > > > > Reviewed-by: Tamer Tas <tmrts@chromium.org> > > > > Reviewed-by: Clemens Backes <clemensb@chromium.org> > > > > Reviewed-by: Georg Neis <neis@chromium.org> > > > > Cr-Commit-Position: refs/heads/master@{#68989} > > > > > > Bug: v8:10577 > > > Change-Id: I31d2794d4f9ff630f3444210100c64d67d881276 > > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2339464 > > > Commit-Queue: Tobias Tebbi <tebbi@chromium.org> > > > Reviewed-by: Clemens Backes <clemensb@chromium.org> > > > Cr-Commit-Position: refs/heads/master@{#69339} > > > > Bug: v8:10577 > > Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng > > Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel_ng > > Change-Id: I4a69dc57a102782cb453144323e3752ac8278624 > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2352770 > > Commit-Queue: Tobias Tebbi <tebbi@chromium.org> > > Reviewed-by: Tobias Tebbi <tebbi@chromium.org> > > Reviewed-by: Clemens Backes <clemensb@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#69433} > > Change-Id: Ib6d2aeb495210f581ac671221c265df58e8e5e70 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2398640 > Commit-Queue: Tobias Tebbi <tebbi@chromium.org> > Reviewed-by: Clemens Backes <clemensb@chromium.org> > Reviewed-by: Tamer Tas <tmrts@chromium.org> > Cr-Commit-Position: refs/heads/master@{#69954} Bug: v8:10577 TBR: clemensb@chromium.org, tmrts@chromium.org Change-Id: Iab2d32cdcc2648934fc52255ccf3ae3ec9ca4d9b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2416386 Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Commit-Queue: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#70000}
2020-09-18 14:40:24 +00:00
// Overwrite the random seed provided by the test runner to make this test less
// flaky. Due to flag contradiction checking, this requires
// --allow-overwriting-for-next-flag to avoid an error.
// Flags: --allow-overwriting-for-next-flag --random-seed=20
// Flags: --nostress-opt --noalways-turbofan --predictable
(function() {
var kHistory = 2;
var kRepeats = 100;
var history = new Uint32Array(kHistory);
function random() {
return (Math.random() * Math.pow(2, 32)) >>> 0;
}
function ChiSquared(m, n) {
var ys_minus_np1 = (m - n / 2.0);
var chi_squared_1 = ys_minus_np1 * ys_minus_np1 * 2.0 / n;
var ys_minus_np2 = ((n - m) - n / 2.0);
var chi_squared_2 = ys_minus_np2 * ys_minus_np2 * 2.0 / n;
return chi_squared_1 + chi_squared_2;
}
for (var predictor_bit = -2; predictor_bit < 32; predictor_bit++) {
// The predicted bit is one of the bits from the PRNG.
for (var random_bit = 0; random_bit < 32; random_bit++) {
for (var ago = 0; ago < kHistory; ago++) {
// We don't want to check whether each bit predicts itself.
if (ago == 0 && predictor_bit == random_bit) continue;
// Enter the new random value into the history
for (var i = ago; i >= 0; i--) {
history[i] = random();
}
// Find out how many of the bits are the same as the prediction bit.
var m = 0;
for (var i = 0; i < kRepeats; i++) {
for (var j = ago - 1; j >= 0; j--) history[j + 1] = history[j];
history[0] = random();
var predicted;
if (predictor_bit >= 0) {
predicted = (history[ago] >> predictor_bit) & 1;
} else {
predicted = predictor_bit == -2 ? 0 : 1;
}
var bit = (history[0] >> random_bit) & 1;
if (bit == predicted) m++;
}
// Chi squared analysis for k = 2 (2, states: same/not-same) and one
// degree of freedom (k - 1).
var chi_squared = ChiSquared(m, kRepeats);
if (chi_squared > 24) {
var percent = Math.floor(m * 100.0 / kRepeats);
if (predictor_bit < 0) {
var bit_value = predictor_bit == -2 ? 0 : 1;
print(`Bit ${random_bit} is ${bit_value} ${percent}% of the time`);
} else {
print(`Bit ${random_bit} is the same as bit ${predictor_bit} ` +
`${ago} ago ${percent}% of the time`);
}
}
// For 1 degree of freedom this corresponds to 1 in a million. We are
// running ~8000 tests, so that would be surprising.
assertTrue(chi_squared <= 24);
// If the predictor bit is a fixed 0 or 1 then it makes no sense to
// repeat the test with a different age.
if (predictor_bit < 0) break;
}
}
}
})();