run-test.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. ################################################################################
  3. #
  4. # A script to run the example as an integration test. It starts up a localnet
  5. # and executes the current directory's rust binary.
  6. #
  7. # Usage:
  8. #
  9. # ./run.sh
  10. #
  11. # Run this script from within the `example/` directory in which it is located.
  12. # The anchor cli must be installed.
  13. #
  14. # cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked
  15. #
  16. ################################################################################
  17. set -euox pipefail
  18. main() {
  19. #
  20. # Build programs.
  21. #
  22. local composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
  23. local basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
  24. local basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
  25. local events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
  26. local optional_pid="FNqz6pqLAwvMSds2FYjR4nKV3moVpPNtvkfGFrqLKrgG"
  27. #
  28. # Bootup validator.
  29. #
  30. solana-test-validator -r \
  31. --bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
  32. --bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
  33. --bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
  34. --bpf-program $events_pid ../../tests/events/target/deploy/events.so \
  35. --bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
  36. > test-validator.log &
  37. sleep 5
  38. #
  39. # Run single threaded test.
  40. #
  41. cargo run -- \
  42. --composite-pid $composite_pid \
  43. --basic-2-pid $basic_2_pid \
  44. --basic-4-pid $basic_4_pid \
  45. --events-pid $events_pid \
  46. --optional-pid $optional_pid
  47. #
  48. # Restart validator for multithreaded test
  49. #
  50. cleanup
  51. solana-test-validator -r \
  52. --bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
  53. --bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
  54. --bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
  55. --bpf-program $events_pid ../../tests/events/target/deploy/events.so \
  56. --bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
  57. > test-validator.log &
  58. sleep 5
  59. #
  60. # Run multi threaded test.
  61. #
  62. cargo run -- \
  63. --composite-pid $composite_pid \
  64. --basic-2-pid $basic_2_pid \
  65. --basic-4-pid $basic_4_pid \
  66. --events-pid $events_pid \
  67. --optional-pid $optional_pid \
  68. --multithreaded
  69. }
  70. cleanup() {
  71. pkill -P $$ || true
  72. wait || true
  73. }
  74. trap_add() {
  75. trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
  76. for trap_add_name in "$@"; do
  77. trap -- "$(
  78. extract_trap_cmd() { printf '%s\n' "${3:-}"; }
  79. eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
  80. printf '%s\n' "${trap_add_cmd}"
  81. )" "${trap_add_name}" \
  82. || fatal "unable to add to trap ${trap_add_name}"
  83. done
  84. }
  85. declare -f -t trap_add
  86. trap_add 'cleanup' EXIT
  87. main