|
8 | 8 | # 1.check parameter |
9 | 9 | if [ ! $1 ]; then |
10 | 10 | echo "Parameter is empty, please enter parameter !" |
11 | | - exit |
| 11 | + exit |
12 | 12 | fi |
| 13 | +EXPECTED_NUM=$1 |
13 | 14 |
|
14 | 15 | # 2.check dir |
15 | 16 | buildPath="./build" |
16 | 17 | 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}" |
25 | 20 |
|
26 | 21 | # 3.change dir |
27 | | -# cd build && mkdir CORPUS_DIR && cd CORPUS_DIR |
28 | | -cd build && mkdir CORPUS_DIR && cd CORPUS_DIR |
| 22 | +cd "${corpusPath}" |
29 | 23 |
|
30 | 24 | # 4.generate *.wasm file |
31 | | -echo "Generate $@ files according to user requirements" |
| 25 | +echo "Generating $EXPECTED_NUM Wasm files for each kind as required" |
32 | 26 |
|
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 | +} |
37 | 42 |
|
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" |
43 | 44 |
|
44 | | -for((i=1; i<($@+1); i++)); |
| 45 | +for i in $(seq 1 $EXPECTED_NUM) |
45 | 46 | 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 |
53 | 49 |
|
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 |
55 | 58 |
|
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" |
0 commit comments