mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 15:05:19 +00:00
wasm-mutator-fuzz: Generate more kinds of corpus (#3487)
This commit is contained in:
parent
5623e4d22a
commit
67638e24f4
|
@ -58,12 +58,12 @@ endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
||||||
# Enable libc builtin support by default
|
# Enable libc builtin support by default
|
||||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
set (WAMR_BUILD_LIBC_BUILTIN 0)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
||||||
# Enable libc wasi support by default
|
# Enable libc wasi support by default
|
||||||
set (WAMR_BUILD_LIBC_WASI 1)
|
set (WAMR_BUILD_LIBC_WASI 0)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||||
|
@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
|
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
|
||||||
# Disable reference types by default
|
# Enable reference type by default
|
||||||
set (WAMR_BUILD_REF_TYPES 0)
|
set (WAMR_BUILD_REF_TYPES 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
|
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
|
||||||
|
|
|
@ -10,49 +10,59 @@ if [ ! $1 ]; then
|
||||||
echo "Parameter is empty, please enter parameter !"
|
echo "Parameter is empty, please enter parameter !"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
EXPECTED_NUM=$1
|
||||||
|
|
||||||
# 2.check dir
|
# 2.check dir
|
||||||
buildPath="./build"
|
buildPath="./build"
|
||||||
corpusPath="$buildPath/CORPUS_DIR"
|
corpusPath="$buildPath/CORPUS_DIR"
|
||||||
if [[ ! -d "$buildPath" ]]; then
|
rm -rf "${corpusPath}"
|
||||||
echo "auto create the build folder !"
|
mkdir -p "${corpusPath}"
|
||||||
mkdir build
|
|
||||||
else # build Folder exists
|
|
||||||
if [[ -d "$buildPath" ]]; then # CORPUS_DIR exists
|
|
||||||
rm -rf $corpusPath
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 3.change dir
|
# 3.change dir
|
||||||
# cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
|
cd "${corpusPath}"
|
||||||
cd build && mkdir CORPUS_DIR && cd CORPUS_DIR
|
|
||||||
|
|
||||||
# 4.generate *.wasm file
|
# 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++));
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
# try_generate_wasm "--min-memories=1 --min-tables=1" "test_min.wasm"
|
||||||
|
|
||||||
|
for i in $(seq 1 $EXPECTED_NUM)
|
||||||
do
|
do
|
||||||
head -c 100 /dev/urandom | wasm-tools smith -o test_$i.wasm
|
# by default
|
||||||
|
try_generate_wasm "" test_$i.wasm
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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
|
done
|
||||||
|
|
||||||
# 5.check wasm file
|
printf "Done\n"
|
||||||
dir=$(pwd)
|
|
||||||
d=$(find . ! -name "." -type d -prune -o -type f -name "*.wasm" -print)
|
|
||||||
#echo "current dir=$dir"
|
|
||||||
num=0
|
|
||||||
|
|
||||||
for((i=1; i<($@+1); i++));
|
|
||||||
do
|
|
||||||
wasmFile="test_$i.wasm"
|
|
||||||
if [[ ! -f "$wasmFile" ]]; then
|
|
||||||
echo "The file $wasmFile is not exists !"
|
|
||||||
else
|
|
||||||
let "num++"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$@ user requirements, $num actually generated !"
|
|
||||||
|
|
||||||
if [ $num == $@ ]; then echo "Wasm file generated successfully !"
|
|
||||||
else echo "Wasm file generated faild !"
|
|
||||||
fi
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
|
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
|
||||||
# Disable reference types by default
|
# Enable reference type by default
|
||||||
set (WAMR_BUILD_REF_TYPES 0)
|
set (WAMR_BUILD_REF_TYPES 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
|
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user