forked from solana-foundation/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-test.sh
More file actions
executable file
·151 lines (133 loc) · 4.84 KB
/
run-test.sh
File metadata and controls
executable file
·151 lines (133 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
################################################################################
#
# A script to run the example as an integration test. It starts up a localnet
# and executes the current directory's rust binary.
#
# Usage:
#
# ./run.sh
#
# Run this script from within the `example/` directory in which it is located.
# The anchor cli must be installed.
#
# cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked
#
################################################################################
set -euox pipefail
main() {
#
# Build programs.
#
local composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
local basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
local basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
local events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
local optional_pid="FNqz6pqLAwvMSds2FYjR4nKV3moVpPNtvkfGFrqLKrgG"
cd ../../tests/composite && anchor build --skip-lint --ignore-keys && cd -
[ $? -ne 0 ] && exit 1
cd ../../examples/tutorial/basic-2 && anchor build --skip-lint --ignore-keys && cd -
[ $? -ne 0 ] && exit 1
cd ../../examples/tutorial/basic-4 && anchor build --skip-lint --ignore-keys && cd -
[ $? -ne 0 ] && exit 1
cd ../../tests/events && anchor build --skip-lint --ignore-keys && cd -
[ $? -ne 0 ] && exit 1
cd ../../tests/optional && anchor build --skip-lint --ignore-keys && cd -
[ $? -ne 0 ] && exit 1
#
# Bootup validator.
#
solana-test-validator -r \
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
> test-validator.log &
test_validator_pid=$!
sleep 5
check_solana_validator_running $test_validator_pid
#
# Run single threaded test.
#
cargo run -- \
--composite-pid $composite_pid \
--basic-2-pid $basic_2_pid \
--basic-4-pid $basic_4_pid \
--events-pid $events_pid \
--optional-pid $optional_pid
#
# Restart validator for multithreaded test
#
cleanup
solana-test-validator -r \
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
> test-validator.log &
test_validator_pid=$!
sleep 5
check_solana_validator_running $test_validator_pid
#
# Run multi threaded test.
#
cargo run -- \
--composite-pid $composite_pid \
--basic-2-pid $basic_2_pid \
--basic-4-pid $basic_4_pid \
--events-pid $events_pid \
--optional-pid $optional_pid \
--multithreaded
#
# Restart validator for async test
#
cleanup
solana-test-validator -r \
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
> test-validator.log &
test_validator_pid=$!
sleep 5
check_solana_validator_running $test_validator_pid
#
# Run async test.
#
cargo run --features async -- \
--composite-pid $composite_pid \
--basic-2-pid $basic_2_pid \
--basic-4-pid $basic_4_pid \
--events-pid $events_pid \
--optional-pid $optional_pid \
--multithreaded
}
cleanup() {
pkill -P $$ || true
wait || true
}
trap_add() {
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
for trap_add_name in "$@"; do
trap -- "$(
extract_trap_cmd() { printf '%s\n' "${3:-}"; }
eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
printf '%s\n' "${trap_add_cmd}"
)" "${trap_add_name}" \
|| fatal "unable to add to trap ${trap_add_name}"
done
}
check_solana_validator_running() {
local pid=$1
exit_state=$(kill -0 "$pid" && echo 'living' || echo 'exited')
if [ "$exit_state" == 'exited' ]; then
echo "Cannot start test validator, see ./test-validator.log"
exit 1
fi
}
declare -f -t trap_add
trap_add 'cleanup' EXIT
main