smith_wasm.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # Larger input seeds tend to generate larger WebAssembly modules. (256KB)
  30. head -c 262144 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME >/dev/null 2>&1
  31. try_i=$((try_i+1))
  32. done
  33. printf -- "-- output ${GENERATED_WASM_NAME} in %d retries\n" $try_i
  34. }
  35. WASM_SHAPE=" --ensure-termination \
  36. --export-everything true \
  37. --fuel 7 \
  38. --generate-custom-sections true \
  39. --min-funcs 10 \
  40. --max-instructions 1024 \
  41. --min-globals 10"
  42. TIERED_A_FEATURE=" --bulk-memory-enabled true \
  43. --extended-const-enabled true \
  44. --memory64-enabled true \
  45. --multi-value-enabled true \
  46. --reference-types-enabled true \
  47. --simd-enabled true \
  48. --tail-call-enabled true \
  49. --threads-enabled true"
  50. for i in $(seq 1 $EXPECTED_NUM)
  51. do
  52. # tiered A wasm files
  53. try_generate_wasm "${WASM_SHAPE} ${TIERED_A_FEATURE}" test_tiered_a_$i.wasm
  54. done
  55. printf "Done\n"