Skip to content

Commit 67638e2

Browse files
authored
wasm-mutator-fuzz: Generate more kinds of corpus (#3487)
1 parent 5623e4d commit 67638e2

3 files changed

Lines changed: 49 additions & 39 deletions

File tree

tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ endif ()
5858

5959
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
6060
# Enable libc builtin support by default
61-
set (WAMR_BUILD_LIBC_BUILTIN 1)
61+
set (WAMR_BUILD_LIBC_BUILTIN 0)
6262
endif ()
6363

6464
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
6565
# Enable libc wasi support by default
66-
set (WAMR_BUILD_LIBC_WASI 1)
66+
set (WAMR_BUILD_LIBC_WASI 0)
6767
endif ()
6868

6969
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
@@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
9292
endif ()
9393

9494
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
95-
# Disable reference types by default
96-
set (WAMR_BUILD_REF_TYPES 0)
95+
# Enable reference type by default
96+
set (WAMR_BUILD_REF_TYPES 1)
9797
endif ()
9898

9999
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)

tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,61 @@
88
# 1.check parameter
99
if [ ! $1 ]; then
1010
echo "Parameter is empty, please enter parameter !"
11-
exit
11+
exit
1212
fi
13+
EXPECTED_NUM=$1
1314

1415
# 2.check dir
1516
buildPath="./build"
1617
corpusPath="$buildPath/CORPUS_DIR"
17-
if [[ ! -d "$buildPath" ]]; then
18-
echo "auto create the build folder !"
19-
mkdir build
20-
else # build Folder exists
21-
if [[ -d "$buildPath" ]]; then # CORPUS_DIR exists
22-
rm -rf $corpusPath
23-
fi
24-
fi
18+
rm -rf "${corpusPath}"
19+
mkdir -p "${corpusPath}"
2520

2621
# 3.change dir
27-
# cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
28-
cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
22+
cd "${corpusPath}"
2923

3024
# 4.generate *.wasm file
31-
echo "Generate $@ files according to user requirements"
25+
echo "Generating $EXPECTED_NUM Wasm files for each kind as required"
3226

33-
for((i=1; i<($@+1); i++));
34-
do
35-
head -c 100 /dev/urandom | wasm-tools smith -o test_$i.wasm
36-
done
27+
# Generate wasm files with different features
28+
# Try on and on until the generated wasm file exists
29+
function try_generate_wasm()
30+
{
31+
SMITH_OPTIONS=$1
32+
GENERATED_WASM_NAME=$2
33+
34+
local try_i=0
35+
until [[ -f $GENERATED_WASM_NAME ]]; do
36+
head -c 100 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME >/dev/null 2>&1
37+
try_i=$((try_i+1))
38+
done
39+
40+
printf -- "-- output ${GENERATED_WASM_NAME} in %d retries\n" $try_i
41+
}
3742

38-
# 5.check wasm file
39-
dir=$(pwd)
40-
d=$(find . ! -name "." -type d -prune -o -type f -name "*.wasm" -print)
41-
#echo "current dir=$dir"
42-
num=0
43+
# try_generate_wasm "--min-memories=1 --min-tables=1" "test_min.wasm"
4344

44-
for((i=1; i<($@+1); i++));
45+
for i in $(seq 1 $EXPECTED_NUM)
4546
do
46-
wasmFile="test_$i.wasm"
47-
if [[ ! -f "$wasmFile" ]]; then
48-
echo "The file $wasmFile is not exists !"
49-
else
50-
let "num++"
51-
fi
52-
done
47+
# by default
48+
try_generate_wasm "" test_$i.wasm
5349

54-
echo "$@ user requirements, $num actually generated !"
50+
# with different features
51+
# mvp
52+
try_generate_wasm "--min-memories=1 --min-tables=1" test_min_$i.wasm
53+
try_generate_wasm "--min-memories=1 --min-tables=1 --bulk-memory-enabled true" test_bulk_$i.wasm
54+
try_generate_wasm "--min-memories=1 --min-tables=1 --reference-types-enabled true" test_ref_$i.wasm
55+
try_generate_wasm "--min-memories=1 --min-tables=1 --multi-value-enabled true" test_multi_$i.wasm
56+
try_generate_wasm "--min-memories=1 --min-tables=1 --simd-enabled true" test_simd_$i.wasm
57+
try_generate_wasm "--min-memories=1 --min-tables=1 --tail-call-enabled true " test_tail_$i.wasm
5558

56-
if [ $num == $@ ]; then echo "Wasm file generated successfully !"
57-
else echo "Wasm file generated faild !"
58-
fi
59+
# enable me when compiling iwasm with those features
60+
#try_generate_wasm "--min-memories=1 --min-tables=1 --threads-enabled true" test_thread_$i.wasm
61+
#try_generate_wasm "--min-memories=1 --min-tables=1 --memory64-enabled true" test_memory64_$i.wasm
62+
#try_generate_wasm "--min-memories=1 --min-tables=1 --exceptions-enabled true" test_exception_$i.wasm
63+
#try_generate_wasm "--min-memories=1 --min-tables=1 --gc-enabled true" test_gc_$i.wasm
64+
# with custom-section
65+
try_generate_wasm "--min-memories=1 --min-tables=1 --generate-custom-sections true" test_custom_$i.wasm
66+
done
67+
68+
printf "Done\n"

tests/fuzz/wasm-mutator-fuzz/workspace/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
9292
endif ()
9393

9494
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
95-
# Disable reference types by default
96-
set (WAMR_BUILD_REF_TYPES 0)
95+
# Enable reference type by default
96+
set (WAMR_BUILD_REF_TYPES 1)
9797
endif ()
9898

9999
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)

0 commit comments

Comments
 (0)