فهرست منبع

wasm-mutator-fuzz: Generate more kinds of corpus (#3487)

liang.he 1 سال پیش
والد
کامیت
67638e24f4

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

@@ -58,12 +58,12 @@ endif ()
 
 if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
   # Enable libc builtin support by default
-  set (WAMR_BUILD_LIBC_BUILTIN 1)
+  set (WAMR_BUILD_LIBC_BUILTIN 0)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
   # Enable libc wasi support by default
-  set (WAMR_BUILD_LIBC_WASI 1)
+  set (WAMR_BUILD_LIBC_WASI 0)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
@@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_REF_TYPES)
-  # Disable reference types by default
-  set (WAMR_BUILD_REF_TYPES 0)
+  # Enable reference type by default
+  set (WAMR_BUILD_REF_TYPES 1)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)

+ 43 - 33
tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh

@@ -8,51 +8,61 @@
 # 1.check parameter
 if [ ! $1 ]; then
 	echo "Parameter is empty, please enter parameter !"
-    exit 
+    exit
 fi
+EXPECTED_NUM=$1
 
 # 2.check dir
 buildPath="./build"
 corpusPath="$buildPath/CORPUS_DIR"
-if [[ ! -d "$buildPath" ]]; then
-    echo "auto create the build folder !"
-    mkdir build
-else # build Folder exists
-    if [[ -d "$buildPath" ]]; then # CORPUS_DIR exists
-        rm -rf $corpusPath
-    fi
-fi
+rm -rf "${corpusPath}"
+mkdir -p "${corpusPath}"
 
 # 3.change dir
-# cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
-cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
+cd "${corpusPath}"
 
 # 4.generate *.wasm file
-echo "Generate $@ files according to user requirements"
+echo "Generating $EXPECTED_NUM Wasm files for each kind as required"
 
-for((i=1; i<($@+1); i++));
-do
-head -c 100 /dev/urandom | wasm-tools smith -o test_$i.wasm
-done
+# Generate wasm files with different features
+# Try on and on until the generated wasm file exists
+function try_generate_wasm()
+{
+    SMITH_OPTIONS=$1
+    GENERATED_WASM_NAME=$2
+
+    local try_i=0
+    until [[ -f $GENERATED_WASM_NAME ]]; do
+        head -c 100 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME  >/dev/null 2>&1
+        try_i=$((try_i+1))
+    done
+
+    printf -- "-- output ${GENERATED_WASM_NAME} in %d retries\n" $try_i
+}
 
-# 5.check wasm file
-dir=$(pwd)              
-d=$(find . ! -name "." -type d -prune -o -type f -name "*.wasm" -print) 
-#echo "current dir=$dir" 
-num=0
+# try_generate_wasm "--min-memories=1 --min-tables=1" "test_min.wasm"
 
-for((i=1; i<($@+1); i++));
+for i in $(seq 1 $EXPECTED_NUM)
 do
-    wasmFile="test_$i.wasm"
-    if [[ ! -f "$wasmFile" ]]; then
-        echo "The file $wasmFile is not exists !"
-    else
-        let "num++"
-    fi
-done
+    # by default
+    try_generate_wasm "" test_$i.wasm
 
-echo "$@ user requirements, $num actually generated !"
+    # with different features
+    # mvp
+    try_generate_wasm "--min-memories=1 --min-tables=1" test_min_$i.wasm
+    try_generate_wasm "--min-memories=1 --min-tables=1 --bulk-memory-enabled true" test_bulk_$i.wasm
+    try_generate_wasm "--min-memories=1 --min-tables=1 --reference-types-enabled true" test_ref_$i.wasm
+    try_generate_wasm "--min-memories=1 --min-tables=1 --multi-value-enabled true" test_multi_$i.wasm
+    try_generate_wasm "--min-memories=1 --min-tables=1 --simd-enabled true" test_simd_$i.wasm
+    try_generate_wasm "--min-memories=1 --min-tables=1 --tail-call-enabled true " test_tail_$i.wasm
 
-if [ $num == $@ ]; then echo "Wasm file generated successfully !"
-else echo "Wasm file generated faild !"
-fi
+    # enable me when compiling iwasm with those features
+    #try_generate_wasm "--min-memories=1 --min-tables=1 --threads-enabled true" test_thread_$i.wasm
+    #try_generate_wasm "--min-memories=1 --min-tables=1 --memory64-enabled true" test_memory64_$i.wasm
+    #try_generate_wasm "--min-memories=1 --min-tables=1 --exceptions-enabled true" test_exception_$i.wasm
+    #try_generate_wasm "--min-memories=1 --min-tables=1 --gc-enabled true" test_gc_$i.wasm
+    # with custom-section
+    try_generate_wasm "--min-memories=1 --min-tables=1 --generate-custom-sections true" test_custom_$i.wasm
+done
+
+printf "Done\n"

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

@@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_REF_TYPES)
-  # Disable reference types by default
-  set (WAMR_BUILD_REF_TYPES 0)
+  # Enable reference type by default
+  set (WAMR_BUILD_REF_TYPES 1)
 endif ()
 
 if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)