diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/input/hello_world.wat | 11 | ||||
-rw-r--r-- | test/unit/input/random_data.txt | 1 | ||||
-rw-r--r-- | test/unit/test_initial_fuzz.py | 35 |
3 files changed, 47 insertions, 0 deletions
diff --git a/test/unit/input/hello_world.wat b/test/unit/input/hello_world.wat new file mode 100644 index 000000000..680ee809a --- /dev/null +++ b/test/unit/input/hello_world.wat @@ -0,0 +1,11 @@ +(module + (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (memory $0 256 256) + (export "add" (func $add)) + (func $add (param $x i32) (param $y i32) (result i32) + (i32.add + (local.get $x) + (local.get $y) + ) + ) +) diff --git a/test/unit/input/random_data.txt b/test/unit/input/random_data.txt new file mode 100644 index 000000000..d5000bfbd --- /dev/null +++ b/test/unit/input/random_data.txt @@ -0,0 +1 @@ +6sgkjdfghk34589n-947-vn98f2yr-nb8f7t08b7gv*~&!%&^@}{PASD kjgsdf768 diff --git a/test/unit/test_initial_fuzz.py b/test/unit/test_initial_fuzz.py new file mode 100644 index 000000000..2ddc29884 --- /dev/null +++ b/test/unit/test_initial_fuzz.py @@ -0,0 +1,35 @@ +import subprocess +from scripts.test import shared +from . import utils + + +class InitialFuzzTest(utils.BinaryenTestCase): + def test_empty_initial(self): + # generate fuzz from random data + data = self.input_path('random_data.txt') + a = shared.run_process(shared.WASM_OPT + ['-ttf', '--print', data], + stdout=subprocess.PIPE).stdout + + # generate fuzz from random data with initial empty wasm + empty_wasm = self.input_path('empty.wasm') + b = shared.run_process( + shared.WASM_OPT + ['-ttf', '--print', data, + '--initial-fuzz=' + empty_wasm], + stdout=subprocess.PIPE).stdout + + # an empty initial wasm causes no changes + self.assertEqual(a, b) + + def test_small_initial(self): + data = self.input_path('random_data.txt') + hello_wat = self.input_path('hello_world.wat') + out = shared.run_process(shared.WASM_OPT + ['-ttf', '--print', data, + '--initial-fuzz=' + hello_wat], + stdout=subprocess.PIPE).stdout + + # the function should be there (perhaps with modified contents - don't + # check that) + self.assertIn('(export "add" (func $add))', out) + + # there should be other fuzz contents added as well + self.assertGreater(out.count('(export '), 1) |