Skip to content

Commit c2af59f

Browse files
aartbikcommit-bot@chromium.org
authored andcommitted
[dart/fuzzer] Add flag to control FP operations
Rationale: Floating-point operations have some potential for false divergences (mostly when going through libc methods that are compiled differently between 32- and 64-bit. To avoid these, a --no-fp flag has been added to dartfuzz.dart which can be used to dartfuzz_test.dart to avoid floating-point operations when comparing 32-/64-bit execution modes. #37335 Change-Id: Ie3c28f2a6e2d257b8e9adbba79d088b3879264ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109891 Reviewed-by: Felicitas Hetzelt <[email protected]> Commit-Queue: Aart Bik <[email protected]>
1 parent ee5a90c commit c2af59f

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

runtime/tools/dartfuzz/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ How to run DartFuzz
1212
===================
1313
To generate a single random Dart program, run
1414

15-
dart dartfuzz.dart [--help] [--seed SEED] FILENAME
15+
dart dartfuzz.dart [--help] [--seed SEED] [--[no-]fp] FILENAME
1616

1717
where
1818

19-
--help : prints help and exits
20-
--seed : defines random seed (system-set by default)
19+
--help : prints help and exits
20+
--seed : defines random seed (system-set by default)
21+
--[no-]fp : enables/disables floating-point operations
2122

2223
The tool provides a runnable main isolate. A typical single
2324
test run looks as:
@@ -52,7 +53,7 @@ where
5253
jit-[debug-]x64 = Dart JIT (x64)
5354
jit-[debug-]arm32 = Dart JIT (simarm)
5455
jit-[debug-]arm64 = Dart JIT (simarm64)
55-
jit-[debug-]dbc = Dart JIT (simdbc)
56+
jit-[debug-]dbc32 = Dart JIT (simdbc)
5657
jit-[debug-]dbc64 = Dart JIT (simdbc64)
5758
aot-[debug-]x64 = Dart AOT (x64)
5859
aot-[debug-]arm32 = Dart AOT (simarm)

runtime/tools/dartfuzz/dartfuzz.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'dartfuzz_api_table.dart';
1313
// Version of DartFuzz. Increase this each time changes are made
1414
// to preserve the property that a given version of DartFuzz yields
1515
// the same fuzzed program for a deterministic random seed.
16-
const String version = '1.13';
16+
const String version = '1.14';
1717

1818
// Restriction on statements and expressions.
1919
const int stmtLength = 2;
@@ -29,7 +29,7 @@ const methodName = 'foo';
2929

3030
/// Class that generates a random, but runnable Dart program for fuzz testing.
3131
class DartFuzz {
32-
DartFuzz(this.seed, this.file);
32+
DartFuzz(this.seed, this.fp, this.file);
3333

3434
void run() {
3535
// Initialize program variables.
@@ -66,7 +66,7 @@ class DartFuzz {
6666
void emitHeader() {
6767
emitLn('// The Dart Project Fuzz Tester ($version).');
6868
emitLn('// Program generated as:');
69-
emitLn('// dart dartfuzz.dart --seed $seed');
69+
emitLn('// dart dartfuzz.dart --seed $seed --${fp ? "" : "no-"}fp');
7070
emitLn('');
7171
emitLn("import 'dart:async';");
7272
emitLn("import 'dart:cli';");
@@ -1008,7 +1008,7 @@ class DartFuzz {
10081008
emitExpr(depth, DartType.INT);
10091009
break;
10101010
case 'D':
1011-
emitExpr(depth, DartType.DOUBLE);
1011+
emitExpr(depth, fp ? DartType.DOUBLE : DartType.INT);
10121012
break;
10131013
case 'S':
10141014
emitExpr(depth, DartType.STRING);
@@ -1039,7 +1039,7 @@ class DartFuzz {
10391039
case 1:
10401040
return DartType.INT;
10411041
case 2:
1042-
return DartType.DOUBLE;
1042+
return fp ? DartType.DOUBLE : DartType.INT;
10431043
case 3:
10441044
return DartType.STRING;
10451045
case 4:
@@ -1119,6 +1119,9 @@ class DartFuzz {
11191119
// Random seed used to generate program.
11201120
final int seed;
11211121

1122+
// Enables floating-point operations.
1123+
final bool fp;
1124+
11221125
// File used for output.
11231126
final RandomAccessFile file;
11241127

@@ -1163,12 +1166,15 @@ int getSeed(String userSeed) {
11631166
main(List<String> arguments) {
11641167
final parser = new ArgParser()
11651168
..addOption('seed',
1166-
help: 'random seed (0 forces time-based seed)', defaultsTo: '0');
1169+
help: 'random seed (0 forces time-based seed)', defaultsTo: '0')
1170+
..addFlag('fp',
1171+
help: 'enables floating-point operations', defaultsTo: true);
11671172
try {
11681173
final results = parser.parse(arguments);
11691174
final seed = getSeed(results['seed']);
1175+
final fp = results['fp'];
11701176
final file = new File(results.rest.single).openSync(mode: FileMode.write);
1171-
new DartFuzz(seed, file).run();
1177+
new DartFuzz(seed, fp, file).run();
11721178
file.closeSync();
11731179
} catch (e) {
11741180
print('Usage: dart dartfuzz.dart [OPTIONS] FILENAME\n${parser.usage}\n$e');

runtime/tools/dartfuzz/dartfuzz_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ abstract class TestRunner {
122122
if (mode.endsWith('debug-x64')) return 'DebugX64';
123123
if (mode.endsWith('debug-arm32')) return 'DebugSIMARM';
124124
if (mode.endsWith('debug-arm64')) return 'DebugSIMARM64';
125-
if (mode.endsWith('debug-dbc')) return 'DebugSIMDBC';
125+
if (mode.endsWith('debug-dbc32')) return 'DebugSIMDBC';
126126
if (mode.endsWith('debug-dbc64')) return 'DebugSIMDBC64';
127127
if (mode.endsWith('ia32')) return 'ReleaseIA32';
128128
if (mode.endsWith('x64')) return 'ReleaseX64';
129129
if (mode.endsWith('arm32')) return 'ReleaseSIMARM';
130130
if (mode.endsWith('arm64')) return 'ReleaseSIMARM64';
131-
if (mode.endsWith('dbc')) return 'ReleaseSIMDBC';
131+
if (mode.endsWith('dbc32')) return 'ReleaseSIMDBC';
132132
if (mode.endsWith('dbc64')) return 'ReleaseSIMDBC64';
133133
throw ('unknown tag in mode: $mode');
134134
}
@@ -282,7 +282,8 @@ class DartFuzzTest {
282282
fileName = '${tmpDir.path}/fuzz.dart';
283283
runner1 = TestRunner.getTestRunner(mode1, top, tmpDir.path, env, rand);
284284
runner2 = TestRunner.getTestRunner(mode2, top, tmpDir.path, env, rand);
285-
isolate = 'Isolate (${tmpDir.path}) '
285+
fp = samePrecision(mode1, mode2);
286+
isolate = 'Isolate (${tmpDir.path}) ${fp ? "" : "NO-"}FP : '
286287
'${runner1.description} - ${runner2.description}';
287288

288289
start_time = new DateTime.now().millisecondsSinceEpoch;
@@ -297,6 +298,10 @@ class DartFuzzTest {
297298
numDivergences = 0;
298299
}
299300

301+
bool samePrecision(String mode1, String mode2) {
302+
return mode1.contains('64') == mode2.contains('64');
303+
}
304+
300305
bool timeIsUp() {
301306
if (time > 0) {
302307
current_time = new DateTime.now().millisecondsSinceEpoch;
@@ -324,7 +329,7 @@ class DartFuzzTest {
324329

325330
void generateTest() {
326331
final file = new File(fileName).openSync(mode: FileMode.write);
327-
new DartFuzz(seed, file).run();
332+
new DartFuzz(seed, fp, file).run();
328333
file.closeSync();
329334
}
330335

@@ -415,6 +420,7 @@ class DartFuzzTest {
415420
String fileName;
416421
TestRunner runner1;
417422
TestRunner runner2;
423+
bool fp;
418424
String isolate;
419425
int seed;
420426

@@ -558,9 +564,9 @@ class DartFuzzTestSession {
558564
// Modes not used on cluster runs because they have outstanding issues.
559565
static const List<String> nonClusterModes = [
560566
// Deprecated.
561-
'jit-debug-dbc',
567+
'jit-debug-dbc32',
562568
'jit-debug-dbc64',
563-
'jit-dbc',
569+
'jit-dbc32',
564570
'jit-dbc64',
565571
// Times out often:
566572
'aot-debug-arm32',

0 commit comments

Comments
 (0)