2016-01-26 10:38:37 +00:00
|
|
|
# Copyright 2016 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.
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from testrunner.local import testsuite
|
2017-12-13 12:47:24 +00:00
|
|
|
from testrunner.objects import testcase
|
2016-01-26 10:38:37 +00:00
|
|
|
|
|
|
|
|
2017-12-13 12:47:24 +00:00
|
|
|
class VariantGenerator(testsuite.VariantGenerator):
|
2016-02-02 09:21:15 +00:00
|
|
|
# Only run the fuzzer with standard variant.
|
2017-12-12 21:33:16 +00:00
|
|
|
def FilterVariantsByTest(self, test):
|
2016-02-02 09:21:15 +00:00
|
|
|
return self.standard_variant
|
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def GetFlagSets(self, test, variant):
|
2016-02-02 09:21:15 +00:00
|
|
|
return testsuite.FAST_VARIANT_FLAGS[variant]
|
|
|
|
|
|
|
|
|
2017-12-13 12:47:24 +00:00
|
|
|
class TestSuite(testsuite.TestSuite):
|
2017-06-21 09:24:03 +00:00
|
|
|
SUB_TESTS = ( 'json', 'parser', 'regexp', 'wasm', 'wasm_async',
|
2017-06-13 14:41:54 +00:00
|
|
|
'wasm_call', 'wasm_code', 'wasm_compile', 'wasm_data_section',
|
[wasm] Syntax- and Type-aware Fuzzer
This is the beginning of a new fuzzer that generates
correct-by-construction Wasm modules. This should allow us to better
exercise the compiler and correctness aspects of fuzzing. It is based off
of ahaas' original Wasm fuzzer.
At the moment, it can generate expressions made up of most binops, and
also nested blocks with unconditional breaks. Future CLs will add
additional constructs, such as br_if, loops, memory access, etc.
The way the fuzzer works is that it starts with an array of arbitrary
data provided by libfuzzer. It uses the data to generate an expression.
Care is taken to make use of the entire string. Basically, the
generator has a bunch of grammar-like rules for how to construct an
expression of a given type. For example, an i32 can be made by adding
two other i32s, or by wrapping an i64. The process then continues
recursively until all the data is consumed.
We generate an expression from a slice of data as follows:
* If the slice is less than or equal to the size of the type (e.g. 4
bytes for i32), then it will emit the entire slice as a constant.
* Otherwise, it will consume the first 4 bytes of the slice and use
this to select which rule to apply. Each rule then consumes the
remainder of the slice in an appropriate way. For example:
* Unary ops use the remainder of the slice to generate the argument.
* Binary ops consume another four bytes and mod this with the length
of the remaining slice to split the slice into two parts. Each of
these subslices are then used to generate one of the arguments to
the binop.
* Blocks are basically like a unary op, but a stack of block types is
maintained to facilitate branches. For blocks that end in a break,
the first four bytes of a slice are used to select the break depth
and the stack determines what type of expression to generate.
The goal is that once this generator is complete, it will provide a one
to one mapping between binary strings and valid Wasm modules.
Review-Url: https://codereview.chromium.org/2658723006
Cr-Commit-Position: refs/heads/master@{#43289}
2017-02-17 17:06:29 +00:00
|
|
|
'wasm_function_sigs_section', 'wasm_globals_section',
|
|
|
|
'wasm_imports_section', 'wasm_memory_section', 'wasm_names_section',
|
|
|
|
'wasm_types_section' )
|
2016-01-26 10:38:37 +00:00
|
|
|
|
|
|
|
def ListTests(self, context):
|
|
|
|
tests = []
|
2017-12-13 12:47:24 +00:00
|
|
|
for subtest in TestSuite.SUB_TESTS:
|
2016-01-26 10:38:37 +00:00
|
|
|
for fname in os.listdir(os.path.join(self.root, subtest)):
|
|
|
|
if not os.path.isfile(os.path.join(self.root, subtest, fname)):
|
|
|
|
continue
|
2017-12-12 21:33:16 +00:00
|
|
|
test = self._create_test('%s/%s' % (subtest, fname))
|
2016-01-26 10:38:37 +00:00
|
|
|
tests.append(test)
|
|
|
|
tests.sort()
|
|
|
|
return tests
|
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def _test_class(self):
|
2017-12-13 12:47:24 +00:00
|
|
|
return TestCase
|
2016-01-26 10:38:37 +00:00
|
|
|
|
2016-02-02 09:21:15 +00:00
|
|
|
def _VariantGeneratorFactory(self):
|
2017-12-13 12:47:24 +00:00
|
|
|
return VariantGenerator
|
2016-02-02 09:21:15 +00:00
|
|
|
|
2016-01-26 10:38:37 +00:00
|
|
|
|
2017-12-13 12:47:24 +00:00
|
|
|
class TestCase(testcase.TestCase):
|
2017-12-12 21:33:16 +00:00
|
|
|
def _get_files_params(self, ctx):
|
|
|
|
suite, name = self.path.split('/')
|
|
|
|
return [os.path.join(self.suite.root, suite, name)]
|
|
|
|
|
|
|
|
def _get_variant_flags(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def _get_statusfile_flags(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def _get_mode_flags(self, ctx):
|
|
|
|
return []
|
|
|
|
|
2017-12-19 14:48:08 +00:00
|
|
|
def get_shell(self):
|
2017-12-12 21:33:16 +00:00
|
|
|
group, _ = self.path.split('/', 1)
|
|
|
|
return 'v8_simple_%s_fuzzer' % group
|
|
|
|
|
|
|
|
|
2016-01-26 10:38:37 +00:00
|
|
|
def GetSuite(name, root):
|
2017-12-13 12:47:24 +00:00
|
|
|
return TestSuite(name, root)
|