smith_wasm.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. # 1.check parameter
  7. if [ ! $1 ]; then
  8. echo "Parameter is empty, please enter parameter !"
  9. exit
  10. fi
  11. EXPECTED_NUM=$1
  12. # 2.check dir
  13. buildPath="./build"
  14. corpusPath="$buildPath/CORPUS_DIR"
  15. rm -rf "${corpusPath}"
  16. mkdir -p "${corpusPath}"
  17. # 3.change dir
  18. cd "${corpusPath}"
  19. # 4.generate *.wasm file
  20. echo "Generating $EXPECTED_NUM Wasm files for each kind as required"
  21. # Generate wasm files with different features
  22. # Try on and on until the generated wasm file exists
  23. function try_generate_wasm()
  24. {
  25. SMITH_OPTIONS=$1
  26. GENERATED_WASM_NAME=$2
  27. local try_i=0
  28. until [[ -f $GENERATED_WASM_NAME ]]; do
  29. head -c 100 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME >/dev/null 2>&1
  30. try_i=$((try_i+1))
  31. done
  32. printf -- "-- output ${GENERATED_WASM_NAME} in %d retries\n" $try_i
  33. }
  34. # try_generate_wasm "--min-memories=1 --min-tables=1" "test_min.wasm"
  35. for i in $(seq 1 $EXPECTED_NUM)
  36. do
  37. # by default
  38. try_generate_wasm "" test_$i.wasm
  39. # with different features
  40. # mvp
  41. try_generate_wasm "--min-memories=1 --min-tables=1" test_min_$i.wasm
  42. try_generate_wasm "--min-memories=1 --min-tables=1 --bulk-memory-enabled true" test_bulk_$i.wasm
  43. try_generate_wasm "--min-memories=1 --min-tables=1 --reference-types-enabled true" test_ref_$i.wasm
  44. try_generate_wasm "--min-memories=1 --min-tables=1 --multi-value-enabled true" test_multi_$i.wasm
  45. try_generate_wasm "--min-memories=1 --min-tables=1 --simd-enabled true" test_simd_$i.wasm
  46. try_generate_wasm "--min-memories=1 --min-tables=1 --tail-call-enabled true " test_tail_$i.wasm
  47. # enable me when compiling iwasm with those features
  48. #try_generate_wasm "--min-memories=1 --min-tables=1 --threads-enabled true" test_thread_$i.wasm
  49. #try_generate_wasm "--min-memories=1 --min-tables=1 --memory64-enabled true" test_memory64_$i.wasm
  50. #try_generate_wasm "--min-memories=1 --min-tables=1 --exceptions-enabled true" test_exception_$i.wasm
  51. #try_generate_wasm "--min-memories=1 --min-tables=1 --gc-enabled true" test_gc_$i.wasm
  52. # with custom-section
  53. try_generate_wasm "--min-memories=1 --min-tables=1 --generate-custom-sections true" test_custom_$i.wasm
  54. done
  55. printf "Done\n"