Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dart/fuzzer] refactor lists into new file
Rationale: Refactor DartFuzz so that long lists of values appear in separate file, making the actual fuzzing code easier to read. Also, this prepares generating some of the lists automaticaly (such a library methods). Note that *no* version bump is required, since this refactoring does not change behavior. Change-Id: Ic58eb7bc1aa63f48ec0d37e3c2399917786086bd Reviewed-on: https://dart-review.googlesource.com/c/87266 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Aart Bik <ajcbik@google.com>
- Loading branch information
Showing
2 changed files
with
181 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Class that represents some common Dart types. | ||
/// | ||
/// TODO(ajcbik): generalize | ||
/// | ||
class DartType { | ||
final String name; | ||
|
||
const DartType._withName(this.name); | ||
|
||
static const VOID = const DartType._withName('void'); | ||
static const BOOL = const DartType._withName('bool'); | ||
static const INT = const DartType._withName('int'); | ||
static const DOUBLE = const DartType._withName('double'); | ||
static const STRING = const DartType._withName('String'); | ||
static const INT_LIST = const DartType._withName('List<int>'); | ||
static const INT_STRING_MAP = const DartType._withName('Map<int, String>'); | ||
|
||
// All value types. | ||
static const allTypes = [BOOL, INT, DOUBLE, STRING, INT_LIST, INT_STRING_MAP]; | ||
} | ||
|
||
/// Class with interesting values for fuzzing. | ||
class DartFuzzValues { | ||
// Interesting characters. | ||
static const interestingChars = | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#&()+- '; | ||
|
||
// Interesting integer values. | ||
static const List<int> interestingIntegers = [ | ||
0x0000000000000000, | ||
0x0000000000000001, | ||
0x000000007fffffff, | ||
0x0000000080000000, | ||
0x0000000080000001, | ||
0x00000000ffffffff, | ||
0x0000000100000000, | ||
0x0000000100000001, | ||
0x000000017fffffff, | ||
0x0000000180000000, | ||
0x0000000180000001, | ||
0x00000001ffffffff, | ||
0x7fffffff00000000, | ||
0x7fffffff00000001, | ||
0x7fffffff7fffffff, | ||
0x7fffffff80000000, | ||
0x7fffffff80000001, | ||
0x7fffffffffffffff, | ||
0x8000000000000000, | ||
0x8000000000000001, | ||
0x800000007fffffff, | ||
0x8000000080000000, | ||
0x8000000080000001, | ||
0x80000000ffffffff, | ||
0x8000000100000000, | ||
0x8000000100000001, | ||
0x800000017fffffff, | ||
0x8000000180000000, | ||
0x8000000180000001, | ||
0x80000001ffffffff, | ||
0xffffffff00000000, | ||
0xffffffff00000001, | ||
0xffffffff7fffffff, | ||
0xffffffff80000000, | ||
0xffffffff80000001, | ||
0xffffffffffffffff | ||
]; | ||
} | ||
|
||
/// Class that represents Dart library methods. | ||
/// The invididual lists are organized by return type. | ||
/// Proto list: | ||
/// [ receiver-type (null denotes none), | ||
/// param1 type (null denotes getter), | ||
/// param2 type, | ||
/// ... | ||
/// ] | ||
/// | ||
/// TODO(ajcbik): generate these lists automatically | ||
/// | ||
class DartLib { | ||
final String name; | ||
final List<DartType> proto; | ||
const DartLib(this.name, this.proto); | ||
|
||
static const boolLibs = [ | ||
DartLib('isEven', [DartType.INT, null]), | ||
DartLib('isOdd', [DartType.INT, null]), | ||
DartLib('isEmpty', [DartType.STRING, null]), | ||
DartLib('isEmpty', [DartType.INT_STRING_MAP, null]), | ||
DartLib('isNotEmpty', [DartType.STRING, null]), | ||
DartLib('isNotEmpty', [DartType.INT_STRING_MAP, null]), | ||
DartLib('endsWith', [DartType.STRING, DartType.STRING]), | ||
DartLib('remove', [DartType.INT_LIST, DartType.INT]), | ||
DartLib('containsValue', [DartType.INT_STRING_MAP, DartType.STRING]), | ||
DartLib('containsKey', [DartType.INT_STRING_MAP, DartType.INT]), | ||
]; | ||
|
||
static const intLibs = [ | ||
DartLib('bitLength', [DartType.INT, null]), | ||
DartLib('sign', [DartType.INT, null]), | ||
DartLib('abs', [DartType.INT]), | ||
DartLib('round', [DartType.INT]), | ||
DartLib('round', [DartType.DOUBLE]), | ||
DartLib('floor', [DartType.INT]), | ||
DartLib('floor', [DartType.DOUBLE]), | ||
DartLib('ceil', [DartType.INT]), | ||
DartLib('ceil', [DartType.DOUBLE]), | ||
DartLib('truncate', [DartType.INT]), | ||
DartLib('truncate', [DartType.DOUBLE]), | ||
DartLib('toInt', [DartType.DOUBLE]), | ||
DartLib('toUnsigned', [DartType.INT, DartType.INT]), | ||
DartLib('toSigned', [DartType.INT, DartType.INT]), | ||
DartLib('modInverse', [DartType.INT, DartType.INT]), | ||
DartLib('modPow', [DartType.INT, DartType.INT, DartType.INT]), | ||
DartLib('length', [DartType.STRING, null]), | ||
DartLib('length', [DartType.INT_LIST, null]), | ||
DartLib('length', [DartType.INT_STRING_MAP, null]), | ||
DartLib('codeUnitAt', [DartType.STRING, DartType.INT]), | ||
DartLib('compareTo', [DartType.STRING, DartType.STRING]), | ||
DartLib('removeLast', [DartType.INT_LIST]), | ||
DartLib('removeAt', [DartType.INT_LIST, DartType.INT]), | ||
DartLib('indexOf', [DartType.INT_LIST, DartType.INT]), | ||
DartLib('lastIndexOf', [DartType.INT_LIST, DartType.INT]), | ||
]; | ||
|
||
static const doubleLibs = [ | ||
DartLib('sign', [DartType.DOUBLE, null]), | ||
DartLib('abs', [DartType.DOUBLE]), | ||
DartLib('toDouble', [DartType.INT]), | ||
DartLib('roundToDouble', [DartType.INT]), | ||
DartLib('roundToDouble', [DartType.DOUBLE]), | ||
DartLib('floorToDouble', [DartType.INT]), | ||
DartLib('floorToDouble', [DartType.DOUBLE]), | ||
DartLib('ceilToDouble', [DartType.INT]), | ||
DartLib('ceilToDouble', [DartType.DOUBLE]), | ||
DartLib('truncateToDouble', [DartType.INT]), | ||
DartLib('truncateToDouble', [DartType.DOUBLE]), | ||
DartLib('remainder', [DartType.DOUBLE, DartType.DOUBLE]), | ||
]; | ||
|
||
static const stringLibs = [ | ||
DartLib('toString', [DartType.BOOL]), | ||
DartLib('toString', [DartType.INT]), | ||
DartLib('toString', [DartType.DOUBLE]), | ||
DartLib('toRadixString', [DartType.INT, DartType.INT]), | ||
DartLib('trim', [DartType.STRING]), | ||
DartLib('trimLeft', [DartType.STRING]), | ||
DartLib('trimRight', [DartType.STRING]), | ||
DartLib('toLowerCase', [DartType.STRING]), | ||
DartLib('toUpperCase', [DartType.STRING]), | ||
DartLib('substring', [DartType.STRING, DartType.INT]), | ||
DartLib('replaceRange', | ||
[DartType.STRING, DartType.INT, DartType.INT, DartType.STRING]), | ||
DartLib('remove', [DartType.INT_STRING_MAP, DartType.INT]), | ||
// Avoid (OOM divergences, TODO(ajcbik): restrict parameters) | ||
// DartLib('padLeft', [DartType.STRING, DartType.INT]), | ||
// DartLib('padRight', [DartType.STRING, DartType.INT]), | ||
]; | ||
|
||
static const intListLibs = [ | ||
DartLib('sublist', [DartType.INT_LIST, DartType.INT]) | ||
]; | ||
} |